
	function validateStringChars (validChars, strValue) {
        /************************************************
        DESCRIPTION: Validates the characters of a string
        against a supplied set of character values.

        PARAMETERS:
        strValue - String to be tested for validity
        validChars - String of characters strValue is validated against

        Examples:
        validChars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

        RETURNS:
        True if valid, otherwise false.
        *************************************************/
        if ((strValue == null) || (trimAll(strValue) == '')){
            return false;
        }
        else {
            var inspectStr = strValue;
            for (var i = 0; i < inspectStr.length; i++){
                var c = inspectStr.charAt(i);
                if (validChars.indexOf(c) == -1 ){
                    return false;
                }
            }
        }

        return true
    }
    
    function validateRegExp (strValue, strMatchPattern) {
        /************************************************
        DESCRIPTION: Validates that a string a matches
        a valid regular expression pattern.

        PARAMETERS:
        strValue - String to be tested for validity
        strMatchPattern - String containing a predefined
        regular expression match pattern variable

        RETURNS:
        True if valid, otherwise false.
        *************************************************/
        var objRegExp = new RegExp(eval(strMatchPattern));      

        //check if string matches pattern
        return objRegExp.test(strValue);
    }

    /**
     * Validates the String is a valid is number including negative values
     *
     * @return boolean
     */
    function validateRegExpNumeric( strValue )
    {
        var objRegExpNumeric = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;    
        return validateRegExp(strValue, objRegExpNumeric);
    }

    /**
     * Validates the String is a valid US zip code
     *   in 5 digit format or zip+4,  format. 99999 or 99999-9999
     *
     * @return boolean
     */
    function validateRegExpUSZip( strValue )
    {
        var objRegExpUSZip = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
        return validateRegExp(strValue, objRegExpUSZip);
    }

    /**
     * Validates the String is a valid social security number
     *   in the form of: 999999999 or 999-99-9999     
     *
     * @return boolean
     */
    function validateRegExpSSN( strValue )
    {
        var objRegExpSSN = /(^\d{9}$)|(^\d{3}-\d{2}-\d{4}$)/;    
        return validateRegExp(strValue, objRegExpSSN);
    }

    /**
     * Validates the String is a whole number including negative values
     *
     * @return boolean
     */
    function validateRegExpInteger( strValue )
    {
        var objRegExpInteger = /(^-?\d\d*$)/;
        return validateRegExp(strValue, objRegExpInteger);
    }

    /**
     * Validates the String is a US currency amount
     *
     *   Two numbers after the decimal point (100th's place) 
     *   Decimal numbers must come at the end 
     *   Commas separating hundreds from thousands,
     *         etc... every three numbers to the left of the decimal point 
     *   One to three numbers to the left of the last comma 
     *   Three numbers between each comma 
     *   Starts with OR without a Dollar sign 
     *
     * @return boolean
     */
    function validateRegExpUSCurrency( strValue )
    {
        var objRegExpUSCurrency = /(^\${0,1}[\d]{1,3}([\,]{1}[\d]{3})*[\.]{1}[\d]{1,2}$)|(^\${0,1}[\d]{1,3}([\,]{1}[\d]{3})*$)|(^\${0,1}\d*[\.]{1}[\d]{1,2}$)|(^\${0,1}[\d]{1}$)/;    
        return validateRegExp(strValue, objRegExpUSCurrency);
    }

    function validateRegExpEmail( strValue) {
        /************************************************
        DESCRIPTION: Validates that a string contains a 
          valid email pattern. 

         PARAMETERS:
           strValue - String to be tested for validity

        RETURNS:
           True if valid, otherwise false.

        REMARKS: Accounts for email with country appended
          does not validate that email contains valid URL
          type (.com, .gov, etc.) and optionally,
          a valid country suffix.  Since email has many
          forms this expression only tests for near valid
          address.  Some additional validation may be
          required.
        *************************************************/
        var objRegExpEmail  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
        return validateRegExp(strValue, objRegExpEmail);
    }

    /**
     * Validates the String is a phone number [like "(123) 555-1212"]
     *
     * @return boolean
     */
    function validateRegExpUSPhoneNumber( strValue )
    {
        var objRegExpUSPhone = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;        
        return validateRegExp(strValue, objRegExpUSPhone);
    }

    /**
     * Attempts to sets the text value contained in _o_field to a valid phone number.
     *
     * This will also generate a Javascript alert if the phone number is deemed invalid
     */
    function setToValidUSPhoneNumber( _o_field )
    {
        var s_text = _o_field.value.replace(/[\(\)\.\-\ ]/g, '');

        if( trimAll(s_text).length != 0 && s_text.length != 10 )
        {
            alert( "Invalid Phone Number" );
            _o_field.focus();
            _o_field.select();
            window.event.returnValue = false;
        }
        else
        {
            var s_new_number = "(" + s_text.substring(0,3) + ") " + s_text.substring(3,6) + "-" + s_text.substring(6,10);
            _o_field.value = s_new_number;
        }
    }    

    function validateUSDate( strValue ) {
    /************************************************
    DESCRIPTION: Validates that a string contains only 
        valid dates with 2 digit month, 2 digit day, 
        4 digit year. Date separator can be ., -, or /.
        Uses combination of regular expressions and 
        string parsing to validate date.
        Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

    PARAMETERS:
       strValue - String to be tested for validity

    RETURNS:
       True if valid, otherwise false.

    REMARKS:
       Avoids some of the limitations of the Date.parse()
       method such as the date separator character.
    *************************************************/
      var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

      //check to see if in correct format
      if(!objRegExp.test(strValue))
        return false; //doesn't match pattern, bad date
      else{
        var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
        var intDay = parseInt(arrayDate[1],10); 
        var intYear = parseInt(arrayDate[2],10);
        var intMonth = parseInt(arrayDate[0],10);

        //check for valid month
        if(intMonth > 12 || intMonth < 1) {
            return false;
        }

        //create a lookup for months not equal to Feb.
        var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                            '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}

        //check if month value and day value agree
        if(arrayLookup[arrayDate[0]] != null) {
          if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
            return true; //found in lookup table, good date
        }

        //check for February
        var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
        if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
          return true; //Feb. had valid number of days
      }
      return false; //any other values, bad date
    }

    function isValidLength (strValue, lenValue) {
        /************************************************
        DESCRIPTION: Validates that a string is not too many characters.

        PARAMETERS:
        strValue - String to be tested for validity
        lenValue - String length to be tested for validity

        RETURNS:
        True if valid, otherwise false.
        *************************************************/
        var strTemp = strValue;
        strTemp = trimAll(strTemp);

        if (strTemp.length < lenValue) {
            return true;
        }  
        return false;
    }


    function isNotEmpty (strValue) {
        /************************************************
        DESCRIPTION: Validates that a string is not all
        blank (whitespace) characters.

        PARAMETERS:
        strValue - String to be tested for validity

        RETURNS:
        True if valid, otherwise false.
        *************************************************/
        var strTemp = strValue;
        strTemp = trimAll(strTemp);

        if (strTemp.length > 0) {
            return true;
        }  
        return false;
    }
    
    function isEmpty_Alert (fldObj, altMessage) {
        /************************************************
        DESCRIPTION: Validates that a is not empty, if it is, alert and focus.

        PARAMETERS:
        fldObj - Field to be tested for validity

        RETURNS:
        True if valid, otherwise false.
        *************************************************/        
        var fldVal = fldObj.value;
        
        if( isNotEmpty(fldVal) )
        {
            return true;
        }
        else 
        {
            alert(altMessage);
            fldObj.focus();
        }
        return false;
    }

    function isValidFldLength_Alert (fldObj, fldLen, altMessage) {
        /************************************************
        DESCRIPTION: Validates that a field is not over a given legth limit in size, if it is, alert and focus.

        PARAMETERS:
        fldObj - Field to be tested for validity

        RETURNS:
        True if valid, otherwise false.
        *************************************************/        
        var fldVal = fldObj.value;
        
        if( isValidLength (fldVal, fldLen) )
        {
            return true;
        }
        else 
        {
            alert(altMessage);
            fldObj.focus();
        }
        return false;
    }


    function isSelectionMade_Alert (fldObj, altMessage) {
        /************************************************
        DESCRIPTION: Validates that a is not empty, if it is, alert and focus.

        PARAMETERS:
        fldObj - Field to be tested for validity

        RETURNS:
        True if valid, otherwise false.
        *************************************************/        
        var selIndex = fldObj.selectedIndex;
        
        if( selIndex >= 0 )
        {
            return true;
        }
        else 
        {
            alert(altMessage);
            fldObj.focus();
        }
        return false;
    }
    
    function isSelectionMadeNotZero_Alert (fldObj, altMessage) {
        /************************************************
        DESCRIPTION: Validates that a is not empty, if it is, alert and focus.

        PARAMETERS:
        fldObj - Field to be tested for validity

        RETURNS:
        True if valid, otherwise false.
        *************************************************/        
        var selIndex = fldObj.selectedIndex;
        
        if( selIndex > 0 )
        {
            return true;
        }
        else 
        {
            alert(altMessage);
            fldObj.focus();
        }
        return false;
    }
    
    function rightTrim (strValue) {
        /************************************************
        DESCRIPTION: Trims trailing whitespace chars.

        PARAMETERS:
        strValue - String to be trimmed.  

        RETURNS:
        Source string with right whitespaces removed.
        *************************************************/
        var objRegExp = /^([\w\W]*)(\b\s*)$/;

        if (objRegExp.test(strValue)) {
            //remove trailing a whitespace characters
            strValue = strValue.replace(objRegExp, '$1');
        }
        return strValue;
    }

    function leftTrim (strValue) {
        /************************************************
        DESCRIPTION: Trims leading whitespace chars.

        PARAMETERS:
        strValue - String to be trimmed

        RETURNS:
        Source string with left whitespaces removed.
        *************************************************/
        var objRegExp = /^(\s*)(\b[\w\W]*)$/;

        if (objRegExp.test(strValue)) {
            //remove leading a whitespace characters
            strValue = strValue.replace(objRegExp, '$2');
        }
        return strValue;
    }

    function trimAll (strValue) {
        /************************************************
        DESCRIPTION: Removes leading and trailing spaces.

        PARAMETERS: Source string from which spaces will
        be removed;

        RETURNS: Source string with whitespaces removed.
        *************************************************/ 
        var objRegExp = /^(\s*)$/;

        //check for all spaces
        if (objRegExp.test(strValue)) {
            strValue = strValue.replace(objRegExp, '');
            if (strValue.length == 0){
                return strValue;
            }
        }

        //check for leading & trailing spaces
        objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;

        if (objRegExp.test(strValue)) {
            //remove leading and trailing whitespace characters
            strValue = strValue.replace(objRegExp, '$2');
        }
        return strValue;
    }


    function LimitText(fieldObj, n_maxchars) {
        /************************************************
        DESCRIPTION: commonly used for textarea inputs to limit
                    the number of characters. function is called
                    on the "onkeypress" event.

        PARAMETERS:
        fieldObj - the textarea input
        maxChars - maximum number of characters

        RETURNS:
        result of onkeypress object event.
        *************************************************/
        var s_fldval = fieldObj.value;
        var s_fldname = fieldObj.name;
        if( s_fldval.length > n_maxchars )
        {
            fieldObj.value = s_fldval.substring(0, n_maxchars - 1);
            alert("This field cannot exceed " + n_maxchars + " characters.");
        }
    }


    
    var defaultEmptyOK = false
/**
 * Checks whether string s is empty
 **/
function isEmpty( s )
{
    return ((s == null) || (s.length == 0))
}

/**
 * isInteger (STRING s [, BOOLEAN emptyOK])
 *
 * Returns true if all characters in string s are numbers.
 *
 *
 * Accepts non-signed integers only. Does not accept floating
 * point, exponential notation, etc.
 *
 * We don't use parseInt because that would accept a string
 * with trailing non-numeric characters.
 *
 * By default, returns defaultEmptyOK if s is empty.
 * There is an optional second argument called emptyOK.
 * emptyOK is used to override for a single function call
 *      the default behavior which is specified globally by
 *      defaultEmptyOK.
 * If emptyOK is false (or any value other than true),
 *      the function will return false if s is empty.
 * If emptyOK is true, the function will return true if s is empty.
 *
 * EXAMPLE FUNCTION CALL:     RESULT:
 * isInteger ("5")            true
 * isInteger ("")             defaultEmptyOK
 * isInteger ("-5")           false
 * isInteger ("", true)       true
 * isInteger ("", false)      false
 * isInteger ("5", false)     true
 * Changed by richa 
 **/
function isInteger( s )
{
    var i;

    if ( isEmpty( s ) )
    {
        if ( isInteger.arguments.length == 1 )
        {
            return defaultEmptyOK;
        }
        else
        {
            return (isInteger.arguments[1] == true);
        }
    }

    // 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);

        if ( !isDigit(c) )
        {
            return false;
        }
    }

        // All characters are numbers.
        return true;
}


/** 
 * isFloat (STRING s [, BOOLEAN emptyOK])
 *
 * True if string s is an unsigned floating point (real) number.
 *
 * Also returns true for unsigned integers. 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 emptyOK,
 * see comments of function isInteger.
 **/
function isFloat( s )
{
    var i;
    var seenDecimalPoint = false;
    var decimalPointDelimiter = ".";

    if ( isEmpty( s ) )
    {
        if( isFloat.arguments.length == 1 )
        {
            return defaultEmptyOK;
        }
        else
        {
            return ( isFloat.arguments[1] == true );
        }
    }

    if ( s == 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);

        if ( ( c == decimalPointDelimiter ) && !seenDecimalPoint )
        {
            seenDecimalPoint = true;
        }
        else if ( !isDigit( c ) )
        {
            return false; 
        }
    }

    // All characters are numbers.
    return true;
}



/**
 * Returns true if character c is a digit
 * (0 .. 9).
 **/
function isDigit (c)
{
    return ((c >= "0") && (c <= "9"))
}


/**
 * Removes all characters which appear in string bag from string s.
 **/
function 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;
}

/**
 * Removes all characters which do NOT appear in string bag
 * from string s.
 **/
function 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;
}


/**
 * Method for checking if a percentage is valid
 * Param1 field     - Field for inputing the decimal format.
 * Param2 name      - Name of field (for use in error message)
 * Param3 before    - Digits allowed before decimal
 * Param4 after     - Digits allowed after decimal
 * Param5 bNoisy    - Message Box required or no.
 * Param6 ""        - if true, empty is ok
 *                    if false, empty is not ok
 *                    if not specified, empty is ok
 *                       if defaultEmptyOK is true 
 **/
function validateNamedPercentField(field, name, bNoisy)
{
    var field_value  = field.value;
    var err_msg = null;

    var passed;

    if ( validateNamedPercentField.arguments.length == 3 ) 
    {
    passed = validateNamedDecimalField( field, name, 3, 2, bNoisy );
    }
    else
    {
    passed = validateNamedDecimalField( field, name, 3, 2, bNoisy, 
                               validateNamedPercentField.arguments[3] );
    }

    if ( !passed )
    {
    return false;
    }

    if ( field_value > 100 || field_value < 0 )
    {
    if ( bNoisy )
    {
        alert( "The " + name + " field must be between 0 and 100." );
        field.focus();
        field.select();
    }

    return false;
    }

    return true;
}

/**
 * Checks that a integer field is valid
 *
 * param1 field - The field to inspect
 * param2 bNoisy - If the field fails inspection, 
 *                 pop and alert and highlight the field.
 **/
function validateNamedIntegerField( field, name, bNoisy )
{
    var field_value = field.value;

    if ( isEmpty(field_value) )
    {
        var declared_arg_count = 3;
        var args = validateNamedIntegerField.arguments;
    
        if ( ( args.length == declared_arg_count && defaultEmptyOK == false ) ||
             ( args.length > declared_arg_count && args[declared_arg_count] == false) )
        {
            if ( bNoisy )
            {
                alert( "The " + name + " field may not be empty." );
                field.focus();
                field.select();
            }
            return false;
        }
        return true;
    }


    if ( !isInteger( field_value ) )
    {
        if ( bNoisy )
        {
            alert( "The " + name + " field must contain a number." );
            field.focus();
            field.select();
        }
        return false;
    }
    return true;
}



/**
 * Checks that a integer field is valid
 *
 * param1 field - The field to inspect
 * param2 bNoisy - If the field fails inspection, 
 *                 pop and alert and highlight the field.
 **/
function validateIntegerField( field, bNoisy )
{
    if ( validateIntegerField.arguments.length == 3 )
    {
        return validateNamedIntegerField( field, "selected integer", bNoisy );
    }
    else
    {
        return validateNamedIntegerField( field, "selected integer", bNoisy, 
                                   validateIntegerField.arguments[3] );
    }
}

/**
 * Method for checking if a float amount is valid
 * Param1 field     - Field for inputing the decimal format.
 * Param2 name      - Name of field (for use in error message)
 * Param3 before    - Digits allowed before decimal
 * Param4 after     - Digits allowed after decimal
 * Param5 bNoisy    - Message Box required or no.
 * Param6 ""        - if true, empty is ok
 *                    if false, empty is not ok
 *                    if not specified, empty is ok
 *                       if defaultEmptyOK is true 
 **/
function validateNamedDecimalField(field, name, before, after, bNoisy)
{
    var field_value  = field.value;
    var err_msg = null;

    if ( isEmpty( field_value ) )
    {
        var declared_arg_count = 5;
        var args = validateNamedDecimalField.arguments;
    
        if ( ( args.length == declared_arg_count && defaultEmptyOK == false ) ||
             ( args.length > declared_arg_count && args[declared_arg_count] == false) )
        {
            if ( bNoisy )
            {
                alert( "The " + name + " field must contain a value." );
                field.focus();
                field.select();
            }
            return false;
        }
        return true;
    }
    

    var decimalPointDelimiter = ".";
    var seenDecimalPoint = false;
    var countBefore = 0;
    var countAfter = 0;

    for (i = 0; i < field_value.length; i++)
    {
        // Check that current character is number.
        var c = field_value.charAt(i);

        if ( ( c == decimalPointDelimiter ) && !seenDecimalPoint )
        {
            if ( !seenDecimalPoint )
            {
                seenDecimalPoint = true;
            }
            else
            {
                if ( bNoisy )
                {
                    alert( "The " + name + 
                           " field has too many decimal points." );
                    field.focus();
                    field.select();
                }
                return false;
            }
        }
        else if ( !isDigit( c ) )
        {
            if ( bNoisy )
            {
                alert( "Invalid character in the " + name + " field." );
                field.focus();
                field.select();
            }
            return false;
        }
        else if ( seenDecimalPoint )
        {
            countAfter++;

            if ( countAfter > after )
            {
                if ( bNoisy )
                {
                    alert( "The " + name + " field only allows " +
                            after + " numbers after decimal point." );
                    field.focus();
                    field.select();
                }
                return false;
            }
        }
        else
        {
            countBefore++;

            if ( countBefore > before )
            {
                if ( bNoisy )
                {
                    var max = 1;

                    for ( var j = 0; j < before; j++ )
                    {
                        max = max * 10;
                    }
                    alert( name + " must be less than " + max + "." );

                    field.focus();
                    field.select();
                }
                return false;
            }
        }
    }

    field.value = field_value;

    // valid decimal amount
    return true;
}



/**
 * Method for checking if a float amount is valid
 * Param1 field     - Field for inputing the decimal format.
 * Param2 bNoisy    - Message Box required or no.
 * Param3 ""        - if true, empty is ok
 *                    if false, empty is not ok
 *                    if not specified, empty is ok
 *                       if defaultEmptyOK is true 
 **/
function validateDecimalAmountField(field, before, after, bNoisy)
{
    if ( validateDecimalAmountField.arguments.length == 4 )
    {
        return validateNamedDecimalField( 
                   field, "selected decimal", before, after, bNoisy );
    }
    else
    {
        return validateNamedDecimalField(
                   field, "selected decimal", before, after, bNoisy, 
                   validateDecimalAmountField.arguments[4] );
    }
}




/**
 * Method for checking if a float amount is valid
 * Param1 field     - Field for inputing the decimal format.
 * Param2 bNoisy    - Message Box required or no.
 * Param3 ""        - if true, empty is ok
 *                    if false, empty is not ok
 *                    if not specified, empty is ok
 *                       if defaultEmptyOK is true 
 **/
function validateLimitedDollarAmountField(field, name, before, bNoisy)
{
    var field_value  = field.value;
    var err_msg = null;

    if ( isEmpty( field_value ) )
    {
        var declared_arg_count = 4;
        var args = validateLimitedDollarAmountField.arguments;
    
        if ( ( args.length == declared_arg_count && defaultEmptyOK == false ) ||
             ( args.length > declared_arg_count && args[declared_arg_count] == false) )
        {
            if ( bNoisy )
            {
                alert( "The " + name + " field must contain a value." );
                field.focus();
                field.select();
            }
            return false;
        }
        return true;
    }


    field_value = stripCharsInBag( field_value, " $," );

    var decimalPointDelimiter = ".";
    var seenDecimalPoint = false;
    var countBefore = 0;
    var countAfter = 0;

    for (i = 0; i < field_value.length; i++)
    {
        // Check that current character is number.
        var c = field_value.charAt(i);

        if ( ( c == decimalPointDelimiter ) && !seenDecimalPoint )
        {
            if ( !seenDecimalPoint )
            {
                seenDecimalPoint = true;
            }
            else
            {
                if ( bNoisy )
                {
                    alert( "Too many decimal points in the " + name + "." );
                    field.focus();
                    field.select();
                }
                return false;
            }
        }
        else if ( !isDigit( c ) )
        {
            if ( bNoisy )
            {
                alert( "Invalid character in the " + name + " field." );
                field.focus();
                field.select();
            }
            return false;
        }
        else if ( seenDecimalPoint )
        {
            countAfter++;

            if ( countAfter > 2 )
            {
                if ( bNoisy )
                {
                    alert( "Only two numbers allowed after " +
                           "decimal point in the " + name + " field." );
                            
                    field.focus();
                    field.select();
                }
                return false;
            }
        }
        else
        {
            countBefore++;

            if ( countBefore > before )
            {
                if ( bNoisy )
                {
                    var max = 1;

                    for ( var j = 0; j < before; j++ )
                    {
                        max = max * 10;
                    }

                    alert( name + " must be less than " + max + "." );

                    field.focus();
                    field.select();
                }
                return false;
            }
        }
    }

    field.value = field_value;

    // valid decimal amount
    return true;
}



/**
 * Method for checking if a dollar amount is valid
 * Param1 field     - Field for inputing the dollar amount format.
 * Param2 bNoisy    - Message Box required or no.
 * Param3 ""        - if true, empty is ok
 *                    if false, empty is not ok
 *                    if not specified, empty is ok
 *                       if defaultEmptyOK is true 
 **/
function validateDollarAmountField(field, bNoisy)
{
    var amount_string = field.value;
    var err_msg = null;

    if ( isEmpty( amount_string ) )
    {
        var declared_arg_count = 2;
        var args = validateDollarAmountField.arguments;
    
        if ( ( args.length == declared_arg_count && defaultEmptyOK == false ) ||
             ( args.length > declared_arg_count && args[declared_arg_count] == false) )
        {
            if ( bNoisy )
            {
                alert( "Dollar Amount field must contain a value." );
                field.focus();
                field.select();
            }
            return false;
        }
        return true;
    }

    amount_string = stripCharsInBag( amount_string, " $," );

    var decimalPointDelimiter = ".";
    var seenDecimalPoint = false;
    var decimalPlaces = 0;

    for (i = 0; i < amount_string.length; i++)
    {
        // Check that current character is number.
        var c = amount_string.charAt(i);

        if ( ( c == decimalPointDelimiter ) && !seenDecimalPoint )
        {
            if ( !seenDecimalPoint )
            {
                seenDecimalPoint = true;
            }
            else
            {
                if ( bNoisy )
                {
                    alert( "Too many decimal points in Dollar Amount field." );
                    field.focus();
                    field.select();
                }
                return false;
            }
        }
        else if ( !isDigit( c ) )
        {
            if ( bNoisy )
            {
                alert( "Invalid character in Dollar Amount field." );
                field.focus();
                field.select();
            }
            return false;
        }
        else if ( seenDecimalPoint )
        {
            decimalPlaces++;

            if ( decimalPlaces > 2 )
            {
                if ( bNoisy )
                {
                    alert( "Too many numbers after decimal point." );
                    field.focus();
                    field.select();
                }
                return false;
            }
        }
    }

    field.value = amount_string;

    // valid dollar amount
    return true;
}

/**
 * Method for Checking the valid entry of EMail address format.
 *
 * Param1 emailStr      - EMail Address String.
 * Param2 bNoisy        - Message Box required or no.
 * Param3 ""            - if true, empty is ok
 *                        if false, empty is not ok
 *                        if not specified, empty is ok
 *                           if defaultEmptyOK is true 
 **/
function validateEmailField( field, bNoisy )
{
    var emailStr = field.value;

    if ( isEmpty( emailStr ) )
    {
        var declared_arg_count = 2;
        var args = validateEmailField.arguments;
    
        if ( ( args.length == declared_arg_count && defaultEmptyOK == false ) ||
             ( args.length > declared_arg_count && args[declared_arg_count] == false) )
        {
            if ( bNoisy )
            {
                alert( "Email field must contain a value." );
                field.focus();
                field.select();
            }
            return false;
        }

        return true;
    }

    var emailPat=/^(.+)@(.+)$/
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    var validChars="\[^\\s" + specialChars + "\]"
    var firstChars=validChars
    var quotedUser="(\"[^\"]*\")"
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    var atom="(" + firstChars + validChars + "*" + ")"
    var word="(" + atom + "|" + quotedUser + ")"
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
    var matchArray=emailStr.match(emailPat)
  
    if (matchArray==null) 
    {
        if ( bNoisy )
        {
            alert("Email address seems incorrect (check @ and .'s)")
            field.focus();
            field.select();
        }
        return false
    }
  
    var user=matchArray[1]
    var domain=matchArray[2]

    if (user.match(userPat)==null) 
    {
        if ( bNoisy )
        {
            alert("Email address seems incorrect (check @ and .'s)")
            field.focus();
            field.select();
        }
        return false
    }
  
    var IPArray=domain.match(ipDomainPat)
  
    if (IPArray!=null) 
    {
        for (var i=1;i<=4;i++) 
        {
            if (IPArray[i]>255) 
            {
                if ( bNoisy )
                {
                    alert("Destination IP address is invalid!")
                    field.focus();
                    field.select();
                }
                return false
            }
        }
        return true
   }

    var domainArray=domain.match(domainPat)
  
    if (domainArray==null) 
    {
        if ( bNoisy )
        {
            alert("The domain name doesn't seem to be valid.")
            field.focus();
            field.select();
        }
        return false
    }
  
    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
  
    if ( domArr[domArr.length-1].length < 2 ||
         domArr[domArr.length-1].length > 3 )  
    {
        if ( bNoisy )
        {
            alert( "The address must end in a three-letter domain, " +
                   "or two letter country." )
            field.focus();
            field.select();
        }
        return false
    }
  
    if ( ( domArr[domArr.length-1].length == 2 ) && ( len < 3 ) ) 
    {
        var errStr="This address ends in two characters, which is a country"
        errStr+=" code.  Country codes must be preceded by "
        errStr+="a hostname and category (like com, co, pub, pu, etc.)"

        if ( bNoisy )
        {
            alert(errStr)
            field.focus();
            field.select();
        }

        return false
    }
  
    if ( ( domArr[domArr.length-1].length == 3 ) && ( len < 2 ) ) 
    {
        var errStr="This address is missing a hostname!"
        if ( bNoisy )
        {
            alert(errStr)
            field.focus();
            field.select();
        }
        return false
    }

    return true;
}
function checkDate(dateV){   
  var dateStr = dateV.value;
  return isValidDate(dateV, dateStr);
} 
function isValidDate(dateV, dateStr){
    // Checks for the following valid date formats:
    // MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY
    // Also separates date into month, day, and year variables
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
   if(matchArray == null){  
     alert("Date must be in the format MM/DD/YYYY")
     dateV.focus();
     return false;
    }
    if(dateStr.length != 10){  
      alert("Date must be in the format  MM/DD/YYYY");
      dateV.focus();
      return false;
    }
    var month = matchArray[1];
    var day = matchArray[3];
    var year = matchArray[4];
    if(month < 1 || month > 12) {
     alert("Month must be between 1 and 12.");
      dateV.focus();
      return false;
    }
    if(day < 1 || day > 31) {
      alert("Day must be between 1 and 31.");
      dateV.focus();
      return false;
    }
   if((month==4 || month==6 || month==9 || month==11) && day==31) {
      if(month==4){monthname="April"}
      if(month==6){monthname="June"}
      if(month==9){monthname="September"}
      if(month==11){monthname="November"}
         alert(monthname+" doesn't have 31 days!");
         dateV.focus();
         return false;
    }
    if(month == 2) {
        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!");
            dateV.focus();
            return false;
        }
    }
    return true;
}
