// ******************** Script Validation Functions ********************** //
// Function: Tests if the object text is a valid date format(mm/dd/yyyy)
// Return: True - Text has valid date format
//         False - Text does not have valid date format
 function CheckDate(THISINPUT, FieldName) 
 {
    datevalue=(THISINPUT.value);
    re = /^([1-9]|0[1-9]|1[012])\/([1-9]|3[01]|0[1-9]|[12]\d)\/((1[89]\d{2})|([2-9]\d{3}))$/;
    checkDate = re.test(datevalue);
    if (checkDate == false)
    {
      alert (FieldName  + " is not a valid Date (or) Date is out of range [1800 - 9999]. Please try again.") ;
      THISINPUT.focus();
      THISINPUT.select();
    }
    return checkDate;
 }

// Function: Tests if the object text is a valid time format(hh:nn)
// Return: True - Text has valid time format
//         False - Text does not have valid time format
 function CheckTime(THISINPUT, FieldName) 
 {
    timevalue=(THISINPUT.value);
    re = /^(\d|2[0-3]|[01]\d)[:]([012345]\d)/;
    checkTime = re.test(timevalue);
    if (checkDate == false)
    {
      alert (FieldName  + " is not a valid Time. Please try again.") ;
      THISINPUT.focus();
      THISINPUT.select();
    }
    return checkTime;
 }

// Function: Tests if the object text is a valid number
// Return: True - Text is a valid number
//         False - Text is not a valid number
 function CheckNumber(THISINPUT, FieldName) 
 {
      numbervalue=(THISINPUT.value);
      checkNumber = isNaN(numbervalue);
      if (checkNumber == true)
      {
        alert (FieldName  + " is not a valid Number. Please try again.") ;
        THISINPUT.focus();
        THISINPUT.select();
      }
      checkNumber = !checkNumber ;
      return checkNumber;
 }

// Function: Tests if the object text is not blank
// Return: True - Text is not blank
//         False - Text is blank
 function CheckBlank(THISINPUT, FieldName) 
 {
      checkBlank = true ;
      if (THISINPUT.value.length == 0)
      {
	 alert (FieldName  + " cannot be a blank. Please enter a value.") ;
         checkBlank = false ;
         THISINPUT.focus();
         THISINPUT.select();
      }
      return checkBlank;
 }

// Function: Tests if the object (listbox) has any value selected
 function CheckBlankList(THISINPUT, FieldName) 
 {
      checkBlank = true ;
      if (THISINPUT.value.length == 0)
      {
	 alert (FieldName  + " cannot be a blank. Please select a value.") ;
         checkBlank = false ;
         THISINPUT.focus();
      }
      return checkBlank;
 }

// Function: Tests if the object text is less that the maximum limit allows
// Return: True - Text does not exceed the limit
//         False - Text exceeds the limit
 function CheckLength(THISINPUT, fieldLen, FieldName) 
 {
    checkLength = true ;
    if (THISINPUT.value.length > fieldLen)
    {
      alert (FieldName  + " length cannot be greater than " + fieldLen + ". Please re-enter.") ;
      checkLength = false ;
      THISINPUT.focus();
      THISINPUT.select();
    }
    return checkLength;
 }

// Function: Tests if the object text is less that the maximum limit allows
//  For html area
// Return: True - Text does not exceed the limit
//         False - Text exceeds the limit
 function CheckLengthHtmlArea(THISINPUT, fieldLen, fieldName) 
 {
    checkLength = true ;
    if (THISINPUT.value.length > fieldLen)
    {
      alert (fieldName + " field length cannot be greater than " + fieldLen + ". Please re-enter.") ;
      checkLength = false ;
     // THISINPUT.focus();
     // THISINPUT.select();
    }
    return checkLength;
 }

// Function: Tests if the object text is a valid telephone number format
// (nnnnnnnnnn / nnn-nnn-nnnn /           XXXXX(nnn)nnn-nnnn)
// Return: True - Text has valid phone format
//         False - Text does not have valid phone format
 function CheckPhone(THISINPUT, FieldName) 
 {
    phonevalue=(THISINPUT.value);
   //re = /^(\()?\d{3}((\))?|(-)?)\d{3}((-)?)\d{4}$/;// ----- (nnn)nnn-nnnn
    re = /^\d{3}(-)?\d{3}(-)?\d{4}$/;
    checkPhone = true;
    if (phonevalue.length > 0 && re.test(phonevalue) == false)
    {
      alert (FieldName  + " is not a valid telephone number. Please try again.") ;
      checkPhone = false;
      THISINPUT.focus();
      THISINPUT.select();
    }
    return checkPhone;
 }

