<!-- //

function BullStatistic()
{
	var colorDepth = window.screen.colorDepth;
	var res = window.screen.width + "," + window.screen.height;
	var referer = escape(document.referrer);
	document.write('<img src="/statystyka/zlicz.php?colors=' + colorDepth + '&resolution=' + res + '&referer=' + referer + '" style="width:0;height:0;" />');
}

function EaZyMap()
{
	this.arrMarkers = new Array();
	this.mapaSM = '';
	this.addMarker = function(lat,lon,txt) {
		var marker = new GMarker(new GLatLng(lat,lon),{title: txt});
		marker.txt = txt;
		GEvent.addListener(marker,"click",function() {
			marker.openInfoWindowHtml(marker.txt);
		});
		this.arrMarkers.push(marker);
		this.mapaSM.addOverlay(marker);
		marker.openInfoWindowHtml(marker.txt);
	}
	this.load = function (box_id,centerPointLat,centerPointLng,zoom) {
		this.mapaSM = new GMap2(document.getElementById(box_id));
		if(zoom == 0) zoom = 15;
		this.mapaSM.setCenter(new GLatLng(centerPointLat,centerPointLng),zoom);
		this.mapaSM.addControl(new GLargeMapControl());
		this.mapaSM.addControl(new GOverviewMapControl());
		this.mapaSM.addControl(new GMapTypeControl());
		if(this.arrMarkers.length>0)
		{
			for(var i = 0; i < this.arrMarkers.length; i++)
			{
				this.mapaSM.addOverlay(this.arrMarkers[i]);
			}
		}
		return this.mapaSM;
	}
}

function ShowTab(number)
{
	jQuery(".productContent").css({display:none});
}

function ChangePicture(id,src)
{
	$_(id).src = src;
}

function ChangeSpecialOffer(t,p,f,m)
{
	jQuery('#oferty_specjalne_'+t).html("<div style=\"padding:30px;text-align:center;font-weight:bold;\">Proszę czekać - ładuję listę.</div>");
	jQuery.get("/include/ajx_getSpecialOffer.php", { t: t, p: p, f: f, m: m },
	function(data)
	{
		jQuery('#oferty_specjalne_'+t).html(data);
	}
	);
}

function Rozpoznanie(warstwa)
{
	if(document.all)
	{
		warstwa = document.all(warstwa);
	}
	else if(document.getElementById)
	{
		warstwa = document.getElementById(warstwa);
	}
	else if(document.layers)
	{
		warstwa = document.layers[warstwa];
	}
	return warstwa;
}

function PokazUkryj(id)
{
	var Obiekt = Rozpoznanie(id);
	if(Obiekt.style.display == "none") Obiekt.style.display = "block";
	else Obiekt.style.display = "none";
}

function ZmienKategorie2( katID )
{
	var ZaznaczonaKategoria = katID;
	var ProducenciSelect = document.forms['grupy2'].elements['proID_grupuj'];

	ProducenciSelect.options.length = 1;
	i = 1;
	for( aPk in producenci )
	{
		for( aPkId in producenci[aPk] )
		{
			if( aPk == ZaznaczonaKategoria )
			{
				ProducenciSelect.options.length++;
				ProducenciSelect.options[i].text = producenci[aPk][aPkId];
				ProducenciSelect.options[i].value = aPkId;
				i++;
			}
		}
	}
}

function kontrola_ilosci(pole,msg)
{
	WzorN = /^[0-9]{1,4}$_/;
	if(!WzorN.test(pole.value))
	{
		window.alert(msg);
		pole.focus();
		return false;
	}
	return true;
}

function PowiekszZdjecie(width, height, url)
{
	var okno = null;
	var ScrWidth = 640;
	var ScrHeight = 480;
	if(window.screen)
	{
		ScrWidth = window.screen.width;
		ScrHeight = window.screen.height;
	}
	var PosX = Math.round((ScrWidth - width) / 2);
	var PosY = Math.round((ScrHeight - height) / 2);
	width = width;
	height = height;
	okno = window.open("", "zdjecie", "menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,copyhistory=no,width=" + width + ",height=" + height + ",left=" + PosX + ",top=" + PosY);
	okno.document.clear();
	okno.document.write("<html><head><title>Mizar.pl</title><meta http-equiv='content-type' content='text/html; charset=ISO-8859-2'></head><style type=\"text/css\">body { margin:0; padding:0; }</style><body><div align=\"center\"><img src=\""+ url +"\" alt=\"Kliknij aby zamknąć to okno\" title=\"Kliknij aby zamknąć to okno\" border=\"0\" onclick=\"window.close();\" /></div></body></html>");
	okno.document.close();
	okno.focus();
}
function PokazZdjeciaProduktu(id,zdj)
{
	var okno = null;
	if(okno) okno.close();
	var ScrWidth = 640;
	var ScrHeight = 480;
	var width = 1000;
	var height = 700;
	if(window.screen)
	{
		ScrWidth = window.screen.width;
		ScrHeight = window.screen.height;
	}
	PosX = Math.round((ScrWidth - width) / 2);
	PosY = Math.round((ScrHeight - height) / 2);
	width = width;
	height = height;
	okno = window.open("/pokaz_zdjecia.php?id="+id+"&zdj="+zdj, "zdjecie", "menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=no,copyhistory=no,width=" + width + ",height=" + height + ",left=" + PosX + ",top=" + PosY);
	okno.focus();
}
function PokazInformacje(url, width, height)
{
	var okno = null;
	var ScrWidth = 640;
	var ScrHeight = 480;
	if(window.screen)
	{
		ScrWidth = window.screen.width;
		ScrHeight = window.screen.height;
	}
	var PosX = Math.round((ScrWidth - width) / 2);
	var PosY = Math.round((ScrHeight - height) / 2);
	okno = window.open(url, "oknododatkowe", "menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=no,copyhistory=no,width=" + width + ",height=" + height + ",left=" + PosX + ",top=" + PosY);
	okno.focus();
}

function sprawdz_form_kontaktu(msg,msg2)
{
	if(document.konakt.imie_i_nazwisko.value.length == 0 || document.konakt.email.value.length == 0 || document.konakt.tresc.value.length == 0)
	{
		alert(msg);
		return false;
	}
	if(!sprawdzemail(document.konakt.email))
	{
		alert(msg2);
		document.konakt.email.focus();
		return false;
	}
	return true;
}

function sprawdzemail(adres)
{
	a = adres.value.search(/@/i);
	a1 = adres.value.substring(0,a);
	a2 = a1.length;
	a = a + 1;
	b = adres.value.indexOf(".");
	b1 = adres.value.substring(a,b);
	b2 = b1.length;
	b = b + 1;
	c = adres.value.length;
	c1 = adres.value.substring(b,c);
	c2 = c1.length;
	if(adres.value.indexOf("@") != "-1" && adres.value.indexOf(".") != "-1" && a2 >= 1 && b2 >= 1 && c2 >= 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function PokazMape(width, height, url)
{
	var okno = null;
	if(okno) okno.close();
	var ScrWidth = 640;
	var ScrHeight = 480;
	if(window.screen)
	{
		ScrWidth = window.screen.width;
		ScrHeight = window.screen.height;
	}
	var PosX = Math.round((ScrWidth - width) / 2);
	var PosY = Math.round((ScrHeight - height) / 2);
	okno = window.open("/popup/mapa.php?sciezka="+url, "mapa", "menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,copyhistory=no,width=" + width + ",height=" + height + ",left=" + PosX + ",top=" + PosY);
	okno.focus();
}
function $_(id){return document.getElementById(id);}

function zaloguj(login,pass)
{
			$("#loginErr").text("poszę czekać ...");
			$.get("/include/ajax_logowanie.php",{e:login, p:pass},
				function(ret) {
					if(ret=="true")
					{
						window.location='/index.php?akcja=aktualizacja_koszyka';
					}else
					{
						$("#loginErr").text("Błędny adres email lub hasło");
					}
				}
			);
}
function przypomnij_haslo(email)
{
	$("#rememberPassErr").text("poszę czekać ...");
	$.get("/include/ajax_przypomnienie_hasla.php",{e:email},
				function(ret) {
					if(ret=="true")
					{
						$('#rememberPassErr').parent().html('Na wskazany adres email została wysłana wiadomość z linkiem akceptacyjnym');
						$('#rememberPass').parent().find("button").hide();
					}else
					{
						$('#rememberPassErr').text('Nie odnaleziono podanego konta');
					}
				}
		);
}


function getSearchPrices(catId)
{
	if(catId>0)
	{
		$('#searchPrices').fadeTo(200,0.2);
		$.getJSON("/include/ajx_getCategoryPrices.php",{category_id:catId},function(data){
			if(data.length==4)
			{

				var html = '<div class="searchPosition"><a href="">poniżej '+data[0]+' zł</a></div>';
				html += '<div class="searchPosition"><a href="">od '+data[0]+' do '+data[1]+' zł</a></div>';
				html += '<div class="searchPosition"><a href="">od '+data[1]+' do '+data[2]+' zł</a></div>';
				html += '<div class="searchPosition"><a href="">od '+data[2]+' do '+data[3]+' zł</a></div>';
				html += '<div class="searchPosition"><a href="">powyżej '+data[3]+' zł</a></div>';
				$('#searchPrices').html(html);
			}
			$('#searchPrices').fadeTo(200,1);
		});
	}
}

var params='';
function setFilter(box_id,sep,url)
{
	var arrValues = [];

	params = params.split(',');
	if(box_id!="searchPricesBox")
	{
		params = jQuery.grep(params, function(a){
			var tmp = a.split(' ');
			return (tmp[0]!=sep);
		});
		params = params.join(',');

		var checked = $('#'+box_id).find('input:checked');
		for(var i=0;i<checked.length;i++)
		{
			arrValues.push(checked[i].value);
		}

		if(arrValues.length>0)
		{
			params+=','+sep+'+'+arrValues.join('-');
		}
	}else
	{

		params = jQuery.grep(params, function(a){
			var tmp = a.split(' ');
			return (tmp[0]!='c1' && tmp[0]!='c2');
		});
		params = params.join(',');

		var c1 = $('#c1').val();
		var c2 = $('#c2').val();
		c1 = parseInt(c1.replace(/\,/g,'.'));
		c2 = parseInt(c2.replace(/\,/g,'.'));
		if(c1)
		params+=',c1+'+c1;
		if(c2)
		params+=',c2+'+c2;
	}
	document.location = url+';'+params.replace(/ /g,'+');
}
function setAllFilter(url)
{
	var arrValues = [];
	params='';

		var c1 = $('#c1').val();
		var c2 = $('#c2').val();
		c1 = parseInt(c1.replace(/\,/g,'.'));
		c2 = parseInt(c2.replace(/\,/g,'.'));
		if(c1)
		params+=',c1+'+c1;
		if(c2)
		params+=',c2+'+c2;


		var checked = $('#searchParams').find('input:checked');


		for(var i=0;i<checked.length;i++)
		{
			sep = $(checked[i]).attr('alt');
			if(arrValues[sep]==undefined)  arrValues[sep] = new Array();
			arrValues[sep].push(checked[i].value);
		}


			for (var sep in arrValues)
			{
				params+=','+sep+'+'+arrValues[sep].join('-');
			}

	document.location = url+';'+params.replace(/ /g,'+');
}

function chkToCompare(obj)
{
	var chk = (obj.checked?true:false);
	$.get("/include/ajx_setProductsToCompare.php",{t:obj.value,checked:chk});
}
$().ready(function(){
$("#logInForm").dialog({
			bgiframe: true,
			autoOpen: false,
			resizable: false,
			height: 250,

			buttons: {
				'Zaloguj': function()
					{
						zaloguj($('#login').val(),$('#password').val());
					},

				'Anuluj': function() {
					$(this).dialog('close');
					}
				}

			});


$("#rememberPass").dialog({
			bgiframe: true,
			autoOpen: false,
			resizable: false,
			height: 160,

			buttons: {
				'Przypomnij': function()
					{
						przypomnij_haslo($('#loginRememberPass').val());
					},

				'Anuluj': function() {
					$(this).dialog('close');
					}
				}

			});


			$("#producersInCategory, #categoriesInCategory, #productsSeries" ).children(".header" ).toggle(function(){$(this).parent().children('.hiddenList').slideDown(400)},function(){$(this).parent().children('.hiddenList').slideUp(400)});
			$("#inpNewsletter").click(function (){this.value=(this.value=='podaj adres e-mail'?'':this.value)});
			$("#inpNewsletter").blur(function (){this.value=(this.value==''?'podaj adres e-mail':this.value)});
			$("#btnNewsletter").click(function (){$.get('/include/ajax_newsletter.php',{e:$('#inpNewsletter').val()},	function(dane){if(dane=="true"){	alert('ok');	}else{	alert('err');	}});});

				}
);

function Newsletter(lang,newsletter_action,msg1,msg2,msg3,msg4,msg5)
{


	if(!CheckValidEmail(jQuery('#newsletter_email').val()))
	{
		jQuery('#newsletter_info').html(msg1);
		jQuery('#newsletter_email').focus();
	}
	else
	{
		jQuery('#newsletter_info').html(msg2);
		jQuery.get("ajax/newsletter.php?lang="+lang, { e: jQuery('#newsletter_email').val(), a: newsletter_action },
		function(data)
		{
			if(data == "true") jQuery('#newsletter_all').html(msg3);
			else if(data == "exists" || data == "notexists") jQuery('#newsletter_all').html(msg5);
			else jQuery('#newsletter_all').html(msg4);
  		}

		);
	}
}

// -->
