var url; // variable to hold the url
url = document.location; // get the url
url = url.toString(); // convert it to string
url = (url.substr((url.indexOf("?")+1),url.length)); // grab the values passed along with URL

var ErrorCode = url.split("|"); // split the url into the array

// function to write error message to page
function generateErrorText(GetErrorCode){
	//error message arrays (please keep in alphabetical order to make finding things easier)
	var chkmodel = new Array(1);
		chkmodel[0] = "Please check a model.<br>";
	var currency = new Array(4);
		currency['lcdp'] = "Please enter Leasing Cash Down Payment using numbers only (e.g. 1000.00).<br>";
		currency['ltradein'] = "Please enter Leasing Trade-In using numbers only (e.g. 1000.00).<br>";
		currency['pcdp'] = "Please enter Purchasing Cash Down Payment using numbers only (e.g. 1000.00).<br>";
		currency['ptradein'] = "Please enter Purchasing Trade-In using numbers only (e.g. 1000.00).<br>";
	var day = new Array(1);
		day[0] = "Please enter day in two digit day format only (e.g 01).<br>";
	var duplicate = new Array(1);
		duplicate['cpo'] = "That manufacturer is already selected. Please choose a different manufacturer from the dropdown.";
	var email = new Array(1);
		email[0] = "Please enter your E-mail Address (e.g. jane@lexus.com).<br>";
	var intrate = new Array(1);
		intrate[0] = "Please enter Interest Rate (e.g. 6.00).<br>";
	var month = new Array(1);
		month[0] = "Please enter month in two digit month format only (e.g 01).<br>";
	var msrp = new Array(1);
		msrp[0] = "The Down Payment plus the Trade In cannot be greater than the MSRP.<br>";
	var numeric = new Array(2);
		numeric['cmil'] = "Please enter Estimated Current Mileage using numbers only (e.g. 1000).<br>";
		numeric['emil'] = "Please enter Estimated Monthly Mileage using numbers only (e.g. 1000).<br>";
	var password = new Array(2);
		password[0] = "Your Password must be 6 to 10 characters.<br>";
		password['nomatch'] = "Your Passwords do not match. Please try again.<br>";
	var phone = new Array(1);
		phone['home'] = "Please enter your Home Phone Number using numbers only.<br>";
	var selectone = new Array(3);
		selectone['contacttype'] = "Please select either Phone or E-mail.<br>";
		selectone['model'] = "Please Select a Model.<br>";
		selectone['state'] = "Please select your State.<br>";
	var selectradio = new Array(1);
		selectradio['contacttype'] = "Please select either Phone or E-mail.<br>";
	var textnotempty = new Array(8);
		textnotempty['address'] = "Please enter your Address.<br>";
		textnotempty['city'] = "Please enter your City.<br>";
		textnotempty['dealer'] = "Dealer cannot be blank.<br>";
		textnotempty['fname'] = "Please enter your First Name.<br>";
		textnotempty['lname'] = "Please enter your Last Name.<br>";
		textnotempty['save'] = "Please enter a name for the item you are saving.<br>";
		textnotempty['search'] = "Search Criteria cannot be blank.<br>";
		textnotempty['state'] = "Please enter your State.<br>";
	var time = new Array(1);
		time[0] = "Please enter Time in time format only (e.g 10:10).<br>";
	var vin = new Array(1);
		vin['reg'] = "The VIN (Vehicle Identification Number) you entered was not found in our database. Please check the number and try again. <br>&nbsp;<br><i>Your VIN is a 17-character combination of numbers and letters.  It is printed on the certificate label located on the front driver's-side door jamb.  There is also a VIN plate located on the lower dashboard (closest to the windshield on the driver's side).</i><br>&nbsp;<br>";
	var year = new Array(1);
		year[0] = "Please enter Year in two digit year format only (e.g 00).<br>";
	var zip = new Array(1);
		zip[0] = "Please enter your 5-digit Zip Code using numbers only.<br>";
		zip[1] = "You are required to enter your zip code.<br>";
		zip['recheck'] = "Please recheck your ZIP code.<br>";

	GetErrorCode = GetErrorCode.split("^"); // split the GetErrorCode and build the array to hold the field types
	var msg = "";
	for (count = 0; count < GetErrorCode.length - 1; count++){
		ErrorMessage = GetErrorCode[count].split("%");
		MessageVersion = ErrorMessage[1];
		Message = ErrorMessage[0]
		//document.write(count+1 + ". " + eval(Message + "[MessageVersion]"));
		msg += count+1 + ". " + eval(Message + "[MessageVersion]");
		
		document.getElementById('errorsDiv').innerHTML = msg;
		document.getElementById('errorsDiv').style.display = 'block';
	}
}

// function to set focus to the first error field
function setFieldFocus(FormName,Field){
	Field = Field.split("^");
	if(!(Field[0].substring(0,8) == "Question")){
		var FieldToSetFocus = eval("window.opener.document."+FormName+"."+Field[0]);
		FieldToSetFocus.focus();
	}
}
