function valida(modulo){
    var okmail = true;
    errore="";
    cog=true;
    nom=true;
    ind=true;
    cit=true;
    ok=true;
    pers=true;
    bam=true;
    anim=true;
    da=true;
    a=true;
    
    with (modulo){
       if (cognome.value.length<1){
             errore="Campo Cognome non inserito\n";
             cog=false;
             cognome.style.backgroundColor="#ffff99";
             cognome.focus();     
       } else cognome.style.backgroundColor="#ffffff";
       
       if (nome.value.length<1){
             errore=errore+"Campo Nome non inserito\n";
             nom=false;
             nome.style.backgroundColor="#ffff99";
             nome.focus();     
       } else nome.style.backgroundColor="#ffffff";
       
       if (indirizzo.value.length<1){
             errore=errore+"Campo Indirizzo non inserito\n";
             ind=false;
             indirizzo.style.backgroundColor="#ffff99";
             indirizzo.focus();     
       } else indirizzo.style.backgroundColor="#ffffff";
       
       if (citta.value.length<1){
             errore=errore+"Campo Città non inserito\n";
             cit=false;
             citta.style.backgroundColor="#ffff99";
             citta.focus();     
       } else citta.style.backgroundColor="#ffffff";

       if (Persone.value.length<1){
             errore=errore+"Campo Numero di Persone non inserito\n";
             pers=false;
             Persone.style.backgroundColor="#ffff99";
             Persone.focus();     
       } else Persone.style.backgroundColor="#ffffff";
       
       if (Bambini.value.length<1){
             errore=errore+"Campo Numero di Bambini non inserito\n";
             bam=false;
             Bambini.style.backgroundColor="#ffff99";
             Bambini.focus();     
       } else Bambini.style.backgroundColor="#ffffff";
        
        if (Animali.value.length<1){
             errore=errore+"Campo Animali non inserito\n";
             anim=false;
             Animali.style.backgroundColor="#ffff99";
             Animali.focus();     
       } else Animali.style.backgroundColor="#ffffff";

       if (Dal.value.length<1){
             errore=errore+"Campo Periodo di interesse Dal non inserito\n";
             da=false;
             Dal.style.backgroundColor="#ffff99";
             Dal.focus();     
       } else Dal.style.backgroundColor="#ffffff";

       if (Al.value.length<1){
             errore=errore+"Campo Periodo di interesse Al non inserito\n";
             a=false;
             Al.style.backgroundColor="#ffff99";
             Al.focus();     
       } else Al.style.backgroundColor="#ffffff";      
         
       okmail = checkmail(email.value);
       if (!okmail)
          email.style.backgroundColor="#ffff99";
       else
          email.style.backgroundColor="#ffffff";
       ok = okmail;
   
       if ((!cog) | (!nom) | (!ind) | (!cit) | (!ok) | (!pers) | (!bam) | (!anim) | (!da) | (!a)){
         errore=errore+"\nDATI NON INVIATI"; 
         alert(errore); 
         cognome.focus();
        }else alert("DATI INVIATI CORRETTAMENTE");    
        return a;    
  }       
}

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;
}

function cancella(modulo){
   with (modulo){   
     cognome.value="";
     cognome.style.backgroundColor="#ffffff";
     nome.value="";
     nome.style.backgroundColor="#ffffff";
     indirizzo.value="";
     indirizzo.style.backgroundColor="#ffffff";
     citta.value="";
     citta.style.backgroundColor="#ffffff";
     Persone.value="";
     Persone.style.backgroundColor="#ffffff";
     Bambini.value="";
     Bambini.style.backgroundColor="#ffffff";
     Animali.value="";
     Animali.style.backgroundColor="#ffffff";
     Dal.value="";
     Dal.style.backgroundColor="#ffffff";
     Al.value="";
     Al.style.backgroundColor="#ffffff";
     email.value="";
     email.style.backgroundColor="#ffffff";
     cognome.focus();
   }
}
