
    function $(id) {
    
        return document.getElementById(id);
    }

    // parser XMLowy
    function pokazPodkategorie(xml) {
         
        record = xml.getElementsByTagName("record");
        
        // petla jadaca po elementach xmla
        for (i = 0; i < record.length; i++) {
            
            // petla wstawiajaca trzy kolumny
            for (j = 0; j < 2; j++) {
            	$("podkategorie").options[i] = new Option(record[i].childNodes[0].childNodes[0].nodeValue, record[i].childNodes[1].childNodes[0].nodeValue);
            }
        }
    } 

    
    function pokazPodkategorie2(xml) {
         
        record = xml.getElementsByTagName("record");
        
        // petla jadaca po elementach xmla
        for (i = 0; i < record.length; i++) {
            
            // petla wstawiajaca trzy kolumny
            for (j = 0; j < 2; j++) {
            	$("podkategorie2").options[i] = new Option(record[i].childNodes[0].childNodes[0].nodeValue, record[i].childNodes[1].childNodes[0].nodeValue);
            }
        }
    }     
    
    function pokazPodkategorie3(xml) {
         
        record = xml.getElementsByTagName("record");
        
        // petla jadaca po elementach xmla
        for (i = 0; i < record.length; i++) {
            
            // petla wstawiajaca trzy kolumny
            for (j = 0; j < 2; j++) {
            	$("podkategorie3").options[i] = new Option(record[i].childNodes[0].childNodes[0].nodeValue, record[i].childNodes[1].childNodes[0].nodeValue);
            }
        }
    }     
      
    
	function aktualizujPodkategorie(idek){

		for(i=document.forma.podkategorie.length; i--; i >= 0){    
			
			document.forma.podkategorie.options[i] = null;
		
		}
		
		
		if(idek != 0){
			document.forma.podkategorie.disabled = false;
			
			advAJAX.get({
	            url : "./modules/podkategorie.php?idKat="+idek,
	            onSuccess : function(obj) {
	            
	            	pokazPodkategorie(obj.responseXML);
	            
	            },
	            onError : function(obj){alert('Nie moge dostac sie do danych.<br/>Can not access the data.');} 
	            
	        });
        
        }else{
        
        	document.forma.podkategorie.disabled = true;
        
        }

	
	} 
	
	function aktualizujPodkategorie2(idek){

		for(i=document.forma.podkategorie2.length; i--; i >= 0){    
			
			document.forma.podkategorie2.options[i] = null;
		
		}
		
		if(idek != 0){
			document.forma.podkategorie2.disabled = false;
			
			advAJAX.get({
	            url : "./modules/podkategorie.php?idKat="+idek,
	            onSuccess : function(obj) { pokazPodkategorie2(obj.responseXML); },
	            onError : function(obj){ alert('Nie moge dostac sie do danych.<br/>Can not access the data.'); } 
	            
	        });

		}else{
        
        	document.forma.podkategorie2.disabled = true;
        
        }
		
	} 	


	function aktualizujPodkategorie3(idek){

		for(i=document.forma.podkategorie3.length; i--; i >= 0){    
			
			document.forma.podkategorie3.options[i] = null;
		
		}
		
		if(idek != 0){
			document.forma.podkategorie3.disabled = false;
			
			advAJAX.get({
	            url : "./modules/podkategorie.php?idKat="+idek,
	            onSuccess : function(obj) { pokazPodkategorie3(obj.responseXML); },
	            onError : function(obj){ alert('Nie moge dostac sie do danych.<br/>Can not access the data.'); } 
	            
	        });

		}else{
        
        	document.forma.podkategorie3.disabled = true;
        
        }
		
	} 	
	
//////////////////////////////////////////////////////////////////////////////////////////	

    function pokazRegiony(xml) {
 
        record = xml.getElementsByTagName("record");
        
        // petla jadaca po elementach xmla
        for (i = 0; i < record.length; i++) {
            
            // petla wstawiajaca trzy kolumny
            for (j = 0; j < 2; j++) {
            	$("regiony").options[i] = new Option(record[i].childNodes[0].childNodes[0].nodeValue, record[i].childNodes[1].childNodes[0].nodeValue);
            }
        }
    }  
	
	function aktualizujRegiony(idek){

		for(i=document.forma.POSTregiony.length; i--; i >= 0){    
			document.forma.POSTregiony.options[i] = null;
		}
		
		if(idek != 0){
			document.forma.regiony.disabled = false;

			advAJAX.get({
	            url : "./modules/regiony.php?idKraju="+idek,
	            onSuccess : function(obj) { pokazRegiony(obj.responseXML); },
	            onError : function(obj){ alert('Nie moge dostac sie do danych.<br/>Can not access the data.'); } 
	            
	        });
		}else{
        
        	document.forma.regiony.disabled = true;
        
        }
		
	} 	
	
//////////////////////////////////////////////////////////////////////////////////////////	
	
	
function echeck(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					
	}

	
	// sprawdzarka loginu
	function authCheck(){
	
	var emailID = document.forma.POSTloginMail;	
	

	    if (document.forma.POSThaslo1.value == '' || document.forma.POSThaslo1.value.length < 3)
	        alert("Brak hasla / Enter Password");	
		else
	    if (document.forma.POSThaslo1.value != document.forma.POSThaslo2.value)
	        alert("Hasla nie sa identyczne / Passwords aren't the Same");
		else
	    if (document.forma.POSTloginMail.value == '') 
	        alert("Brak Loginu-Emaila / Enter Login Email");
		else
		if (echeck(emailID.value) == false)
	        alert("Niepoprawny Email / Incorect Email");	
		else    
	    if (document.forma.POSTloginMail.value != document.forma.POSTloginMail2.value) 
	        alert("Loginy-Email'e nie sa identyczne / Login Emails aren't the Same"); 		    
		else{
		email = document.forma.POSTloginMail.value;
		haslo = document.forma.POSThaslo1.value;
		
		advAJAX.get({
            url : "./modules/usersCheck.php?e="+email+"&p="+haslo,
            onSuccess : function(obj) { 
            
	            if(obj.responseText == 2){
					$("authKom").innerHTML = '<span class="authGood">Witam nowy uzytkowniku! Mozesz wypelniac dalej formularz.<br/><br/>Welcome, fill the form.</span>';

	            	document.forma.CORRECTlogin.value = document.forma.POSTloginMail.value;
	            	document.forma.CORRECThaslo.value = document.forma.POSThaslo1.value;
	            	
	            	document.forma.POSThaslo2.disabled = true;
	            	document.forma.authClick.disabled = true;
	            	document.forma.POSTloginMail.disabled = true;
	            	document.forma.POSThaslo1.disabled = true;
	            	document.forma.POSTloginMail2.disabled = true;
	            	document.forma.POSThaslo2.disabled = true;
	            	
	            	
	            }
	            if(obj.responseText == 0){
	            	//alert('Nie mozesz juz dodawac firm. / You cant add new firm.');
	            	$("authKom").innerHTML = '<span class="authFault">Nie mozesz juz dodawac firm. <br/><br/>You can not add new firm.</span>';
	            }
	            if(obj.responseText == 1){
	            	//alert('Mozesz dodac firme. / You can add new firm.');
	            	$("authKom").innerHTML = '<span class="authGood">Mozesz dodac firme. <br/><br/>You can add new firm.</span>';
	            	  
	            	document.forma.CORRECTlogin.value = document.forma.POSTloginMail.value;
	            	document.forma.CORRECThaslo.value = document.forma.POSThaslo1.value; 
	            	            	
	            	document.forma.authClick.disabled = true;
	            	document.forma.POSTloginMail.disabled = true;
	            	document.forma.POSThaslo1.disabled = true;
	            	document.forma.POSTloginMail2.disabled = true;
	            	document.forma.POSThaslo2.disabled = true;
	            }	            
	            if(obj.responseText == 4){
	            	//alert('Dane Nieprawidlowe. Prosze Popraw Dane / Incorrect Data. Please Correct It. ');
	            	$("authKom").innerHTML = '<span class="authFault">Dane Nieprawidlowe. Prosze Poprawic Dane.<br/>Nie pamietasz hasla? Napisz do Admina. <br/><br/>Incorrect Data. Please Correct It.<br/>Forgot your password. Contact Admin.</span>';
	            	   	            	
	            }	            

            },
            onError : function(obj){ alert('Nie moge dostac sie do danych.<br/>Can not access the data.'); } 
            
        });
        
        
        }
        		
		
	}
///////////////////////////////////////////////////////////////////////////////////////


    function showPod1(xml) {
         
        record = xml.getElementsByTagName("record");
        
        // petla jadaca po elementach xmla
        for (i = 0; i < record.length; i++) {
            
            // petla wstawiajaca trzy kolumny
            for (j = 0; j < 2; j++) {
            	$("podkategorie1").options[i] = new Option(record[i].childNodes[0].childNodes[0].nodeValue, record[i].childNodes[1].childNodes[0].nodeValue);
            }
        }
    }


	function moveListSubCat1(idek){

		for(i=document.formaMove.podkategorie1.length; i--; i >= 0){    
			document.formaMove.podkategorie1.options[i] = null;
		}
		
		if(idek != 0){
			document.formaMove.podkategorie1.disabled = false;
			
			advAJAX.get({
	            url : "./modules/podkategorie.php?idKat="+idek,
	            onSuccess : function(obj) { showPod1(obj.responseXML); },
	            onError : function(obj){ alert('Nie moge dostac sie do danych.<br/>Can not access the data.'); } 
	            
	        });

		}else{
        
        	document.formaMove.podkategorie1.disabled = true;
        
        }
		
	}
	
    function showPod2(xml) {
         
        record = xml.getElementsByTagName("record");
        
        // petla jadaca po elementach xmla
        for (i = 0; i < record.length; i++) {
            
            // petla wstawiajaca trzy kolumny
            for (j = 0; j < 2; j++) {
            	$("podkategorie2").options[i] = new Option(record[i].childNodes[0].childNodes[0].nodeValue, record[i].childNodes[1].childNodes[0].nodeValue);
            }
        }
    }


	function moveListSubCat2(idek){

		for(i=document.formaMove.podkategorie2.length; i--; i >= 0){    
			document.formaMove.podkategorie2.options[i] = null;
		}
		
		if(idek != 0){
			document.formaMove.podkategorie2.disabled = false;
			
			advAJAX.get({
	            url : "./modules/podkategorie.php?idKat="+idek,
	            onSuccess : function(obj) { showPod2(obj.responseXML); },
	            onError : function(obj){ alert('Nie moge dostac sie do danych.<br/>Can not access the data.'); } 
	            
	        });

		}else{
        
        	document.formaMove.podkategorie2.disabled = true;
        
        }
		
	}
	
///////////////////////////////////////////////////////////////////////////////////////

    function searchShowPodkategorie(xml) {
         
        record = xml.getElementsByTagName("record");
       
        $("SEARCHpod").options[0] = new Option("All / Wszystkie", 0);
                     
        // petla jadaca po elementach xmla
        for (i = 1; i < record.length+1; i++) {
            
            // petla wstawiajaca trzy kolumny
            for (j = 0; j < 2; j++) {
            	$("SEARCHpod").options[i] = new Option(record[i-1].childNodes[0].childNodes[0].nodeValue, record[i-1].childNodes[1].childNodes[0].nodeValue);
            }
        }
    }


	function listaPod(idek){

		for(i=document.formSearch.SEARCHpod.length; i--; i >= 0){    
			document.formSearch.SEARCHpod.options[i] = null;
		}
		
		advAJAX.get({
            url : "./modules/podkategorie.php?idKat="+idek,
            onSuccess : function(obj) { searchShowPodkategorie(obj.responseXML); },
            onError : function(obj){ alert('Nie moge dostac sie do danych.<br/>Can not access the data.'); } 
            
        });
		
	}
	
	
    function showRegions(xml) {
 
        record = xml.getElementsByTagName("record");
        
       $("SEARCHregion").options[0] = new Option("All / Wszystkie", 0);
               
        
        // petla jadaca po elementach xmla
        for (i = 1; i < record.length+1; i++) {
            
            // petla wstawiajaca trzy kolumny
            for (j = 0; j < 2; j++) {
            	$("SEARCHregion").options[i] = new Option(record[i-1].childNodes[0].childNodes[0].nodeValue, record[i-1].childNodes[1].childNodes[0].nodeValue);
            }
        }
        
  
    }  
	
	function searchRegiony(idek){

		for(i=document.formSearch.SEARCHregion.length; i--; i >= 0){    
			document.formSearch.SEARCHregion.options[i] = null;
		}

			advAJAX.get({
	            url : "./modules/regiony.php?idKraju="+idek,
	            onSuccess : function(obj) { showRegions(obj.responseXML); },
	            onError : function(obj){ alert('Nie moge dostac sie do danych.<br/>Can not access the data.'); } 
	            
	        });
		
	} 
	
	
function Prnt(x){
 var i,strefa=document.getElementById('strefaDrukowania'),
  W=strefa.getElementsByTagName('div')
 for(i=0; i<W.length; i++)
  W[i].className=x.parentNode==W[i]?'print':'noprint'
 window.print()
}
function PrntAll(){
 var i,strefa=document.getElementById('strefaDrukowania'),
  W=strefa.getElementsByTagName('div')
 for(i=0; i<W.length; i++)
  W[i].className='print'
 window.print()
}		


function sprawdzNewsletter(f){

	var emailID = document.formaNewsletter.emailAdres;	
	
	if (echeck(emailID.value) == false){
	    alert("Prosze podac Email / Please enter correct Email.");	
		return false
	}
	
}


function zmienJezyk(param){

	document.location= "index.php?a=katalog&f=zmienJezyk&lang="+param;
					
}


function sprawdzList(f){

	var emailID = document.forma.EMAILemail;	
	
	if (f.EMAILname.value == '' || f.EMAILname.value.length < 3){
	    alert("Prosze podac Imie / Please put your Name.");	
		return false
	}
	
	if (echeck(emailID.value) == false){
	    alert("Prosze podac Email / Please enter correct Email.");	
		return false
	}
	
	if (f.EMAILtresc.value == '' || f.EMAILtresc.value.length < 3){
	    alert("Prosze wpisac tresc / Please enter your message.");	
		return false
	}
	
}


function sprawdzYourMail(f){

	var emailID = document.forma.EMAILmy;	
	
	if (f.EMAILname.value == '' || f.EMAILname.value.length < 3){
	    alert("Prosze podac Imie / Please put your Name.");	
		return false
	}
	
	if (echeck(emailID.value) == false){
	    alert("Prosze podac Email / Please enter correct Email");	
		return false
	}
	
	if (f.EMAILtresc.value == '' || f.EMAILtresc.value.length < 3){
	    alert("Prosze wpisac tresc / Please enter your message.");	
		return false
	}
	
}

function sprawdzPrzyjaciela(f){

	var emailID = document.forma.EMAILmy;	
	var emailID2 = document.forma.EMAILodbiorca;
	
	
	if (f.EMAILname.value == '' || f.EMAILname.value.length < 3){
	    alert("Prosze podac Imie / Please put your Name.");	
		return false
	}
	
	if (echeck(emailID.value) == false){
	    alert("Prosze podac Email / Please enter correct Email.");	
		return false
	}
	
	if (echeck(emailID2.value) == false){
	    alert("Prosze podac Email / Please enter correct Email.");
		return false
	}
	
	if (f.EMAILtresc.value == '' || f.EMAILtresc.value.length < 3){
	    alert("Prosze wpisac tresc / Please enter your message.");	
		return false
	}
	
}
