/*
 * Validation data types and formats 
 */
// utility & generic
var _VALIDATION_ISLOADED = true;
var _VALIDATION_SPECIALCHARS = "\"\\`\\'\\~\\^\\$\\@\\#\\&\\|\\!\\_\\;\\:\\,\\.\\?\\<\\>\\(\\)\\[\\]\\{\\}\\+\\*\\-\\/\\\\%\\=";
var _VALIDATION_SPECIALCHARS_WITHOUT_HYPHEN = "\"\\`\\'\\~\\^\\$\\@\\#\\&\\|\\!\\_\\;\\:\\.\\?\\<\\>\\(\\)\\[\\]\\{\\}\\+\\*\\/\\\\%\\=";
var _VALIDATION_NUMERIC = "0-9";
var _VALIDATION_HEXA = /[^a-f0-9]/i;
var _VALIDATION_ALPHA = "^0-9" + _VALIDATION_SPECIALCHARS + "";
var _VALIDATION_ALPHANUMERIC = "^" + _VALIDATION_SPECIALCHARS + "";
var _VALIDATION_ALPHANUMERIC_WITH_HYPHEN = "^" + _VALIDATION_SPECIALCHARS_WITHOUT_HYPHEN + "";
var _VALIDATION_BLANKCHARS = "\\s";
var _VALIDATION_ALPHANUMERIC_WITHOUT_BLANKCHARS = _VALIDATION_ALPHANUMERIC + _VALIDATION_BLANKCHARS;

// data types
var _VALIDATION_ADDRESS = new RegExp("^([" + _VALIDATION_ALPHANUMERIC + "]|[\\#\\,\\-\\.\\' ])*$");
var _VALIDATION_VENDOR = new RegExp("^([" + _VALIDATION_ALPHANUMERIC + "]|[\\_\\.\\s])*$");
var _VALIDATION_MONEY = new RegExp("^[" + _VALIDATION_NUMERIC + "\\$\\,]*\\.?[" + _VALIDATION_NUMERIC + "]*$");
var _VALIDATION_CITY = new RegExp("^([" + _VALIDATION_ALPHA + "]|[\\- \\.\\'])*$");
var _VALIDATION_ODOMETER = new RegExp("^[" + _VALIDATION_NUMERIC + "\\,]*$");
var _VALIDATION_LATLONG = new RegExp("^[" + _VALIDATION_NUMERIC + "\\.\\-]*$");
var _VALIDATION_CREDITCARDNUMBER = new RegExp("^[" + _VALIDATION_NUMERIC + "\\- ]*$");
var _VALIDATION_TRACKINGFIELDS = new RegExp("^((.*(\\/|\\\\))?([^" + _VALIDATION_SPECIALCHARS + " ]|[\\.\\_]){1,250})?$");
var _VALIDATION_ASSETNAME = new RegExp("^((.*(\\/|\\\\))?([^" + _VALIDATION_SPECIALCHARS + " ]|[\\.\\_]){1,80})?$");
var _VALIDATION_LIBRARYNAME = new RegExp("^([^" + _VALIDATION_SPECIALCHARS + "]|[ \\-\\_])*$");

// data formats
var _VALIDATION_DATE_ORDER = ["m","d","y"];
var _VALIDATION_DATE_MAP = {"01":"31", "02":"28", "03":"31", "04":"30", "05":"31", "06":"30", "07":"31", "08":"31", "09":"30", "10":"31", "11":"30", "12":"31"}
var _VALIDATION_DATE_DL = "\/";
var _VALIDATION_DATE_THIRTYONEDAYS = "((0[1-9])|([12][0-9])|(3[01]))";
var _VALIDATION_DATE_THIRTYDAYS = "((0[1-9])|([12][0-9])|(30))";
var _VALIDATION_DATE_TWENTYEIGHTDAYS = "((0[1-9])|(1[0-9])|(2[0-8]))";
var _VALIDATION_DATE_TWENTYNINEDAYS = "((0[1-9])|(1[0-9])|(2[0-9]))";
var _VALIDATION_DATE_THIRTYONEDAYMONTHS = "((0[13578])|(1[02]))";
var _VALIDATION_DATE_THIRTYDAYMONTHS = "((0[469])|(11))";
var _VALIDATION_DATE_FEBRUARY = "(02)";
var _VALIDATION_DATE_ALLYEARS = "(((19)|(20))[0-9]{2})";
var _VALIDATION_DATE_LEAPYEARS = "(((19)|(20))(([02468][048])|([13579][26])))";
var _VALIDATION_DATE_NOTLEAPYEARS = "(((19)|(20))(([02468][^048])|([13579][^26])))";
var _VALIDATION_DATE = new RegExp("^((((" + _VALIDATION_DATE_THIRTYONEDAYMONTHS + _VALIDATION_DATE_DL + _VALIDATION_DATE_THIRTYONEDAYS + ")|(" + _VALIDATION_DATE_THIRTYDAYMONTHS + _VALIDATION_DATE_DL + _VALIDATION_DATE_THIRTYDAYS + "))" + _VALIDATION_DATE_DL + _VALIDATION_DATE_ALLYEARS + ")|(" + _VALIDATION_DATE_FEBRUARY + _VALIDATION_DATE_DL + "((" + _VALIDATION_DATE_TWENTYEIGHTDAYS + _VALIDATION_DATE_DL + _VALIDATION_DATE_NOTLEAPYEARS + ")|(" + _VALIDATION_DATE_TWENTYNINEDAYS + _VALIDATION_DATE_DL + _VALIDATION_DATE_LEAPYEARS + "))))?$");

var _VALIDATION_EMAIL = /^[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
var _VALIDATION_PROTOCOL = new RegExp("^((?:[" + _VALIDATION_ALPHA + "]+:\\/?\\/?)|#)(.*)$", "i");
var _VALIDATION_URL = new RegExp("^(([" + _VALIDATION_ALPHA + "]+:\\/?\\/?)?([^\":]+))?$", "i");
var _VALIDATION_PHONEFAX = new RegExp("^(\\(?[A-Z" + _VALIDATION_NUMERIC + "]{3}\\)?[\\. -]?[A-Z" + _VALIDATION_NUMERIC + "]{3}[\\. -]?[A-Z" + _VALIDATION_NUMERIC + "]{4})?$");
var _VALIDATION_NUMERIC_PHONEFAX = new RegExp("^(\\(?[" + _VALIDATION_NUMERIC + "]{3}\\)?[\\. -]?[" + _VALIDATION_NUMERIC + "]{3}[\\. -]?[" + _VALIDATION_NUMERIC + "]{4})?$");
var _VALIDATION_ZIP = new RegExp("^([" + _VALIDATION_NUMERIC + "]{5}((-| )[" + _VALIDATION_NUMERIC + "]{4})?)?$");
var _VALIDATION_SSN = new RegExp("^([" + _VALIDATION_NUMERIC + "]{3}-[" + _VALIDATION_NUMERIC + "]{2}-[" + _VALIDATION_NUMERIC + "]{4})?$");
var _VALIDATION_NAME = "^0-9\"\\`\\~\\^\\$\\@\\#\\&\\|\\!\\_\\;\\:\\,\\.\\?\\<\\>\\(\\)\\[\\]\\{\\}\\+\\*\\-\\/\\\\%\\=";
var _VALIDATION_ZIP_LENGTH = 5;

// validation format errors
var _VALIDATION_FORMATERROR_ADDRESS = "Enter address";
var _VALIDATION_FORMATERROR_CITY = "Enter city";
var _VALIDATION_FORMATERROR_EMAIL = "Enter valid email address";
var _VALIDATION_FORMATERROR_NUMERIC_PHONEFAX = "Enter phone number, (123) 456 7890 format";
var _VALIDATION_FORMATERROR_ZIP = "Enter zip code, numbers only";

var ALL_YEARS = "All Years";
var ALL_LOCATIONS = "All Locations";
var ALL_MAKES = "All Makes";
var ALL_MODELS = "All Models";
var ALL_TRIMS = "All Trims";
var ALL_TYPES = "All Types";
var ANY = "Any";
var BROWSE_INVENTORY = "Browse Inventory";
var BOOKMARK_ERROR_MSG = "Press <Ctrl>+D to bookmark"
var CERTIFIED = "Certified";
var CONFIRM_FORM_RESET = "Are you sure you want to reset this form?";
var CONTACT_US = "Contact Us";
var DGP_MILES = "miles";
var ENTER_ZIP = "Enter Zip";
var ERROR_CODE = "Error code";
var ERRORMESSAGE_BAD_REQUEST = "A directions request could not be successfully parsed.";
var ERRORMESSAGE_CAPTCHA_VERIFICATION = "The keyword text you entered did not match the image displayed. Please try entering the text again.";
var ERRORMESSAGE_DOWNPAYMENTTOOLARGE = "The Down Payment is larger than the Purchase Price.";
var ERRORMESSAGE_EMAIL_FORM = "Our system was unable to process your request. Please verify that all email addresses are entered correctly, and try again. If the problem persists, please try again at a later time.";
var ERRORMESSAGE_ENTER_REQUIRED_DATA = "Please enter valid information in the highlighted required field(s) and resend your request.";
var ERRORMESSAGE_ENTER_REQUIRED_DATA_BACK_GMCL = "\nIf you've already entered information, be sure to check your spelling.";
var ERRORMESSAGE_ENTER_REQUIRED_DATA_EMAIL_GMCL = "Information appears to be misspelled or inaccurate.\nPlease verify the spelling and accuracy of the information in the following areas: ";
var ERRORMESSAGE_ENTER_REQUIRED_DATA_FRONT_GMCL = "Information appears to be missing.\nPlease enter information in the following areas: ";
var ERRORMESSAGE_ENTER_VALID_DATA = "The information entered is invalid for the highlighted fields.  Please enter valid information and resend your request. ";
var ERRORMESSAGE_GET_DIRECTIONS = "Please complete the fields highlighted below."
var ERRORMESSAGE_INVALID_KEY = "The given key is either invalid or does not match the domain for which it was given.";
var ERRORMESSAGE_INVALID_RADIUS = "Please select a default radius in [#] before saving.";
var ERRORMESSAGE_LOCATION_NOT_FOUND = "No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.";
var ERRORMESSAGE_NOT_PROCESSED = "A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.";
var ERRORMESSAGE_NO_NEAREST_DEALER = "There are no dealers in the ZIP code + distance you selected.  Here are the closest dealers";
var ERRORMESSAGE_PARAMETER_MISSING = "The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.";
var ERRORMESSAGE_UNKNOWN_DIRECTIONS = "The GDirections object could not compute directions between the points mentioned in the query. This is usually because there is no route available between the two points, or because we do not have data for routing in that region.";
var ERRORMESSAGE_UNAVAILABLE_ADDRESS = "The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.";
var ERRORMESSAGE_UNKNOWN_ERROR = "An unknown error occurred.";
var FLASH_UPDATE_MESSAGE = "<strong>This content requires a more recent version of the Macromedia Flash Player. You may have to restart your browser after downloading the new version.<br><br></strong><a href=\"http://www.adobe.com/products/flashplayer/\" target=\"_new\">Click here to upgrade your Flash Player.</a>";
var GET_A_QUOTE = "Get a Quote";
var GET_DIRECTIONS = "Get Directions";
var INVALID_FROM_ADDRESS = "Please enter a valid From address";
var INVALID_ZIP_CODE = " is an invalid zip code. Please enter a valid zip code";
var INVENTORY = "Inventory";
var LEADFORM_FIELDSET_HIDEOPTIONAL = "Click here to hide optional form fields";
var LEADFORM_FIELDSET_SHOWOPTIONAL = "Click here to show optional form fields";
var MILES = " miles";
var NEW = "New";
var NO_INVENTORY_AVAILABLE = "No Inventory Available";
var NON_CERTIFIED = "Non-Certified";
var PREOWNED = "Used";
var SALES = "Sales";
var SCHEDULE_SERVICE = "Schedule Service";
var SELECT_ONE = "Select One";
var SERVICE = "Service";
var SHOW_LOCATION = "Show Location";
var UP_TO = "Up to ";
var USED = "Used";
var VIEW = "View";
var WEBSITE = "Website";
var SELECTED = "Selected";

// Constants for LSLP
var LINK_HOME = "Home Page";
var LINK_INVENTORY = "Search Inventory";
var LINK_SPECIALS = "View Specials";
var LINK_SERVICE = "Schedule Service";

//Localization content for Video
var VIDEO_CONTENT_NOT_AVAILABLE = "Video content not available";
/* 
* Chris-T: Adding two new methods, getType() and setType() for CIR.
*/
var i18nLabels = {
	getYears : function() { return (i18nLabels["year"] || ALL_YEARS); },
	getLocation : function() { return (i18nLabels["location"] || ALL_LOCATIONS); },
	getMake : function() { return (i18nLabels["make"] || ALL_MAKES); },
	getModel : function() { return (i18nLabels["model"] || ALL_MODELS); },
	getSearchType : function() { return (i18nLabels["searchType"] || ALL_TYPES); },
	getType : function() { return (i18nLabels["searchType"] || ALL_TYPES); },
	getTrim : function() { return (i18nLabels["trim"] || ALL_TRIMS); },
	setYears : function(yearLabel) { i18nLabels["year"] = yearLabel; },
	setLocation : function(locationLabel) { i18nLabels["location"] = locationLabel; },
	setMake : function(makeLabel) { i18nLabels["make"] = makeLabel; },
	setModel : function(modelLabel) { i18nLabels["model"] = modelLabel; },
	setSearchType : function(searchTypeLabel) { i18nLabels["searchType"] = searchTypeLabel; },
	setType : function(searchTypeLabel) { i18nLabels["searchType"] = searchTypeLabel; },
	setTrim : function(trimLabel) { i18nLabels["trim"] = trimLabel; }
};

var payCalc = {
	getFormattedPrice : function(price, decimalPlaces) {
		if (arguments.length == 1) var decimalPlaces = 0;
		var formattedPrice = "$" + getFormattedNumber(price, decimalPlaces);
		return formattedPrice;
	}
};
function getFormattedNumber(num, decimalPlaces) {
	if (arguments.length == 1) var decimalPlaces = 0;
	numPieces = new String(num).split(".");
	var wholeNum = numPieces[0];
	var formattedNum = "";
	var place = -1;
	for (var i=wholeNum.length-1; i>=0; i--) {
		if ((++place % 3 == 0) && (place > 0)) formattedNum = "," + formattedNum;
		formattedNum = wholeNum.charAt(i) + formattedNum;
	}
	if (decimalPlaces > 0) {
		var fraction = (numPieces.length > 1) ? numPieces[1] : "";
		if (fraction.length < decimalPlaces) {
			for (var j=fraction.length; j<=decimalPlaces; j++) fraction = fraction + "0";
		}
		truncatedFraction = fraction.substring(0, decimalPlaces);
		formattedNum += "." + truncatedFraction;
	}
	return formattedNum;
}

/** DEPRECATED **/
var ERROR_SELECTMAKEMODEL = "Please select a vehicle make and model.";
var FORM_PREOWNED = "Pre-Owned";
var FORM_CERTIFIED = "Certified pre-owned";

function showmilesWithComma(strregexp,domEle) {
	var strregexp=strregexp.toString();
	var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');
	 while(objRegExp.test(strregexp)) 
	 {
       	strregexp = strregexp.replace(objRegExp, '$1,$2');
     }
	jQuery(domEle).val(strregexp);		
}