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 verificaForm(){
	if (Trim(document.preventivo.Citta1.value) == "")
	{
	alert("Inserire la cittā di destinazione")
	document.preventivo.Citta1.focus();
	return false;
	}
	if (Trim(document.preventivo.Indirizzo1.value) == "")
	{
	alert("Inserire l'indirizzo di destinazione")
	document.preventivo.Indirizzo1.focus();
	return false;
	}
	if (Trim(document.preventivo.destinatario.value) == "")
	{
	alert("Selezionare la sede di destinazione")
	document.preventivo.destinatario.focus();
	return false;
	}
	//controllo inserimento corretto mail
	var x = document.preventivo.mail.value;
	if (x == "")
	{
	alert("Inserire la mail");
	document.preventivo.mail.focus();
	return false;
	}

	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");
		document.preventivo.mail.focus();
		return false;
	}
	return true;
}

