// VARIABLE DECLARATIONS
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var phoneNumberDelimiters = "()- ";
var whitespace = " \t\n\r";
var decimalPointDelimiter = "."
var puncs = ".-',;/";
var SSNDelimiters = "- ";
var ZIPCodeDelimiters = "-";
var USStateChars = "alkszrcotedfmlguhinyvjpwxALKSZRCOTEDFMLGUHINYVJPWX"
var emails = ".-_@";
var dates = "/";

// characters which are allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;

// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";

// characters which are allowed in Social Security Numbers
var validSSNChars = digits + SSNDelimiters;

// U.S. Social Security Numbers have 9 digits.
var digitsInSocialSecurityNumber = 9;

// U.S. phone numbers have 10 digits.
var digitsInUSPhoneNumber = 10;

// our preferred delimiter for reformatting ZIP Codes
var ZIPCodeDelimeter = "-"
var validZIPCodeChars = digits + ZIPCodeDelimiters

// U.S. ZIP codes have 5 or 9 digits.
// They are formatted as 12345 or 12345-6789.
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9

// CONSTANT STRING DECLARATIONS
var mPrefix = "You did not enter a value into the \""
var mSuffix = "\" field. This is a required field. Please enter it before proceeding."
var mPreA = "The \""
var mPostA = "\" field can only contain alphabetic charaters. This is a required field. Please correct it before proceeding."
var mPreAN = "The \""
var mPostAN = "\" field can only contain alphabetic charaters and/or number. This is a required field. Please correct it before proceeding."
var mPreN = "The \""
var mPostN = "\" field can only contain numbers. This is a required field. Please correct it before proceeding."
var mPreE = "The \""
var mPostE = "\" field can only contain numbers. This is a required field. Please correct it before proceeding."

// i is an abbreviation for "invalid"
var iStateCode = "This field must be a valid two character U.S. state abbreviation (like CA for California). Please reenter it now."
var iZIPCode = "This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please reenter it now."
var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now."
var iWorldPhone = "This field must be a valid international phone number. Please reenter it now."
var iSSN = "This field must be a 9 digit U.S. social security number (like 123 45 6789). Please reenter it now."
var iFEIN = "This field must be a 9 digit U.S. federal employer identification number (like 12 3456789). Please reenter it now."
var iEmail = "This field must be a valid email address (like joe@abc.com). Please reenter it now."
var iDay = "This field must be a day number between 1 and 31.  Please reenter it now."
var iMonth = "This field must be a month number between 1 and 12.  Please reenter it now."
var iYear = "This field must be a 2 or 4 digit year number.  Please reenter it now."
var iDatePrefix = "This is not a valid date for "
var iDateSuffix = "."

// p is an abbreviation for "prompt"
var pEntryPrompt = "Please enter a "
var pStateCode = "2 character code (like CA)."
var pZIPCode = "5 or 9 digit U.S. ZIP Code (like 94043)."
var pUSPhone = "10 digit U.S. phone number (like 415 555 1212)."
var pWorldPhone = "international phone number."
var pSSN = "9 digit U.S. social security number (like 123 45 6789)."
var pFEIN = "9 digit U.S. federal employer identification number (like 12 3456789)."
var pEmail = "valid email address (like joe@abc.com)."
var pCreditCard = "valid credit card number."
var pDay = "day number between 1 and 31."
var pMonth = "month number between 1 and 12."
var pYear = "2 or 4 digit year number."

// Global variable defaultEmptyOK defines default return value 
var defaultEmptyOK = false

// Attempting to make this library run on Navigator 2.0,
function makeArray(n)
{
	for (var i = 1; i <= n; i++) 
		this[i] = 0;
	return this;
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   //programmatically check
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

// Valid U.S. Postal Codes for states, territories, armed forces, etc.
var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP"

function getKeyDown(event)
{
	var str = "";
	var data = null;
	if(null == event.which)
	{
		data = event.keyCode;
		//alert(event.keyCode);
	}
	else
	{
		data = event.which;
		//alert(event.which);
	}
	if(20 > data)
		str = true;
	else
		str = String.fromCharCode(data);

	return str;
}

// Check whether string s is empty.
function isEmpty(s)
{   
	//if(true === s)
	
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)
{   var i;

    // Is s empty?
    if (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 (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isWhitespaceChar (c)
{   
    if (whitespace.indexOf(c) == -1) return false;
    return true;
}

function isPunc (c)
{   
    if (puncs.indexOf(c) == -1) return false;
    return true;
}

function isStateChar (c)
{   
	prompt("");
	if(true === c) return true;
    if (USStateChars.indexOf(c) == -1)
	{	
		prompt("Please enter a valid US State abbreviation.");
		return false;
	}
    return true;
}
function isDateChar (c)
{   
	prompt("");
	if(true === c) return true;
    if ((dates.indexOf(c) == -1) && (digits.indexOf(c) == -1))
	{	
		prompt("Please enter a number, or forward slash.");
		return false;
	}
    return true;
}
function isZIPChar (c)
{   
	prompt("");
	if(true === c) return true;
    if ((ZIPCodeDelimiters.indexOf(c) == -1) && (digits.indexOf(c) == -1))
	{	
		prompt("Please enter a number or a dash.");
		return false;
	}
    return true;
}
function isPhoneChar (c)
{   
	prompt("");
	if(true === c) return true;
    if ((phoneNumberDelimiters.indexOf(c) == -1) && (digits.indexOf(c) == -1))
	{	
		prompt("Please enter a number, dash, space, or parenthesis.");
		return false;
	}
    return true;
}
function isSSNChar (c)
{   
	prompt("");
	if(true === c) return true;
    if ((SSNDelimiters.indexOf(c) == -1) && (digits.indexOf(c) == -1))
	{	
		prompt("Please enter a number, dash, or space.");
		return false;
	}
    return true;
}
function isEmailChar (c)
{   
	prompt("");
	if(true === c) return true;
    if ((lowercaseLetters.indexOf(c) == -1) && (emails.indexOf(c) == -1) && (uppercaseLetters.indexOf(c) == -1) && (digits.indexOf(c) == -1))
	{	
		prompt("Please enter a letter, number, dash, at-sign, underscore, or period.");
		return false;
	}
    return true;
}

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

// Removes all whitespace characters from s.
function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}

// WORKAROUND FUNCTION FOR NAVIGATOR 2.0.2 COMPATIBILITY.
function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;}
    return false;
}

// Removes initial (leading) whitespace characters from s.
function stripInitialWhitespace (s)
{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    return s.substring (i, s.length);
}

// Returns true if character c is an English letter 
function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

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

// Returns true if character c is a letter or digit.
function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

// isInteger (STRING s [, BOOLEAN emptyOK])
function isInteger (s)
{   var i;

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

    // Search through string's characters one by one
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c))
		{
			prompt("Please enter a numeric character such as 0 to 9.");
			return false;
		}
    }
    // All characters are numbers.
    return true;
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
function isSignedInteger (s)
{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg));
    }
}

// isPositiveInteger (STRING s [, BOOLEAN emptyOK])
function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}

// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

// isNegativeInteger (STRING s [, BOOLEAN emptyOK])
function isNegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNegativeInteger.arguments.length > 1)
        secondArg = isNegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );
}

// isNonpositiveInteger (STRING s [, BOOLEAN emptyOK])
function isNonpositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonpositiveInteger.arguments.length > 1)
        secondArg = isNonpositiveInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );
}

// isFloat (STRING s [, BOOLEAN emptyOK])
function isFloat (s)
{   var i;
    var seenDecimalPoint = false;

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

    if (s == decimalPointDelimiter) return false;

    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;
}

// isSignedFloat (STRING s [, BOOLEAN emptyOK])
function isSignedFloat (s)
{   if (isEmpty(s)) 
       if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedFloat.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedFloat.arguments.length > 1)
            secondArg = isSignedFloat.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isFloat(s.substring(startPos, s.length), secondArg))
    }
}

// isAlphabetic (STRING s [, BOOLEAN emptyOK])
function isAlphabetic (s)
{   var i;

	prompt("");
	if(true === s) return true;
    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

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

        if (!(isLetter(c) || isWhitespaceChar(c)))
		{
			prompt("Please enter an alphabetic character such as A/a to Z/z.");
			return false;
		}
    }

    // All characters are letters.
    return true;
}

// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
function isAlphanumeric (s)
{   var i;

	prompt("");
	if(true === s) return true;
    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

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

        if (! (isLetter(c) || isDigit(c) || isWhitespaceChar(c)) )
		{
			prompt("Please enter an alphanumeric character such as A/a to Z/z or 0 to 9.");
			return false;
		}
    }

    // All characters are numbers or letters.
   return true;
}

function isExtended (s)
{   var i;

	prompt("");
if(true === c) return true;
   if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);
        if ( (isLetter(c) && isDigit(c) && isWhitespaceChar(c) && isPunc(c)) )
		{
			prompt("Please enter a character such as A/a to Z/z, 0 to 9, or a period, dash, apostrophe, or comma.");
			return false;
		}
    }

    // All characters are numbers or letters.
    return true;
}
function isAll (s)
{return true;}

// reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

// isSSN (STRING s [, BOOLEAN emptyOK])
function isSSN (s)
{   if (isEmpty(s)) 
       if (isSSN.arguments.length == 1) return defaultEmptyOK;
       else return (isSSN.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInSocialSecurityNumber);
}

// isUSPhoneNumber (STRING s [, BOOLEAN emptyOK])
function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber);
}

// isInternationalPhoneNumber (STRING s [, BOOLEAN emptyOK])
function isInternationalPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isInternationalPhoneNumber.arguments[1] == true);
    return (isPositiveInteger(s));
}

// isZIPCode (STRING s [, BOOLEAN emptyOK])
function isZIPCode (s)
{  if (isEmpty(s)) 
       if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
       else return (isZIPCode.arguments[1] == true);
   return (isInteger(s) && 
            ((s.length == digitsInZIPCode1) ||
             (s.length == digitsInZIPCode2)));
}

// isStateCode (STRING s [, BOOLEAN emptyOK])
function isStateCode(s)
{
	if (isEmpty(s)) 
       if (isStateCode.arguments.length == 1) return defaultEmptyOK;
       else return (isStateCode.arguments[1] == true);
    return ( (USStateCodes.indexOf(s) != -1) &&
             (s.length == 2) );
}

// isEmail (STRING s [, BOOLEAN emptyOK])
function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    if (isWhitespace(s)) return false;
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

// isYear (STRING s [, BOOLEAN emptyOK])
function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    if (!isInteger(s, false)) return false;

    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

// isMonth (STRING s [, BOOLEAN emptyOK])
function isMonth (s)
{   if (isEmpty(s))
	{ 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
	}
	if(2 == s.length)
		if('0' == s[0])
			s = s[1];
    return isIntegerInRange (s, 1, 12);
}

// isDay (STRING s [, BOOLEAN emptyOK])
function isDay (s)
{   if (isEmpty(s)) 
	{
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
	}
	if(2 == s.length)
		if('0' == s[0])
			s = s[1];
    return isIntegerInRange (s, 1, 31);
}

// daysInFebruary (INTEGER year)
function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

// Display prompt string s in status bar.

function prompt (s)
{   window.status = s;
}

// Display data entry prompt string s in status bar.
function promptEntry (s)
{   window.status = pEntryPrompt + s;
}

// Notify user that required field theField is empty.
function warnEmpty (theField, s)
{   
    alert(mPrefix + s + mSuffix);
    theField.focus();
	return false;
}



// Notify user that contents of field theField are invalid.
function warnInvalid (theField, s)
{   alert(s);
	theField.focus();
    theField.select();
    return false;
}

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
function checkString (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    if (!isAlphanumeric(theField.value)) 
       return warnInvalid (theField, mPreAN + s + mPostAN);
    else return true;
}

function checkAlpha (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkAlpha.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    if (!isAlphabetic(theField.value)) 
       return warnInvalid (theField, mPreA + s + mPostA);
    else return true;
}

function checkNumber (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkNumber.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    if (!isInteger(theField.value)) 
       return warnInvalid (theField, mPreN + s + mPostN);
    else return true;
}

function checkExtended (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkExtended.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    if (!isExtended(theField.value)) 
       return warnInvalid (theField, mPreE + s + mPostE);
    else return true;
}

function checkAll(theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkAll.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else return true;
}

// checkStateCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkStateCode (theField, s, emptyOK)
{   if (checkStateCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  theField.value = theField.value.toUpperCase();
       if (!isStateCode(theField.value, false)) 
          return warnInvalid (theField, iStateCode);
       else return true;
    }
}

// takes ZIPString, a string of 5 or 9 digits;
function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}

// checkZIPCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkZIPCode (theField, s, emptyOK)
{   if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters)
      if (!isZIPCode(normalizedZIP, false)) 
         return warnInvalid (theField, iZIPCode);
      else 
      {  // if you don't want to insert a hyphen, comment next line out
         theField.value = reformatZIPCode(normalizedZIP)
         return true;
      }
    }
}

// takes USPhone, a string of 10 digits
function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
}

// checkUSPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkUSPhone (theField, s, emptyOK)
{   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return warnInvalid (theField, iUSPhone);
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          //theField.value = normalizedPhone
          return true;
       }
    }
}

// checkInternationalPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkInternationalPhone (theField, s, emptyOK)
{   if (checkInternationalPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  if (!isInternationalPhoneNumber(theField.value, false)) 
          return warnInvalid (theField, iWorldPhone);
       else return true;
    }
}

// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
function checkEmail (theField, s, emptyOK)
{   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else if (!isEmail(theField.value, false)) 
       return warnInvalid (theField, iEmail);
    else return true;
}

// takes SSN, a string of 9 digits
function reformatSSN (SSN)
{   return (reformat (SSN, "", 3, "-", 2, "-", 4))
}
function reformatFEIN (FEIN)
{   return (reformat (FEIN, "", 2, "-", 7))
}

// Check that string theField.value is a valid SSN.
function checkSSN (theField, s, emptyOK)
{   if (checkSSN.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedSSN = stripCharsInBag(theField.value, SSNDelimiters)
       if (!isSSN(normalizedSSN, false)) 
          return warnInvalid (theField, iSSN);
       else 
       {  // if you don't want to reformats as 123-456-7890, comment next line out
          theField.value = reformatSSN(normalizedSSN)
          //theField.value = normalizedSSN
          return true;
       }
    }
}

function checkFEIN (theField, s, emptyOK)
{   if (checkFEIN.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedFEIN = stripCharsInBag(theField.value, SSNDelimiters)
       if (!isSSN(normalizedFEIN, false)) 
          return warnInvalid (theField, iFEIN);
       else 
       {  // if you don't want to reformats as 123-456-7890, comment next line out
          theField.value = reformatFEIN(normalizedFEIN)
          //theField.value = normalizedFEIN
          return true;
       }
    }
}

// Check that string theField.value is a valid Year.
function checkYear (theField, emptyOK)
{   if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value, false)) 
       return warnInvalid (theField, iYear);
    else return true;
}

// Check that string theField.value is a valid Month.
function checkMonth (theField, emptyOK)
{   if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isMonth(theField.value, false)) 
       return warnInvalid (theField, iMonth);
    else return true;
}

// Check that string theField.value is a valid Day.
function checkDay (theField, emptyOK)
{   if (checkDay.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isDay(theField.value, false)) 
       return warnInvalid (theField, iDay);
    else return true;
}

// checkDate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
function checkWhackoDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkWhackoDate.arguments.length == 4) OKtoOmitDay = false;
    if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
    if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    else if (!isDay(dayField.value)) 
       return warnInvalid (dayField, iDay);
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true; 
    alert (iDatePrefix + labelString + iDateSuffix)
    return false
}

// split up a field that contains full date (mm/dd/yyyy format only) into pieces to 
// be used by the checkDate function
// sheri bierman, Telperion 5/31/02
// whacked out by Lou at a later date...
function checkDate (theField, myLabel, emptyOK)
{
	if (checkDate.arguments.length == 2) emptyOK = defaultEmptyOK;
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	if (isWhitespace(theField.value))
		return warnEmpty (theField, s);
	var dateToSplit = theField.value;
	if(0 > dateToSplit.indexOf('/'))
	{
      warnInvalid (theField, iDatePrefix + myLabel + iDateSuffix);
      return false;
	}
	var arrFullDate = dateToSplit.split('/');
	if (3 != arrFullDate.length)
	{
      warnInvalid (theField, iDatePrefix + myLabel + iDateSuffix);
      return false;
	}
	if (arrFullDate[2].length != 4)
	{
      warnInvalid (theField, iDatePrefix + myLabel + iDateSuffix);
      return false;
	}
	if (!isDate(arrFullDate[2], arrFullDate[0], arrFullDate[1]))
	{
      warnInvalid (theField, iDatePrefix + myLabel + iDateSuffix);
      return false;
	}
	else
	{
		return true;
	}
}

// Get checked value from radio button.
function getRadioButtonValue (radio)
{   
	//alert(radio);
	for (var i = 0; i < radio.length; i++)
    {   
		if (radio[i].checked) { break }
    }
	//alert(radio.length);
    return radio[i].value
}

function CheckEmptySelect(arg_str, arg_label)
{
	var objCB = null;
	var arr = window.document.getElementsByName(arg_str);
	
	if(null == arr)
	{
		alert("Whoops - null arr");
		return false;
	}
	
	if(2 == arr.length)
		objCB = arr[1];
	else
		objCB = arr[0];

	if((false == objCB.disabled) && (0 >= objCB.selectedIndex))
	{
		alert("Please select a "+arg_label);
		objCB.focus();
		return false;
	}

	return true;
}