ns4 = (document.layers)? true:false;
ie4 = (document.all) && !(document.getElementById)? true:false;
ie5 = (document.getElementById) && (document.all)? true:false;
ns6 = (document.getElementById) && !(document.all)? true:false;


var Formularz = {
	
	EmailFocus : function (obj) {
		if (obj.value=='tutaj wpisz swój adres e-mail') {
			obj.value='';
			obj.style.color='#000000';
		}
	},

	EmailBlur : function (obj) {
		if (obj.value=='') {
			obj.value='tutaj wpisz swój adres e-mail';
			obj.style.color='#aaaaaa';
		}
	},

	DrukujRegulamin : function () {
		
		var szer = 650;
		var wys = 600;

		wys = parseInt(wys,10)+10;
		szer = parseInt(szer,10)+10;		
		var newTop = (screen.height/2)-(wys/2);
		
		var newLeft = (screen.width/2)-(szer/2);

		var TrescRegulaminu = document.getElementById('TrescRegulamin').innerHTML;

		var okno=window.open("","","menubar=no,resizable=yes,toolbar=no,location=no,scrollbars=yes,left="+newLeft+",top="+newTop+",height=1,width=1"); 			
		var tekst="<body style='cursor:hand;cursor:pointer;margin:0px;' onLoad='window.print();'><div style='width:90%;'>"+TrescRegulaminu+"</div></body>";
		var header='<head><link rel=stylesheet href="style.css" type ="text/css"><title>Ośrodek Usług Technicznych MEZAR Sp. z o.o.</title></head>';
		okno.document.open();
		okno.document.write("<HTML>"+header+tekst+"</HTML>");
		okno.resizeTo(szer,wys);			
		okno.document.close();	
		
		if(ie5) {
			roznicaH = wys - okno.document.body.clientHeight;
			roznicaW = szer - okno.document.body.clientWidth;
		}
		else {
			roznicaH = wys - okno.window.innerHeight;
			roznicaW = szer - okno.window.innerWidth;
		}

		if(roznicaH<0) roznicaH=0;
		if(roznicaW<0) roznicaW=0;
		
		
		okno.resizeTo(szer+roznicaW,wys+roznicaH);
	},
	
	InfoSzukanie : function (obj,napis,opcja) {
		
		if (obj.value==napis && opcja==1) obj.value='';
		if (obj.value=='' && opcja==2) obj.value=napis;
	},

	TestFraza : function (id) {
		obj = document.getElementById(id);
		
		if(obj.value.length<3) {
			alert('Szukana fraza musi zawierać przynajmniej 3 znaki');
			return false;
		}
		else obj.form.submit();		
	},
	

	FormaPotwierdzenia : function(opcja) {		

		if(opcja==1) document.getElementById('zadaniepotwierdzenie').value='drukuj potwierdzenie';		
		else if(opcja==2) document.getElementById('zadaniepotwierdzenie').value='wyślij potwierdzenie';
		
	},

	PotwierdzZamowienie : function(obj) {
		if(document.getElementById('co1').checked) {
			obj.form.submit();
		}
		else if(document.getElementById('co2').checked) {
			if(this.TestEmail(document.getElementById('adresemailsend').value)) {
				obj.form.submit();			
			}
			else alert("Podany adres email jest niepoprawny.");
		}
	},

	TestEmail : function(adres) {			
		var re=/^[0-9a-z\._-]+@[0-9a-z\._-]+\.[a-z]{2,4}$/i;	
		if(re.test(adres)) return true;	
		else return false;
	},


	Potwierdzenie : function(wys,szer,akcja) {
		
		wys = parseInt(wys,10)+10;
		szer = parseInt(szer,10)+10;		
		newTop = (screen.height/2)-(wys/2);
		
		newLeft = (screen.width/2)-(szer/2);
		okno=window.open("potwierdz.php?akcja=","","menubar=no,resizable=yes,toolbar=no,location=no,scrollbars=auto,left="+newLeft+",top="+newTop+",height=1,width=1"); 			
		
		okno.resizeTo(szer,wys);							
		
		if(ie5) {
			roznicaH = wys - okno.document.body.clientHeight;
			roznicaW = szer - okno.document.body.clientWidth;
		}
		else {
			roznicaH = wys - okno.window.innerHeight;
			roznicaW = szer - okno.window.innerWidth;
		}
		
		if(roznicaH<0) roznicaH=0;
		if(roznicaW<0) roznicaW=0;		
		
		okno.resizeTo(szer+roznicaW,wys+roznicaH);		
		
	},


	
	Zamowienie : function(obj) {
		
		error=0;

		
		if(this.OID('NazwaF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Nazwa firmy lub imię i nazwisko musi zostać uzupełnione");
			error=1;
			return;
		}
		if(this.OID('UlicaF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Ulica musi zostać uzupełnione");
			error=1;
			return;
		}		
		if(this.OID('NrDomF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Nr domu musi zostać uzupełnione");
			error=1;
			return;
		}		
		
		if(this.OID('MiastoF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Miasto musi zostać uzupełnione");
			error=1;
			return;
		}
		
		if(this.OID('KodF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Kod pocztowy musi zostać uzupełnione");
			error=1;
			return;
		}
				
		if(this.OID('NazwaW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Nazwa firmy lub imię i nazwisko musi zostać uzupełnione");
			error=1;
			return;
		}
		
		if(this.OID('UlicaW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Ulica musi zostać uzupełnione");
			error=1;
			return;
		}
		
		if(this.OID('NrDomW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Nr domu musi zostać uzupełnione");
			error=1;
			return;
		}		

		if(this.OID('MiastoW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Miasto musi zostać uzupełnione");
			error=1;
			return;
		}

		if(this.OID('KodW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Kod pocztowy musi zostać uzupełnione");
			error=1;
			return;
		}

		if(this.OID('NazwaK').value.length==0) {
			alert("OSOBA DO KONTAKTU: \n - pole Nazwisko i imię osoby składającej zamówienie musi zostać uzupełnione");
			error=1;
			return;
		}

		if(this.OID('EmailK').value.length==0) {
			alert("OSOBA DO KONTAKTU: \n - pole E-mail kontaktowy musi zostać uzupełnione");
			error=1;
			return;
		}
		
		
		if(this.OID('TelefonK').value.length==0) {
			alert("OSOBA DO KONTAKTU: \n - pole Telefon kontaktowy musi zostać uzupełnione");
			error=1;
			return;
		}
		
		
		if(!this.OID('Platnosc1').checked && !this.OID('Platnosc2').checked) {
			alert("SPOSÓB UREGULOWANIA PŁATNOŚCI: \n - Musisz wybrać formę płatności");
			error=1;
			return;
		}
		
		if(this.OID('Platnosc2').checked && this.OID('PrzedplataData').value.length==0) {
			alert("SPOSÓB UREGULOWANIA PŁATNOŚCI: \n - Musisz podać termin dokonania przedpłaty");
			error=1;
			return;
		}
		
		if(!this.OID('RegulaminOk').checked) {
			alert("INFORMACJE DODATKOWE: \n - Musisz zaakceptować regulamin");
			error=1;
			return;
		}	
		
		/*
		if(!this.OID('PrzetwarzanieOk').checked) {
			alert("INFORMACJE DODATKOWE: \n - Musisz wyrazić zgodę na przetwarzanie danych osobowych");
			error=1;
			return;
		}
		*/
		
		if(error==0) obj.form.submit();
		

	},


	KlientDane : function(obj) {
		obj.form.submit();
	},
	
	OID : function (id) {
		return document.getElementById(id);
	},

	PrzepiszDane : function(obj) {
		if(obj.checked) {
			this.OID('NazwaW').value=this.OID('NazwaF').value;
			this.OID('UlicaW').value=this.OID('UlicaF').value;
			this.OID('NrDomW').value=this.OID('NrDomF').value;
			this.OID('NrMieszkanieW').value=this.OID('NrMieszkanieF').value;
			this.OID('MiastoW').value=this.OID('MiastoF').value;
			this.OID('KodW').value=this.OID('KodF').value;
		
		

		}
		else {
			this.OID('NazwaW').value="";
			this.OID('UlicaW').value="";
			this.OID('NrDomW').value="";
			this.OID('NrMieszkanieW').value="";
			this.OID('MiastoW').value="";
			this.OID('KodW').value="";
		}
	},
	



	TestRejestracja : function (obj) {		
		
		login = document.getElementById('RejLogin').value;
		haslo = document.getElementById('RejHaslo').value;
		haslo2 = document.getElementById('RejHaslo2').value;
		
		var re=/^[0-9a-z]{1,15}$/i;	
		var error=0;
		
		if(!re.test(login)) {
			error=1;
			alert('Pole \"nazwa użytkownika\" zawiera niepoprawne dane.\nDozwolone są tylko cyfry i litery.\nMaksymalna liczba znakow wynosi 15.');
			return;
		}
		
		if(!re.test(haslo)) {
			error=1;
			alert('Pole \"hasło\" zawiera niepoprawne dane.\nDozwolone są tylko cyfry i litery.\nMaksymalna liczba znakow wynosi 15.');
			return;
		}

		if(haslo!=haslo2) {
			error=1;
			alert('Hasło i jego powtórzenie nie są identyczne.');
			return;
		}
		
		
		if(this.OID('NazwaF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Nazwa firmy lub imię i nazwisko musi zostać uzupełnione");
			error=1;
			return;
		}
		if(this.OID('UlicaF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Ulica musi zostać uzupełnione");
			error=1;
			return;
		}		
		if(this.OID('NrDomF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Nr domu musi zostać uzupełnione");
			error=1;
			return;
		}		
		
		if(this.OID('MiastoF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Miasto musi zostać uzupełnione");
			error=1;
			return;
		}
		
		if(this.OID('KodF').value.length==0) {
			alert("DANE DO FAKTURY: \n - pole Kod pocztowy musi zostać uzupełnione");
			error=1;
			return;
		}
				
		if(this.OID('NazwaW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Nazwa firmy lub imię i nazwisko musi zostać uzupełnione");
			error=1;
			return;
		}
		
		if(this.OID('UlicaW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Ulica musi zostać uzupełnione");
			error=1;
			return;
		}
		
		if(this.OID('NrDomW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Nr domu musi zostać uzupełnione");
			error=1;
			return;
		}		

		if(this.OID('MiastoW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Miasto musi zostać uzupełnione");
			error=1;
			return;
		}

		if(this.OID('KodW').value.length==0) {
			alert("DANE DO WYSYŁKI: \n - pole Kod pocztowy musi zostać uzupełnione");
			error=1;
			return;
		}

		if(this.OID('NazwaK').value.length==0) {
			alert("OSOBA DO KONTAKTU: \n - pole Nazwisko i imię osoby składającej zamówienie musi zostać uzupełnione");
			error=1;
			return;
		}

		if(this.OID('EmailK').value.length==0) {
			alert("OSOBA DO KONTAKTU: \n - pole E-mail kontaktowy musi zostać uzupełnione");
			error=1;
			return;
		}
		
		
		if(this.OID('TelefonK').value.length==0) {
			alert("OSOBA DO KONTAKTU: \n - pole Telefon kontaktowy musi zostać uzupełnione");
			error=1;
			return;
		}		
				
		if(!this.OID('RegulaminOk').checked) {
			alert("INFORMACJE DODATKOWE: \n - Musisz zaakceptować regulamin");
			error=1;
			return;
		}	
		
		/*
		if(!this.OID('PrzetwarzanieOk').checked) {
			alert("INFORMACJE DODATKOWE: \n - Musisz wyrazić zgodę na przetwarzanie danych osobowych");
			error=1;
			return;
		}
		*/
		


		if(error==0) obj.form.submit();
	},

	


	TestZmianaHasla : function (obj) {		
		
		hasloOld = document.getElementById('RejHasloOld').value;
		haslo = document.getElementById('RejHaslo').value;
		haslo2 = document.getElementById('RejHaslo2').value;
		
		var re=/^[0-9a-z]{1,15}$/i;	
		var error=0;
		
		if(!re.test(hasloOld)) {
			error=1;
			alert('Pole \"poprzednie hasło\" zawiera niepoprawne dane.\nDozwolone są tylko cyfry i litery.\nMaksymalna liczba znakow wynosi 15.');
			return;
		}
		
		if(!re.test(haslo)) {
			error=1;
			alert('Pole \"hasło\" zawiera niepoprawne dane.\nDozwolone są tylko cyfry i litery.\nMaksymalna liczba znakow wynosi 15.');
			return;
		}

		if(haslo!=haslo2) {
			error=1;
			alert('Hasło i jego powtórzenie nie są identyczne.');
			return;
		}

		if(hasloOld==haslo) {
			error=1;
			alert('Stare i nowe hasło są identyczne.');
			return;
		}

		if(error==0) obj.form.submit();
	},




	
	TestLogowanie : function (obj) {		
		
		login = document.getElementById('RejLogin').value;
		haslo = document.getElementById('RejHaslo').value;		
		
		var re=/^[0-9a-z]{1,15}$/i;	
		var error=0;
		
		if(!re.test(login)) {
			error=1;
			alert('Pole \"nazwa użytkownika\" zawiera niepoprawne dane.\nDozwolone są tylko cyfry i litery.\nMaksymalna liczba znakow wynosi 15.');
			return;
		}
		
		if(!re.test(haslo)) {
			error=1;
			alert('Pole \"hasło\" zawiera niepoprawne dane.\nDozwolone są tylko cyfry i litery.\nMaksymalna liczba znakow wynosi 15.');
			return;
		}		

		if(error==0) obj.form.submit();
	},


	KopiujPole : function (obj,DoceloweId) {
		
		if(document.getElementById('ToSamo').checked) {
			document.getElementById(DoceloweId).value=obj.value;
		}		

	}


};



var Koszyk = {

	Usun : function (obj,idcennik) {
		document.getElementById('ActionKoszyk'+idcennik).value='usuń';		
		obj.form.submit();
	},

	Zmiana : function(obj,idcennik) {
		
		var ok=false;
		

		ilosc = document.getElementById('IloscKoszyk'+idcennik).value;

		
		rExp = /^[1-9]{1,5}0*$/;		
		
		if(ilosc.search(rExp)>=0) ok = true;		
		else {
			if(ilosc==10) ok = true;
			else ok = false;
		}
		

		if(ok==true) {
			document.getElementById('ActionKoszyk'+idcennik).value='zmiana';		
			obj.form.submit();
		}
		
	}

};


var Kolor = {
	
	UstawKolorTlo : function(obj,opcja) {
		if(opcja==1) obj.style.background='#ececec';
		else obj.style.background='#ffffff';
	}
};


var Obrazek = {

	Powieksz : function(sciezka,wys,szer) {
			
		wys = parseInt(wys,10)+10;
		szer = parseInt(szer,10)+10;		
		var newTop = (screen.height/2)-(wys/2);		
		var newLeft = (screen.width/2)-(szer/2);
		var okno=window.open("","","menubar=no,resizable=yes,toolbar=no,location=no,scrollbars=no,left="+newLeft+",top="+newTop+",height=1,width=1"); 			
		var tekst="<body style='cursor:hand;cursor:pointer;margin:0px;margin-top:3px;margin-left:3px;text-align:center;' onClick='window.close();'><img src='"+sciezka+"'></body>";
		var header='<head><link rel=stylesheet href="style.css" type ="text/css"><title>Ośrodek Usług Technicznych MEZAR Sp. z o.o.</title></head>';
				
		okno.document.open();
		okno.document.write("<HTML>"+header+tekst+"</HTML>");
		okno.resizeTo(szer,wys);			
		okno.document.close();	
				
		if(ie5) {
			roznicaH = wys - okno.document.body.clientHeight;
			roznicaW = szer - okno.document.body.clientWidth;
		}
		else {
			roznicaH = wys - okno.window.innerHeight;
			roznicaW = szer - okno.window.innerWidth;
		}

		if(roznicaH<0) roznicaH=0;
		if(roznicaW<0) roznicaW=0;
		
		
		okno.resizeTo(szer+roznicaW,wys+roznicaH);
		
	}

};


var MenuLewa = {
	
	Klikniety:0,

	PokazSchowajPodgrupy : function(Id) {
		
		podgrupy = document.getElementById("POD"+Id);
		
		if(document.getElementById("POD"+Id)) {
			if(podgrupy.style.display=="none") this.PokazKlikniety(Id);
			else this.SchowajKlikniety(Id);
		}

	},

	
	PokazKlikniety : function(Id) {
		
		obj = document.getElementById("LG"+Id);
		podgrupy = document.getElementById("POD"+Id);
		obrazek = document.getElementById("IMG"+Id);
		
		if(document.getElementById("POD"+Id)) {
			podgrupy.style.display="block";
			obrazek.src="images/down.gif";
		}
		else {
			if(document.getElementById("IMG"+Id)) obrazek.src="images/right.gif";
		}
		
		if(document.getElementById("LG"+Id)) {
			obj.style.fontWeight='bold';
		
			
		}
		
		this.Klikniety=Id;

	},
	
	
	SchowajKlikniety : function() {		
		
		obj = document.getElementById("LG"+this.Klikniety);
		podgrupy = document.getElementById("POD"+this.Klikniety);
		obrazek = document.getElementById("IMG"+this.Klikniety);

		podgrupy.style.display="none";
		obj.style.fontWeight='normal';
		obrazek.src="images/right.gif";
		this.Klikniety=0;
	}

};


var Chmurki = {

	czasID:null,
	warstwy:0,

	Pokaz : function (e,warstwa) {
		
		var dlugosc;
		var dlmax = screen.availWidth-60; 	
		var czas = 300;   
		
		if(this.warstwy==1) {	 
			
			if(!e) e = window.event;
			
			if(e) {
				if ( e.pageX || e.pageY ) {
					posx = e.pageX;
					posy = e.pageY;
				}
				else if ( e.clientX || e.clientY ) {
					posx = e.clientX + document.body.scrollLeft;
					posy = e.clientY + document.body.scrollTop;
				}
				
				if(document.getElementById(warstwa)) {
					
					obj = document.getElementById(warstwa);
					obj.style.top = posy+10;
					dlugosc = parseInt((obj.style.width).slice(0,3));
					
					if(parseInt(dlugosc,10)+posx>dlmax) posx=posx-((dlugosc+posx)-dlmax);   
					
					obj.style.left = posx-10;
					this.czasID = setTimeout("obj.style.display = 'block'",czas);
				}
			}  
		}
	},



	Schowaj : function (warstwa) {  

		clearTimeout(this.czasID);
		
		if(document.getElementById(warstwa)) document.getElementById(warstwa).style.display = "none";  
		
	}

};



var ZaznaczanieMapa = {

	zaznaczony:0,

	Zaznacz : function(id) {
		document.getElementById(id).style.color='#cc0000';
		document.getElementById(id).style.fontWeight='bold';
		this.zaznaczony=id;
	},

	Odznacz : function() {
		if(this.zaznaczony!=0) {
			document.getElementById(this.zaznaczony).style.color='#000000';
			document.getElementById(this.zaznaczony).style.fontWeight='normal';
		}
	}

};