function rst()
{	
	document.Preventivo.nome.style.color='#999999'
	document.Preventivo.cognome.style.color='#999999'
	document.Preventivo.data_start.style.color='#999999'
	document.Preventivo.data_end.style.color='#999999'
	document.Preventivo.nome='nome';	
	document.Preventivo.cognome='cognome'
	document.Preventivo.add_start.value='';
	document.Preventivo.add_end.value='';
	document.Preventivo.data_start.value='gg/mm/aaaa';
	document.Preventivo.data_end.value='gg/mm/aaaa';
	document.Preventivo.city_start.value='';
	document.Preventivo.city_end.value='';
}


function dataStartInit()
{
	var dtinit=new Date();
	var dtinit_Day=dtinit.getDate();
	var dtinit_Month=dtinit.getMonth();
	var dtinit_Year=dtinit.getFullYear();
	dtinit_Month=dtinit_Month+1;
	document.Preventivo.data_start.value=dtinit_Day+"/"+dtinit_Month+"/"+dtinit_Year;
	
}


function data_startf()
{

	var dt=document.Preventivo.data_start.value;
	var pattern= new RegExp ("(\\d{2})*(\\/)*(\\d{2})*(\\/)*(\\d{4})");
	var result;
	if((result=pattern.exec(dt))!=null)
	{
		var dtsc=new Date();
		var dtsc_Day=dtsc.getDate();
		var dtsc_Month=dtsc.getMonth();
		var dtsc_Year=dtsc.getFullYear();
		var dts = dt.split("/");
		var day=dts[0];
		var month=dts[1];
		var year=dts[2];
		dtsc_Month=dtsc_Month+1;
		if(year<dtsc_Year)
		{
		alert('Anno Antecedente');
		document.Preventivo.data_start.focus();
		document.Preventivo.data_start.value='gg/mm/aaaa';
		return false;
		}
			
		else if ((day<dtsc_Day&&month<=dtsc_Month)&&(year<=dtsc_Year))
		{
			alert('Giorno Antecedente');
			document.Preventivo.data_start.focus();
			document.Preventivo.data_start.value='gg/mm/aaaa';
			return false;
			
			
		}
		
		else if (month<dtsc_Month&&year<=dtsc_Year)
		{
				alert('Mese Antecedente');
				document.Preventivo.data_start.focus();
				document.Preventivo.data_start.value='gg/mm/aaaa';
				return false;
			
			
		}
		
		
	}
	else if ((result=pattern.exec(dt))=="gg/mm/aaaa"|| dt=="undefined")
	{
		alert('Campo Data Obbligatorio');
		
		document.Preventivo.data_start.focus();
		document.Preventivo.data_start.value='gg/mm/aaaa';
		return false;
		
	}
	
	
	var pattern_alfa= new RegExp("[a-zA-Z]");
	if(result=pattern_alfa(dt)!=null)
	{
		alert('formato data sbagliato');
		document.Preventivo.data_start.focus();
		document.Preventivo.data_start.value='gg/mm/aaaa';
		return false;
	}

var mese= new Array ();
mese[0]=31;
mese[1]=28;
mese[2]=31;
mese[3]=30;
mese[4]=31;
mese[5]=30;
mese[6]=31;
mese[7]=31;
mese[8]=30;
mese[9]=31;
mese[10]=30;
mese[11]=31;
var yearBis=year/4;
if(yearBis==503 || yearBis==504 || yearBis==505 || yearBis==506 || yearBis == 507 || yearBis== 508 || yearBis == 509 || yearBis ==510)
{
	mese[1]=29;
}

if(month>12)
{
	alert('il mese non esiste')
	document.Preventivo.data_start.focus();
	document.Preventivo.data_start.value='gg/mm/aaaa';
	return false;
}

month=month-1;

var daymax=mese[month];

if(day>daymax || day==00)
{
	alert('il giorno non esiste')
	document.Preventivo.data_start.focus();
	document.Preventivo.data_start.value='gg/mm/aaaa';
	return false;
}


}


function data_starte()
{

	var dte=document.Preventivo.data_end.value;
	var pattern= new RegExp ("(\\d{2})*(\\/)*(\\d{2})*(\\/)*(\\d{4})");
	var result;
	var dtse=new Date();
	var dtse_Day=dtse.getDate();
	var dtse_Month=dtse.getMonth();
	var dtse_Year=dtse.getFullYear();
	var dtsend = dte.split("/");
	var daye=dtsend[0];
	var monthe=dtsend[1];
	var yeare=dtsend[2];
	var dt=document.Preventivo.data_start.value;
	var dts = dt.split("/");
	var day=dts[0];
	var month=dts[1];
	var year=dts[2];
	
	if((result=pattern.exec(dte))!=null)
	{
		
		 if ((result=pattern.exec(dte))=="gg/mm/aaaa"|| dte=="undefined" )
		{
			alert('Campo Data Obbligatorio');
		
			document.Preventivo.data_end.focus();
			document.Preventivo.data_end.value='gg/mm/aaaa';
			return false;
		
		}
		
		else if(yeare<year)
		{
			alert('Anno di arrivo antecedente a quello di partenza');
			
			document.Preventivo.data_end.focus();
			document.Preventivo.data_end.value='gg/mm/aaaa';
			return false;
		}
		
		else if(((daye<day)&&(monthe<=month))&&(yeare<=year))
		{
			alert('Giorno di arrivo antecedente a quella di partenza');
			
			document.Preventivo.data_end.focus();
			document.Preventivo.data_end.value='gg/mm/aaaa';
			return false;
		}
		else if ((monthe<month)&&(yeare<=year))
		{
			alert('Mese di arrivo antecedente a quella di partenza');
			
			document.Preventivo.data_end.focus();
			document.Preventivo.data_end.value='gg/mm/aaaa';
			return false;
		}		
		
	}

	var pattern_alfa= new RegExp("[a-zA-Z]");
	if(result=pattern_alfa(dte)!=null)
	{
		alert('formato data sbagliato');
		document.Preventivo.data_end.focus();
		document.Preventivo.data_end.value='gg/mm/aaaa';
		return false;
	}


	var mese_end= new Array ();
	mese_end[0]=31;
	mese_end[1]=28;
	mese_end[2]=31;
	mese_end[3]=30;
	mese_end[4]=31;
	mese_end[5]=30;
	mese_end[6]=31;
	mese_end[7]=31;
	mese_end[8]=30;
	mese_end[9]=31;
	mese_end[10]=30;
	mese_end[11]=31;
	var yearBis_end=year/4;
	if(yearBis_end==503 || yearBis_end==504 || yearBis_end==505 || yearBis_end==506 || yearBis_end== 507 || yearBis_end== 508 || yearBis_end== 509 || yearBis_end==510)
	{
		mese_end[1]=29;
	}

	if(month>12)
	{
		alert('il mese non esiste')
				document.Preventivo.data_start.focus();
		document.Preventivo.data_start.value='gg/mm/aaaa';
		return false;
	}

	month=month-1;

	var daymax_end=mese_end[month];

	if(day>daymax_end || day==00)
	{
		alert('il giorno non esiste')
				document.Preventivo.data_start.focus();
		document.Preventivo.data_start.value='gg/mm/aaaa';
		return false;
	
	
        }
}









function copydate()
{
	var num_dat=document.Preventivo.data_start.value;
	document.Preventivo.data_end.value=num_dat;
}

function nomef()

{

var nome=document.Preventivo.nome.value;
var nome2=new RegExp("\\d","g");
var nome3="";

if ((nome == "") || (nome == "undefined") || (nome == "nome")) 
  {
	  alert("Il campo Nome e' obbligatorio.");
	  document.Preventivo.nome.value="";
	  document.Preventivo.nome.focus();
	  return false;
  }

  else if((nome3=nome2.exec(nome))!=null)
  {
	  alert ('Il nome contiene numeri');	 
	  document.Preventivo.nome.focus();
	  document.Preventivo.nome.value="";
	  return false;
  }
  
}

function cognomef()

{

	var cognome=document.Preventivo.cognome.value;
	var cognome2=new RegExp("\\d","g");
	var cognome3="";

	if ((cognome == "") || (cognome == "undefined") || (cognome=="cognome")) 
	{
		alert("Il campo Cognome e' obbligatorio.");
		document.Preventivo.cognome.value="";
		document.Preventivo.cognome.focus();
		return false;
	}

	else if((cognome3=cognome2.exec(cognome))!=null)
	{
		alert ("Il cognome contiene numeri");	 
		document.Preventivo.cognome.focus();
		document.Preventivo.cognome.value="";
		return false;
	}

}
function emailf()
{
	var email=document.Preventivo.from.value;
	/*var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;*/
	var email_reg_exp = new RegExp("(\\w)+(\\@)+(\\w)+(\\.)+(\\w)");
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert("Inserire un indirizzo email corretto.");
		document.Preventivo.from.focus();
		return false;
	}

}

function cityf()
{

		var city=document.Preventivo.city_start.value;
		var city2=new RegExp("\\d","g");
		var city3="";

		if ((city == "") || (city == "undefined")) 
		{
			alert("Il campo Citta' di Partenza e' obbligatorio.");
			document.Preventivo.city_start.value="";
			document.Preventivo.city_start.focus();
			return false;
		}

		else if((city3=city2.exec(city))!=null)
		{
			alert ("La citta' di partenza contiene numeri");	 
			document.Preventivo.city_start.focus();
			document.Preventivo.city_start.value="";
			return false;
		}


}

function citye()
{

	var citye=document.Preventivo.city_end.value;
	var city2e=new RegExp("\\d","g");
	var city3e="";

	if ((citye == "") || (citye == "undefined")) 
	{
		alert("Il campo Citta' di Arrivo e' obbligatorio.");
		document.Preventivo.city_end.value="";
		document.Preventivo.city_end.focus();
		return false;
	}

	else if((city3e=city2e.exec(citye))!=null)
	{
		alert ("La citta' di arrivo contiene numeri");	 
		document.Preventivo.city_end.focus();
		document.Preventivo.city_end.value="";
		return false;
	}


}






function invio()
{
	var nome=document.Preventivo.nome.value;
	var nome2=new RegExp("\\d","g");
	var nome3="";
	var cognome=document.Preventivo.cognome.value;
	var cognome2=new RegExp("\\d","g");
	var cognome3="";
	var email=document.Preventivo.from.value;
	var email_reg_exp = new RegExp("(\\w)+(\\@)+(\\w)+(\\.)+(\\w)");
	var city=document.Preventivo.city_start.value;
	var city2=new RegExp("\\d","g");
	var city3="";
	var dt=document.Preventivo.data_start.value;
	var pattern= new RegExp ("(\\d{2})*(\\/)*(\\d{2})*(\\/)*(\\d{4})");
	var pattern_alfa= new RegExp("[a-zA-Z]");
	var result;
	var dtsc=new Date();
	var dtsc_Day=dtsc.getDay();
	var dtsc_Month=dtsc.getMonth();
	var dtsc_Year=dtsc.getFullYear();
	var dts = dt.split("/");
	var day=dts[0];
	var month=dts[1];
	var year=dts[2];
	var dte=document.Preventivo.data_end.value;
	var pattern= new RegExp ("(\\d{2})*(\\/)*(\\d{2})*(\\/)*(\\d{4})");
	var result;
	var dtse=new Date();
	var dtse_Day=dtse.getDate();
	var dtse_Month=dtse.getMonth();
	var dtse_Year=dtse.getFullYear();
	var dtsend = dte.split("/");
	var daye=dtsend[0];
	var monthe=dtsend[1];
	var yeare=dtsend[2];
	var citye=document.Preventivo.city_end.value;
	var city2e=new RegExp("\\d","g");
	var city3e="";
	
	if ((nome == "") || (nome == "undefined") || (nome == "nome"))
	{
		alert("Il campo Nome e' obbligatorio.");
		document.Preventivo.nome.focus();
		return false;
	}

	else if((nome3=nome2.exec(nome))!=null)
	{
		alert ('Il nome contiene numeri');	 
		document.Preventivo.nome.focus();
		return false;
	}
	else if ((cognome == "") || (cognome == "undefined") || (cognome=="cognome")) 
	{
		alert("Il campo Cognome e' obbligatorio.");
		document.Preventivo.cognome.focus()
		return false;
	}

	else if((cognome3=cognome2.exec(cognome))!=null)
	{
		alert ("Il cognome contiene numeri");	 
		document.Preventivo.cognome.focus()
		return false;
	}
	
	else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) 
	{
		alert("Inserire un indirizzo email corretto.");
		document.Preventivo.from.focus()
		return false;
	}

	
	else if ((city == "") || (city == "undefined")) 
	{
		alert("Il campo Citta' di Partenza e' obbligatorio.");
		document.Preventivo.city_start.focus();
		return false;
	}

	else if((city3=city2.exec(city))!=null)
	{
		alert ("La citta' di partenza contiene numeri");	 
		document.Preventivo.city_start.focus();
		return false;
	}
	

	else if ((result=pattern.exec(dt))=="gg/mm/aaaa"|| dt=="undefined" )
	{
		alert('Campo Data Obbligatorio');
		
		document.Preventivo.data_start.focus();
		document.Preventivo.data_start.value='gg/mm/aaaa';
		return false;
		
	}


	else if(year<dtsc_Year)
		{
			alert('Anno Antecedente');
			document.Preventivo.data_start.focus();
			document.Preventivo.data_start.value='gg/mm/aaaa';
			return false;
		}
			
		else if ((day<dtsc_Day&&month<=dtsc_Month)&&(year<=dtsc_Year))
		{
			alert('Giorno Antecedente');
			document.Preventivo.data_start.focus();
			document.Preventivo.data_start.value='gg/mm/aaaa';
			return false;
			
			
		}
		
		else if (month<dtsc_Month&&year<=dtsc_Year)
		{
			alert('Mese Antecedente');
			document.Preventivo.data_start.focus();
			document.Preventivo.data_start.value='gg/mm/aaaa';
			return false;
			
			
		}
		
		
	

	
	
	
	else if(result=pattern_alfa(dt)!=null)
	{
		alert('formato data sbagliato');
		document.Preventivo.data_start.focus();
		document.Preventivo.data_start.value='gg/mm/aaaa';
		return false;
	}

	else	if ((result=pattern.exec(dte))=="gg/mm/aaaa"|| dte=="undefined" )
		{
			alert('Campo Data Obbligatorio');
		
			document.Preventivo.data_end.focus();
			document.Preventivo.data_end.value='gg/mm/aaaa';
			return false;
		
		}
		
		else if(yeare<year)
		{
			alert('Anno di arrivo antecedente a quello di partenza');
			
			document.Preventivo.data_end.focus();
			document.Preventivo.data_end.value='gg/mm/aaaa';
			return false;
		}
		else if(((daye<day)&&(monthe<=month))&&(yeare<=year))
		{
			alert('Giorno di arrivo antecedente a quella di partenza');
			
			document.Preventivo.data_end.focus();
			document.Preventivo.data_end.value='gg/mm/aaaa';
			return false;
		}
		else if ((monthe<month)&&(yeare<=year))
		{
			alert('Mese di arrivo antecedente a quella di partenza');
			
			document.Preventivo.data_end.focus();
			document.Preventivo.data_end.value='gg/mm/aaaa';
			return false;
		}		
		
	

	
	else if(result=pattern_alfa(dte)!=null)
	{
		alert('formato data sbagliato');
		document.Preventivo.data_end.focus();
		document.Preventivo.data_end.value='gg/mm/aaaa';
		return false;
	}

	



	else if ((citye == "") || (citye == "undefined")) 
	{
		alert("Il campo Citta' di Arrivo e' obbligatorio.");
		document.Preventivo.city_end.value="";
		document.Preventivo.city_end.focus();
		return false;
	}

	else if((city3e=city2e.exec(citye))!=null)
	{
		alert ("La citta' di Arrivo contiene numeri");	 
		document.Preventivo.city_end.focus();
		document.Preventivo.city_end.value="";
		return false;
	}
	
	
	
	else 
	{
	        document.Preventivo.esito.value=1;
		/*document.Preventivo.submit();*/
		alert("invio email preventivo");
		
	}
}