// JavaScript Document

function svuota()
{
document.form1.note.value="Note:";
}


  
function controllo_richiesta(lingua) {
var themessage = "Compilare i seguenti campi ";
var themessage_ted = "Notwendige Angaben ";
var themessage_ing = "Fill the fields";
var messaggio_in_lingua="";

if (document.form1.nome_cliente.value=="") {
	themessage = themessage + "\n - Nome ";
	themessage_ted = themessage_ted + "\n - Vorname ";
	themessage_ing = themessage_ing + "\n - Name ";
}

if (document.form1.mail.value=="") {
themessage = themessage + "\n - e-mail";
themessage_ted = themessage_ted + "\n - E-Mail";
themessage_ing = themessage_ing + "\n - e-mail";
} else if (document.form1.mail.value.indexOf('@') <1) {
	themessage = themessage + "\n - e-mail corretta";
	themessage_ted = themessage_ted + "\n - E-Mail korrekt";
	themessage_ing = themessage_ing + "\n - correct e-mail";
	}
	else if (document.form1.mail.value.indexOf('.') <4) {
		themessage = themessage + "\n - e-mail corretta";
		themessage_ted = themessage_ted + "\n - E-Mail korrekt";
		themessage_ing = themessage_ing + "\n - correct e-mail";
	}

if (differenza_in_giorni()<=0) {
	themessage = themessage + "\n - Inserire le date corrette";
	themessage_ted = themessage_ted + "\n - An-und Abreise zu korrigieren";
	themessage_ing = themessage_ing + "\n - correct dates";

}


//alert if fields are empty and cancel form submit
if (themessage == "Compilare i seguenti campi ") {
	document.form1.submit();
	//if(document.getElementById('grazie_mailing'))
	//	document.getElementById('grazie_mailing').innerHTML="Invio richiesta in corso<br><br>Attendere prego";
		
	
}
else {
	switch(lingua){
		case 'ted': messaggio_in_lingua=themessage_ted; break;
		case 'rus': 
		case 'ing': messaggio_in_lingua=themessage_ing; break;
		default: messaggio_in_lingua=themessage; break;
	} 
	
	alert(messaggio_in_lingua);
return false;
   }

}


function controllo_richiesta_ing() {
	controllo_richiesta('ing');
/*
var themessage = "Fill the fields";

if (document.form1.nome_cliente.value=="") {
themessage = themessage + "\n - Name ";
}
if (document.form1.cognome_cliente.value=="") {
themessage = themessage + "\n - Surname";
}

if (document.form1.mail.value=="") {
themessage = themessage + "\n - e-mail";
} else if (document.form1.mail.value.indexOf('@') <1) {
	themessage = themessage + "\n - correct e-mail";
	}
	else if (document.form1.mail.value.indexOf('.') <4) {
	themessage = themessage + "\n - correct e-mail";
	}

if (differenza_in_giorni()<=0) {
themessage = themessage + "\n - correct dates";
}

//alert if fields are empty and cancel form submit
if (themessage == "Fill the fields") {
	document.form1.submit();
	//if(document.getElementById('grazie_mailing'))
	//	document.getElementById('grazie_mailing').innerHTML="Invio richiesta in corso<br><br>Attendere prego";
		
	
}
else {
alert(themessage);
return false;
   }
*/
}


function differenza_in_giorni(){
dala=document.form1.dala.value;
dalm=document.form1.dalm.value;
dalg=document.form1.dalg.value;

ala=document.form1.ala.value;
alm=document.form1.alm.value;
alg=document.form1.alg.value;

dal_data = new Date( dala, dalm-1, dalg);
al_data  = new Date( ala, alm-1, alg);

return (al_data-dal_data)/86400000;

}



function verify_mail() {
var themessage = "Compilare i seguenti campi: \n\n";
var mail=document.form_mail.mail.value;
if (!mail_corretta(mail)) {	
	themessage = themessage + "    - E-mail\n";
}

//alert if fields are empty and cancel form submit

if (themessage == "Compilare i seguenti campi: \n\n") {
	document.form_mail.submit();
}
else {
alert(themessage);
}

}

function verify_cancella() {
var themessage = "Compilare i seguenti campi: \n\n";
var mail=document.form_cancella.mail.value;
if (!mail_corretta(mail)) {	
	themessage = themessage + "    - E-mail\n";
}

//alert if fields are empty and cancel form submit

if (themessage == "Compilare i seguenti campi: \n\n") {
	document.form_cancella.submit();
}
else {
alert(themessage);
}

}

function mail_corretta(mail){
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	if (!espressione.test(mail))
	{
		//alert("errore");
	    return false
	}
	return true;
}
