// JavaScript Document
var correctcolor='#111111';
var errorcolor='#f048b0';

function checkString(element){
	var bool = true;
	
	if(	$("input[name='"+element+"']").val().length < 1 ){
		bool = bool && false;
  	//$(element).setStyle('background-color',errorcolor);
	 $("input[name='"+element+"']").addClass("input-error");

	}
	else{		
			bool = bool && true;
			$("input[name='"+element+"']").addClass("valid-input");
  		//$(element).setStyle('background-color',correctcolor);		
	}
	return bool;
}

function checkForm(){

var bool = true;


bool =  checkString('surname')&& bool;
bool =  checkString('tel') && bool;
bool =  checkString('coperti') && bool;
bool =  checkString('dataora') && bool;
//bool =  checkString('evento') && bool;

/*if(echeck($('email').getProperty('value') )){ 
	$('email').setStyle('background-color',correctcolor);
}
else { 
	$('email').setStyle('background-color',errorcolor);
}*/

//bool =  echeck($('email').getProperty('value')) && bool;

if(bool == true) {
			//	var mFx = new Fx.Tween($('send'));  
			//	mFx.start('margin-left', '200px', '670px');
			$("form[name='sendmail']").submit();	
				//An anonymous function which waits a second and then alerts.
//(function(){$('sendmail').submit();  }).delay(3000);

				 
	}
}
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					
	}