// JavaScript Document

function IsEmailValid(){
  var EmailOk = true
  var Temp = document.frmModulo.email.value;
  var AtSym = Temp.indexOf('@')
  var Period = Temp.lastIndexOf('.')
  var Space = Temp.indexOf(' ')
  var Length = Temp.length - 1
  if (Temp == "") {
    return true; }
  if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space != -1))
{
    alert("Inserire un indirizzo E-mail valido.");
    document.frmModulo.email.focus();
    EmailOk = false
  }   return EmailOk
}

function Convalida(){
  if (document.frmModulo.nome.value==""){
    alert("Inserire nome e cognome.");
    document.frmModulo.nome.focus();
    return false;
  }
  
  if (document.frmModulo.email.value==""){
    alert("Inserire l'e-mail");
    document.frmModulo.email.focus();
    return false;
  }

  if (document.frmModulo.phone.value==""){
    alert("Inserire il numero di telefono");
    document.frmModulo.phone.focus();
    return false;
  }
  
  if (document.frmModulo.luogo.value==""){
    alert("Inserire la cittą di provenienza");
    document.frmModulo.phone.focus();
    return false;
  }

    var checkOK = "0123456789-/-()";
    var checkStr = document.frmModulo.phone.value;
    var allValid = true;
    for (i = 0; i < checkStr.length; i++)
   {
      ch = checkStr.charAt(i);
      for (j = 0; j < checkOK.length; j++)
        if (ch == checkOK.charAt(j))
         break;
      if (j == checkOK.length)
     {
        allValid = false;
        break;
      }
    }
    if (!allValid)
    {
      alert("Inserire solo cifre e \"/-()\" caratteri nel campo \"Telefono\".");
      document.frmModulo.phone.focus();
      return (false);
     }

 if (document.frmModulo.subject.value==""){
    alert("Inserire l'oggetto");
    document.frmModulo.subject.focus();
    return false;
  }
  
  if (document.frmModulo.messaggio.value==""){
    alert("Inserire il messaggio da inviare");
    document.frmModulo.messaggio.focus();
    return false;
  }

if (IsEmailValid()==false){
return false;
}
return true;

}