/* ======================================================================
FUNCTION: 	convalida di un modulo

INPUT:	all'invio		

DESC: consente l'invio del form con tutti i campi correttamente
      compilati
      
Autore: luciano@bragwebdesign.com						
====================================================================== */


function Prenotazioni(theForm){
re  =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$//* imposto l'espressione*/
/* controllo nome =====================================================*/
  if (theForm.nome.value == "")
  {
    alert("Inserire il nome della persona di riferimento.");
    theForm.nome.focus();
    return (false);
  }
  

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ- \t\r\n\f";
  var checkStr = theForm.nome.value;
  var allValid = true;
  var validGroups = 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("E' stato inserito un carattere non valido nel campo \"Nome\"!\nE' possibile inserire solo lettere");
    theForm.nome.focus();
    theForm.nome.select();
    return (false);
  }
/* controllo cognome =====================================================*/  
if (theForm.cognome.value == "")
  {
    alert("Inserire il cognome della persona di riferimento.");
    theForm.cognome.focus();
    return (false);
  }
  

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ- \t\r\n\f";
  var checkStr = theForm.cognome.value;
  var allValid = true;
  var validGroups = 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("E' stato inserito un carattere non valido nel campo \"Cognome\"!\nE' possibile inserire solo lettere");
    theForm.cognome.focus();
    theForm.cognome.select();
    return (false);
  }
 /* controllo telefono =====================================================*/ 
  if (theForm.telefono.value == "")
  {
    alert("Inserire un numero di telefono: ci occorre per contattarvi in caso di necessità");
    theForm.telefono.focus();
    return (false);
  }
  
  var checkOK = "0123456789.- \t\r\n\f";
  var checkStr = theForm.telefono.value;
  var allValid = true;
  var validGroups = 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("E' stato inserito un carattere non valido nel campo \"Telefono\"!\nE' possibile inserire solo numeri");
    theForm.telefono.focus();
    theForm.telefono.select();
    return (false);
  }
 /* controllo numero ospiti =====================================================*/   
if (theForm.numeroospiti.value == "" || theForm.numeroospiti.value < "1")
  {
    alert("Il campo \"Quanti ospiti\" è vuoto \noppure è stato indicato un numero inferiore ad 1!");
    theForm.numeroospiti.focus();
    return (false);
  } 
  var checkOK = "0123456789.- \t\r\n\f";
  var checkStr = theForm.numeroospiti.value;
  var allValid = true;
  var validGroups = 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("E' stato inserito un carattere non valido nel campo \"Quanti ospiti\"!\nE' possibile inserire solo numeri");
    theForm.numeroospiti.focus();
    theForm.numeroospiti.select();
    return (false);
  }  
/* controllo camere doppie =====================================================*/
if (theForm.doppie.value == "")
  {
    alert("Il campo \"Camere doppie\" è vuoto!\nSe non vi occorrono camere doppie per cortesia inserire \"0\"");
    theForm.doppie.focus();
    return (false);
  } 
  var checkOK = "0123456789.- \t\r\n\f";
  var checkStr = theForm.doppie.value;
  var allValid = true;
  var validGroups = 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("E' stato inserito un carattere non valido nel campo \"Camere doppie\"!\nE' possibile inserire solo numeri");
    theForm.doppie.focus();
    theForm.doppie.select();
    return (false);
  }  
 /* controllo camere singole =====================================================*/ 
  if (theForm.singole.value == "")
  {
    alert("Il campo \"Camere singole\" è vuoto!\nSe non vi occorrono camere singole per cortesia inserire \"0\"");
    theForm.singole.focus();
    return (false);
  } 
  var checkOK = "0123456789.- \t\r\n\f";
  var checkStr = theForm.singole.value;
  var allValid = true;
  var validGroups = 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("E' stato inserito un carattere non valido nel campo \"Camere singole\"!\nE' possibile inserire solo numeri");
    theForm.singole.focus();
    theForm.singole.select();
    return (false);
  }   
 /* controllo incrociato numero camere =====================================================*/ 
if (theForm.singole.value < "1" && theForm.doppie.value < "1")
  {
    alert("Il campo \"Camere singole\" ed il campo \"Camere doppie\" indicano entrambi \"0\"");
    theForm.singole.focus();
    return (false);
  } 
 /* controllo consenso =====================================================*/ 
 
 if(theForm.consenso[0].checked ==true ) {

      alert('Per le disposizioni vigenti in materia abbiamo bisogno\ndel consenso al trattamento dei dati personali.');
                             return false
        if(theForm.consenso[0].checked==false)
                             return true
                           
  }     
        if(re.test(theForm.email.value)){     
                             return true
                     
    }
      alert("Indirizzo di posta elettronica non valido")
                theForm.email.focus()            
                theForm.email.select()         
                             return false  
}

