// JavaScript Document

function ControllaForm()

{

 var controllo=false;

var conta = 0;

 var email=true;

 var browserselezionato=true;
 var come=false;

 var uso=true;

 var testo = "ERRORE!:\n\n";


// Funzioni per il controllo della correttezza dei dati inseriti
 function isNumber(strInput)
 {
 var re = new RegExp("^([0-9]{1,})$");
 if (!re.test(strInput))
 return false

 return true;
 }

 function isName(strInput)
 {
var re = new RegExp("^([a-zA-Z\ ]{2,})$");
 if (!re.test(strInput))
 {
 return false;
 }
 return true;
 }


 function isValidHomeNumber(strInput)
 {
 var i = new RegExp("^0.{6,}$");
if (!i.test(strInput))
 {
 return false;
}
return true;
}

 function isValidMobileNumber(strInput)
 {
 var i = new RegExp("^3.{6,}$");
 if (!i.test(strInput))
 {
 return false;
 }
 return true;
 }

 function isEmail(strInput)
 {
 var i = new

 RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
 if (!i.test(strInput))
 {
 return false;
 }
 return true;
 }

// Controllo

 if ( ( document.dati.nome.value == "" ) || isNumber(document.dati.nome.value) )
 {
 controllo=true;
 testo = testo+"- Il campo Nome e' necessario\n";
}

 if ( ( document.dati.cognome.value == "" ) || isNumber(document.dati.cognome.value) )
 {
 controllo=true;
 testo = testo+"- Il campo Cognome e' necessario\n";
}

if ( !isEmail(document.dati.email.value) )
 {
 controllo=true;
 testo = testo+"- Il campo E-mail e' necessario e dev'essere un indirizzo valido\n";
 }

 if ( !isValidHomeNumber(document.dati.telefono.value) )
 {
 controllo=true;
 testo = testo+"- Il campo Telefono e' necessario e dev'essere numerico\n";
 }

if (!document.dati.AutorizzazioneTrDati.checked )
 {
 controllo=true;
 testo = testo+"- E' necessario selezionare il check della privacy\n";
 }

 var sms = document.getElementById("si");
 if (sms.checked && !isValidMobileNumber(document.dati.cellulare.value) )
 {
 controllo=true;
 testo = testo+"- Il campo Cellulare e' necessario e dev'essere numerico se vuoi ricevere materiale pubblicitario o informativo via SMS\n";
}

// Fine controllo



if (controllo){

 testo = testo+"- - - Grazie\n";



 alert(testo);

return false;}

else if(!Wait_invia()) {return false}

else {return true}

}


var click_count=0; // First time switch to stop multiple clicks

function Wait_invia() {

 click_count++;

 if (click_count == 1) return true;

 else {

alert("Attendere! invio dati in corso.");

return false;

 }

}



