mkPopup=function(mypage,myname,w,h,scroll){
 var winl=(screen.width-w)/2;
 var wint=(screen.height-h)/2;
 var settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no';
 win=window.open(mypage,myname,settings);
}
resBody=function(o){
	return true;
	var w=o.width;
	var h=o.height;
	if (w>0&&h>0) {
		var resWidth = w + 0;
		var resHeight = h + 40;
		var ua = navigator.userAgent.toLowerCase();
		var isOp=(ua.indexOf("opera")!=-1?true:false);
		var isIe=(ua.indexOf("msie")!=-1&&!isOp?true:false);
		if (isIe) {
			resWidth = w + 35;
			resHeight = h + 65;
		}
	
		if (window.screen.width < resWidth)resWidth=window.screen.width-20;
		if (window.screen.height < resHeight)resHeight=window.screen.height-20;
		
		window.resizeTo(resWidth, resHeight);
		
		var wx=(screen.width-w)/2, wy=(screen.height-h)/2;
 		window.moveTo(wx,wy);
		//self.focus();
	}
}
function preloadImg(src) {
	new Image().src=src;
}

function gourl(u)
{
	document.location.replace(u);
	return false;
}

function cart()
{
	this.addProduct = function(prodId, sizeObj)
	{
		//alert('Obsługa dodania do koszyka produktu o ident. '+prodId)
		var _size = '';
		if (sizeObj)
		{
			if (sizeObj.selectedIndex==0)
			{
				alert('Wybierz rozmiar.');
				return false;
			}
			else
			{
				var _sizeId = sizeObj.getValue()
				_size = _sizeId;
			}
		}
		document.location.replace(SERVOFFSET+'/koszyk.html?a=prod_add&p='+prodId+'&s='+_size);
	}
}

function chmimg(imgid) {
	if (imgs[imgid]) {
		$('prod_mimg').src = imgs[imgid].D;
		$('prod_mimg').parentNode.href=imgs[imgid].D;
		new Image().src=imgs[imgid].D;
	}
}

cart = new cart();
function checkOrderFrm(fobj)
{
	var paytype_checked = false;
	for(var i=0; i<fobj.paytype.length; i++)
	{
		if (fobj.paytype[i].checked)
		{
			paytype_checked = true;
			throw $break;
		}
	}
	if (!paytype_checked)
	{
		alert('Wybierz sposób płatności.');
		return false;
	}
}

/* newsletter */
function newsletter_change(obj){input_change(obj,'Wpisz swój adres e-mail')}
function input_change(obj,txt){if(obj.value==txt)obj.value=''};
function class_change(obj,cls){obj.className=cls};
var newsletter = {
	optin: function(o) {
		if (typeof o == 'undefined') {
			o = '';
		}
		var err=false;
		var eObj = $('#newsletter_email'+o)[0];
		if (eObj.value==null||eObj.value==''||eObj.value=='Wpisz adres e-mail'||!isEmail(eObj.value))
		{
			err=true;
			console.log(eObj.value);
			alert('Wpisz poprawny adres e-mail.');
			eObj.focus();
			return false;
		}
		
		advAJAX.get({
			url: SERVOFFSET+"/index.php?m=newsletter&a=addemail&email="+eObj.value,
			onLoading : function(obj){ /* Wy?wietlenie obrazka wskazuj?cego na ?adowanie */ },
			onComplete : function(obj) { /* Ukrycie obrazka... */ },
			onSuccess : function(obj) {
				eval('ret = obj.responseText');
				if (ret == '-1') {
					alert('Podany adres email już został dopisany do naszej bazy.');
					eObj.value='';
					eObj.focus();
				} else if (ret == '1') {
					alert('Dziękujemy. Twój email został dopisany do naszego newslettera.');
					eObj.value='';
				} else {
					alert('Wpisz poprawny adres e-mail.');
				}
			}
		})
		return false;
	},
	optout: function(o) {
		if (typeof o == 'undefined') {
			o = '';
		}
		var err=false;
		var eObj = $('newsletter_email'+o);
		if (eObj.value==null||eObj.value==''||eObj.value=='Wpisz adres e-mail'||!isEmail(eObj.value))
		{
			err=true;
			alert('Wpisz poprawny adres e-mail.');
			eObj.focus();
			return false;
		}
		
		advAJAX.get({
			url: SERVOFFSET+"/index.php?m=newsletter&a=rememail&email="+eObj.value,
			onLoading : function(obj){ /* Wy?wietlenie obrazka wskazuj?cego na ?adowanie */ },
			onComplete : function(obj) { /* Ukrycie obrazka... */ },
			onSuccess : function(obj) {
				eval('ret = obj.responseText');
				if (ret == '1') {
					alert('Twój email został usunięty z naszego newslettera.');
					eObj.value='';
				} else {
					alert('Wpisz poprawny adres e-mail.');
					eObj.value='';
					eObj.focus();
				}
			}
		})
		return false;
	}
}

function search_change(obj){input_change(obj,'szukaj...')}

/** email validation stuff. Based on: SmartWebby.com (http://www.smartwebby.com/dhtml/) */
isEmail=function(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if (str.indexOf(" ")!=-1){
		return false
	}

	return true					
}

function checkHeight(d) {
	if (!d) return false;
	var divHeight=0;
	//d=$(arguments[0]);
	if(d.offsetHeight)
		divHeight=d.offsetHeight;
	else if(d.style.pixelHeight)
		divHeight=d.style.pixelHeight;
	return divHeight;
}
function max(a,b) {return (a>b)?a:b}
function bim(){try{window.event.returnValue=false}catch(e){};return false}

function addToFavorite()
{
	try {
		if ((navigator.userAgent.toLowerCase().indexOf('msie') > 0) && window.external) {
			window.external.AddFavorite(document.location, document.title);
		}
		else if (window.sidebar) {
			window.sidebar.addPanel(document.title,document.location,"");
		}
	} catch(e) {
		alert('Jeżeli chcesz dodać tę stronę do ulubionych, naciśnij OK a następnie CTRL+D');
	}
	return false;
}

function popover_colors(prod)
{
	try{
		var bW = document.body.getWidth(), bH = document.body.getHeight();
	}
	catch(e)
	{
		var bW = document.body.scrollWidth, bH = document.body.scrollHeight;
	}
	if (!$('shadow'))
	{
		var div = document.createElement('div');
		div.className = 'popover-shadow';
		div.style.width = bW+'px';
		div.style.height = bH+'px';
		div.id = 'shadow';
		document.body.insertBefore(div, document.body.childNodes[0]);
	}
	else
	{
		$('shadow').style.display = 'block';
	}
	$('shadow').onclick = popover_close;
	
	var div = document.createElement('div');
	div.className = 'popover-window';
	div.style.left = ((bW-750)/2)+'px';
	div.style.top = (40+(document.documentElement||document.body).scrollTop)+'px';
	div.id = 'popover_window';
	document.body.insertBefore(div, $('shadow').nextSibling);
	$('popover_window').innerHTML = '<p class="loading">Trwa ładowanie...<br /><img src="'+SERVOFFSET+'/i/loading.gif" width="220" height="19"/></p><div class="btn-close"><img src="../i/lightbox/closelabel.gif" class="link" onclick="javascript:popover_close()"/></div>';
	
	advAJAX.get({
		url: SERVOFFSET+"/ajax.php?m=okladziny&a=getProdLinks&p="+prod,
		onLoading : function(obj){ /* Wy?wietlenie obrazka wskazuj?cego na ?adowanie */ },
		onComplete : function(obj) { /* Ukrycie obrazka... */ },
		onSuccess : function(obj) {
			var ret = eval('(' + obj.responseText + ')');
			if (ret.length)
			{
				$('popover_window').innerHTML = '';
				ret.each(function(e){
					var _d = document.createElement('div');
					var r = '<h2><strong>cena: <span>'+(1*e.c)+' zł</span></strong>'+e.k+'</h2>';
					r += '<p>';
					if (e.o.length)
					{
						r += 'Opis... <span class="link" onclick="javascript:alert(\''+e.o+'\')">&raquo;</span>';
					}
					else
					{
						r += '&nbsp;';
					}
					r += '</p>';
					_d.innerHTML = r;
					var _ul = document.createElement('ul');
					e.l.each(function(ee){
						var _li = document.createElement('li');
						_li.className = 'link';
						_li.onclick = function(){
							$('prod_kolor').innerHTML = '<img src="'+SERVOFFSET+'/i/cms/'+ee.z+'" width="30" height="30"/>';
							$('prod_cena_box').innerHTML = 1*e.c + ' PLN';
							$('prod_cena_value').value = 1*e.c;
							$('prod_okl').value = ee.i;
							popover_close();
						};
						_li.innerHTML = '<img src="'+SERVOFFSET+'/i/cms/'+ee.z+'" width="70" height="70"/><br/>'+ee.o;
						_ul.appendChild(_li);
					})
					_d.appendChild(_ul);
					
					var _c = document.createElement('div');
					_c.className = 'okl-kat';
					_c.appendChild(_d);
					
					$('popover_window').appendChild(_c);
				})
				var _d = document.createElement('div');
				_d.innerHTML = '<br/>&nbsp;';
				$('popover_window').appendChild(_d);
				_d = document.createElement('div');
				_d.setAttribute('class', 'btn-close');
				_d.innerHTML = '<img src="../i/lightbox/closelabel.gif" class="link" onclick="javascript:popover_close()"/>';
				$('popover_window').appendChild(_d);
				
				var bH = (document.documentElement||document.body).scrollHeight;
				$('shadow').style.height = bH+'px';
			}
		}
	})
}

function popover_close()
{
	if ($('popover_window'))
	{
		$('popover_window').remove();
	}
	if($('shadow'))
	{
		$('shadow').style.display = 'none';
	}
}

tabs = {
	panels: ['details', 'comments', 'add_comment'],
	switchmode: true,
	clkfunction: '',
	return_value: false,
	ch: function(obj)
	{
		if ($('#tabs_'+obj).className=='a' && $('#tab_'+obj).style.display=='block')
		{
			return false;
		}
		
		//Zamknięcie pozostałych zakładek
		$.each(tabs.panels, function(i,p){
			if ($('#tabs_'+p) && $('#tab_'+p))
			{
				$('#tabs_'+p).removeClass('a');
				if (tabs.switchmode) {
					$('#tab_'+p).hide();
				}
			}
		});
		$.each(tabs.panels, function(i,p){
			if (p==obj)
			{
				$('#tabs_'+p).addClass('a');
				if (tabs.switchmode) {
					$('#tab_'+p).show();
				}
			}
		})
		
		if (tabs.clkfunction!='') {
			eval(tabs.clkfunction+'(\''+obj+'\')');
		}
		
		return tabs.return_value;
	}
}

// Creates a marker at the given point with the given number label
gMaps = {
	accom_tpl: function(t,i,tx,tp,ds,im,s) {
		var h = '<div class="gmap-wnd"><div><img src="'+im+'"/><h2>'+t+'</h2><p>'+tx+' <a href="'+SERVOFFSET+'/Accomodation/'+t+','+i+'.html">more&nbsp;&raquo;</a></p></div><p><strong>ACCOMODATION:</strong> '+tp+' / <strong>District:</strong> '+ds+'</p></div>';
		return h;
	},
	rest_tpl: function(t,i,tx,tp,ds,im) {
		var h = '<div class="gmap-wnd"><div><img src="'+im+'"/><h2>'+t+'</h2><p>'+tx+' <a href="'+SERVOFFSET+'/Restaurants/'+t+','+i+'.html">more&nbsp;&raquo;</a></p></div><p><strong>RESTAURANT:</strong> '+tp+' / <strong>District:</strong> '+ds+'</p></div>';
		return h;
	},
	nlife_tpl: function(t,i,tx,tp,ds,im) {
		var h = '<div class="gmap-wnd"><div><img src="'+im+'"/><h2>'+t+'</h2><p>'+tx+' <a href="'+SERVOFFSET+'/Nightlife/'+t+','+i+'.html">more&nbsp;&raquo;</a></p></div><p><strong>NIGHTLIFE:</strong> '+tp+' / <strong>District:</strong> '+ds+'</p></div>';
		return h;
	},
	shop_tpl: function(t,i,tx,tp,ds,im) {
		var h = '<div class="gmap-wnd"><div><img src="'+im+'"/><h2>'+t+'</h2><p>'+tx+' <a href="'+SERVOFFSET+'/Shopping/'+t+','+i+'.html">more&nbsp;&raquo;</a></p></div><p><strong>SHOPPING:</strong> '+tp+' / <strong>District:</strong> '+ds+'</p></div>';
		return h;
	},
	thingstodo_tpl: function(t,i,tx,tp,ds,im) {
		var h = '<div class="gmap-wnd"><div><img src="'+im+'"/><h2>'+t+'</h2><p>'+tx+' <a href="'+SERVOFFSET+'/Things to do/'+t+','+i+'.html">more&nbsp;&raquo;</a></p></div><p><strong>THINGS TO DO:</strong> '+tp+' / <strong>District:</strong> '+ds+'</p></div>';
		return h;
	},
	tourattr_tpl: function(t,i,tx,tp,ds,im) {
		var h = '<div class="gmap-wnd"><div><img src="'+im+'"/><h2>'+t+'</h2><p>'+tx+' <a href="'+SERVOFFSET+'/Tourist attractions/'+t+','+i+'.html">more&nbsp;&raquo;</a></p></div><p><strong>TOURIST ATTRACTIONS:</strong> '+tp+' / <strong>District:</strong> '+ds+'</p></div>';
		return h;
	},
	taxi_tpl: function(t,tx,tp) {
		var h = '<div class="gmap-wnd"><div>'+(t!=''?('<h2>'+t+'</h2>'):'')+'<p>'+tx+'</p></div><p><strong>TAXI point:</strong> '+tp+'</p></div>';
		return h;
	},
	buses_tpl: function(t,tx,tp,f) {
		var h = '<div class="gmap-wnd"><div>'+(t!=''?('<h2>'+t+'</h2>'):'')+'<p>'+tx+'</p></div>'+(f=='T'?'<p>Additional info: <strong>Night stop.</strong></p>':'')+'</div>';
		return h;
	},
	trams_tpl: function(t,tx,tp,f) {
		var h = '<div class="gmap-wnd"><div>'+(t!=''?('<h2>'+t+'</h2>'):'')+'<p>'+tx+'</p></div>'+(f=='T'?'<p>Additional info: <strong>Night stop.</strong></p>':'')+'</div>';
		return h;
	}
}
function gMapCreateMarkerWnd(point, c, index) {
	var markerParams = {};
	if (typeof index != 'undefined') {
		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		var index = 1;
		// Create a lettered icon for this point using our icon class
		var letter = String.fromCharCode("A".charCodeAt(0) + index - 1);
		var letteredIcon = new GIcon(baseIcon);
		letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	   markerParams.icon = letteredIcon;
	}
	var marker = new GMarker(point, markerParams);
   GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(c);
   });
   return marker;
}
function gMapCreateMarker(point) {
   var marker = new GMarker(point);
   return marker;
} 
function checkFltrAny(o) {
	if (this.checked) {
		$.each($('input[type=checkbox][value'+(-1==this.value?'!':'')+'=-1]', $(this).parents().parents()[0]), function(e,i){i.checked=false});
	}
}

function fsubmitg(f) {
	var n,m={};
	$.each($('input', $('#'+f)), function(e,i){
		if (i.type=='checkbox'&&i.checked){
			n=i.name.substring(0,i.name.length-2)
			if (typeof m[n] == 'undefined')m[n]=[];
			m[n].push(i.value);
			$.each(m, function(e,i){
				if ($('#f'+f+' input[name='+e+']'))
					$('#f'+f+' input[name='+e+']')[0].value=i.join(',');
			})
		}
	})
	$('#f'+f).submit();
}
