
//-------------------------------------------------------------------------------------------------------//

function ValidLength(str,number)
{
  if (str < number)
    return false;
  return true;
}

function ValidChars(CheckStr,chars)
{
  for (i = 0;  i < CheckStr.length;  i++)
  {
    ch = CheckStr.charAt(i);
    for (j = 0;  j < chars.length;  j++)
      if (ch == chars.charAt(j))
        break;
      if (j == chars.length)
        return false;
  }
  return true;
}  

function ValidString(CheckStr,RepeatNum)
{
  if (CheckStr.length >= RepeatNum)
  {
    for (k = 0; k < CheckStr.length - 2; k++)
    {
      l = k+1;
      if  (CheckStr.charAt(k) == CheckStr.charAt(l))
      {
        m = l+1;
        if (CheckStr.charAt(k) == CheckStr.charAt(m))
        {
          return false;
          break;
        }
        else
        {
          k++;
        };
      }  
    }
  }
  return true;
}

  
function ValidVowel(checkStr)
{
  checkVowel = "AEIOUYaeiouy";
  for (z = 0; z < checkStr.length; z++)
  {
    for (a = 0; a < checkVowel.length; a++)
    {
      if (checkStr.charAt(z) == checkVowel.charAt(a))
      {  
        return true;
      } 
    }
  }
  return false;
}

function ValidNumber (checkStr)
{
  checkNumber = "0123456789";
  for (z = 0; z < checkStr.length; z++)
  {
    for (a = 0; a < checkNumber.length; a++)
    {
      if (checkStr.charAt(z) == checkNumber.charAt(a))
      {  
        return true;
      } 
    }
  }
  return false;
}  



//--------------Main Procedure------------------------------------------------------------------------------//


function Valid(theForm)
{

/*  if (!ValidLength(theForm.azienda.value.length, 1))
  {
    alert ("Inserisci la Ragione Sociale.");
    theForm.azienda.focus();
    return false;
  }
*/

 /*------------------ Begin Nome e Cognome Validation ----------------*/

  var FormLName = theForm.nome.value;
  if (!ValidLength(FormLName.length, 1))
  {
    alert ("Inserisci il Nome.");
    theForm.nome.focus();
    return false;
  }
  
    if (!ValidLength(theForm.cognome.value.length, 1))
  {
    alert ("Inserisci il Cognome.");
    theForm.cognome.focus();
    return false;
  }
  

  /*--------------------- End Nome Validation ----------------------*/
  
  /*-----------------------Begin Indirizzo Validation -------------------*/

  var FormAddr1 = theForm.indirizzo.value ;
  var ValidAddyChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzùàòèéì'0123456789 *°#.-/,";
  if (!ValidLength(FormAddr1.length, 3))
  {
    alert ("Inserisci l'Indirizzo!");
    theForm.indirizzo.focus();
    return false;
  }  
  
  if (!ValidNumber(FormAddr1))
  {
    alert ("Indirizzo non Valido! es.: via Roma, n°28");
    theForm.indirizzo.focus();
    return false;
  }  
  
  if (!ValidChars(FormAddr1,ValidAddyChars))
  {
    alert ("Indirizzo non Valido! es.: via Roma, n°28");
    theForm.indirizzo.focus();
    return false;
  }
  

  /*------------------ End Indirizzo Validation --------------------*/

  
 /*-----------------------Begin Città Validation -------------------*/
 

  var FormAddr1 = theForm.citta.value ;
  if (!ValidLength(FormAddr1.length, 3))
  {
    alert ("Inserisci la città!");
    theForm.citta.focus();
    return false;
  }  
  

  /*------------------ End Città Validation --------------------*/
  
 if (theForm.cap.value == "")
{
    alert("Inserisci C.A.P.");
    theForm.cap.focus();
    return false;
}  
if (theForm.provincia.value == 0)
{
    alert("Inserisci la provincia");
    theForm.provincia.focus();
    return false;
}  
  
/*------------------ Begin Telefono Validation -------*/

  var FormTel = theForm.telefono.value
  var telNums = "0123456789-/telfaxTELFAX. ";
    
if (FormTel.length == 0)
{
    alert("Inserisci il numero di telefono");
    theForm.telefono.focus();
    return false;
}

    if (!ValidChars(FormTel,telNums))
    {
      alert("Inserisci un Numero di Telefono Valido!");
      theForm.telefono.focus();
      return false;
    }

  /*-------------- End Telefono Validation ---------------*/
 
  /*----------- Begin Email Validation -------------------------*/

  
  var FormEmail = theForm.email.value
  ValidEmailChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
   
  if (!ValidLength(FormEmail.length, 5))
  {
    alert ("Inserisci l' E-mail!");
    theForm.email.focus();
    return false;
  }
  
  dot = FormEmail.indexOf(".");
  afterdot = FormEmail.charAt(dot +1);
  if (dot == -1 || afterdot == "") 
  {
    alert("Inserisci un'E-mail valida.");
    theForm.email.focus();
    return false;
  }

  at = FormEmail.indexOf("@");
  afterat = FormEmail.charAt(at +1);
  if (at == -1 || afterat == "")
  {
    alert("Inserisci un'E-mail valida.");
    theForm.email.focus();
    return false;
  }
  
  if (!ValidChars(FormEmail, ValidEmailChars))
  {
    alert("Il tuo indirizzo E-mail non è valido!");
    theForm.email.focus();
    return false;
  }
  
		if (theForm.userid.value.length > 16){
		alert("UserID non puo superare i 16 caratteri!");
		theForm.userid.focus();
		return false;
		}
		if (theForm.userid.value.length < 6){
		alert("UserID deve essere di almeno 6 caratteri!");
		theForm.userid.focus();
		return false;		
		}
		if (theForm.userid.value.length == 0){
		alert("Scegliere lo UserID!");
		theForm.userid.focus();
		return false;		
		}	
		if (theForm.pass.value.length > 16){
		alert("La Password non puo superare i 16 caratteri!");
		theForm.pass.focus();
		return false;
		}
		if (theForm.pass.value.length < 6){
		alert("La Password deve essere di almeno 6 caratteri!");
		theForm.pass.focus();
		return false;		
		}
		if (theForm.pass.value.length == 0){
		alert("Scegliere la Password!");
		theForm.pass.focus();
		return false;		
		}		 
		if (theForm.newpass.value.length != 0){
			if (theForm.newpass.value.length > 16){
			alert("La Password non puo superare i 16 caratteri!");
			theForm.newpass.focus();
			return false;
			}
			if (theForm.newpass.value.length < 6){
			alert("La Password deve essere di almeno 6 caratteri!");
			theForm.newpass.focus();
			return false;		
			}
			if (theForm.newpass.value != theForm.newpass2.value){
			alert("Ricontrollare la password inserita!");
			theForm.newpass.focus();
			return false;		
			}		 	
		}		

  
  /*-------------- End Email Validation ---------------*/
  return true;  
}  

//-->
