

var sendable = false;

function checkForm()
{
   var emailRequired = new Array("@",".");
   if (document.layers) {theForm = document.layers.forms['myForm'];}
   else if (document.all) {theForm = document.all.myForm;}
   else if (document.getElementById) {theForm = document.forms['myForm'];}

//*** controllo campi obbligatori ***//
   for (i=0; i<theForm.length; i++)
   {
       var tempobj=theForm.elements[i];
       
       if (tempobj.name.substring(0,4)=="req_")
       {
            if ((tempobj.type == "text" || tempobj.type == "password" || tempobj.type == "textarea") && (tempobj.value == ""))
            {
               shortFieldName=tempobj.name.substring(4,30).toUpperCase();
               alert("Attenzione: il campo \""+shortFieldName+"\" è obbligatorio.");
               tempobj.focus();
               return false;
            }
       
//*** se "email" è obbligatorio: controllo caratteri speciali ***//
            if ((tempobj.name == "req_email"))
            {
                for (x=0; x<emailRequired.length; x++)
                {
                    if (tempobj.value.indexOf(emailRequired[x]) == -1)
                    {
                       alert("Attenzione: l'indirizzo E-MAIL non è corretto.");
                       tempobj.select();
                       tempobj.focus();
                       return false;
                    }
                }
            }
       }

//*** se "email" NON è obbligatorio: controllo caratteri speciali ***//
       else if ((tempobj.name == "email") && (tempobj.value != 0))
       {
           for (x=0; x<emailRequired.length; x++)
           {
               if (tempobj.value.indexOf(emailRequired[x]) == -1)
               {
                    alert("Attenzione: l'indirizzo E-MAIL non è corretto.");
                    tempobj.select();
                    tempobj.focus();
                    return false;
               }
           }
       }
   }

   // questa variabile serve per far decidere alla funzione sendForm() se fare il submit oppure no.
   sendable="true";
}


// Non ho potuto fare il submit del Form direttamente qui sopra (nella funz. checkForm()) perché se nell'HRef metto solo la funzione checkForm (che fa da sola il submit),
// allora quando c'è un "Return false" il "false" viene tornato appunto nell'Href, nell'URL, sicché si apre una pagina vuota con scritto "False".
// Se invece nell'HRef richiamo un'altra funzione DOPO la checkForm() [ad es. href="checkForm();sendForm();"], allora il "false" viene tornato
// non all'Href, ma a Javascript.
// D'altra parte, non potevo richiamare la funzione del Submit nell'Onclick (che quindi non avrebbe dato problemi di "return false") perché IE
// permette di fare il submit via Js solo se lo si richiama direttamente nell'attributo Href (e non in un EventHandler).
function sendForm()
{
   if (document.layers) {theForm = document.layers.forms['myForm'];}
   else if (document.all) {theForm = document.all.myForm;}
   else if (document.getElementById) {theForm = document.forms['myForm'];}

   if (sendable)
   {
      theForm.submit();
   }
}

function sendFormLogin()
{
   if (sendable)
   {
      alert('Attenzione: dati non validi!');
      location.reload();
   }
}

function confirmCanc()
{
   if (document.layers) {theForm = document.layers.forms['myForm'];}
   else if (document.all) {theForm = document.all.myForm;}
   else if (document.getElementById) {theForm = document.forms['myForm'];}

   if (confirm ('Sicuro di voler cancellare i dati del modulo?'))
   {
      theForm.reset();
   }
}