var bsubmit = false;
var digits = "0123456789";

var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"

var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var specialchar = "_*"
//var specialchar = "_"
var strSearch="0123456789/-"
var sErrors=""
var sErrorsBegin="<ul>"
var sErrorsEnd="</ul>"


// 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 sAccntNum = "Bill Account Number"
var sPayeeName = "Payee Name"
var sPayeeNickName = "Payee Nickname"
var sNameOnAccount = "Name on the Account"
var sUSLastName = "Last Name"
var sUSFirstName = "First Name"
var sAppName = "Applicant's 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"
var sSavingsNum = "Savings Account Number"


// Home Improvement Loan Application Specific
var sbranch_number = "Branch Number"
var sbc_name = "BC Name"
var sloan_amount_requested = "Loan Amount Requested"
var sterm_requested = "Loan Term Requested"
var sprimary_residence = "Primary Residence"
var ssubject_property_address = "Property Address"
var ssubject_property_city = "Property City"
var ssubject_property_state = "Property State"
var ssubject_property_zip1 = "Property Zip Code"
var ssubject_property_county = "Property County"
var syear_purchased = "Year Property Purchased"
var spurchase_price = "Property Purchase Price"
var scurrent_value = "Current Property Value"

var sname_first="First Name"
var sname_middle="Middle Name or Initial"
var sname_last="Last Name"
var shome_phone="Home Phone Number"
var saddress_years = "Years in Residence"
var smail_address = "Mailing Address"
var smail_city = "Mailing City"
var smail_state = "Mailing State"
var smail_zip1 = "Mailing Zip Code"
var sprev_address = "Previous Address"
var sprev_city = "Previous City"
var sprev_state = "Previous State"
var sprev_zip1 = "Previous Zip Code"
var semail_address = "E-Mail Address"
var semail_address2 = "E-Mail Address Verification"
var sssn = "Social Security Number"
var sdob = "Date of Birth"
var sself_employed = "Self-Employed"
var sretired = "Retired"
var semployer = "Employer's Name"
var semployer_address = "Employer's Address"
var sposition = "Position"
var semployment_length_years = "Employment Length - Years"
var semployment_length_months = "Employment Length - Months"
var sgross_income = "Gross Income"
var sbusiness_phone = "Work Phone Number"
var saddtl_income = "Amount of Additional Income"
var saddtl_source = "Source of Additional Income"
var saddtl_length_years = "Secondary Employment Length - Years"
var saddtl_length_months = "Secondary Employment Length - Months"
var saddtl_address = "Secondary Employer Address"
var saddtl_phone = "Secondary Employer Phone Number"

var sguaranty_customer = "Guaranty Bank Customer"
var sother_bank_checking_account = "Other Checking Account"
var sother_bank_checking_balance = "Other Checking Account Balance"
var sother_bank_savings_account = "Other Savings Account"
var sother_bank_savings_balance = "Other Savings Account Balance"
var sretirement_balance = "Retirement/401k Account Balance"
var smortgage_co = "Mortgage Company Name"
var smortgage_pmt = "Mortgage Payment"
var smortgage_balance = "Mortgage Balance"
var smaint_pmt = "Separate Maintenance Payment"
var sdebt_consolidation = "Debt Consolidation"
var sdebt_name = "Debt Account Name"
var sdebt_pmt = "Debt Monthly Payment"
var sdebt_bal = "Approximate Debt Balance"

var smarital_status = "Marital Status"
var scitizen = "U.S. Citizen"
//var sresident_alien = "Resident Alien"
var scashout_loan = "Previous Home Equity Loan"
var scoapplicant = "Co-Applicant"


// i is an abbreviation for "invalid"

var iStateCode = "The State field must be a valid two character U.S. state abbreviation (like CA for California)."
var iZIPCode = "The Zip Code field must be a 5 or 9 digit U.S. ZIP Code (like 94043)."
var iUSPhone = "The phone field must be a 10 digit U.S. phone number (like 415 555 1212)."
var iWorldPhone = "This field must be a valid international phone number."
var iSSN = "The SSN field must be a 9 digit U.S. social security number (like 123 45 6789)."
var iEmail = "The E-mail field must be a valid email address (like name@service.com)."
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.)"
var iDay = "This field must be a day number between 1 and 31."
var iMonth = "This field must be a month number between 1 and 12."
var iYear = "This field must be a 2 or 4 digit year number."
var iDatePrefix = "The Day, Month, and Year for "
var iDateSuffix = " do not form a valid date."

var iUSAccount = "The Account Number field must be in digit only."

var iBDateYear="This field must be a 4 digit year number."
var iInvalidMonth="This field must be between 1(January) and 12(December)."

var iFirstName="The First Name field is empty."
var iLastName="The Last name field is empty."
var iAddress="The Address field is empty."
var iCity="The City field is empty."
var iEmailADD = "The primary E-mail field is empty or has an invalid email format."
var iEmailADD2 = "The verification E-mail field is empty or has an invalid email format."
var iEmailEqual="The primary and verification E-mail fields do not match."
var iAggreement="Please read and check the Online Banking Agreement Box!"
var iMaiden="The Mother's Maiden name field is empty"



var defaultEmptyOK = false





// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

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;
}




// 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 isUIDChar (s)
{	
	var i;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (UIDChar.indexOf(c) == -1) 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 
// 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;
}



// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}




// WORKAROUND FUNCTION FOR NAVIGATOR 2.0.2 COMPATIBILITY.
//
// The below function *should* be unnecessary.  In general,
// avoid using it.  Use the standard method indexOf instead.
//
// However, because of an apparent bug in indexOf on 
// Navigator 2.0.2, the below loop does not work as the
// body of stripInitialWhitespace:
//
// while ((i < s.length) && (whitespace.indexOf(s.charAt(i)) != -1))
//   i++;
//
// ... so we provide this workaround function charInString
// instead.
//
// charInString (CHARACTER c, STRING s)
//
// Returns true if single character c (actually a string)
// is contained within string s.

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.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

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 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}



// Returns true if character c is a digit 
// (0 .. 9).

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))
}



// isAlphabetic (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isAlphabetic (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }

    // All characters are letters.
    return true;
}




// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric 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 or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}





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])
// 
// isSSN returns true if string s is a valid U.S. Social
// Security Number.  Must be 9 digits.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

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])
// 
// isUSPhoneNumber returns true if string s is a valid U.S. Phone
// Number.  Must be 10 digits.
//
// NOTE: Strip out any delimiters (spaces, hyphens, parentheses, etc.)
// from string s before calling this function.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

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)
}



function isUSAccount(s)
{	if (isEmpty(s))
		if (isUSAccount.arguments.length == 1) return defaultEmptyOK;
		else return (isUSAccount.arguments[1] == true);
	return isInteger(s)
}



// isZIPCode (STRING s [, BOOLEAN emptyOK])
// 
// isZIPCode returns true if string s is a valid 
// U.S. ZIP code.  Must be 5 or 9 digits only.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.  
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

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)))
}





// isUserNameNew (STRING s [, BOOLEAN emptyOK])
// isUserNameNew returns true if string s is a valid User-ID
// Must be 8-20 characters long.
//
// For explanation of optional argument emptyOK,
// see comments of function isAlphanumeric.





// isStateCode (STRING s [, BOOLEAN emptyOK])
// 
// Return true if s is a valid U.S. Postal Code 
// (abbreviation for state).
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

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.indexOf(USStateCodeDelimiter) == -1) )
}






// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       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;
}


// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}







/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */


// 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.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.

function warnEmpty (theField, s)
{   alert(mPrefix + s + mSuffix)
	if (!bsubmit){
	theField.focus();
	theField.select();}
	window.event.returnValue = 0;
    return false
}



// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   alert(s)
	if (!bsubmit){
	theField.select();
	theField.focus();}
	window.event.returnValue = 0;
    return false
}

function resetfocus(ofield)
{
	ofield.focus()
	return true
}


/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

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 (s);
    else return true;
}





// takes ZIPString, a string of 5 or 9 digits;
// if 9 digits, inserts separator hyphen

function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}




// checkZIPCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid ZIP code.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkZIPCode (theField, 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
// and reformats as (123) 456-789

function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ")", 3, "-", 4))

}



// checkUSPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid US Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkUSPhone (theField, 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)
          return true;
       }
    }
}






// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkEmail (theField, 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
// and reformats as 123-45-6789

function reformatSSN (SSN)
{   return (reformat (SSN, "", 3, "-", 2, "-", 4))
}


// Check that string theField.value is a valid SSN.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkSSN (theField, 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-46-7890, comment next line out
          theField.value = reformatSSN(normalizedSSN)
          return true;
       }
    }
}







// *********************************************************************************************************
// Check that string theField.value is a valid User-ID.



// Merges string USFirstName and USLastName into AppName.

function createAppName ()
{
	var firstname = document.regapp.AppNameFirst.value 
	var lastname = document.regapp.AppNameLast.value
	lastnamelen = lastname.length;
 	document.regapp.AppName.value = firstname.substring(0,(19-lastnamelen))+" "+lastname.substring(0,19);
	return true;
	
}


function ValidNumbers (theField)
{	
		var c = String.fromCharCode(window.event.keyCode)
		if (strSearch.indexOf(c) == -1)
		{ window.event.returnValue = 0;}
	
	
}

/*function ValidNumbers(theField)
{
	if(document.all){
	var c = String.fromCharCode(window.event.keyCode)
		
		if (strSearch.search(c) == -1) {
			window.event.keyCode=0;
			window.event.returnValue = 0;
		}
	}
}
*/
function checkdate(objName)
 {
	var datefield = objName;
	if (chkdate(objName) == false)
	 {
		datefield.select();
		alert("That date is invalid.  Please try again.");
		datefield.focus();
		return false;
	}
	else
	 {
		return true;
   	}
}

function chkdate(objName)
 {
	var strDatestyle = "US"; //United States date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var oname=datefield.name;
	
	
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield.value;
	if (strDate.length==0){
	  return true;
	}  
	if (strDate.length < 8)
	 {
		return false;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
		strDateArray = strDate.split(strSeparatorArray[intElementNr]);
		if (strDateArray.length != 3)
		 {
			err = 1;
			return false;
		}
		else 
		{
			strDay = strDateArray[0];
			strMonth = strDateArray[1];
			strYear = strDateArray[2];
		}
		booFound = true;
   		}
	}
	if (booFound == false)
	 {
		if (strDate.length>5)
	 	{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
   		}
	}
	if (strYear.length < 4)
	{
		return false;
		//strYear = '20' + strYear;
	}
	
	var dtcurr=new Date();
	var yrcurr=dtcurr.getYear();
	
	
	
	
	
	
	if (strDay.length < 2)
	{
		strDay="0" + strDay;
		//strYear = '20' + strYear;
	}
	if (strMonth.length < 2)
	{
		strMonth="0" + strMonth;
		//strYear = '20' + strYear;
	}
	
	
	if (strDatestyle == "US") 
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) 
	{
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) 
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
   			}
		}
		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
   		}
	}	
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return false;
	}
	
	if ((oname=='COAPPDLEXPIRES') || (oname=='APPDLEXPIRES')){
	   if (intYear>=2500){
	     err = 4;
		return false;
	   }
	}
	else{
	if ((oname!='COAPPDLEXPIRES') || (oname!='APPDLEXPIRES')){
	   if (intYear>=yrcurr){
	     err = 4;
		return false;
	   }
	}
	}
	
	
	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 	
	{
		err = 7;
		return false;
	}
	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true)
		 {
			if (intday > 29)
			 {
				err = 9;
				return false;
			}
		}
		else 
		{
			if (intday > 28) 
			{
				err = 10;
				return false;
			}
		}
	}
	/*if (strDatestyle == "US") 
	{
		datefield.value = strMonth + "-" + strDay+ "-" + strYear;
	}
	else 
	{
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}*/
	datefield.value = strMonth + "-" + strDay+ "-" + strYear;
	
return true;
}

function LeapYear(intYear)
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) { return true; }
	}
	else 
	{
	if ((intYear % 4) == 0) { return true; }
	}
return false;
}


/* function ShowSubMenu(theField)
{	//alert(window.event.screenX)
	//sLeft=parseInt(theField.style.left,10)+10
	//sLeft=window.event.x
	//sTop=parseInt(theField.style.top,10)+10
	//sTop=window.event.y+10
	sLeft= window.event.clientX
	sTop=window.event.clientY+document.body.scrollTop 
	targetID=document.all("MESSAGE")
	targetID.style.left=sLeft
	targetID.style.top=sTop
	targetID.style.display=""
	document.all("MESSAGE1").innerHTML=iUserNameNew

}

  function HideSubMenu(theField)
{
	targetID=document.all("MESSAGE")
	
	targetID.style.display="none"
}
*/


function UIDField(theField)
{
	if (document.all)
	{
	//alert(String.fromCharCode(window.event.keyCode));
	var c = String.fromCharCode(window.event.keyCode)
	if (UIDChars.indexOf(c) == - 1) 
		window.event.returnValue = 0;
	}
}

function NumberOnly(theField)
{
	if(document.all){
	var c = String.fromCharCode(window.event.keyCode)
		if (!isDigit(c)) 
			window.event.returnValue = 0;
	}
}

function Field_onfocus(theField, imax, idim, pPrompt)
{
	var items = theField.value
	promptEntry(pPrompt)
	if (items.length == imax)
	{
		theField.value = unformat(items)
		theField.maxLength = idim
	}
}
function BDField_onfocus(theField, imax, idim, pPrompt)
{
	var items = theField.value
	promptEntry(pPrompt)
	
}




function SSNcheck (theField, emptyOK)
{   if (SSNcheck.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedSSN = unformat(theField.value)
       if (!isSSN(normalizedSSN, false)) 
	   {  theField.value = normalizedSSN
          return warnInvalid (theField, iSSN);
	   }
       else 
       {  // if you don't want to reformats as 123-46-7890, comment next line out
	   	  theField.maxLength = 9
          theField.value = reformatSSN(normalizedSSN)
          return true;
       }
    }
}

function SSNblur (theField)
{
	var sitem = theField.value
	if (sitem.length == 9 )
	{
		theField.maxLength = 11
		theField.value = reformatSSN(sitem)
		return true;
	}
}
function BDateYearblur (theField)
{
	var sitem = theField.value
	if (sitem.length < 4)
	{
		alert(iBDateYear);
		theField.select();
		theField.focus()
		
	}
}
function ValidMonth (theField,theDayField)
{
	var sitem = theField.value
	
	if (!inRange(sitem,1,12))
	{
		alert(iInvalidMonth);
		theField.select();
		theField.focus();
	}else if(!CompareMonthDays(theDayField,theField)) {
		alert("You have entered an invalid day for the chosed month. Please reenter now.");
		theDayField.select();
		theDayField.focus();	
	
	}
}
function inRange(inputStr, lo, hi) {

var num = parseInt(inputStr,10);

if (num < lo || num > hi) {
return false;
}
return true;
}
function ValidateDay (theField,iMonthField)
{	var dDay=theField.value
	
if (!isNaN(parseInt(dDay,10)))
 {
	if (!isNaN(parseInt(iMonthField.value,10)))
	{	if(!CompareMonthDays(theField,iMonthField))
			{alert("You have entered an invalid day for the chosed month. Please reenter now.");
				theField.select();
				theField.focus();	
			}	
	}
 }
}

function CompareMonthDays(theDayField,theMonthField)
{
		var dDay=theDayField.value
	var monthArray=new Array("Jan","Feb","Mar","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec")
	
	var dMonth=monthArray[parseInt(theMonthField.value,10)-1]
	
	switch(dMonth){
		case "Jan" :
			
			if(!inRange(dDay,1,31))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.");
				//theField.select();
				//theField.focus();	
				return false;
			}else{return true;}
			break;
		case "Feb" :
			
			if(!inRange(dDay,1,29))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;
		case "Mar" :
			
			if(!inRange(dDay,1,31))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;
		case "Apr" :
			
			if(!inRange(dDay,1,30))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;		
		case "May" :
			
			if(!inRange(dDay,1,31))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;
		case "June" :
			
			if(!inRange(dDay,1,30))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;
		case "July" :
			
			if(!inRange(dDay,1,31))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;
		case "Aug" :
			
			if(!inRange(dDay,1,31))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;
		case "Sep" :
			
			if(!inRange(dDay,1,30))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;
		case "Oct" :
			
			if(!inRange(dDay,1,30))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();	
				return false;
			}else{return true;}
			break;
		case "Nov" :
			
			if(!inRange(dDay,1,30))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();	
				return false;
			}else{return true;}
			break;
		case "Dec" :
			
			if(!inRange(dDay,1,31))
			{
				//alert("You have entered an invalid day for the chosed month. Please reenter now.")
				//theField.select();
				//theField.focus();
				return false;
			}else{return true;}
			break;								
	
	//switch end
	}	
}


function checkZIP (theField, emptyOK)
{   if (checkZIP.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    { var normalizedZIP = unformat(theField.value)
      if (!isZIPCode(normalizedZIP, false)) 
	  {  theField.value = normalizedZIP	 
         return warnInvalid (theField, iZIPCode);
	  }
      else 
      {  // if you don't want to insert a hyphen, comment next line out
	  	 theField.maxLength = 10
         theField.value = reformatZIPCode(normalizedZIP)
         return true;
      }
    }
}

function Zipblur (theField)
{
	var sitem = theField.value
	if (sitem.length == 9 )
	{
		theField.maxLength = 10
		theField.value = reformatZIPCode(sitem)
		return true;
	}
}

function CheckPhone(theField, emptyOK)
{	if (CheckPhone.arguments.length == 1) emptyOK = defaultEmptyOK; 
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	else
	{ var items = unformat(theField.value) 
		if (!isUSPhoneNumber(items, false))
		{	theField.value = items
			return warnInvalid (theField, iUSPhone);
		}
		else
		{	theField.maxLength = 13
			theField.value = reformatUSPhone(items)
			return true;
		}
	}
}

function USPhoneblur (theField)
{
	var sitem = theField.value
	if (sitem.length == 10 )
	{
		theField.maxLength = 13
		theField.value = reformatUSPhone(sitem)
		return true;
	}
}

function CheckAccount(theField, emptyOK)
{
	if (CheckAccount.arguments.length == 1) emptyOK = defaultEmptyOK;
	if((emptyOK == true) && (isEmpty(theField.value))) return true;
	else
	{
	var items = unformat(theField.value)
		if(!isUSAccount(items, false))
		{
		theField.value = items
		return warnInvalid (theField, iUSAccount);
		}
		else return true;
	}
}

function unformat (str)
{	
	var arg;
	var resultString = "";
	for (var i=0; i < str.length ; i++)
	{
		arg = str.charAt(i)
		if (isDigit(arg)) resultString += arg;

	}
	return resultString;
}

function validateEmail(theField)
{
	if (theField.value != document.all.app_email_address.value)
			{
			alert("The E-mail Fields does not match. Please try again");
			theField.focus();
			}
}
function validateEmail2(theField)
{
	if (theField.value != document.all.coapp_email_address.value)
			{
			alert("The E-mail Fields does not match. Please try again");
			theField.focus();
			}
}

function formatCurrency(num) {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
			num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num*100+0.50000000001);
			cents = num%100;
			num = Math.floor(num/100).toString();
		if(cents<10)
			cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + '$' + num + '.' + cents);
}

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
function validate(){
//alert("hello");
return true;
}
///////////////////////////////////////////////////////////////////////////////
function validatecontact(){

sErrors="";
var bvalidate=true;

//validation for a drop down list
//var svariablename=document.formname.formfield.options[document.formname.formfield.selectedIndex].value;

//validation for text field, textarea, radiobuttons (use hidden text field as formfield name)
//var svariablename=window.document.formname.formfield.value;

var stxtfname=window.document.frmContact.txtFName.value;
var stxtlname=window.document.frmContact.txtLName.value;
var stxtaddress1=window.document.frmContact.txtAddress1.value;
var stxtcity=window.document.frmContact.txtCity.value;
var stxtstate=window.document.frmContact.txtState.value;
var stxtzip=window.document.frmContact.txtZip.value;
var stxtphoneday=window.document.frmContact.txtPhoneDay.value;
var stxtemail=window.document.frmContact.txtEmail.value;

if (navigator.appName=='Netscape'){
       if (stxtfname.length==0){alert('Please enter your first name.');bvalidate=false;}
  else if (stxtlname.length==0){alert('Please enter your last name.');bvalidate=false;}
  else if (stxtaddress1.length==0){alert('Please enter your address.');bvalidate=false;}
  else if (stxtcity.length==0){alert('Please enter your city.');bvalidate=false;}
  else if (stxtstate.length==0){alert('Please enter your state.');bvalidate=false;}
  else if (stxtzip.length==0){alert('Please enter your zip code.');bvalidate=false;}
  else if (stxtphoneday.length==0){alert('Please enter your daytime phone number.');bvalidate=false;}
  else if (stxtemail.length==0){alert('Please enter your e-mail address.');bvalidate=false;}
}
else{
  if (stxtfname.length==0){ChangeColor('stxtfname',true);bvalidate = false;}else{ChangeColor('stxtfname',false)}
  if (stxtlname.length==0){ChangeColor('stxtlname',true);bvalidate = false;}else{ChangeColor('stxtlname',false)}
  if (stxtaddress1.length==0){ChangeColor('stxtaddress1',true);bvalidate = false;}else{ChangeColor('stxtaddress1',false)}
  if (stxtcity.length==0){ChangeColor('stxtcity',true);bvalidate = false;}else{ChangeColor('stxtcity',false)}
  if (stxtstate.length==0){ChangeColor('stxtstate',true);bvalidate = false;}else{ChangeColor('stxtstate',false)}
  if (stxtzip.length==0){ChangeColor('stxtzip',true);bvalidate = false;}else{ChangeColor('stxtzip',false)}
  if (stxtphoneday.length==0){ChangeColor('stxtphoneday',true);bvalidate = false;}else{ChangeColor('stxtphoneday',false)}
  if (stxtemail.length==0){ChangeColor('stxtemail',true);bvalidate = false;}else{ChangeColor('stxtemail',false)}

  if (bvalidate != true) {targetID=document.all("Errors");targetID.innerHTML=sErrorsBegin + sErrors + sErrorsEnd;window.scrollTo(0,0);}
}

return bvalidate;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
function ChangeColor(sname,bError)
{	var serror;
	
		if(sname!="sEMAIL"){snameObj=document.all(sname +"FONT");}
	
	if (bError){
		if(sname!="sEMAIL"){snameObj.style.color="firebrick";}
		serror=document.all("ERROR");
		serror.style.display="";
		switch(sname){
          case "stxtfname":
				sErrors=sErrors + "<li>" + "Please enter your first name.";
				break;
          case "stxtlname":
				sErrors=sErrors + "<li>" + "Please enter your last name.";
				break;
          case "stxtaddress1":
				sErrors=sErrors + "<li>" + "Please enter your address.";
				break;
          case "stxtcity":
				sErrors=sErrors + "<li>" + "Please enter your city.";
				break;
          case "stxtstate":
				sErrors=sErrors + "<li>" + "Please enter your state.";
				break;
          case "stxtzip":
				sErrors=sErrors + "<li>" + "Please enter your zip code.";
				break;
          case "stxtphoneday":
				sErrors=sErrors + "<li>" + "Please enter your daytime phone number.";
				break;
          case "stxtemail":
				sErrors=sErrors + "<li>" + "Please enter your e-mail address.";
				break;
//			 case "stxtemail":
//				sErrors=sErrors + "<li>" + iEmailEqual;
//				snameObj=document.all("stxtemailFONT");
//				snameObj.style.color="firebrick";
//				snameObj=document.all("sEMAILADDR2FONT");
//				snameObj.style.color="firebrick";
//				break;						
						
			}		
	
		}else{
		snameObj.style.color="black"
		
	}
}	
///////////////////////////////////////////////////////////////////////////////
function warnEmpty (s)
{   alert("Missing " + s)
	if (!bsubmit){
	}
	window.event.returnValue = 0;
    return false
}
