/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) 
{
		var at="@"
		var dot="."
		var lat=str.value.indexOf(at)
		var lstr=str.value.length
		var ldot=str.value.indexOf(dot)
		
		if (str.value.indexOf(at)==-1){
		   alert("Nieprawidłowy adres e-mail!")
		   return false
		}

		if (str.value.indexOf(at)==-1 || str.value.indexOf(at)==0 || str.value.indexOf(at)==lstr){
		   alert("Nieprawidłowy adres e-mail!")
		   return false
		}

		if (str.value.indexOf(dot)==-1 || str.value.indexOf(dot)==0 || str.value.indexOf(dot)==lstr){
		    alert("Nieprawidłowy adres e-mail!")
		    return false
		}

		 if (str.value.indexOf(at,(lat+1))!=-1){
		    alert("Nieprawidłowy adres e-mail!")
		    return false
		 }

		 if (str.value.substring(lat-1,lat)==dot || str.value.substring(lat+1,lat+2)==dot){
		    alert("Nieprawidłowy adres e-mail!")
		    return false
		 }

		 if (str.value.indexOf(dot,(lat+2))==-1){
		    alert("Nieprawidłowy adres e-mail!")
		    return false
		 }
		
		 if (str.value.indexOf(" ")!=-1){
		    alert("Nieprawidłowy adres e-mail!")
		    return false
		 }

 		 return true					
	}

function checkMail(id)
{
	form=document.getElementById(id);

	var mail_address=document.getElementById('mail_address');
	var mail_content=document.getElementById('mail_content');
	
	if ((mail_address.value==null)||(mail_address.value=="")){
		alert("Proszę podać adres e-mail!")
		mail_address.focus()
		mail_address.style.background="#FFDFDF";
		return false
	}
	if (echeck(mail_address)==false){
		mail_address.focus()
		mail_address.style.background="#FFDFDF";
		return false
	}
	if ((mail_content.value==null)||(mail_content.value=="")){
		alert("Proszę wpisać treść wiadomości!")
		mail_content.focus()
		mail_content.style.background="#FFDFDF";
		return false
	}
	
	
	mail_address.style.background="#DFFFDF";
	mail_content.style.background="#DFFFDF";
	form.submit();
	return true;
 }
