// JavaScript Document

function FrontPage_Form1_Validator(theForm) {
	
	var counter=0;
	var invalidChar = ":.;<>\"'|-_òàù+èé*§°ç@#[]!£$%&/()=?^ì";
	var invalidChar2 = "qwertyuioplkjhgfdsazxcvbnmMNBVCXZASDFGHJKLPOIUYTREWQ:.;<>\"'|-_òàù+èé*§°ç@#[]!£$%&/()=?^ì";
	var badChar;
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;

   if (theForm.nome.value == "")
		{
		alert("Campo \"Nome\" e' obbligatorio");
    theForm.nome.focus();
		return (false);
    }
	
	  if (theForm.cognome.value == "")
		{
		alert("Campo \"Cognome\" e' obbligatorio");
    theForm.cognome.focus();
		return (false);
    }
	
	
   if (theForm.regione.value == "" && theForm.nazione.value == "Italia")
		{
		alert("Campo \"Regione\" e' obbligatorio");
    theForm.regione.focus();
		return (false);
    }
	
  if (theForm.provincia.value == "" && theForm.nazione.value == "Italia")
		{
		alert("Campo \"Provincia\" e' obbligatorio");
    theForm.provincia.focus();
		return (false);
    }
	
	
		if (theForm.SMS.checked == true && theForm.cellulare.value == "")
		{
		alert("Campo \"Cellulare\" e' obbligatorio se volete ricevere anche attraverso SMS la newsletter");
    theForm.cellulare.focus();
		return (false);
    }
	
		    if(theForm.cellulare.value.length > 0) {
                //Controlla caratteri non ammessi
 		for (var i=0; i < invalidChar2.length; i++) {
                        badChar = invalidChar2.charAt(i);
                        if(theForm.cellulare.value.indexOf(badChar,0) != -1) {
         			alert ("Mai inserito caratteri non validi !!");
         			theForm.cellulare.focus();
         			return (false);
    }}}
	

	
if (!(theForm.sesso[0].checked || theForm.sesso[1].checked ))
		{
		alert("Campo \"Sesso\" e' obbligatorio!");
    theForm.sesso[0].focus();
		return (false);
    }
	
	if (theForm.username.value.length < 6)
		{
		alert("Username incompleto!");
    theForm.username.focus();
		return (false);
    }

		if (theForm.password.value.length < 6)
		{
		alert("Password incompleto!");
    theForm.password.focus();
		return (false);
    }





  if (theForm.username.value == "")
		{
		alert("Campo \"Username\" e' obbligatorio");
    theForm.username.focus();
		return (false);
    }
	
	
	  if (theForm.password.value == "")
		{
		alert("Campo \"Password\" e' obbligatorio");
    theForm.password.focus();
		return (false);
    }
	
	  if (theForm.password2.value == "")
		{
		alert("Campo \"Password2\" e' obbligatorio");
    theForm.password2.focus();
		return (false);
    }
	  if (theForm.password.value != theForm.password2.value)
		{
		alert("Le password non coincidono!");
    theForm.password.focus();
		return (false);
    }
	
	

	  if (theForm.email.value == "")
		{
		alert("Campo \"E-mail\" e' obbligatorio");
    theForm.email.focus();
		return (false);
    }

		if (theForm.privacy[1].checked )
		{
		alert("Senza autorizzazione non puoi procedere alla registrazione");
    theForm.privacy[0].focus();
		return (false);
    }

   EmailAddr = theForm.email.value;
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return (true);
   else
      {
      alert("Controlla l'indirizzo di e-mail inserito");
      theForm.email.focus();
      return (false);
      }



    }