// Function for Email validation
function ValidaEmail(Email){
  var LastChar = Email.length - 1;
  var CharPos = Email.indexOf("@");
  if ((CharPos < 1) || (CharPos == LastChar)) return false;
  // position of first .
  var CharPos = Email.indexOf(".");
  if (CharPos < 1) return false;
  // position of last .
  var CharPos = Email.lastIndexOf(".");
  if (CharPos == LastChar) return false;
  return true;
}

function isAlphaNumeric(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is a number or letter.
        //var c = s.charAt(i);
        var c = s.charCodeAt(i);
        //if ((c < "0") || ((c > "9") && (c < "A")) || ((c > "Z") < (c < "a")) || (c > "z")) return false;
        if ((c < 48) || ((c > 57) && (c < 65)) || ((c > 90) && (c < 97)) || (c > 122)) return false;
    }
    // All characters are numbers.
    return true;
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function countAreaChars(areaName,counter,limit)
{
if (areaName.value.length>limit)
areaName.value=areaName.value.substring(0,limit);
else
counter.value = limit - areaName.value.length;
}


function CheckSubsForm(theForm)
{
   if (theForm.Ragionesociale.value == "")
  {
    alert("Prego inserire la ragione sociale");
    theForm.Ragionesociale.focus();
    return (false);
  }
  
  

   if (theForm.aziendaTipo.value == "0")
  {
    alert("Prego specificare il tipo di azienda");
    theForm.aziendaTipo.focus();
    return (false);
  }
   if (theForm.iva.value.length < 11)
  {
    alert("Prego inserire un numero partita iva valido");
    theForm.iva.focus();
    return (false);
  }
   if (theForm.dipendenti.value == "0")
  {
    alert("Prego specificare il numero di dipendenti");
    theForm.dipendenti.focus();
    return (false);
  }
   if (theForm.settoreAttivita.value == "0")
  {
    alert("Prego specificare il settore attivitą");
    theForm.settoreAttivita.focus();
    return (false);
  }
   if (theForm.fatturato.value == "0")
  {
    alert("Prego specificare il fatturato");
    theForm.fatturato.focus();
    return (false);
  }


   if (theForm.indirizzo.value == "")
  {
    alert("Prego inserire l'indirizzo dell'azienda");
    theForm.indirizzo.focus();
    return (false);
  }

   if (theForm.citta.value == "")
  {
    alert("Prego specificare la cittą");
    theForm.citta.focus();
    return (false);
  }


   if (theForm.provincia.value == "0")
  {
    alert("Prego specificare la provincia");
    theForm.provincia.focus();
    return (false);
  }
  

   if (theForm.cap.value.length != 5) 
  {
  	alert("Prego specificare il C.A.P.");
    theForm.cap.focus();
    return (false);
  }

   if (!isInteger(theForm.cap.value)) 
  {
  	alert("Prego specificare correttamente il C.A.P.");
    theForm.cap.focus();
    return (false);
  }


   if (theForm.centralino.value == "")
  {
    alert("Prego specificare il numero di centralino");
    theForm.centralino.focus();
    return (false);
  }

   if (theForm.emailinfo.value == "")
  {
    alert("Prego inserire l'indirizzo email dell'azienda");
    theForm.emailinfo.focus();
    return (false);
  }
  if (!ValidaEmail(theForm.emailinfo.value))
  {
    alert("Prego inserire un dato valido nel campo Email dell'azienda");
    theForm.emailinfo.focus();
    return (false);
  }




 if (theForm.nome.value == "")
  {
    alert("Prego inserire il suo nome");
    theForm.nome.focus();
    return (false);
  }
   if (theForm.cognome.value == "")
  {
    alert("Prego inserire il suo cognome");
    theForm.cognome.focus();
    return (false);
  }
  
   if (theForm.email.value == "")
  {
    alert("Prego inserire il suo indirizzo email");
    theForm.email.focus();
    return (false);
  }
  if (!ValidaEmail(theForm.email.value))
  {
    alert("Prego inserire un dato valido nel campo Email");
    theForm.email.focus();
    return (false);
  }


   if ((theForm.email.value.indexOf("@virgilio.it") > -1) ||
(theForm.email.value.indexOf("@email.it") > -1) ||
(theForm.email.value.indexOf("@libero.it") > -1) ||
(theForm.email.value.indexOf("@tin.it") > -1) ||
(theForm.email.value.indexOf("@gmail.com") > -1) ||
(theForm.email.value.indexOf("@msn.it") > -1) ||
(theForm.email.value.indexOf("@msn.com") > -1) ||
(theForm.email.value.indexOf("@hotmail.it") > -1) ||
(theForm.email.value.indexOf("@hotmail.com") > -1) ||
(theForm.email.value.indexOf("@fastwebnet.it") > -1) ||
(theForm.email.value.indexOf("@tiscali.it") > -1) ||
(theForm.email.value.indexOf("@tiscalinet.it") > -1) ||
(theForm.email.value.indexOf("@yahoo.it") > -1) ||
(theForm.email.value.indexOf("@tele2.it") > -1) ||
(theForm.email.value.indexOf("@alice.it") > -1))
  {
    alert("Non sono accettati indirizzi email privati (@virgilio.it, @gmail.com, @libero.it, ecc.)");
    theForm.email.focus();
    return (false);
  }

 if (theForm.ruolo.value == "")
  {
    alert("Prego specificare il suo ruolo aziendale");
    theForm.ruolo.focus();
    return (false);
  }  

   if (theForm.telefono.value == "")
  {
    alert("Prego specificare il numero di telefono");
    theForm.telefono.focus();
    return (false);
  }


   if (theForm.password.value.length < 6)
  {
    alert("Prego inserire una password di almeno 6 caratteri");
    theForm.password.focus();
    return (false);
  }

   if (!isAlphaNumeric(theForm.password.value))
  {
    alert("Prego inserire una password composta solo di lettere e numeri");
    theForm.password.focus();
    return (false);
  }

   if (theForm.passwordcheck.value != theForm.password.value)
  {
    alert("Le password non coincidono. Inserire nuovamente le password.");
    theForm.passwordcheck.focus();
    return (false);
  }


  var radioSelected = false;
  for (i = 0;  i < theForm.Provenienteda.length;  i++)
  {
    if (theForm.Provenienteda[i].checked)
        radioSelected = true;
  }

  if (!radioSelected)
  {
    alert("Prego selezionare una opzione per indicare come avete conosciuto Eccellere.");
    return (false);
  }
  
   if (theForm.accettazione.value == "No")
  {
    alert("Non possiamo procedere alla registrazione se non dichiara di aver letto e di acconsentire al trattamento dei dati aziendali e di accettare i termini del contratto.");
    theForm.accettazione.focus();
    return (false);
  }



return (true);
}






function Checkpwd(theForm)
{

   if (theForm.password.value.length < 6)
  {
    alert("Prego inserire una password di almeno 6 caratteri");
    theForm.password.focus();
    return (false);
  }

   if (!isAlphaNumeric(theForm.password.value))
  {
    alert("Prego inserire una password composta solo di lettere e numeri");
    theForm.password.focus();
    return (false);
  }

   if (theForm.passwordcheck.value != theForm.password.value)
  {
    alert("Le password non coincidono. Inserire nuovamente le password.");
    theForm.passwordcheck.focus();
    return (false);
  }


return (true);
}

