// VARIABLE DECLARATIONS
	if (errorText == "")	{
var errorText = "<table class='errorbox' border='0' cellspacing='0' cellpadding='0'><tr><td class='errorhdr'><img src='/images/errorMrkr.gif' width='14' height='14' valign='middle'/>&nbsp;&nbsp;Limited Vehicle Information</td></tr><tr><td><p class='errorInstructions'>Please correct the errors below before continuing:</p><ul>";
	}

var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var whitespace = " \t\n\r\f\v";
var decimalPointDelimiter = "."
var phoneNumberDelimiters = "()- ";
var validUSPhoneChars = digits + phoneNumberDelimiters;
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";
var SSNDelimiters = "- ";
var validSSNChars = digits + SSNDelimiters;
var digitsInSocialSecurityNumber = 9;
var digitsInUSPhoneNumber = 10;
var ZIPCodeDelimiters = "-";
var ZIPCodeDelimeter = "-"
var validZIPCodeChars = digits + ZIPCodeDelimiters
var digitsInZIPCode1 = 5
var digitsInZIPCode2 = 9
var creditCardDelimiters = " "

var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."

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"
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."
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."
var isUSR = false;
var isHBXError = false;
var defaultEmptyOK = false
var wssErrorText = "";

function wssError(eText){
	eText = eText.replace(/' '/, '+');
	if(isUSR && isHBXError) {hbx.pec = eText;}
	}

function wssErrorAdd(eText){
eText = eText.replace(/' '/, '+');
	if(wssErrorText.length > 0){
	wssErrorText += "|";
	}
wssErrorText += eText;
wssError(wssErrorText);
}

function isPhoneNumber(prefix,exchange,houseNumber,contactType,phoneExt)
   {

   var str  = prefix;
   var str1 = exchange;
   var str2 = houseNumber;
   var str3 = phoneExt;
	
   // Return false if area code field is blank.
   if (str == "")
      {
	   wssErrorAdd("Phone");
      errorText += "<li>The area code field of your phone number is blank.\n\nPlease enter your area code.";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";
      return false;
      }
   if (str.length != 3)
      {
	   wssErrorAdd("Phone");
      errorText += "<li>The area code of your phone number must contain three digits. Please re-enter your area code.</li>";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
		return false;
      }
   // Return false if characters are not digits '0-9'.
   for (var i = 0; i < str.length; i++) 
      {
      var ch = str.substring(i, i + 1);
      if (ch < "0" || "9" < ch)
         {
		  wssErrorAdd("Phone");
         errorText += "<li>The area code field of your phone number only accepts digits \"0-9\".\n\nPlease re-enter your area code.";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
         return false;
         }
      }
   // Return false if phone prefix field is blank.
   if (str1 == "")
      {
	   wssErrorAdd("Phone");
      errorText += "<li>The prefix field of your phone number is blank.\n\nPlease enter your phone prefix.";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
      return false;
      }
   if (str1.length != 3)
      {
	   wssErrorAdd("Phone");
      errorText += "<li>The prefix field of your phone number requires three digits.\n\nPlease re-enter your phone prefix.";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
      return false;
      }
   // Return false if characters are digits '0-9'.
   for (var i = 0; i < str1.length; i++) 
      {
      var ch = str1.substring(i, i + 1);
      if (ch < "0" || "9" < ch)
         {
		  wssErrorAdd("Phone");
         errorText += "<li>The prefix field of your phone number only accepts digits '0-9'.\n\nPlease re-enter your phone prefix.";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
         return false;
         }
      }
   // Return false if phone number field is blank.
   if (str2 == "")
      {
	   wssErrorAdd("Phone");
      errorText += "<li>The phone number field of your phone number is blank.\n\nPlease enter your phone number.";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
      return false;
      }
   if (str2.length != 4)
      {
	   wssErrorAdd("Phone");
      errorText += "<li>The last part of your phone number must contain four digits. Please re-enter the last four digits of your phone number.</li>";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
      return false;
      }
		
   // Return false if characters are not digits '0-9'.
   for (var i = 0; i < str2.length; i++) 
      {
      var ch = str2.substring(i, i + 1);
      if (ch < "0" || "9" < ch)
         {
		  wssErrorAdd("Phone");
         errorText += "<li>The phone number field of your phone number only accepts digits \"0-9\".\n\nPlease re-enter your phone number.";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
         return false;
         }
      }
		

   // Return false if characters are not digits '0-9'.
   for (var i = 0; i < str3.length; i++) 
      {
      var ch = str3.substring(i, i + 1);
      if (ch < "0" || "9" < ch)
         {
		  wssErrorAdd("Phone");
         errorText += "<li>The extension field of your phone number only accepts digits '0-9'.\n\nPlease re-enter your phone number.";
		document.getElementById("oeFormcontactType"+contactType+"Container").className="error";			
         return false;
         }
      }
		
		

		
		
   return true;   
   }

function limitSP() {
	var spTempString = new String(document.oeForm.comments.innerHTML);
 	
	if (spTempString.length > 500) {
		alert ("You have reached the limit of 500 characters for this field.");
		spTempString = spTempString.substr(0,500);
		document.oeForm.comments.innerHTML = spTempString;
		document.oeForm.comments.focus();
	}
}

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;   // must programmatically check this
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;

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 isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}


function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

function stripInitialWhitespace (s)

{   var i = 0;

    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    
    return s.substring (i, s.length);
}


function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}


function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    return true;
}


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))
    }
}


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) ) );
}


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) ) );
}


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) ) );
}



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) ) );
}


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++)
    {   
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    return true;
}

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))
    }
}


function isAlphabetic (s)

{   var i;

    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))
        return false;
    }

    // All characters are letters.
    return true;
}

function isAlphanumeric (s)

{   var i;

    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) ) )
        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;
}


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)
}


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 isInternationalPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isInternationalPhoneNumber.arguments[1] == true);
    return (isPositiveInteger(s))
}


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)))
}

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) )
}


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 j = 1;
	 var count = 0;
    var sLength = s.length;
	 

	 if(s.indexOf('#') != -1 || s.indexOf('-')  != -1 || s.indexOf('&')  != -1 || s.indexOf('*')  != -1 || s.indexOf('!')  != -1 || s.indexOf('%')  != -1 || s.indexOf('^')  != -1 || s.indexOf('(')  != -1 || s.indexOf(')')  != -1 || s.indexOf('+')  != -1 || s.indexOf('=')  != -1 || s.indexOf('www.') != -1) {return false;}

	if(s.indexOf('..') < -1){
		return false;
	}

	
	
    // look for double @
    while (j < sLength ){ 
		if(s.charAt(j) == "@"){
			count++;
		}
		j++;
    }

	if (count > 1)return false;
	
	 	
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}



function 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));
}



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));
	
}

function isMonth (s){   


	if (isEmpty(s)) {
	      if (isMonth.arguments.length == 1){

			 	return defaultEmptyOK;
	      } else {
		
				return (isMonth.arguments[1] == true);
			}
	}

   return isIntegerInRange (s, 1, 12);
}


function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}


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.

//alert("isMonth: " + isMonth(month, false));

    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function isDateMDY (dateEntry) {
  
  var datevalues=dateEntry.split("/");
  
  if(datevalues.length != 3)return false;
  
  //if there is a leading 0 before day or month, strip it.
  if(datevalues[0].charAt(0)=="0")datevalues[0]=datevalues[0].charAt(1);
  if(datevalues[1].charAt(0)=="0")datevalues[1]=datevalues[1].charAt(1);
  
  if ( !isDate(datevalues[2],datevalues[0],datevalues[1]) ){
    return false;
  }
  return true;

}


function prompt (s)
{   window.status = s
}


function promptEntry (s)
{   window.status = pEntryPrompt + s
}



function warnEmpty (theField, s)
{   theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return 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);
    else return true;
}


function checkStateCode (theField, 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;
    }
}



function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}


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;
      }
    }
}


function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "", 3, "-", 3, "-", 4))
}


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-7890, comment next line out
          theField.value = reformatUSPhone(normalizedPhone)
          return true;
       }
    }
}


function checkInternationalPhone (theField, 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;
    }
}


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;
}

function reformatSSN (SSN)
{   return (reformat (SSN, "", 3, "-", 2, "-", 4))
}


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-456-7890, comment next line out
          theField.value = reformatSSN(normalizedSSN)
          return true;
       }
    }
}


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;
}


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;
}



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;
}

function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkDate.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
}


function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    return radio[i].value
}

function checkCreditCard (radio, theField)
{   var cardType = getRadioButtonValue (radio)
    var normalizedCCN = stripCharsInBag(theField.value, creditCardDelimiters)
    if (!isCardMatch(cardType, normalizedCCN)) 
       return warnInvalid (theField, iCreditCardPrefix + cardType + iCreditCardSuffix);
    else 
    {  theField.value = normalizedCCN
       return true
    }
}


function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }


  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

} // END FUNCTION isCreditCard()



function isVisa(cc)
{
  if (((cc.length == 16) || (cc.length == 13)) &&
      (cc.substring(0,1) == 4))
    return isCreditCard(cc);
  return false;
}  // END FUNCTION isVisa()


function isMasterCard(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == 5) &&
      ((seconddig >= 1) && (seconddig <= 5)))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isMasterCard()


function isAmericanExpress(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == 3) &&
      ((seconddig == 4) || (seconddig == 7)))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isAmericanExpress()


function isDinersClub(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 14) && (firstdig == 3) &&
      ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
    return isCreditCard(cc);
  return false;
}

function isCarteBlanche(cc)
{
  return isDinersClub(cc);
}


function isDiscover(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isDiscover()



function isEnRoute(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 15) &&
      ((first4digs == "2014") ||
       (first4digs == "2149")))
    return isCreditCard(cc);
  return false;
}

function isJCB(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) &&
      ((first4digs == "3088") ||
       (first4digs == "3096") ||
       (first4digs == "3112") ||
       (first4digs == "3158") ||
       (first4digs == "3337") ||
       (first4digs == "3528")))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isJCB()


function isAnyCard(cc)
{
  if (!isCreditCard(cc))
    return false;
  if (!isMasterCard(cc) && !isVisa(cc) && !isAmericanExpress(cc) && !isDinersClub(cc) &&
      !isDiscover(cc) && !isEnRoute(cc) && !isJCB(cc)) {
    return false;
  }
  return true;

} // END FUNCTION isAnyCard()



function isCardMatch (cardType, cardNumber)
{

        cardType = cardType.toUpperCase();
        var doesMatch = true;

        if ((cardType == "VISA") && (!isVisa(cardNumber)))
                doesMatch = false;
        if ((cardType == "MASTERCARD") && (!isMasterCard(cardNumber)))
                doesMatch = false;
        if ( ( (cardType == "AMERICANEXPRESS") || (cardType == "AMEX") || (cardType == "AMERICAN EXPRESS") )
                && (!isAmericanExpress(cardNumber))) doesMatch = false;
        if ((cardType == "DISCOVER") && (!isDiscover(cardNumber)))
                doesMatch = false;
        if ((cardType == "JCB") && (!isJCB(cardNumber)))
                doesMatch = false;
        if ((cardType == "DINERS") && (!isDinersClub(cardNumber)))
                doesMatch = false;
        if ((cardType == "CARTEBLANCHE") && (!isCarteBlanche(cardNumber)))
                doesMatch = false;
        if ((cardType == "ENROUTE") && (!isEnRoute(cardNumber)))
                doesMatch = false;
        return doesMatch;

}  // END FUNCTION CardMatch()

	function msg(obj,str)
	{
		alert(str);
		obj.select();
		obj.focus();
	}  // END FUNCTION msg()  added by Anil Reddy A


function makeLarge(url,name,winoptions){
carWin=window.open(url,name,winoptions);
carWin.focus();
}
function checkWin(){
if (window.carWin){
window.carWin.close();
	}
}


	
	
function validateZip(formname, submissionType) {

   var cZip = "";
  	var checkOK = "0123456789";
  	var checkStr = formname.locationZip.value;
	var isValidZip = true;



  if (isValidZip){ // skip if thrown an error already
      for (i = 0;  i < checkStr.length;  i++) {
       ch = checkStr.charAt(i);
       for (j = 0;  j < checkOK.length;  j++){
        if (ch == checkOK.charAt(j))
           break;
        }
       if (j == checkOK.length) {
         isValidZip = false;
         break;
       }
      }
	}
	
	//alert(checkStr.indexOf('-'));
/*
	if (checkStr.indexOf('-') != -1 && checkStr.indexOf('-') != 5){
		isValidZip = false;
		cZip += "<li>The '-' character is mislocated. The correct format is 60604 or 60604-2913</li>";	
	}

	if (formname.locationZip.value.length < 5 && isValidZip){
		isValidZip = false;
		cZip += "<li>The zip code needs to be at least 5 digits</li>";
   }

  if (formname.locationZip.value.length > 5 && isValidZip) {
		isValidZip = false;
    	cZip += "<li>The zip code needs to be at most 5 digits</li>";
  }



  if (formname.locationZip.value.length != 5 && formname.locationZip.value.length != 10 && isValidZip) {
		isValidZip = false;
    	cZip += "<li>Invalid zip code. Valid zip code should be either 5 or 10 digits long. Example: 60604 or 60604-2913</li>";
  }
  
*/  
  if (formname.locationZip.value.length != 5 && isValidZip) {
		isValidZip = false;
  }


   if (!isValidZip) {
		if(submissionType != 2){
		 wssErrorAdd("Zip");
			var errorText = "<table class='errorbox' border='0' cellspacing='0' cellpadding='0'><tr><td class='errorhdr'><img src='/images/errorMrkr.gif' width='14' height='14' valign='middle'/>&nbsp;&nbsp;Please fix the following problems before continuing. </td></tr><tr><td><p class='errorInstructions'>The following field(s) contain invalid or incomplete information:</p><ul>";
	
	
			errorText = errorText + "<li>" + error["uzipcode,label"] + ": " + error["uzipcode,invalid_zip_format"] +"</li>" + "</ul></td></tr></table><br/>";
			window.scrollTo(0,0);
         if(formname.locationZip) {
			   formname.locationZip.focus();
         }
         if(formname.zipEntry) {
            formname.zipEntry.focus()
         }
			document.getElementById("zipSublocationZipContainer").className="error";				
			document.getElementById("errorText").innerHTML = errorText;	

		}

		
		switch  (submissionType){
			case 1: return false;
			case 2: return errorText;
		}
errorText = "";
					      
   }
	else if (submissionType != 2){
		wssTrack();
		formname.submit();
   }
	else if (submissionType == 2){
		return "";
	}
}

/*---------------------------------------------------------------------------------*/

/* Function requiredOk(required, form)
 * Use this function to check the required fields on a form
 * @param required - a comma sepearated list of required fields
 */

var foundRequiredErrors = new Array();  // array to store the found errors
var requiredErrorCount = 0; // error counter
var requiredErrors = "" // String to hold the error message

function requiredOk(required, form){
   // take the required fields from the form and split in to an array
   var requiredFields = stripWhitespace(required).split(",");
   //clean out any old errors in the found errors array
   foundRequiredErrors.length = 0;
   //ensure the error count is 0 to start
   requiredErrorCount = 0;
   //ensure the required errors field is blank
   requiredErrors = "";
   // loop through the required fields array and determine if any fields are blank
   for(var i=0; i < requiredFields.length; i++) {
      field = form[requiredFields[i]];
		
      if(field && !field.length){
         if(field.type == "text" || field.type == "textarea" || field.type == "password" || field.type == "hidden" || field.type == "checkbox") {
		 	
            fieldval = field.value;
			
			if (field.type == "checkbox"){
				if (document.oeForm.sellerType.checked == false){
					fieldval=null;
				}			
			}
			
            if(fieldval == "" || fieldval == null || isWhitespace(fieldval)){
               errorFound(requiredFields[i], form);
            }				
   		}
         
      }
      else {
         if(field && (field.type == "select-one" || field.type == "select-multiple")) {
            for(var j=0; j < field.options.length; j++){
               if(field.options[j].selected){
                  if(field.options[j].value == "") {
                     errorFound(requiredFields[i], form);
                  }
               }
            } 
         }
         if(field && (field.type == "checkbox" || field.type == "radio")) {
            var countNotChecked = 0;
            for(var k=0; k < field.length; k++){  
               if(field[k].checked != true) {
   			   countNotChecked += 1;
   			   }
   		   }
   		   if(field && countNotChecked == field.length){
               errorFound(requiredFields[i], form);
               countNotChecked = 0;
            }
         }
      }
   }
	
	
	
   if(foundRequiredErrors.length > 0) {     
      requiredErrors = "<p><b>" + required_error_header + " </b><p>"; 
      for(err = 0; err < foundRequiredErrors.length; err++) {

         requiredErrors += "<li>" + error[foundRequiredErrors[err] + ",label"] + "</li>";
      }

      return false;
   }
   return true;
}

/* errorFound(field, form)
 * puts the field name in the error array and sets the container to error
 * then increments the error counter
 * @param field - the name of the field with the error
 *        form - the name of the form to see the error class
 */
function errorFound(field, form){
   foundRequiredErrors[requiredErrorCount] = field;
	wssErrorAdd("REQ_" + field);
   document.getElementById(form.name + field+"Container").className="error";	
   requiredErrorCount += 1;
}

/* clearErrorStyles(tagName) function
 * removes the style="error" from all tags of a given type
 * @param tagName - the type of tag to remove the error style from
 */
 
function clearErrorStyles(tagName) {
   for(i=0; i < document.getElementsByTagName(tagName).length; i++){      
      if(document.getElementsByTagName(tagName)[i].className == 'error'){
         document.getElementsByTagName(tagName)[i].className = "";
      }
   }
}

/* isPasswordOk (s) function
 * checks that the password matches cars.com format
 * @param s - the password to check
 */
function isPasswordOk (s){
   if(s.length < 6 || s.length > 12) {
      return false;
   }
   if(s.match(/\s/)){
      return false;
   }
   for (var i = 0; i < s.length; i++){   
      if (s.charCodeAt(i) > 127){
         return false;
      }
   }
   return true;
}

var emailErrorCode = "";
function isValidEmail(emailToValidate) {
var errorNotFound = true;
// something found in e-mail. validate.
   if (emailToValidate != "")	{
      var emailRegEx = /^([\-\w_\.]+)@{1}([\-\w_]+)(\.\w+)+(\w$)/i;
		//var emailRegEx = /@/;
      var result = emailToValidate.match(emailRegEx);
      if(result != null){
         if(emailToValidate.match(/^(www\.)/i)!=null){
            emailErrorCode = "www_found";
            errorNotFound = false;
         }
         else {
            var illegalEmailArray = new Array ('a@a.com','b@b.com','c@c.com','d@d.com','e@e.com','f@f.com','g@g.com','h@h.com','i@i.com','j@j.com','k@k.com','l@l.com','m@m.com','n@n.com','o@o.com','p@p.com','q@q.com','r@r.com','s@s.com','t@t.com','u@u.com','v@v.com','w@w.com','x@x.com','y@y.com','z@z.com','1@1.com','2@2.com','3@3.com','4@4.com','5@5.com','6@6.com','7@7.com','8@8.com','9@9.com','0@0.com','mickey@mouse.com','mickeymouse@mickeymouse.com','me@me.com');
   			for (i=0; i < illegalEmailArray.length; i++)	{
      			if (emailToValidate == illegalEmailArray[i])	{
      				emailErrorCode = "invalid_email_address"
      				errorNotFound = false;
      			}
      		}
         }
      }
      else {
         emailErrorCode = "invalid_email_address";
         errorNotFound = false;
      }    
   }
   else {
      emailErrorCode = "invalid_email_address";
      errorNotFound = false;
   }
   return errorNotFound;
}      

