var digits = "0123456789";
 
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
 
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
 
// whitespace characters
var whitespace = " \t\n\r";
 
 
// decimal point character differs by language and culture
var decimalPointDelimiter = ".";
 
 
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
 
 
// 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 + "+";
 
 
// non-digit characters which are allowed in 
// Social Security Numbers
var SSNDelimiters = "- ";
 
 
 
// characters which are allowed in Social Security Numbers
var validSSNChars = digits + SSNDelimiters;
 
 
 
// U.S. Social Security Numbers have 9 digits.
// They are formatted as 123-45-6789.
var digitsInSocialSecurityNumber = 9;
 
 
 
// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;
 
 
 
// non-digit characters which are allowed in ZIP Codes
var ZIPCodeDelimiters = "-";
 
 
 
// our preferred delimiter for reformatting ZIP Codes
var ZIPCodeDelimeter = "-"
 
 
// characters which are allowed in Social Security Numbers
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
 
// non-digit characters which are allowed in credit card numbers
var creditCardDelimiters = " "
 
 
// CONSTANT STRING DECLARATIONS
// (grouped for ease of translation and localization)
 
// m is an abbreviation for "missing"
 
var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."
 
// s is an abbreviation for "string"
 
var sUSLastName = "Last Name"
var sUSFirstName = "First Name"
var sWorldLastName = "Family Name"
var sWorldFirstName = "Given Name"
var sTitle = "Title"
var sCompanyName = "Company Name"
var sUSAddress = "Street Address"
var sWorldAddress = "Address"
var sCity = "City"
var sStateCode = "State Code"
var sWorldState = "State, Province, or Prefecture"
var sCountry = "Country"
var sZIPCode = "ZIP Code"
var sWorldPostalCode = "Postal Code"
var sPhone = "Phone Number"
var sFax = "Fax Number"
var sDateOfBirth = "Date of Birth"
var sExpirationDate = "Expiration Date"
var sEmail = "Email"
var sSSN = "Social Security Number"
var sCreditCardNumber = "Credit Card Number"
var sOtherInfo = "Other Information"
 
 
 
 
// 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 iEmail = "This field must be a valid email address (like foo@bar.com). Please reenter it now."
var iCreditCardPrefix = "This is not a valid "
var iCreditCardSuffix = " credit card number. (Click the link on this form to see a list of sample numbers.) 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 = "The Day, Month, and Year for "
var iDateSuffix = " do not form a valid date.  Please reenter them now."
  
// 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 pEmail = "valid email address (like foo@bar.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 
// for many functions when they are passed the empty string. 
// By default, they will return defaultEmptyOK.
//
// defaultEmptyOK is false, which means that by default, 
// these functions will do "strict" validation.  Function
// is// passed a string containing an integer; if it is passed
// the empty string, it will return false.
//
// You can change this default behavior globally (for all 
// functions which use defaultEmptyOK) by changing the value
// of defaultEmptyOK.
//
// Most of these functions have an optional argument emptyOK
// which allows you to override the default behavior for 
// the duration of a function call.
//
// This functionality is useful because it is possible to
// say "if the user puts anything in this field, it must
// be an integer (or a phone number, or a string, etc.), 
// but it's OK to leave the field empty too."
// This is the case for fields which are optional but which
// must have a certain kind of content if filled in.
 
var defaultEmptyOK = false
 
 
 
//Integer, for example, will only return true if it is
function warnEmpty (theField, s)
{   theField.focus();
    alert(s + " is empty! Please correct!!");
    return false;
}
 
function isEmpty(xxx)
{
  if (xxx.length == 0){
  return (true);
  }
  else
  {
  return false;
  }
 
}
 
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 (c != ' ') return false;
    }
 
    // All characters are whitespace.
    return true;
}
 
 
function checkString (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    emptyOK = true;
    if (checkString.arguments.length == 2) emptyOK = false;
    if (isEmpty(theField.value))
    {
       if (emptyOK) { return true;} else {return warnEmpty (theField, s);}
    }
    if (isWhitespace(theField.value))
        return warnEmpty (theField, s);
    else return true;
}
 
function promptEntry (s)
{   window.status = pEntryPrompt + s
}
 
function isEmail (s, option)
{  
    if (isEmpty(s))
    {
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
    }
 
    // is s whitespace?
    if (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;
return true;
}
 
 function warnInvalid(field, s)
 {
field.focus();
    field.select();
 alert(s);
 return false;
 }
 
function checkEmail(theField, emptyOK)
{
   if (checkEmail.arguments.length == 1) emptyOK = false;
    if ((isEmpty(theField.value)) && (emptyOK)) return true;
    else if (!isEmail(theField.value))
       return warnInvalid (theField, "Invalid Email! Please correct!!");
    else return true;
}



