// JavaScript Document
function Trim(StringToTrim) { 
// CONTROLLA CHE IL VALORE IN INPUT SIA DI TIPO STRING
if (typeof(StringToTrim) != "string") { return StringToTrim; }
// CATTURA IL PRIMO CARATTERE DELLA STRINGA PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO
var StringBlank = StringToTrim.substring(0, 1);
// ELIMINA LO SPAZIO VUOTO DALLA PRIMA POSIZIONE DELLA STRINGA 
while (StringBlank == " ") { 
StringToTrim = StringToTrim.substring(1, StringToTrim.length); 
StringBlank = StringToTrim.substring(0, 1);
}
// CATTURA L'ULTIMO CARATTERE DELLA STRINGA PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO 
StringBlank = StringToTrim.substring(StringToTrim.length - 1, StringToTrim.length);
// ELIMINA LO SPAZIO VUOTO DALL'ULTIMA POSIZIONE DELLA STRINGA 
while (StringBlank == " ") {
StringToTrim = StringToTrim.substring(0, StringToTrim.length-1); 
StringBlank = StringToTrim.substring(StringToTrim.length-1, StringToTrim.length); 
} 
// ELIMINA POTENZIALI SPAZI VUOTI MULTIPLI ALL'INIZIO ED ALLA FINE DI UNA STRINGA 
while (StringToTrim.indexOf(" ") != -1) {
StringToTrim = StringToTrim.substring(0, StringToTrim.indexOf(" ")); 
StringToTrim += StringToTrim.substring(StringToTrim.indexOf(" ") + 1, StringToTrim.length);
}
// RESTITUISCE IL VALORE FINALE SENZA SPAZI VUOTI DI CONTORNO 
return StringToTrim;
}


function OpenPOP_UP(strURL,top,left){
  window.open(strURL,'winpopup','width=800,height=800,status=1,scrollbars=yes');
}



function verificaForm(){
	if (Trim(formContatti.nome.value) == "")
	{
	alert("Inserire il nome")
	formContatti.nome.focus();
	return false;
	}

	if (Trim(formContatti.cognome.value) == "")
	{
	alert("Inserire il cognome")
	formContatti.cognome.focus();
	return false;
	}

	if (Trim(formContatti.email.value) == "")
	{
	alert("Inserire la mail")
	formContatti.email.focus();
	return false;
	}

	//controllo inserimento corretto mail
	var x = formContatti.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) ;
	else
	{
		alert("L'indirizzo mail inserito non è corretto");
		return false;
	}

	
}


function verificaModuloOfferte(form) {
	var controlli
	controlli = true
	
	/*if (Trim(form.aereoporto.value) == "")
	{
	alert("Inserire l\'aereoporto di partenza")
	form.aereoporto.focus();
	controlli =  false;
	return false
	}*/
	
	if (Trim(form.nome.value) == "")
	{
	alert("Inserire il nome")
	form.nome.focus();
	controlli =  false;
	return false
	}

	if (Trim(form.Cognome.value) == "")
	{
	alert("Inserire il cognome")
	form.Cognome.focus();
	controlli =  false;
	return false
	}

	if (form.Mail.value == "")
	{
	alert("Inserire la mail")
	form.Mail.focus();
	controlli =  false;
	return false
	}


	//controllo inserimento corretto mail
	var x = form.Mail.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) ;
	else 
	{
		alert("L'indirizzo mail inserito non è corretto");
		controlli =  false;
		return false
	}
	
		if (form.Indirizzo.value == "")
	{
	alert("Inserire l'indirizzo")
	form.Indirizzo.focus();
	controlli =  false;
	return false
	}

	
	if (form.Telefono.value == "")
	{
	alert("Inserire il telefono")
	form.Telefono.focus();
	controlli =  false;
	return false
	}
	
}

