function zaznacz(id,layer) {
	var theForm = document.getElementById(layer).getElementsByTagName('input');
	
	if(layer != '')
		showLayer(layer);
		
	for(z=0; z<theForm.length;z++) {
   	if(theForm[z].type == 'checkbox') {
   		if(id.checked) {
			  	theForm[z].checked = true;
			} else {
				theForm[z].checked = false;
			}
		}
	}
}

function zaznaczWybrane(id,value) {
	var theForm = document.getElementById(id).getElementsByTagName('input');
	var i = 0;
	for(z=0; z<theForm.length;z++) {
		if(theForm[z].type == 'checkbox') {
			if(theForm[z].value == value) {
				theForm[z].checked = true;
			}
			i++;
		}
	}

	return i;
}

function checkEmail(y) {
	if (y == "") {
		return false;
	}

	var x= new String(y);
	x.toLowerCase();
	var ret= new String();
	var znaki1= ".-+_@";
	var znaki= "0123456789zxcvbnmasdfghjklqwertyuiop" + znaki1;

	if ( x.length < 1 )
		return false;

	if ( x.indexOf("@") == -1 ) {
		ok= 0;
		return false;
	}

	if ( x.indexOf("@") != x.lastIndexOf("@") ) {	
		ok= 0;
		return false;
	}

	for ( i=0; i < x.length; ++i)
		if ( znaki.indexOf(""+x.charAt(i)) == -1 ) {
			ok= 0;
			return false;
		}

	if ( znaki1.indexOf(x.charAt(x.length-1)) != -1 ) {
		ok= 0;
		return false;
	}
			
	return true;
}

function CheckInteger(y) 
{	if (y == "") 
		return false;

	var x= new String(y);
	var znaki= "0123456789";
	if ( x.length < 1 )
		return false;
	
	for ( i=0; i < x.length; ++i)
		if ( znaki.indexOf(""+x.charAt(i)) == -1 )
		{	ok= 0;
			return false;
		}

	return true;
}

function checkRegisterForm() {
	
	var pola = ['woj1','woj2','woj4','woj5','woj6','woj7','woj8','woj10', 'woj11','woj12', 'woj13'];
	var chociazJedno = 0;
	
	for(j = 0; j<pola.length; j++) {
		try {
			var theForm = document.getElementById(pola[j]).getElementsByTagName('input');
		} catch(err) {}
		if (theForm) {
			for(z=0; z<theForm.length;z++) {
				if(theForm[z].type == 'checkbox') {
					if(theForm[z].checked) {
						chociazJedno++;
					}
				}
			}
		} // if theForm
	}
	
	if(chociazJedno == 0) {
		alert("Musisz wybrać przynajmniej jedną pozycję newslettera.");
		return false;
	}
	
	if(!checkEmail(document.getElementById('email').value)) {
		alert("Musisz podać poprawny adres email.");
		return false;
	}
	
	if(document.getElementById('rabat').checked) {	
		
		
		if(document.getElementById('imie').value == '') {
			alert("Podaj swoje imię.");
			return false;
		}
		
		if(document.getElementById('nazwisko').value == '') {
			alert("Podaj swoje nazwisko.");
			return false;
		}
		
		if(document.getElementById('radio_button').value == 'firma') {
			if(document.getElementById('firma').value == '') {
				alert("Podaj nazwę firmy.");
				return false;
			}
		}
		
		//alert(document.getElementById('Telefon').value);
		if(document.getElementById('telefon').value == '') {
			alert("Podaj telefon.");
			return false;
		}
		
		if(document.getElementById('ulica').value == '') {
			alert("Podaj ulicę.");
			return false;
		}
		
		if(!CheckInteger(document.getElementById('kod').value) || !CheckInteger(document.getElementById('pocztowy').value)) {
			alert("Podaj poprawny kod pocztowy.");
			return false;
		}
		
		if(document.getElementById('miejscowosc').value == '') {
			alert("Podaj miejscowość.");
			return false;
		}
		
		if(document.getElementById('wiek').value == 'BRAK') {
			alert("Podaj przedział wiekowy.");
			return false;
		}
		
		if(document.getElementById('wyksztalcenie').value == 'BRAK') {
			alert("Wybierz wykształcenie.");
			return false;
		}
		
		if(document.getElementById('status').value == 'BRAK') {
			alert("Wybierz status zawodowy.");
			return false;
		}
		
		if(document.getElementById('branza').value == 'BRAK') {
			alert("Wybierz branże.");
			return false;
		}
		
	}

	if(!document.getElementById('regulamin').checked) {
		alert("Musisz zapoznać się z regulaminem newslettera.");
		return false;
	}
	
	if(!document.getElementById('zgoda').checked) {
		alert("Bez zgody na przetwarzanie danych osobowych nie możemy wysyłać newsletterów. Jeżeli chcesz otrzymywać newsletter odkliknij checkbox przy zaznaczeniu.");
		return false;
	}
	//alert('test');
	return true;
}


function checkEditForm() {
	if(!checkEmail(document.getElementById('email').value)) {
		alert("Musisz podać poprawny adres email.");
		return false;
	}

	return true;
}


function changeSelectForUserPreferences(wiek,wyksztalcenie,status,branza) {
	if(wiek != '') {
		document.getElementById('wiek').value = wiek;
	}

	if(wyksztalcenie != '') {
		document.getElementById('wyksztalcenie').value = wyksztalcenie;
	}

	if(status != '') {
		document.getElementById('status').value = status;
	}

	if(branza != '') {
		document.getElementById('branza').value = branza;
	}
}

function addToPrintList(nr) {
	$.get("index.html",{ action: 'addtolist', numer: nr }, function(data) {  });
}

function printAll() {
	window.open("popup.html?action=printAll", null, "height = 700, width= 690, left = 270, top = 184, status=0, toolbar=no, menubar=no, location=no, scrollbars");
}

function print(id) {
	window.open("popup.html?idn=" + id, null, "height = 700, width= 690, left = 270, top = 184, status=0, toolbar=no, menubar=no, location=no, scrollbars");
}

function sendToFriend(id) {
	window.open("popup.html?action=sendfriend&idn=" + id, null, "height = 450, width= 500, left = 270, top = 184, status=0, toolbar=no, menubar=no, location=no, scrollbars");
}

function showCheckbox() {
	var theForm = document.getElementById('content').getElementsByTagName('input');
	
	for(z=0; z<theForm.length;z++) {
	   	if(theForm[z].type == 'checkbox') {
	   		theForm[z].style.visibility = 'visible';
		}
	}

	document.getElementById('listawydrukow').innerHTML = '<img src="templates/default/img/c_right_li.gif">&nbsp; &nbsp; <a href="#" onClick="printAllChecked();">drukuj</a><br>';
}

function printAllChecked() {
	var doDruk = new Array();
	var theForm = document.getElementById('content').getElementsByTagName('input');
	
	for(z=0; z<theForm.length;z++) {
	   	if(theForm[z].type == 'checkbox') {
	   		if(theForm[z].checked) {
				doDruk.push(theForm[z].value);
			}
		}
	}
	window.open("popup.html?action=printChecked&id="+escape(doDruk), null, "height = 700, width= 690, left = 270, top = 184, status=0, toolbar=no, menubar=no, location=no, scrollbars");
}

function checkShortRegisterForm() {
	var pola = ['woj10'];
	var chociazJedno = 0;
	for(j = 0; j<pola.length; j++) {
		var theForm = document.getElementById(pola[j]).getElementsByTagName('input');
		for(z=0; z<theForm.length;z++) {
	   	if(theForm[z].type == 'checkbox') {
	   		if(theForm[z].checked) {
				  	chociazJedno++;
				}
			}
		}
	}
	if(chociazJedno == 0) { 	alert("Musisz wybrać przynajmniej jedną pozycję newslettera.");	return false; }
	if(!checkEmail(document.getElementById('email').value)) { alert("Musisz podać poprawny adres email.");	return false;	}
	if(document.getElementById('rabat').checked) {	
		if(document.getElementById('imie').value == '') { alert("Podaj swoje imię.");return false;	}
		if(document.getElementById('nazwisko').value == '') { alert("Podaj swoje nazwisko."); return false; }
		if(document.getElementById('radio_button').value == 'firma') {	
			if(document.getElementById('firma').value == '') { alert("Podaj nazwę firmy.");	return false; }
		}
		if(document.getElementById('Telefon').value == '') { alert("Podaj telefon.");return false; }
		if(document.getElementById('ulica').value == '') { alert("Podaj ulicę."); return false; }
		if(!CheckInteger(document.getElementById('kod').value) || !CheckInteger(document.getElementById('pocztowy').value)) {
			alert("Podaj poprawny kod pocztowy."); 	return false; }
		if(document.getElementById('miejscowosc').value == '') { alert("Podaj miejscowość."); return false; }
		if(document.getElementById('wiek').value == 'BRAK') { alert("Podaj przedział wiekowy."); return false; }
		if(document.getElementById('wyksztalcenie').value == 'BRAK') { 	alert("Wybierz wykształcenie."); return false; }
		if(document.getElementById('status').value == 'BRAK') {	alert("Wybierz status zawodowy.");	return false; }
		if(document.getElementById('branza').value == 'BRAK') {	alert("Wybierz branżę."); return false; }
	}
	if(!document.getElementById('regulamin').checked) {	alert("Musisz zapoznać się z regulaminem newslettera.");return false;	}
	if(!document.getElementById('zgoda').checked) { 	alert("Bez zgody na przetwarzanie danych osobowych nie możemy wysyłać newsletterów. Jeżeli chcesz otrzymywać newsletter odkliknij checkbox przy zaznaczeniu.");		return false;	}
	return true;
} // checkShortRegisterForm

function checkShortRegisterFormSamorzad() {
	var pola = ['woj12'];
	var chociazJedno = 0;
	for(j = 0; j<pola.length; j++) {
		var theForm = document.getElementById(pola[j]).getElementsByTagName('input');
		for(z=0; z<theForm.length;z++) {
	   	if(theForm[z].type == 'checkbox') {
	   		if(theForm[z].checked) {
				  	chociazJedno++;
				}
			}
		}
	}
	if(chociazJedno == 0) { 	alert("Musisz wybrać przynajmniej jedną pozycję newslettera.");	return false; }
	if(!checkEmail(document.getElementById('email').value)) { alert("Musisz podać poprawny adres email.");	return false;	}
	if(document.getElementById('rabat').checked) {	
		if(document.getElementById('imie').value == '') { alert("Podaj swoje imię.");return false;	}
		if(document.getElementById('nazwisko').value == '') { alert("Podaj swoje nazwisko."); return false; }
		if(document.getElementById('radio_button').value == 'firma') {	
			if(document.getElementById('firma').value == '') { alert("Podaj nazwę firmy.");	return false; }
		}
		if(document.getElementById('Telefon').value == '') { alert("Podaj telefon.");return false; }
		if(document.getElementById('ulica').value == '') { alert("Podaj ulicę."); return false; }
		if(!CheckInteger(document.getElementById('kod').value) || !CheckInteger(document.getElementById('pocztowy').value)) {
			alert("Podaj poprawny kod pocztowy."); 	return false; }
		if(document.getElementById('miejscowosc').value == '') { alert("Podaj miejscowość."); return false; }
		if(document.getElementById('wiek').value == 'BRAK') { alert("Podaj przedział wiekowy."); return false; }
		if(document.getElementById('wyksztalcenie').value == 'BRAK') { 	alert("Wybierz wykształcenie."); return false; }
		if(document.getElementById('status').value == 'BRAK') {	alert("Wybierz status zawodowy.");	return false; }
		if(document.getElementById('branza').value == 'BRAK') {	alert("Wybierz branżę."); return false; }
	}
	if(!document.getElementById('regulamin').checked) {	alert("Musisz zapoznać się z regulaminem newslettera.");return false;	}
	if(!document.getElementById('zgoda').checked) { 	alert("Bez zgody na przetwarzanie danych osobowych nie możemy wysyłać newsletterów. Jeżeli chcesz otrzymywać newsletter odkliknij checkbox przy zaznaczeniu.");		return false;	}
	return true;
} // checkShortRegisterForm