

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

INPUT:	all'invio		

DESC: consente l'invio del form con tutti i campi correttamente
      compilati
      
Autore: l.bragalone@libero.it						
====================================================================== */


function Verifica(theForm)
{
re  =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$//* imposto l'espressione*/

  if (theForm.nomecognome.value == "")
  {
    alert("Inserire il \"Nome e Cognome\".");
    theForm.nomecognome.focus();
    return (false);
  }
  

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ- \t\r\n\f";
  var checkStr = theForm.nomecognome.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 e Cognome\"! E' possibile inserire solo lettere");
    theForm.nomecognome.focus();
    theForm.nomecognome.select();
    return (false);
  }
  

  if (theForm.citta.value == "")
  {
    alert("Inserire il nome della \"Città\"");
    theForm.citta.focus();
    return (false);
  }
  
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ- \t\r\n\f";
  var checkStr = theForm.citta.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 \"Città\"! E' possibile inserire solo lettere");
    theForm.citta.focus();
    theForm.citta.select();
    return (false);
  }
  
  
  
  
   if (theForm.indirizzo.value == "")
  {
    alert("Non è stato inserito \"l'indirizzo\"");
    theForm.indirizzo.focus();
    return (false);
  } 
  
  
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789,- \t\r\n\f";
  var checkStr = theForm.indirizzo.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 \"Indirizzo\"! E' possibile inserire solo lettere e numeri");
    theForm.indirizzo.focus();
    theForm.indirizzo.select();
    return (false);
  }
  
   
  if (theForm.telefono.value == "")
  {
    alert("Il numero di \"telefono\" ci è utile per poterVi contattare rapidamente");
    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\"! E' possibile inserire solo numeri e .-_+");
    theForm.telefono.focus();
    theForm.telefono.select();
    return (false);
  }
  
 if (theForm.comunicazioni.value == "")
  {
    alert("Il campo \"Comunicazioni\" è vuoto!");
    theForm.comunicazioni.focus();
    return (false);
  }
 
 if(theForm.consenso[0].checked ==true ) {

                             alert('Per le disposizioni vigenti in materia abbiamo bisogno del 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
 
  
}

