<!--

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'Output     :
'Comment    : ModName form object build.
'------------------------------------------------------------------------------
*/
function ModNameBuild (oForm) {
	if (typeof oForm.cboModName != "undefined") {									// Not undefined
		var oManName = oForm.cboManName, oModName = oForm.cboModName, oMakeModel = oForm.cboMakeModel, sModel = "";

		oModName.length = 1;														// Remove models from object
		setPointerHourGlass();														// Change mousepointer

		for (var x=0; x < oMakeModel.length; x++) {									// Process all make and models
			if (oMakeModel[x].value == oManName.value) {							// Model matches make
				sModel = oMakeModel[x].text											// Store model
				oModName[oModName.length] = new Option(sModel, sModel);  			// Add model to object
			}
			else if (oModName.length > 1) {											// Processed in order so break if match not found but elements exist
				break;																// Exit
			}
		}

		setPointerReset();															// Change mousepointer
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'			  2) Cookie name
'Output     :
'Comment    : Search action.
'------------------------------------------------------------------------------
*/
function cmdSearch_OnClick (oForm) {
	var jsCrLf = "\r\n", sError = new String();										// Crlf and error string

	if (typeof oForm.chkNew != "undefined" && 
	    typeof oForm.chkUsed != "undefined") {										// Not undefined
		if (oForm.chkNew.checked == false && oForm.chkUsed.checked == false) {		// New and used both unchecked
			oForm.chkNew.checked = true;											// Default to ticked
			oForm.chkUsed.checked = true;											// Default to ticked
		}
	}

	sError = ValidateFromTo(oForm.cboYearMin, oForm.cboYearMax, "Year", "<", sError); 
	sError = ValidateFromTo(oForm.cboCCMin, oForm.cboCCMax, "Engine", ">", sError);
	sError = ValidateFromTo(oForm.cboMileageMin, oForm.cboMileageMax, "Mileage", ">", sError); 
	sError = ValidateFromTo(oForm.cboTradePriceMin, oForm.cboTradePriceMax, "Price", ">", sError);
	sError = ValidateFromTo(oForm.cboRetailPriceMin, oForm.cboRetailPriceMax, "Price", ">", sError);

	if (sError.length != 0) {														// Errors found
		alert("Sorry - unable to continue due to the following values being incorrect" + jsCrLf + jsCrLf + sError + jsCrLf + jsCrLf + "Please correct this information and try again.");
		return false;																// Return false
	}
	return true;																	// Return true
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Object from
'			  2) Object to
'			  3) Text to display if error
'			  4) Operator
'			  5) Error message
'Output     :
'Comment    : Validates object to and from to
'------------------------------------------------------------------------------
*/
function ValidateFromTo(oObjectFrom, oObjectTo, sText, sOperator, sError) { 
	var jsCrLf = "\r\n";															// Crlf

	if (typeof oObjectFrom == "undefined") {										// Undefined
		return sError;																// Return
	}

	oObjectFrom.style.backgroundColor = "white";									// Correct style
	oObjectTo.style.backgroundColor   = "white";									// Correct style

	if (oObjectFrom.selectedIndex != 0 && oObjectTo.selectedIndex != 0) {			// From /to selected
		if ((sOperator != "<" && oObjectFrom.selectedIndex > oObjectTo.selectedIndex) || (sOperator != ">" && oObjectFrom.selectedIndex < oObjectTo.selectedIndex)) {
			if (sError == "") {														// Error empty
				oObjectFrom.focus()													// Focus on first error
				}
			else {																	// Errors already exist
				sError = sError + jsCrLf											// Append crlf to error
			}
			sError = sError + sText + " " + oObjectFrom[oObjectFrom.selectedIndex].text + " is greater than " + sText + " " + oObjectTo[oObjectTo.selectedIndex].text;
			oObjectFrom.style.backgroundColor = "pink";								// Indicate problem object
			oObjectTo.style.backgroundColor   = "pink";								// Indicate problem object
		}
	}
	return sError;																	// Return error
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'			  2) Cookie name
'Output     :
'Comment    : Search action.
'------------------------------------------------------------------------------
*/
function SearchSubmit (oForm, sCookieName) {
	var oObject, bTrue = "1", bFalse = "0";
	var sAction = new String(), sName = new String(), sValue = new String();
	var sCookie = new String()

	GenerateCookie(sCookieName, " ");												// Initialise cookie

	for (var i=0; i < oForm.elements.length; i++) {									// Process all form objects
		oObject = oForm.elements[i]													// Set object
		sName = "s" + oObject.name.substring(3, oObject.name.length)				// Set object name without notation prefix
		sValue = ""																	// Set object value

		switch (oObject.type) {														// Object type
			case "checkbox" :														// Checkbox
				if (oObject.checked == true) {										// Ticked?
					sValue = bTrue;													// Set value to true
				}
				else if (oObject.name == "chkNew" || oObject.name == "chkUsed" || oObject.name == "chkThumbnails") {
					sValue = bFalse;												// Set value to false
				}
				break;																// Exit
			case "text" :															// Textbox
				if (oObject.style.visibility != "hidden") {							// Object visible
					sValue=oObject.value;											// Set value
				}
				break;																// Exit
			case "select-one" :														// Dropdownlist
				if (oObject.style.visibility != "hidden") {							// Object visible
					sValue=oObject.value;											// Set value
				}
				break;																// Exit
		}

		if (sValue != "" && sValue != "Any") {										// Value
			if (sAction.length != 0) {												// Contains value
				sAction = sAction + "&"												// Append delimeter
				sCookie = sCookie + "&"												// Append delimeter
			}

			sAction = sAction + sName + "=" + sValue;								// Add name=value to url
			sCookie = sCookie + oObject.name + "=" + sValue;						// Add name=value to cookie
		}
	}
	if (sCookie != "") {															// Cookie value
		GenerateCookie(sCookieName, sCookie);										// Generate cookie
	}
	oForm.action = ReplaceUrl(oForm.txtFormAction.value, sAction);					// Set form action
	return true																		// Set return value
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'Output     : True
'Comment    : Reset all form objects
'------------------------------------------------------------------------------
*/
function ResetForm(oForm) {
	var oObject;

	for (var i=0; i < oForm.elements.length; i++) {									// Process all form objects
		oObject = oForm.elements[i]													// Set object
		if (oObject.type == "text" || oObject == "select-one") {					// Object text or select-one
			oObject.style.backgroundColor = "white";								// Initialise background color
		}
		switch (oObject.type) {														// Object type
			case "checkbox" : {														// Checkbox
				oObject.checked = false;											// Default to false
				break;
			}
			case "text" : {															// Textbox
				oObject.value = "";													// Default to empty
				break;																// Exit
			}				
			case "select-one" : {													// Dropdownlist
				if (oObject.style.visibility != "hidden") {							// Object visible
					oObject.selectedIndex = 0;										// Default to first item
				}
				break;																// Exit
			}
		}
	}
	return true																		// Set return value
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'Output     : True
'Comment    : Reset vehicle age objects
'------------------------------------------------------------------------------
*/
function ResetVehicleAge(oForm) {
	if (typeof oForm.chkNew != "undefined" && 
	    typeof oForm.chkUsed != "undefined") {										// Not undefined
		oForm.chkNew.checked = true;												// Reset to ticked
		oForm.chkUsed.checked = true;												// Reset to ticked
	}
}
/*  
'------------------------------------------------------------------------------
'Input      :
'Output     :
'Comment    : Set mousepointer to hourglass
'------------------------------------------------------------------------------
*/
function setPointerHourGlass() { 
	document.body.style.cursor = "Wait";											// Change mousepointer
} 

/*  
'------------------------------------------------------------------------------
'Input      :
'Output     :
'Comment    : Set mousepointer to default
'------------------------------------------------------------------------------
*/
function setPointerReset() { 
	document.body.style.cursor = "Default";											// Change mousepointer
} 

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'Output     : True
'Comment    : ObjectFocus - Set the focus to the first textbox on the form.
'------------------------------------------------------------------------------
*/
function ObjectFocus(oForm) {
	var oObject;

	for (var i=0; i < oForm.elements.length; i++) {									// Process all form objects
		oObject = oForm.elements[i]													// Set object

		if (oObject.type == "text") {												// Set focus to object
			oObject.focus()															// Set the focus
			return true																// Exit for and set return value
		}
	}
	return true																		// Set return value
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'Output     : True =Form data valid.
'             False=Form data invalid.
'Comment    :
'------------------------------------------------------------------------------
*/
function ValidateForm (oForm) {

	if (oForm.txtName.value == "") {
		alert( "Please enter your Name" );
		oForm.txtName.focus();
		return false ;
	}

	if (oForm.txtTelephone.value == "") {
		alert( "Please enter your Telephone Number" );
		oForm.txtTelephone.focus();
		return false ;
	}

	if (oForm.txtEmail.value == "") {
		alert( "Please enter your Email Address" );
		oForm.txtEmail.focus();
		return false ;
	}
	FormToCookies(oForm, "Enquiry");												// Write form to cookies
	oForm.cmdSubmit.disabled = true													// Disable button
	return true;
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'			  2) Cookie name
'Output     :
'Comment    : Process all input text boxes on a form and write one single
'			  cookie named parameter 2.
'------------------------------------------------------------------------------
*/
function FormToCookies(oForm, sCookieName) {
	var oObject, sCookie = new String();

	GenerateCookie(sCookieName, " ");												// Initialise cookie

	for (var i=0; i < oForm.elements.length; i++) {									// Process form elements
		oObject = oForm.elements[i]													// Set object
		if (oObject.type == "text" && oObject.value != "") {						// Input object and contains value
			if (sCookie.length != 0) {												// Value
				sCookie = sCookie + "&"												// Append delimeter
			}
			sCookie = sCookie + oObject.name + "=" + oObject.value;					// Add name=value to cookie
		}
	}
	if (sCookie != "") {															// Cookie value
		GenerateCookie(sCookieName, sCookie);										// Generate cookie
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'		      2) Cookie name
'Output     :
'Comment    : Process all input text boxes on a form and default the value to a 
'			  previously stored cookie if one exists.
'------------------------------------------------------------------------------
*/
function CookiesToForm(oForm, sCookieName) {
	var oObject, sCrumb, bTrue = "1", bFalse = "0";									// Variables

	if (typeof oForm.elements != "undefined") {										// Not undefined
		for (var i=0; i < oForm.elements.length; i++) {								// Process form elements
			oObject = oForm.elements[i]												// Set object
			sCrumb = GetCookie(sCookieName, oObject.name)							// Store crumb

			if (sCrumb != "") {														// Cookie exists
				if (oObject.type == "text" && oObject.value == "") {				// input object
					oObject.value = sCrumb											// Set value to crumb
				}
				else if (oObject.type == "select-one") {
					for (var x=0; x < oObject.length; x++) {						// Process all items
						if (oObject[x].value == sCrumb) {							// item matches cookie
							oObject.selectedIndex = [x]								// Set selected index
							if (oObject.name == 'cboManName') {
								ModNameBuild (oForm);								// Refresh model object
							}
							break;													// Exit
						}
					}
				}
				else if (oObject.type == "checkbox") {
					if (sCrumb == bTrue) {
						oObject.checked = true;
					}
					else if (sCrumb == bFalse) {
						oObject.checked = false;
					}
				}
			}
		}
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Cookie to write
'			  2) Cookie value
'Output     : True =Form data valid.
'             False=Form data invalid.
'Comment    : This function loops until the client accepts the cookie.
'			  The cookie will expire in a years time.
'------------------------------------------------------------------------------
*/
function GenerateCookie(sCookie, sCookieValue) {
	var dExpiryDate = new Date()

	if (sCookieValue != "") {														// Cookie value
		dExpiryDate.setDate(dExpiryDate.getDay()+365)								// Expiry date
		document.ignore = sCookie + "=" + escape(sCookieValue) + ";EXPIRES=" + dExpiryDate.toGMTString() + ";"	// Write cookie
        }
        return;																		// Return
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Cookie name
'			  2) Cookie name from cookie string
'Output     : True =Form data valid.
'             False=Form data invalid.
'Comment    : Retrieve the value of the cookie with a specified name.
'------------------------------------------------------------------------------
*/
function GetCookie(sCookieName, sName) {
	var aCookie = document.cookie.split("; ");										// Cookie array
	var aCrumb																		// Individual cookie 

	for (var i=0; i < aCookie.length; i++) {										// Process all cookies
		aCrumb = aCookie[i].split("=");												// a name/value pair (a crumb) is separated by an equal sign

		if (sCookieName == aCrumb[0]) {												// Specified cookie
			return GetCookieValue(unescape(aCrumb[1]), sName);						// Return cookie value from cookies
  		}
	}
	return "";																		// Cookie not found
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Cookie name
'Output     : True =Form data valid.
'             False=Form data invalid.
'Comment    : Retrieve the value of the cookie with a specified name.
'------------------------------------------------------------------------------
*/
function GetCookieValue(sCookies, sName) {
	var aCookie	= sCookies.split("&");												// Cookie array
	var aCrumb																		// Individual cookie 

	if (sName == "") {																// No specific name
		return sCookies																// Return all cookies
	}

	for (var i=0; i < aCookie.length; i++) {										// Process all cookies
		aCrumb = aCookie[i].split("=");												// a name/value pair (a crumb) is separated by an equal sign
		if (sName == aCrumb[0]) {													// Specified cookie
			return unescape(aCrumb[1]);												// Return cookie value
  		}
	}
	return "";																		// Cookie not found
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Url
'			  2) Parameters
'Output     : Url
'Comment    : Generate url from a url and parameters.
'------------------------------------------------------------------------------
*/
function ReplaceUrl(sUrl, sParameters) {
	var bQMark = false, sChar

	if (sParameters != "") {														// Parameters exist
		for (var x = 0; x < sUrl.length; x++) {										// Process all characters in url
			sChar = sUrl.substr(x,1)												// Store character
			if (sChar == "?") {														// Question mark
				bQMark = true														// Set question mark flag
				break																// Exit
			}
		}

		if (bQMark == true) {														// Question mark found
			sUrl = sUrl + "&" + sParameters											// Question mark already in url, so use &
		}
		else {																		// No question mark in url
			sUrl = sUrl + "?" + sParameters											// Use question mark
		}
	}
	return sUrl																		// Return
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) PicturePath src
'			  2) PicturePath suffix
'			  3) PicturePath object name
'Output     : None
'Comment    : Swap main picture for selected thumbnail.
'------------------------------------------------------------------------------
*/
function PicturePathSwapImage(sPicturePathSrc, sPicturePathSuffix, sPicturePathName) {
	PicturePathSlideShowCheck();													// Slideshow check
	sPicturePathSrc += sPicturePathSuffix;											// Append suffix to src
	document.getElementById(sPicturePathName).src = sPicturePathSrc;				// Swap src of main picture

	if (typeof document.all["canvas0"] != "undefined" &&
	    typeof document.all["canvas1"] != "undefined") {							// Not undefined
		document.all["canvas0"].innerHTML = PicturePathHTML(sPicturePathSrc, "canvas0", false);	// Update canvas image
		document.all["canvas1"].innerHTML = PicturePathHTML(sPicturePathSrc, "canvas1", false);	// Update canvas image
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) New Window (True/False)
'Output     : None
'Comment    : Show vehicle details pictures in current or new window.
'------------------------------------------------------------------------------
*/
function ShowVehicleDetailsPictures(bNewWindow) {
	var oForm = document.frmStock													// Set form object
	
	event.returnValue=false															// Set return value
	event.cancelBubble=true															// Cancel bubble

	if (typeof oForm.VehicleDetailsPicturePathLast != "undefined") {				// Not undefined
		oForm.VehicleDetailsPicturePathLast.value = oForm.PicturePath.src			// Update picture path last hidden object
	}
	
	if (bNewWindow == true) {														// Submit to new window?
		var sFeatures = "height=400,"    + 
						"left=10,"       + 
						"location=0,"    + 
						"menubar=0,"     + 
						"resizable=0,"   + 
						"scrollbars=no," + 
						"status=0,"      + 
						"toolbar=no,"    +   
						"top=10,"        +
						"width=480";												// Window features
		var oNewWindow = window.open('', 'NewWindow', sFeatures);					// Open new window
		oForm.target = 'NewWindow';													// Set target
	}
	oForm.submit() ;																// Submit form
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'			  2) Cookie name
'		      3) New Window
'Output     : True/False
'Comment    : Stock search footer OnSubmit event.
'------------------------------------------------------------------------------
*/
function StockSearchOnSubmit(oForm, sCookieName, bNewWindow) {
	event.returnValue=false															// Set return value
	event.cancelBubble=true															// Cancel bubble

	if (SearchSubmit(oForm, sCookieName) == true) {									// Search submit valid
		StockSearchSubmit(oForm, bNewWindow);										// Submit form
	}
	else {																			// Search submit invalid
		return false;																// Return
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'			  2) New Window (True/False)
'Output     : None
'Comment    : Submit stock search footer
'------------------------------------------------------------------------------
*/
function StockSearchSubmit(oForm, bNewWindow) {
	if (bNewWindow == true) {														// Submit to new window?
		if ((screen.width>=1024) && (screen.height>=768)) {							// 1024x768 or higher
			var iHeight=650, iLeft=162, iTop=20, iWidth=700;						// Set dimensions
		}
		else {																		// Low resolution
			var iHeight=480, iLeft=50, iTop=20, iWidth=700;							// Set dimensions
		}

		var sFeatures	= "height="         + iHeight + "," + 
						  "left="           + iLeft   + "," + 
						  "location=0,"     + 
						  "menubar=0,"      + 
						  "resizable=1,"    + 
						  "scrollbars=yes," + 
						  "status=1,"       + 
						  "toolbar=no,"     +   
						  "top="            + iTop    + "," +
						  "width="          + iWidth;								// Window features
		var sWindowName = 'NewWindow' + GetDate();									// Window name
		var oNewWindow  = window.open('', sWindowName, sFeatures);					// Open new window
		oForm.target    = sWindowName;												// Set target
	}
	oForm.submit() ;																// Submit form
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'Output     : None
'Comment    : Vehicle finance calculate
'------------------------------------------------------------------------------
*/
function VehicleFinanceCalculate(oForm){
	var lLoanAmount = oForm.txtVehiclePrice.value - oForm.cboDeposit.value - oForm.cboFinalPayment.value;
	var sCurrency   = String.fromCharCode(163);										// Pound sign
	var lYear1MonthlyPayment, lYear2MonthlyPayment, lYear3MonthlyPayment, lYear4MonthlyPayment;

	if (lLoanAmount > 0) {															// Loan amount
		vMPR                               = Math.pow((1+(oForm.cboAPR.value/100)),(1/12))-1;

		oForm.txtLoanAmount.value          = sCurrency + lLoanAmount;				// Loan amount
																					// Monthly payments
		lYear1MonthlyPayment               = Math.round((((lLoanAmount/((1/vMPR)-(1/(vMPR *(Math.pow(1+vMPR,12))))))+(oForm.cboFinalPayment.value * vMPR) )));
		lYear2MonthlyPayment               = Math.round((((lLoanAmount/((1/vMPR)-(1/(vMPR *(Math.pow(1+vMPR,24))))))+(oForm.cboFinalPayment.value * vMPR) )));
		lYear3MonthlyPayment               = Math.round((((lLoanAmount/((1/vMPR)-(1/(vMPR *(Math.pow(1+vMPR,36))))))+(oForm.cboFinalPayment.value * vMPR) )));
		lYear4MonthlyPayment               = Math.round((((lLoanAmount/((1/vMPR)-(1/(vMPR *(Math.pow(1+vMPR,48))))))+(oForm.cboFinalPayment.value * vMPR) )));

		oForm.txtYear1MonthlyPayment.value = sCurrency + lYear1MonthlyPayment;		// Update form
		oForm.txtYear2MonthlyPayment.value = sCurrency + lYear2MonthlyPayment;
		oForm.txtYear3MonthlyPayment.value = sCurrency + lYear3MonthlyPayment;
		oForm.txtYear4MonthlyPayment.value = sCurrency + lYear4MonthlyPayment;

		oForm.txtYear1TotalPayment.value   = sCurrency + (lYear1MonthlyPayment * 12);
		oForm.txtYear2TotalPayment.value   = sCurrency + (lYear2MonthlyPayment * 24);
		oForm.txtYear3TotalPayment.value   = sCurrency + (lYear3MonthlyPayment * 36);
		oForm.txtYear4TotalPayment.value   = sCurrency + (lYear4MonthlyPayment * 48);
	}
	else {																			// Initialise form
		oForm.txtLoanAmount.value          = sCurrency + "0";

		oForm.txtYear1MonthlyPayment.value = sCurrency + "0";
		oForm.txtYear2MonthlyPayment.value = sCurrency + "0";
		oForm.txtYear3MonthlyPayment.value = sCurrency + "0";				
		oForm.txtYear4MonthlyPayment.value = sCurrency + "0";

		oForm.txtYear1TotalPayment.value   = sCurrency + "0";
		oForm.txtYear2TotalPayment.value   = sCurrency + "0";
		oForm.txtYear3TotalPayment.value   = sCurrency + "0";
		oForm.txtYear4TotalPayment.value   = sCurrency + "0";
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Send to mobile link
'			  2) Photo link
'			  3) Suffix
'Output     : send to mobile url
'Comment    :
'------------------------------------------------------------------------------
*/
function VehicleDetailsSendToMobile(oSendToMobileLink, oPicturePath, sSuffix){
	var VehicleDetailsSendToMobile = oSendToMobileLink.value;						// Initialise

	if (Right(oPicturePath.href, 8) != 'car_blur') {								// Picture exists
		VehicleDetailsSendToMobile += "&Photo=" + oPicturePath.href;				// Append photo
		if (Right(oPicturePath.href, sSuffix.length) != sSuffix) {					// Suffix not already in href
			VehicleDetailsSendToMobile += sSuffix;									// Append suffix
		}
	}
	return VehicleDetailsSendToMobile;												// Return url
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) String
'			  2) Length
'Output     : Right of string
'Comment    :
'------------------------------------------------------------------------------
*/
function Right(sString, lLength) {
	var sRight = new String(sString);
	return sRight.substring(sRight.length - lLength, sRight.length);
}

/*  
'------------------------------------------------------------------------------
'Input      : None
'Output     : Date/Time
'Comment    :
'------------------------------------------------------------------------------
*/
function GetDate() {
	return new Date().getTime();
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Form
'			  2) Format type
'			  3) Report name
'Output     :
'Comment    :
'------------------------------------------------------------------------------
*/
function ReportOnSubmit(oForm, sFormatType, sReportName) {
	var sAction     = new String("sFormatType=" + sFormatType);						// Format type
	var sActionSave = new String(oForm.action);										// Form action save

	event.returnValue =false														// Set return value
	event.cancelBubble=true															// Cancel bubble

	if (sReportName != "") {														// Report name
		sAction += "&sReportName=" + sReportName;									// Overriding report name
	}

	oForm.action = ReplaceUrl(oForm.txtFormActionReport.value, sAction);			// Set form action
	ReportSubmit(oForm, true);														// Submit form
	oForm.action = sActionSave;														// Restore form action

	return true																		// Set return value
}

/*
'------------------------------------------------------------------------------
'Input      : 1) Form
'			  2) New Window (True/False)
'Output     : None
'Comment    : Submit report
'------------------------------------------------------------------------------
*/
function ReportSubmit(oForm, bNewWindow) {
	var sTargetSave = new String(oForm.target);										// Form target save

	if (bNewWindow == true) {														// Submit to new window?
		if ((screen.width>=1024) && (screen.height>=768)) {							// 1024x768 or higher
			var iHeight=580, iLeft=87, iTop=20, iWidth=850;							// Set dimensions
		}
		else {																		// Low resolution
			var iHeight=450, iLeft=15, iTop=20, iWidth=760;							// Set dimensions
		}

		var sFeatures	= "height="         + iHeight + "," + 
						  "left="           + iLeft   + "," + 
						  "location=0,"     + 
						  "menubar=1,"      + 
						  "resizable=1,"    + 
						  "scrollbars=yes," + 
						  "status=1,"       + 
						  "toolbar=no,"     +   
						  "top="            + iTop    + "," +
						  "width="          + iWidth;								// Window features
		var sWindowName = 'NewWindow' + GetDate();									// Window name
		var oNewWindow  = window.open('', sWindowName, sFeatures);					// Open new window
		oForm.target    = sWindowName;												// Set target
	}
	oForm.submit() ;																// Submit form
	oForm.target = sTargetSave;														// Restore form target
}

/*
'------------------------------------------------------------------------------
'Input      : 1) Button object
'Output     : None
'Comment    : Start/Stop picture slideshow.
'------------------------------------------------------------------------------
*/
function cmdPicturePathSlideShow_OnClick(oObject) {

	oObject.disabled = true;														// Disable object

	if (oObject.value == "Start Slideshow") {										// Start clicked
		bRotateImage  = true;														// Set flag to start slideshow
		oObject.value = "Stop Slideshow";											// Set caption
	}
	else {																			// Stop clicked
		bRotateImage  = false;														// Set flag to stop slideshow events
		oObject.value = "Start Slideshow";											// Set caption
   }

	oObject.disabled = false;														// Enable object
}

/*  
'------------------------------------------------------------------------------
'Input      : None
'Output     : None
'Comment    : Check if slideshow running, if so force stop.
'------------------------------------------------------------------------------
*/
function PicturePathSlideShowCheck() {
	var oObject = document.all["cmdPicturePathSlideShow"];							// Object

	if (typeof oObject != "undefined") {											// Not undefined
		if (oObject.value == "Stop Slideshow") {									// Slideshow running
			cmdPicturePathSlideShow_OnClick(oObject);								// Slideshow stop
		}
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Image src
'			  2) Image name
'		      3) Dimensions
'Output     : None
'Comment    : Picture path image html for slideshow div innerHTML.
'------------------------------------------------------------------------------
*/
function PicturePathHTML (sSrc, sImgName, bDimensions) {
	var sHTML    = new String(""),
	    sOnClick = new String(""),
	    sAlt     = new String(""),
	    sClass   = new String(""),
	    sWidth   = new String("")
	    sHeight  = new String("");													// Html declarations

	if (sSrc.substring(sSrc.length - sPicturePathSuffix.length) != sPicturePathSuffix) {
		sOnClick = "onclick='document.frmStock.PicturePath.onclick()' ";			// Image clickable
		sAlt     = "alt='' ";
		sClass   = "class='MouseOver' ";
	}

	if (bDimensions == true                    &&
	    typeof slideshow_width  != "undefined" && 
	    typeof slideshow_height != "undefined") {									// Specify object dimensions
		sWidth   = "width='"  + slideshow_width  + "' ";
		sHeight  = "height='" + slideshow_height + "' ";
	}

	sHTML    = "<img "                     +
			   "id='img" + sImgName + "' " +
	           "src='"   + sSrc     + "' " +
	           sOnClick                    +
	           sAlt                        +
	           sClass                      +
	           sWidth					   +
	           sHeight                     +
	           "/>";																// Set img html
	return sHTML
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Image src
'Output     : None
'Comment    : Ensure background objects are in sync with slideshow.
'------------------------------------------------------------------------------
*/
function PicturePathRefresh (sSrc) {
	if (typeof document.all["PicturePath"] != "undefined") {						// Defined
		document.all.PicturePath.src = sSrc;										// Update src property
	}
	if (typeof document.all["VehicleDetailsPicturePathLast"] != "undefined") {		// Defined
		document.all.VehicleDetailsPicturePathLast.value = sSrc;					// Update src property
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : None
'Output     : None
'Comment    : Slideshow [http://www.dynamicdrive.com]
'------------------------------------------------------------------------------
*/
function PicturePathSlideShowStartIt() {
	var crossobj = ie4? eval("document.all." + curcanvas) : document.getElementById(curcanvas);

	PicturePathSlideShowDynamic();
	crossobj.innerHTML = PicturePathHTML(fadeimages[curimageindex], curcanvas, true);
	PicturePathRefresh(fadeimages[curimageindex]);
	bRotateImage = true;															// Initialise rotate flag
	RotateImage();
}

/*  
'------------------------------------------------------------------------------
'Input      : None
'Output     : None
'Comment    : Slideshow [http://www.dynamicdrive.com]
'------------------------------------------------------------------------------
*/
function RotateImage() {
	if (bRotateImage == true) {
		if (ie4 || dom) {
			PicturePathSlideShowDynamic();
			ResetIt(curcanvas);
			var crossobj = tempobj = ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas);
			var temp     = 'setInterval("FadePic()",50)';
			crossobj.style.zIndex++;
			dropslide    = eval(temp);
			curcanvas    = (curcanvas=="canvas0")? "canvas1" : "canvas0";

			if (typeof nextcanvas != "undefined") {
				if (typeof document.all["img" + nextcanvas] != "undefined") {
					PicturePathRefresh(document.all["img" + nextcanvas].src);
				}
			}
		}
		else {
			PicturePathRefresh(fadeimages[curimageindex]);
			curimageindex = (curimageindex < fadeimages.length-1)? curimageindex+1 : 0;
		}
	}
	else {
		tmrRotateImage    = setTimeout("RotateImage()", pause);
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : None
'Output     : None
'Comment    : Slideshow [http://www.dynamicdrive.com]
'------------------------------------------------------------------------------
*/
function FadePic() {
	if (curpos < 100) {
		curpos += 10;

		if (tempobj.filters) {
			tempobj.filters.alpha.opacity = curpos;
		}
		else if (tempobj.style.MozOpacity) {
			tempobj.style.MozOpacity      = curpos/100;
		}
	}
	else {
		clearInterval(dropslide);
		nextcanvas        = (curcanvas=="canvas0")? "canvas0" : "canvas1";
		tempobj           = ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas);
		tempobj.innerHTML = PicturePathHTML(fadeimages[nextimageindex], nextcanvas, true);
		nextimageindex    = (nextimageindex < fadeimages.length-1)? nextimageindex + 1 : 0;
		tmrRotateImage    = setTimeout("RotateImage()", pause);
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) What
'Output     : None
'Comment    : Slideshow [http://www.dynamicdrive.com]
'------------------------------------------------------------------------------
*/
function ResetIt(what) {
	var crossobj = ie4? eval("document.all." + what) : document.getElementById(what);

	curpos = 10;

	if (crossobj.filters) {
		crossobj.filters.alpha.opacity = curpos;
	}
	else if (crossobj.style.MozOpacity) {
		crossobj.style.MozOpacity = curpos / 100;
	}
}

/*  
'------------------------------------------------------------------------------
'Input      :
'Output     :
'Comment    : v4.01
'------------------------------------------------------------------------------
*/
function MM_FindObj(n, d) {
	var p,i,x;  
	
	if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_FindObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	
	return x;
}

/*  
'------------------------------------------------------------------------------
'Input      :
'Output     :
'Comment    : Execute animation for each item in object.
'------------------------------------------------------------------------------
*/
function YY_AnimateImgLoad() {
	if (typeof oYY_AnimateImg != "undefined") {										// Not undefined
		for (var x in oYY_AnimateImg) {												// Process object
			eval(oYY_AnimateImg[x]);												// Execute code
		}
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) Image name
'Output     :
'Comment    : Clear animaton timeouts.
'------------------------------------------------------------------------------
*/
function YY_AnimateImgClearTimeout(sImgName) {
	var yyImgArray = eval(sImgName);												// Find timeout
	
	for (var x=0; x < yyImgArray.length; x++) {										// Process array
		clearTimeout(yyImgArray[x].yyTimeout);										// Clear timeout
	}
}

/*  
'------------------------------------------------------------------------------
'Input      :
'Output     :
'Comment    : copyright (c)1999,2001 yaromat.com v3.04
'------------------------------------------------------------------------------
*/
function YY_AnimateImg() {
	var args = YY_AnimateImg.arguments;

	if (document.images) {
		var yyani=eval(args[1]);

		if (args.length>5) {
			eval(args[3]+"= new Array()");
			
			for (var i=5;i<args.length;i=i+2) {
				eval(args[3]+"["+ args[3] + ".length]= new Image");
				eval(args[3]+"["+ args[3] + ".length-1].src=\'"+args[i]+"\'");
				eval(args[3]+"["+ args[3] + ".length-1].yyto=\'"+args[i+1]+"\'");
			}
		}
		
		var yyImgArray = eval(args[3]);
		var yyImage = MM_FindObj(args[4]);
		
		if(yyImgArray[yyani]) {
			if(yyImgArray[yyani].yyTimeout) clearTimeout(yyImgArray[yyani].yyTimeout);
			if(yyImage)yyImage.src = yyImgArray[yyani].src;
		}
		
		if(yyani>=yyImgArray.length-1){args[0]=(args[0]!="-1")?(args[0]-1):args[0]}
		
		var argStr= 'YY_AnimateImg(\"' +args[0]+ '\",\"' +((yyani>=yyImgArray.length-1 && args[0]!=0)?'0':(yyani+1));
		for (var i=2; i<5; i++){argStr+='\",\"'+args[i]}
		argStr+='\")';
		
		if ((yyani<yyImgArray.length-1) || args[0]!=0&&yyImgArray[yyani]){
			if(yyImgArray[yyani].yyTimeout) clearTimeout(yyImgArray[yyani].yyTimeout);
			yyImgArray[yyani].yyTimeout = setTimeout(argStr,yyImgArray[yyani].yyto);
		}
		else {
			if(args[2]!='#')setTimeout(args[2],10)
		}
	}
}

/*  
'------------------------------------------------------------------------------
'Input      : 1) OnLoad function
'Output     :
'Comment    : [http://javascript.about.com]
'------------------------------------------------------------------------------
*/
function SafeAddOnload(f) {
	// Browser Detection
	isMac   = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	NS4     = (document.layers) ? true : false;
	IEmac   = ((document.all)&&(isMac)) ? true : false;
	IE4plus = (document.all) ? true : false;
	IE4     = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	IE5     = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	ver4    = (NS4 || IE4plus) ? true : false;
	NS6     = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

	if (IEmac && IE4) {																// IE 4.5 blows out on testing window.onload
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload) {
		if (window.onload != SafeOnload) {
			gSafeOnload[0] = window.onload;
			window.onload  = SafeOnload;
		}
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		if (typeof f != "undefined") {
   		   window.onload = f;
        }
}

/*  
'------------------------------------------------------------------------------
'Input      :
'Output     :
'Comment    : [http://javascript.about.com]
'------------------------------------------------------------------------------
*/
function SafeOnload() {
	for (var i=0; i < gSafeOnload.length; i++) {
		if (typeof gSafeOnload[i] != "undefined") {
			gSafeOnload[i]();
		}
	}
}


/*  
'------------------------------------------------------------------------------
'Input      :
'Output     :
'Comment    : Dimensions of slideshow dynamic depending on preloaded images.
'			  If heights or widths the same on all images, these dimensions
'			  will be used instead of the default.  If widths/heights differ
'			  between images, the default dimensions will be used.
'------------------------------------------------------------------------------
*/
function PicturePathSlideShowDynamic() {
	if (preloadedimages.length == 0) {return false}									// No preloaded images to return

	var slideshow_width_dynamic  = '';												// Dynamic width
	var slideshow_width_bypass   = false;											// Dynamic width bypass
	var slideshow_height_dynamic = '';												// Dynamic height
	var slideshow_height_bypass  = false;											// Dynamic height bypass
	var slideshow_dynamic_check  = true;											// Dynamic check

	for (var p = 0; p < fadeimages.length;p++) {									// Process preloaded images
		if (preloadedimages[p].width == 0 || preloadedimages[p].height == 0) {		// Dimensions not available
			slideshow_dynamic_check = false;										// Set dimension flag
			break;																	// Exit
		}
	}

	if (slideshow_dynamic_check == true) {											// Dynamic checking
		for (var p = 0; p < preloadedimages.length;p++) {							// Process preloaded images
			switch (true) {
				case (slideshow_width_bypass == true) :								// Bypass
					 break;															// Exit
				case (slideshow_width_dynamic == '') :								// No dynamic dimension
					 slideshow_width_dynamic = preloadedimages[p].width;			// Set dimension
					 break;															// Exit
				case (slideshow_width_dynamic != preloadedimages[p].width ) :		// Dimension different
					 slideshow_width_bypass   = true;								// Set bypass flag
					 slideshow_width_dynamic  = '';									// Initialise dimension
					 break;															// Exit
			}

			switch (true) {
				case (slideshow_height_bypass == true) :							// Bypass
					 break;															// Exit
				case (slideshow_height_dynamic == '') :								// No dynamic dimension
					 slideshow_height_dynamic = preloadedimages[p].height;			// Set dimension
					 break;															// Exit
				case (slideshow_height_dynamic != preloadedimages[p].height ) :		// Dimension different
					 slideshow_height_bypass   = true;								// Set bypass flag
					 slideshow_height_dynamic  = '';								// Initialise dimension
					 break;															// Exit
			}
		}

		if (slideshow_width_dynamic  != '') {										// Dynamic dimension so reset canvas and slideshow
			if (typeof document.all["canvas"]  != "undefined") { document.all["canvas"].style.width  = slideshow_width_dynamic + 'px'; }
			if (typeof document.all["canvas0"] != "undefined") { document.all["canvas0"].style.width = slideshow_width_dynamic + 'px'; }
			if (typeof document.all["canvas1"] != "undefined") { document.all["canvas1"].style.width = slideshow_width_dynamic + 'px'; }
			slideshow_width = slideshow_width_dynamic;
		}

		if (slideshow_height_dynamic != '') {										// Dynamic dimension so reset canvas and slideshow
			if (typeof document.all["canvas"]  != "undefined") { document.all["canvas"].style.height  = slideshow_height_dynamic + 'px'; }
			if (typeof document.all["canvas0"] != "undefined") { document.all["canvas0"].style.height = slideshow_height_dynamic + 'px'; }
			if (typeof document.all["canvas1"] != "undefined") { document.all["canvas1"].style.height = slideshow_height_dynamic + 'px'; }
			slideshow_height = slideshow_height_dynamic;
		}
		preloadedimages = new Array();												// Initialise preloaded array
	}
}

// ->