
//**********************
// Validità Campo Empty
//**********************
function TestEmpty (Ctrl,msg)
 {if (Ctrl.value == "")
   {alert (msg);
    Ctrl.focus();
    return (false);
   }
  else
   return (true);   
 }

function TestEmail (Ctrl)
 {
  if (Ctrl.value == "")
   {alert ("Inserire l'e-mail!");
    Ctrl.focus();
    return (false);
   }
    
  //deve esserci una sola @
  pos=Ctrl.value.indexOf('@', 0)
  if (pos == 0)
   {alert ("Insert e-mail!!");
    Ctrl.focus();
    return (false);
   }

  if (pos == -1) 
   {alert ("Insert e-mail!!");
    Ctrl.focus();
    return (false);
   }
  else
   {if (Ctrl.value.indexOf('@', pos+1) != -1)
    {alert ("Insert e-mail!!");
     Ctrl.focus();
     return (false);
    }
   }

  //devono esserci almeno 4 caratteri dopo @
  if (Ctrl.value.substring(pos+1,Ctrl.value.length).length < 4)
   {alert ("Insert e-mail!!");
    Ctrl.focus();
    return (false);
   }

  //deve esserci almeno un . dopo @
  if (Ctrl.value.indexOf('.', pos+1) == -1)      
   {alert ("Insert e-mail!!");
    Ctrl.focus();
    return (false);
   }

  //devono esserci almeno 2 caratteri dopo .
  pos=Ctrl.value.indexOf('.', pos+1);
  if (Ctrl.value.substring(pos+1,Ctrl.value.length).length < 2)
   {alert ("Insert e-mail!!");
    Ctrl.focus();
    return (false);
   }

  //caratteri ammessi
  stremail=Ctrl.value.toUpperCase()
  for (var i = 0; i < stremail.length; i++)
   {if (".-_0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(stremail.charAt(i)) == -1) 
    {alert ("Insert e-mail correctly!!");
     Ctrl.focus();
     return (false);
    }
   }
  //Tutto OK
  return (true);   
 }


// Validità trattamento
// =============
function TestTrattamento()
  {
   if (document.form1.autorizzo.checked) return (true)
     alert('To sent this request, it is necessary to agree to the treatment of personal data!');
     document.form1.autorizzo.focus();
     return (false);
  }

function runSubmit()
  {
   //Eventuali test sull'input
   if (!TestEmpty(document.form1.ragionesociale,"The field Company's name has to be filled!")) return;
   if (!TestEmpty(document.form1.nome,'The field Name and Surname has to be filled!')) return;
   if (!TestEmpty(document.form1.indirizzo,"The field Address has to be filled!")) return;
   if (!TestEmpty(document.form1.citta,"The field City has to be filled!")) return;
   if (!TestEmpty(document.form1.telefono,"The field Phone number has to be filled!")) return;
   if (!TestEmail(document.form1.email)) return;
   if (!TestEmpty(document.form1.messaggio,"The field Message has to be filled!")) return;
   if (!TestTrattamento()) return;
   document.form1.submit();

  }
