
function autoSelect(selectTarget) {
 	if(selectTarget != null && ((selectTarget.childNodes.length == 1
      && selectTarget.childNodes[0].nodeName == "#text") || (selectTarget.tagName == "INPUT"
      && selectTarget.type == "text"))) {
  		if(selectTarget.tagName == 'TEXTAREA' || (selectTarget.tagName == "INPUT" && selectTarget.type == "text")) {
  			 selectTarget.select();
  		} 
 		}
	}
/*  FORM */
function emailvalidation(entered, alertbox)
{
with (entered)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

function emptyvalidation(entered, alertbox)
{
with (entered)
{
if (value==null || value=="" || value.search("#") != -1)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

function checkboxvalidation(entered, alertbox)
{
with (entered)
{
if (checked == false)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function valbutton(entered, alertbox) {
myOption = -1;
for (i=entered.length-1; i > -1; i--) {
	if (entered[i].checked) {
	myOption = i; i = -1;
	}
}
if (myOption == -1) {alert(alertbox);return false;}
else {return true;}
}

// editare solo questa funzione
function validaRichiesta(thisform)
{
with (thisform)
{
if (emptyvalidation(nome,"Compilare tutti i campi #Nome")==false) {autoSelect(nome); return false;};
if (emptyvalidation(cognome,"Compilare tutti i campi #Cognome")==false) {autoSelect(cognome); return false;};
//if (emptyvalidation(indirizzo,"Compilare tutti i campi")==false) {indirizzo.focus(); return false;};
if (emailvalidation(email,"Indirizzo e-mail non valido")==false) {autoSelect(email); return false;};
if (emptyvalidation(tel,"Compilare tutti i campi #Telefono")==false) {autoSelect(tel); return false;};
if (checkboxvalidation(autorizzo1,"Per proseguire autorizzare il trattamento dei dati personali")==false) {autorizzo1.focus(); return false;};

}

}

function validaRichiesta1(thisform)
{
with (thisform)
{
if (emptyvalidation(nome,"Compilare tutti i campi #Nome")==false) {autoSelect(nome); return false;};
if (emptyvalidation(cognome,"Compilare tutti i campi #Cognome")==false) {autoSelect(cognome); return false;};
if (valbutton(co,"Cerchi o Offri?")==false) {return false;};
if (emptyvalidation(locale,"Compilare tutti i campi #Tipologia di Locale")==false) {autoSelect(locale); return false;};
if (emptyvalidation(tel,"Compilare tutti i campi #Telefono")==false) {autoSelect(tel); return false;};
if (emailvalidation(email,"Indirizzo e-mail non valido")==false) {autoSelect(email); return false;};
if (checkboxvalidation(autorizzo1,"Per proseguire autorizzare il trattamento dei dati personali")==false) {autorizzo1.focus(); return false;};
}
}

function validaRichiesta2(thisform)
{
with (thisform)
{
	if (emptyvalidation(nome,"Compilare tutti i campi #Nome")==false) {autoSelect(nome); return false;};
if (emptyvalidation(cognome,"Compilare tutti i campi #Cognome")==false) {autoSelect(cognome); return false;};
if (valbutton(co,"Vuoi diventare o cerchi un agente?")==false) {return false;};
if (emptyvalidation(settore1,"Compilare tutti i campi #Settore commerciale")==false) {autoSelect(settore1); return false;};
if (emptyvalidation(zona,"Compilare tutti i campi #Zona geografica")==false) {autoSelect(zona); return false;};
if (emptyvalidation(tel,"Compilare tutti i campi #Telefono")==false) {autoSelect(tel); return false;};
if (emailvalidation(email,"Indirizzo e-mail non valido")==false) {autoSelect(email); return false;};
if (checkboxvalidation(autorizzo1,"Per proseguire autorizzare il trattamento dei dati personali")==false) {autorizzo1.focus(); return false;};
}
}

function validaRichiesta3(thisform)
{
with (thisform)
{
	if (emptyvalidation(nome,"Compilare tutti i campi #Nome")==false) {autoSelect(nome); return false;};
if (emptyvalidation(cognome,"Compilare tutti i campi #Cognome")==false) {autoSelect(cognome); return false;};
if (emptyvalidation(tel,"Compilare tutti i campi #Telefono")==false) {autoSelect(tel); return false;};
if (emailvalidation(email,"Indirizzo e-mail non valido")==false) {autoSelect(email); return false;};
if (checkboxvalidation(autorizzo1,"Per proseguire autorizzare il trattamento dei dati personali")==false) {autorizzo1.focus(); return false;};
}
}
