var from = escape(document.referrer);
var query = location.search;
var colorDepth = window.screen.colorDepth;
var res = window.screen.width + "," + window.screen.height;
document.write("<img src='statystyka/zlicz.php?referer=" + from + "&query=" + query + "&kolory=" + colorDepth + "&rozdzielczosc=" + res + "' align='middle' style='display:none'>");

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 WyszukiwarkaCzysc()
{
	if(document.wyszukiwarka.fraza.value == "wpisz szukaną frazę")
	{
		document.wyszukiwarka.fraza.value = "";
	}
}

function WyszukiwarkaSprawdz()
{
	if(document.wyszukiwarka.fraza.value == "")
	{
		document.wyszukiwarka.fraza.value = "wpisz szukaną frazę";
	}
}

var okno = null;
function PowiekszZdjecie(url, width, height)
{
	height = height + 4;
	ScrWidth = 640;
	ScrHeight = 480;
	if(window.screen)
  	{
   	ScrWidth = window.screen.width;
		ScrHeight = window.screen.height;
  	}
  	PosX = Math.round((ScrWidth - width) / 2);
  	PosY = Math.round((ScrHeight - height) / 2);
  	okno = window.open("galeria.php?sciezka="+url, "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.focus();
}

function PokazInformacje(url, width, height)
{
	ScrWidth = 640;
	ScrHeight = 480;
	if(window.screen)
  	{
   	ScrWidth = window.screen.width;
		ScrHeight = window.screen.height;
  	}
  	PosX = Math.round((ScrWidth - width) / 2);
  	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_zam(msg, msg2)
{
  	if( jQuery("input[name=\'zam_platnosc_id\']:checked").val() == 7 )
  	{
   		if ( ! jQuery('#eraty_zgoda').is(':checked') )
   		{
   			alert('Zapoznaj się z procedurą udzielenia kredytu ratalnego Raty Żagiel.');
   			return false;
   		}
  	}
	if(document.form_zam.klient_imie.value.length == 0 || document.form_zam.klient_nazwisko.value.length == 0 || document.form_zam.klient_ulica.value.length == 0 || document.form_zam.klient_kod_pocztowy.value.length == 0 || document.form_zam.klient_miasto.value.length == 0 ||  document.form_zam.klient_tel.value.length == 0 || document.form_zam.klient_email.value.length == 0)
  	{
		alert(msg);
		return false;
  	}
  	if(!document.form_zam.regulamin.checked)
  	{
	   	alert(msg2);
		return false;
  	}
  	return true;
}

function sprawdz_form_rej(msg)
{
	if(document.form_rej.klient_login.value.length == 0 || document.form_rej.klient_haslo.value.length == 0 || document.form_rej.klient_haslo_p.value.length == 0 || document.form_rej.klient_imie.value.length == 0 || document.form_rej.klient_nazwisko.value.length == 0 || document.form_rej.klient_ulica.value.length == 0 || document.form_rej.klient_kod_pocztowy.value.length == 0 || document.form_rej.klient_miasto.value.length == 0  || document.form_rej.klient_tel.value.length == 0 || document.form_rej.klient_email.value.length == 0)
  	{
		alert(msg);
		return false;
  	}
  	return true;
}

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 sprawdz_form_negocjuj(msg,msg2)
{
	if(document.negocjuj.imie_i_nazwisko.value.length == 0 || document.negocjuj.nowa_cena.value.length == 0 || document.negocjuj.email.value.length == 0)
  	{
		alert(msg);
		return false;
  	}
  	if(!sprawdzemail(document.negocjuj.email))
  	{
  		alert(msg2);
  		document.negocjuj.email.focus();
		return false;
  	}
  	return true;
}

function sprawdz_form_zapytaj(msg,msg2)
{
	if(document.zapytaj.imie_i_nazwisko.value.length == 0 || document.zapytaj.email.value.length == 0)
  	{
		alert(msg);
		return false;
  	}
  	if(!sprawdzemail(document.zapytaj.email))
  	{
  		alert(msg2);
  		document.zapytaj.email.focus();
		return false;
  	}
  	return true;
}

function sprawdz_form_pomyslyiuwagi(msg,msg2)
{
	if(document.pomyslyiuwagi.imie_i_nazwisko.value.length == 0 || document.pomyslyiuwagi.email.value.length == 0 || document.pomyslyiuwagi.tresc.value.length == 0 || document.pomyslyiuwagi.temat.value.length == 0)
  	{
		alert(msg);
		return false;
  	}
  	if(!sprawdzemail(document.pomyslyiuwagi.email))
  	{
  		alert(msg2);
  		document.pomyslyiuwagi.email.focus();
		return false;
  	}
  	return true;
}

function sprawdz_form_recenzji(msg)
{
	if(document.recenzja.uzytkownik.value.length == 0)
  	{
		alert(msg);
		document.recenzja.uzytkownik.focus();
		return false;
  	}
  	if(document.recenzja.opinia.value.length == 0)
  	{
		alert(msg);
		document.recenzja.opinia.focus();
		return false;
  	}
  	return true;
}

function WyczyscFormRecenzji()
{
	document.recenzja.uzytkownik.value = '';
	document.recenzja.opinia.value = '';
}

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 $(id){return document.getElementById(id);};

function showAvailablity(id)
{
	var img = new Image();
	img.src = "images/b_sprawdz_dostepnosc.gif";
	//alert(img.src);
	//$('bxCheckAvailability').innerHTML = 'podaj adres email: <input type="text" name="chkAemail" id="chkAemail" style="vertical-align:middle;" /> ';
	$('bxCheckAvailability').style.display = '';
	$('bxCheckAvailabilityInput').style.display = 'none';

}

function btnCheckAvailability(email,id)
{

	if(sprawdzemail(email))
	{
		advAJAX.get({
	    url: "include/sendAvailabilityQuery.php",
	    email : email.value,
	    id : id,
	    onSuccess : function(obj) { if(obj.responseText=="1"){$('bxCheckAvailability').innerHTML="Zapytanie o dostępność zostało poprawnie wysłane. <br /> Odpowiedź zostanie przesłana na wskazany adres email po sprawdzeniu stanu magazynowego.";}else{$('bxCheckAvailability').innerHTML ='Błąd podczas próby wysłania zapytania podaj adres email ponownie: <input type="text" name="chkAemail" id="chkAemail" /><input type="button" value="Sprawdź dostępność" onclick="btnCheckAvailability($(\'chkAemail\').value);" />';} },
	    onError : function(obj) { $('bxCheckAvailability').innerHTML ='Błąd podczas próby wysłania zapytania podaj adres email ponownie: <input type="text" name="chkAemail" id="chkAemail" /><input type="button" value="Sprawdź dostępność" onclick="btnCheckAvailability($(\'chkAemail\').value);" />' }
		});
    }
}
