function valida(modulo){
    var okmail = true;
    errore="";
    ok=true;
    reg=true;
    loc=true;
    cam=true;
    bag=true;
    pos=true;
    prop=true;
    prov=true;
    descr=true;

    with (modulo){  
       if (proprietario.value.length<1){
             errore=errore+"Campo Proprietario non inserito\n";
             prop=false;
             proprietario.style.backgroundColor="#ffff99";
             proprietario.focus();     
       } else proprietario.style.backgroundColor="#ffffff";


      if (maxposti.value.length<1){
             errore=errore+"Campo Posti Letto non inserito\n";
             pos=false;
             maxposti.style.backgroundColor="#ffff99";
             maxposti.focus();     
       } else maxposti.style.backgroundColor="#ffffff";



      if (bagni.value.length<1){
             errore=errore+"Campo Bagni non inserito\n";
             bag=false;
             bagni.style.backgroundColor="#ffff99";
             bagni.focus();     
       } else bagni.style.backgroundColor="#ffffff";


  
      if (camere.value.length<1){
             errore=errore+"Campo Camere non inserito\n";
             cam=false;
             camere.style.backgroundColor="#ffff99";
             camere.focus();     
       } else camere.style.backgroundColor="#ffffff";
       
       

      if (descrizione.value.length<2){
             errore=errore+"Campo Descrizione non inserito\n";
             descr=false;
             descrizione.style.backgroundColor="#ffff99";
             descrizione.focus();     
       } else descrizione.style.backgroundColor="#ffffff";
      
            

      if (localita.value.length<2){
             errore=errore+"Campo Localita non inserito\n";
             loc=false;
             localita.style.backgroundColor="#ffff99";
             localita.focus();     
       } else localita.style.backgroundColor="#ffffff";
       
           

      if (Provincia.value.length<1){
             errore=errore+"Campo Provincia non inserito\n";
             prov=false;
             Provincia.style.backgroundColor="#ffff99";
             Provincia.focus();     
       } else Provincia.style.backgroundColor="#ffffff";


      if (Regione.value.length<1){
             errore=errore+"Campo Regione non inserito\n";
             reg=false;
             Regione.style.backgroundColor="#ffff99";
             Regione.focus();     
       } else Regione.style.backgroundColor="#ffffff";

         
       okmail = checkmail(email.value);
       if (!okmail)
          email.style.backgroundColor="#ffff99";
       else
          email.style.backgroundColor="#ffffff";
       ok = okmail;
   
    
       if ((!ok) | (!cam) | (!loc) | (!bag) | (!pos) | (!prop) | (!reg) | (!prov) | (!descr)){
         errore=errore+"\nDATI NON INVIATI"; 
         alert(errore); 
     } else alert("DATI INVIATI CORRETTAMENTE");
       return ok;
  }       
}


function checkmail (email){
  var ok = true;
  var lunghezza = email.length;
  if (lunghezza == 0){
    ok = false;
    errore=errore+"Campo Email vuoto\n";
  }
  else{
  var chioc = email.search('@');
  if (chioc == -1){
    ok = false;
    errore = errore+"Manca la chiocciola\n";
  }
  else{
    var primo = email.charAt (0);
    primo = primo.toUpperCase();
    if ((primo == '@') || (primo<'A') || (primo>'Z')){
      ok = false;
      errore=errore+"Il primo carattere non puņ essere una chiocciola o un carattere non alfabetico\n";
    }
    else{
      var lun = email.length;
      var dopochioc=email.substring(chioc+1, lun);
      var lunsub=dopochioc.length;
      var chiocdopochioc=dopochioc.search('@');
      if ((lunsub < 4) || (chiocdopochioc != -1)){
        ok = false;
        errore=errore+"Dopo la chiocciola ci devono essere almeno 4 caratteri e non ci puņ essere un'altra chiocciola\n";
      }      
      else{
        var punto = dopochioc.indexOf('.');
        if (punto == -1){
          ok = false;
          errore=errore+"Manca il punto dopo la chiocciola\n";
        }
        else{
          var primo2 = dopochioc.charAt (0);
          if (primo2 == '.'){
            ok = false;
            errore=errore+"Il punto dopo la chiocciola non puņ essere in prima posizione\n";
          }
          else{
            var dopopunto=dopochioc.substring(punto+1, lunsub);
            var luntld = dopopunto.length;
            if (luntld<2){
              ok = false;
              errore=errore+"Il dominio di primo livello deve essere lungo almeno due caratteri\n";
            }
          }
        }   
      }
    }
  }
 }
  return ok;
}
