//------------------------------------------------------------------------------------------
//---  Controlla che il carattere sia una lettera
//------------------------------------------------------------------------------------------
function isLetter(theChar)
{
   var charArray = new Array(
      ' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 
      'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 
      'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
      'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 
      's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '_')

      for (j = 0; j < charArray.length; j++)
         if (theChar == charArray[j])
            return true
   return false
}

//------------------------------------------------------------------------------------------
//---  Controlla che il carattere sia un numero
//------------------------------------------------------------------------------------------
function isDigit(theDigit)
{
   var digitArray = new Array('0','1','2','3','4',
         '5','6','7','8','9')

      for (j = 0; j < digitArray.length; j++)
         if (theDigit == digitArray[j])
            return true
   return false
}

//------------------------------------------------------------------------------------------
//---  Controlla che la stringa contenga numeri e lettere
//------------------------------------------------------------------------------------------
function isAlphaNumeric(TheField)
{
   var myStringa = String(TheField.value)

   for (i = 0; i <=myStringa.length-1 ; i++){
      if (!isDigit( myStringa.charAt(i) ) ){
        if (!isLetter( myStringa.charAt(i) ) ) return false
      }
   }
   return true
}

//------------------------------------------------------------------------------------------
//---  Controlla che il campo inserito sia un numero
//------------------------------------------------------------------------------------------
function isNumber(TheField)
{
   var ThePhone = new String(TheField.value)
   var theChar
   
   for (var i = 0; i < ThePhone.length; i++)
   {
      theChar = ThePhone.charAt(i)
      if ( !isDigit(theChar) ) return false
   }
   return true
}

//------------------------------------------------------------------------------------------
//---  Controlla la validità del numero di telefono
//------------------------------------------------------------------------------------------
function isValidPhone(TheField)
{
   var ThePhone = new String(TheField.value)
   var theChar
   for (var i = 0; i < ThePhone.length; i++)
   {
      theChar = ThePhone.charAt(i)
      if ( !isDigit(theChar) )
      {
         if ( !((theChar == '/') || (theChar == '(') || (theChar == ')') || (theChar == '-') || (theChar == '+')) ) return false
      }
   }
   return true
}

function isValidPhone2(TheField, primonum)
{
   var ThePhone = new String(TheField.value)
  	 var theChar
   	if (!(ThePhone.charAt(0) == primonum)) return false
   	for (var i = 0; i < ThePhone.length; i++)
   	{
   	  theChar = ThePhone.charAt(i)
      if ( !isDigit(theChar) )
      {
         if ( !((theChar == '/') || (theChar == '(') || (theChar == ')') || (theChar == '-') || (theChar == '+')) ) return false
      }
   	}
   return true
}

//------------------------------------------------------------------------------------------
//---  Controlla la validità dell'indirizzo e-mail
//------------------------------------------------------------------------------------------
function isEmail(TheField)
{
   var theEmail = new String(TheField.value)
   var theChar

   PosET     = theEmail.indexOf("@")
   PosPnt    = theEmail.lastIndexOf(".")
   BeforeET  = theEmail.charAt(PosET-1)
   BeforePnt = theEmail.charAt(PosPnt-1)

   var cont = 0
   for (j = theEmail.length; j >=0 ; j--){
      if (theEmail.charAt(j)!=".") 
         cont+=1
      else 
         break
   }

  if ( (PosET==-1)||(PosPnt==-1)||(BeforeET=="")||(BeforePnt=="@")||(PosET>PosPnt)||(cont-1<2) ) return false

   return true
}

//------------------------------------------------------------------------------------------
//---  Controlla la lunghezza minima del campo
//------------------------------------------------------------------------------------------
function isMinLength(TheField, minLength) {
	if (TheField.value.length >= minLength)
		return true
	else {
		return false
	     }
}


//------------------------------------------------------------------------------------------
//---  Controlla la lunghezza minima del campo
//------------------------------------------------------------------------------------------
function Hilite(TheField, msg) {
	TheField.focus()
	TheField.select()
	alert(msg)
	return false
}