var error;
function checkString (str) {
	
	if (str == "") {
		error = "Błąd w adresie e-mail\n";
		return;
	}
	
	
	var check;
	forbidden = new Array("/",":",";","!","@","#","$","%","^","&","*","(",")","+","=","\\","|","\"","'","<",",",">","?"," ");
	for (var j = 0 ; j < forbidden.length ; j++) {
		check = str.indexOf(forbidden[j])
		if (check >= 0) {
			error = error + "W adresie e-mail użyto nieprawidłowych znaków\n";
		}
	}
	
	for (var i = 0 ; i < str.length ; i++ ) {
		check = str.charCodeAt([i]);
		if (check >= 127) {
			error = error + "W adresie e-mail użyto polskich liter\n";
		}
	}
	
	if (str.indexOf(".") == 0 || str.lastIndexOf(".") == (str.length-1)) {
		error = error + "Nieprawidłowa pozycja kropki w adresie e-mail\n";
	}
	
}
function checkDomena(str) {
	if (str.indexOf(".")<0) {
		error = error + "Nieprawidłowa domena w adresie e-mail\n";
	}
}
function checkMail(email, form) {
	error = "";
	
	if (email == "") {
		error = "Nie wpisano adresu e-mail";
	} else {
	
	splitter = email.indexOf("@");
	
	if(splitter == -1) {
		error = "Brak znaku @ w adresie e-mail";
	} else if (email.indexOf("@") != email.lastIndexOf("@")) {
		error = "Zbyt wiele znaków @ w adresie e-mail";

	} else {
	
	splits = email.split("@");
	
	
	
	checkString(splits[0]);
	checkString(splits[1]);
	checkDomena(splits[1]);
	}
	}
	if (error == "") {
		
document.ptunform.email.value = splits[0] + "@" + splits[1];
		document.ptunform.submit();

	} else {
		alert(error);
	}
}



function CheckForm() {
	if ((document.ptunform.imie.value != "") &&
	    (document.ptunform.nazwisko.value != "")) {

	    	checkMail(document.ptunform.user.value, 'ptunform')
	    	
		//document.ptunform.submit();
	} else {
		window.alert("\nNie wszystkie wymagane pola zostały wypełnione!" +
		             "\nWypełnij WSZYSTKIE pola oznaczone gwiazdką.");
	}
} // End of CheckForm function


		function isMail(email) {
			var re = /^([A-Za-z0-9_]|-|.)+@(([A-Za-z0-9_]|-)+.)+[A-Za-z]{2,4}$/;
			return re.test(email);
		}
	
		function isBlank(value) {
			var re = /^s+$/;
			if (value == "" || re.test(value)) {
				return true;
			}
			return false;
		}	

	function checkup(EV_form) {

		if (isBlank(EV_form.imie.value)) { alert("Proszę podać imię."); return false; }
		if (isBlank(EV_form.nazwisko.value)) { alert("Proszę podać nazwisko."); return false; }
//		if (isBlank(EV_form.stanowisko.value)) { alert("Proszę podać stanowisko."); return false; }
//		if (isBlank(EV_form.firma.value)) { alert("Proszę podać nazwę firmy."); return false; }
		if (isBlank(EV_form.email.value)|| !isMail(EV_form.email.value)) { alert("Proszę podać email."); return false; }

		EV_form.submit();
	}