

// Ustawia date przy formularzu rejestracji produktów

function ustaw(f) {
  var rok=f.rok[f.rok.selectedIndex].value;
  var miesiac=f.miesiac[f.miesiac.selectedIndex].value;
  var dni = 32-new Date(rok, miesiac-1, 32).getDate();
  for (i=f.dzien.options.length;i>=0;i--) f.dzien.options[i]=null;
  for (i=0;i<dni;i++) 
   f.dzien.options[i]=new Option(i+1,i+1);
}
//-----------------------------------------------------
// Sprawdza czy przy zamawianiu koszyk nie jest pusty
//-----------------------------------------------------
function checkWartoscKoszyk(wartosc1) {
	var wartosc = wartosc1;
	if (wartosc <= 0){
		alert('Koszyk jest pusty!');
		return false;
	}
	
	return true;
	
}

//-------------------------------------------------------
// Sprawdza czy wypełniono odpowiednie pola w formularzu
// rejestracji produktu
//-------------------------------------------------------

function testujProductRegister() {
	
    if (document.register.numerProduktuId.selectedIndex<1) {
    	alert("Wybierz numer produktu lub nazwę"); 
    	return false;
    }
  
    if (document.register.nazwaProduktuId.selectedIndex<1) {
    	alert("Wybierz numer produktu lub nazwę"); 
    	return false;
    }
   
    if ((document.register.ilosc.value == 0) || (!document.register.ilosc.value.match(/^[0-9]+$/))) {
        alert("Nie podano ilo¶ci lub wpisano niedozwolon± warto¶ć!"); 
        return false; 
    }
    
    // Spradza czy nie wybrano daty z przyszlosci
    
    var data    = new Date();
  	var m       = data.getMonth()+1;
  	//var d       = data.getDate();
    var r       = data.getFullYear();
    var dzisiaj = ""+r+((m<10)?"0":"")+m;
 
    var pr=document.register.rok[document.register.rok.selectedIndex].value;
    var pm=document.register.miesiac[document.register.miesiac.selectedIndex].value;
 // var pd=document.register.dzien[document.register.dzien.selectedIndex].value;
    var wybrany=""+pr+pm;
 
    if (dzisiaj<wybrany) {
    	alert("Wybrano datę z przyszło¶ci!");
    	return false;
    } 
  
  	return true;
}

//Sprawdza poprawno¶ć wypełnionych pól przy składaniu zamówienia (koszyk)
function testujDaneWysylka(f) {

	if (f.firma.value.length < 1) {
 	    alert('Podaj nazwę firmy!');
 	 	f.firma.focus();
 	 	return false;
    }
    
    if (f.imie.value < 1) {
    	alert('Wypełnij pole imię!');
    	f.imie.focus();
    	return false;
    }
    
    // if (!f.imie.value.match(/^[a-zA-ZˇĆĘŁŃÓ¦Ż¬±ćęłńó¶żĽ ]+$/)) {
 	// 	alert('Imię może zawierać tylko litery i spację!');
 	// 	f.imie.focus();
 	// 	return false;
 	//}
    
    if (f.nazwisko.value < 1) {
    	alert('Wypełnij pole nazwisko!');
    	f.nazwisko.focus();
    	return false;
    }
    
    //if (!f.nazwisko.value.match(/^[a-zA-ZˇĆĘŁŃÓ¦Ż¬±ćęłńó¶żĽ ]+$/)) {
 	// 	alert('Nazwisko może zawierać tylko litery i spację!');
 	// 	f.nazwisko.focus();
 	// 	return false;
 	//}
 	
 	if (!f.email.value.match(/^[0-9a-zA-Z_.-]+@([0-9a-z-]+\.)+[a-z]{2,6}$/)) {
    	alert("Podaj poprawny adres e-mail!");
    	f.email.focus();
    	return false;
 	}
 	
    if (f.ulica.value < 1) {
    	alert('Wypełnij pole ulica!');
    	f.ulica.focus();
    	return false;
    }
    //if (!f.ulica.value.match(/^[0-9a-zA-ZˇĆĘŁŃÓ¦Ż¬±ćęłńó¶żĽ -]+$/)) {
 	// 	alert('Nazwa ulicy może zawierać litery, cyfry, my¶lnik i spację!');
 	// 	f.ulica.focus();
 	// 	return false;
 	//}
 	
 	if (!f.kod.value.match(/^\d\d-\d\d\d$/)) {
 	 	alert('Kod pocztowy musi mieć format: xx-xxx');
 	 	f.kod.focus();
 	 	return false;
 	}
 	
    if (f.miasto.value < 1) {
    	alert('Podaj nazwę miasta!');
    	f.miasto.focus();
    	return false;
    }
   
 	//if (!f.miasto.value.match(/^[0-9a-zA-ZˇĆĘŁŃÓ¦Ż¬±ćęłńó¶żĽ -]+$/)) {
 	// 	alert('Nazwa miasta może zawierać litery, cyfry, my¶lnik i spację!');
 	// 	f.miasto.focus();
 	// 	return false;
 	//}
 	
 	if (!f.telefon.value.match(/^[0-9 +()-.]+$/)) {
 	 	alert('Telefon może zawierać cyfry, spację , plus, minus, kropkę, nawias !');
 	 	f.telefon.focus();
 	 	return false;
 	}
 	
 	if (f.nip.value.value == 0) {
 		alert('Numer NIP musi mieć 10 cyfr bez spacji!');
 	 	f.nip.focus();
 	 	return false;
 	} else {
 	 	 var nip = f.nip.value.replace(/[^0-9]/g,"");
  	     var suma = 0;
         	if (nip.length==10 && nip!=0) {
         		var wagi = new Array(6,5,7,2,3,4,5,6,7);
         		for (var i=0;i<9;i++) suma += nip.charAt(i)*wagi[i];
         		if ((suma%11)%10==nip.charAt(9)) {
            		return true;
         		}
         	}
         	alert('Numer NIP musi mieć 10 cyfr bez spacji!');
         	f.nip.focus();
         	return false;
 	}
 	
  	return true;
}

//==================================================================
//  Sprawdza czy wypełniono wszystkie pola w formularzu rejestracji
//==================================================================
function checkRegistrationForm() {
	formularz = document.getElementById("formRejestracja");
	
	j=0
	for (var i=0; i<formularz.elements.length; i++) {
		
		
  		//	alert(formularz.elements[1].name);
  		//	return false;
  		
  		
		
  		if (formularz.elements[i].type == 'text' && formularz.elements[i].value.length == 0){
  			alert('Proszę wypełnić wszystkie pola!');
  			return false;
  		}
  		
  		if (formularz.elements[i].type == 'select-one' && formularz.elements[i].selectedIndex <1){
  			alert('Proszę wybrać z listy!');
  			return false;
  		}
  		
  		if (formularz.elements[i].type == 'checkbox') {
  			if (!formularz.elements[i].checked) {
  				alert('Aby dokończyć proces rejestracji, należy wyrazić zgodę na \nprzetwarzanie danych osobowych, zaznaczaj±c pola checkbox \nznajduj±ce się przy o¶wiadczeniach!');
  				return false;
  			//alert (formularz.elements[i].checked);
  			}
  		}
  		
  		// Sprawdzamy poprawno¶ć email
  		if (formularz.elements[i].name == 'email') {
  			var email = formularz.elements[i].value;	
  		
  			if (!email.match(/^[0-9a-zA-Z_.-]+@([0-9a-z-]+\.)+[a-z]{2,6}$/) ) {
    			alert("Proszę podać poprawny adres e-mail!");
    			return false;
 			}
  		}
  		
  		// Sprawdzamy poprawno¶ć nip
  		if (formularz.elements[i].name == 'nip') {
  			var nip = formularz.elements[i].value.replace(/[^0-9]/g,"");
  	       	     	
         	if (nip.length!=10 || !nip.match(/^[0-9]{10,10}$/)) {
         		alert('Numer NIP musi mieć 10 cyfr bez spacji!');
         	    return false;
         	}
   		}
	}
	return true;
}


function windowUwaga(tekst) {
var windowWidth = 400;
var windowHeight = 300;
var posLeft = (screen.width-windowWidth)/2;
var posTop = (screen.height-windowHeight)/2;
        newWindow = window.open("","newWindow","width="+windowWidth+",height="+windowHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
        newWindow.document.open();
        newWindow.document.write('<html><head><title>Uwagi</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"><style type="text/css">');
        newWindow.document.write('body {');
        newWindow.document.write('font-size: 12px; font-family: Arial,Helvetica,sans-serif; margin: 30px;');
        newWindow.document.write('}');
        newWindow.document.write('p {');
        newWindow.document.write('font-size: 12px; font-family: Arial,Helvetica,sans-serif; line-height: 14px;');
        newWindow.document.write('padding: 4px 0; color:#757575;}');
        newWindow.document.write('</style></head><body bgcolor="#FFFFFF" onblur="self.close()">');
        newWindow.document.write('<p>'+tekst+'</p>');
        newWindow.document.write('</body></html>');
        newWindow.document.close();
        newWindow.focus();
}
function displayCenterWindow(theURL,winName,winWidth,winHeight) {
var window_width = winWidth;
var window_height = winHeight;
var window_top = (screen.height-window_height)/2;
var window_left = (screen.width-window_width)/2;
newWindow=window.open
(''+ theURL + '&p=1','edytuj','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left);
}
function closeEdytuj(){
if (newWindow && newWindow.open && !newWindow.closed) newWindow.close();
}




