//<script>

   function FormFieldValidation(){ 
   this.digits = "0123456789";
   this.lowercaseLetters      = "abcdefghijklmnopqrstuvwxyz";
   this.uppercaseLetters      = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   this.whitespace            = " \t\n\r";
   this.defaultEmptyOK        = true;
   this.decimalPointDelimiter = ".";

   this.isLetter              = FormFieldValidation_isLetter;
   this.isDigit               = FormFieldValidation_isDigit;
   this.isLetterOrDigit       = FormFieldValidation_isLetterOrDigit;
   this.isEmpty               = FormFieldValidation_isEmpty;
   this.isWhiteSpace          = FormFieldValidation_isWhiteSpace;
   
   this.stripCharsInBag       = FormFieldValidation_stripCharsInBag;
   this.stripCharsNotInBag    = FormFieldValidation_stripCharsNotInBag;
   
   this.isFloat               = FormFieldValidation_isFloat;
   this.isMoney               = FormFieldValidation_isMoney;
   
   this.isDate                = FormFieldValidation_isDate;
   this.isEmail		      = FormFieldValidation_isEmail;
   }

   function FormFieldValidation_isDate(oInput, bEmptyOk){
   var strDate = new String(oInput);
   var patDate = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
   var aMatch = strDate.match(patDate); // is the format ok?

     if (aMatch == null) {
   //  alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
     return false;
     }

     var month = aMatch[1]; // parse date into variables
     var day   = aMatch[3];
     var year  = aMatch[5];

     if (month < 1 || month > 12) { // check month range
     alert("Month must be between 1 and 12.");
     return false;
     }

     if (day < 1 || day > 31) {
    // alert("Day must be between 1 and 31.");
     return false;
     }

     if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    // alert("Month "+month+" doesn't have 31 days!")
     return false;
     }

     if (month == 2) { // check for february 29th
     var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
       if (day > 29 || (day==29 && !isleap)) {
     //  alert("February " + year + " doesn't have " + day + " days!");
       return false;
       }
     }
   return true; // date is valid
   }
   
   function FormFieldValidation_isMoney(oInput, bEmptyOk){
   // strip commas and dollar sign, if any
   var s = this.stripCharsInBag(oInput.value,"$, ");
     if (this.isFloat(s, bEmptyOk)){
     if (this.isEmpty(s)){
     s = "0.00";
     }
     var fValue = parseFloat(s);
     oInput.value = fValue.toFixed(2);
     return true;      
     } else {
     return false;
     }   
   }

// ----------------------------------------------------------------------
// method......: isFloat (STRING s [, BOOLEAN bEmptyOK])
// parameters..:
// returns.....: true if string s is an unsigned floating point (real) number. 
//             : Also returns true for unsigned integers. 
// notes.......: If you wish to distinguish between integers and 
//               floating point numbers, first call isInteger, 
//               then call isFloat.
//               Does not accept exponential notation.
//               For explanation of optional argument bEmptyOK,
// ----------------------------------------------------------------------
   function FormFieldValidation_isFloat(s,bEmptyOk){
   var i;
   var bSeenDecimalPoint = false;
  // test for empty string 
     if (this.isEmpty(s)){ 
    // test for number of arguments
       if (this.isFloat.arguments.length == 1) {
    // return default value for empty field (true)
       return this.defaultEmptyOK; 
       } else {
    // returns true if argument == true else false
       return (this.isFloat.arguments[1] == true);
       }
     }
  // test for only a decimal?   
     if (s == this.decimalPointDelimiter) return false;
  // search through string's characters one by one
  // until we find a non-numeric character
  // when we do, return false; if we don't, return true.
     for (i = 0; i < s.length; i++)
     {   
  // check that current character is number.
     var c = s.charAt(i);
    // test for a decimal and we haven't seen one yet   
       if ((c == this.decimalPointDelimiter) && !bSeenDecimalPoint) {
       bSeenDecimalPoint = true;
       } else {
       if (!this.isDigit(c)) return false;
       }
     }
// all characters are numbers.
   return true;
   }

// -------------------------------------------------------
// primitives   
// -------------------------------------------------------
   function FormFieldValidation_isEmpty(s){
   return ((s == null) || (s.length == 0))
   }
   
   function FormFieldValidation_isLetter (c){
   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
   }

   function FormFieldValidation_isDigit (c){
   return ((c >= "0") && (c <= "9"))
   }

   function FormFieldValidation_isLetterOrDigit (c){
   return (isLetter(c) || isDigit(c))
   }

// -------------------------------------------------------
// function....: isWhiteSpace()
// parameters..: s = string to check
// returns.....: true if string s is empty or false if not
// -------------------------------------------------------
   function FormFieldValidation_isWhiteSpace(s){   
   var i;
    // Is s empty?
    if (this.isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (this.whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function FormFieldValidation_isEmail (s)
{   if (this.isEmpty(s)) 
       if (this.isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (this.isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (this.isWhiteSpace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


// -------------------------------------------------------
// function....: stripCharsInBag()
// parameters..: s   = string to check
//             : bag = set of characters to strip
// returns.....: string with "bag" characters removed
// -------------------------------------------------------
   function FormFieldValidation_stripCharsInBag (s, bag){
   var i;
   var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
     for (i = 0; i < s.length; i++){   
  // Check that current character isn't whitespace.
     var c = s.charAt(i);
       if (bag.indexOf(c) == -1) returnString += c;
     }
   return returnString;
   }

// -------------------------------------------------------
// function....: stripCharsNotInBag()
// parameters..: s   = string to check
//             : bag = set of characters to strip
// returns.....: string with "non-bag" characters removed
// -------------------------------------------------------
   function FormFieldValidation_stripCharsNotInBag (s, bag){
   var i;
   var returnString = "";
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.
     for (i = 0; i < s.length; i++) {   
  // Check that current character isn't whitespace.
     var c = s.charAt(i);
       if (bag.indexOf(c) != -1) returnString += c;
     }
   return returnString;
   }