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 controllo(){
	if (Trim(document.festival.nome.value) == "")
	{
	alert("Inserire il proprio nominativo")
	document.festival.nome.focus();
	return false;
	}
	
	if (Trim(document.festival.cognome.value) == "")
	{
	alert("Inserire il proprio cognome")
	document.festival.cognome.focus();
	return false;
	}
	
	if (Trim(document.festival.azienda.value) == "")
	{
	alert("Inserire l'azienda")
	document.festival.azienda.focus();
	return false;
	}
	
	if (Trim(document.festival.piva.value) == "")
	{
	alert("Inserire la P.IVA")
	document.festival.piva.focus();
	return false;
	}
	
	if (Trim(document.festival.attivita.value) == "0")
	{
	alert("Selezionare l\'attivitā aziendale")
	document.festival.attivita.focus();
	return false;
	}

	if (Trim(document.festival.posizione.value) == "0")
	{
	alert("Selezionare la posizione aziendale")
	document.festival.posizione.focus();
	return false;
	}

	if (Trim(document.festival.via.value) == "")
	{
	alert("Inserire la via")
	document.festival.via.focus();
	return false;
	}


	if (Trim(document.festival.cap.value) == "")
	{
	alert("Inserire il cap")
	document.festival.cap.focus();
	return false;
	}
	
	if (Trim(document.festival.citta.value) == "")
	{
	alert("Inserire la citta")
	document.festival.citta.focus();
	return false;
	}
	
	if (Trim(document.festival.nazione.value) == "")
	{
	alert("Inserire la nazione")
	document.festival.nazione.focus();
	return false;
	}
	
	if (Trim(document.festival.tel.value) == "")
	{
	alert("Inserire il telefono")
	document.festival.tel.focus();
	return false;
	}
	
	if (Trim(document.festival.interesse.value) == "")
	{
	alert("Selezione area interesse")
	document.festival.interesse.focus();
	return false;
	}
	
	
	if (Trim(document.festival.mail.value) == "")
	{
	alert("Inserire la mail")
	document.festival.mail.focus();
	return false;
	}
	

	//controllo inserimento corretto mail
	var x = festival.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");
		return false;
	}
	
	
	 if (document.festival.privacy.checked=="")	
	 {
	  alert("L'autorizzazione al trattamento dei dati personali č obbligatoria per inviare la richiesta")
	  document.festival.privacy.focus()
	  return false
	 }	

	
	
	return true;
}
// JavaScript Document