<!--
//*******************************************************
// FUNCTION: showErrorMessage
//*******************************************************
// DESC:		Shows the message in the errorDiv
// PARAMS:		strErrorMsg
// RETURNS:		nothing
//*******************************************************
function showErrorMessage(strErrorMsg)
{
	if(strErrorMsg.length > 0){
		var strError = "Please correct the following:<ul style='margin-bottom:10px'><li>" + strErrorMsg;
		document.getElementById("errorDiv").innerHTML=strError;
		document.getElementById("errorDiv").style.display = "inline";
		strError = strError + "</li></ul><br>"
		document.location = "#top";
	}
}
//*******************************************************

//*******************************************************
// FUNCTION: clearErrorMessage
//*******************************************************
// DESC:		Clears and hides (collapses) the message in the errorDiv
// PARAMS:		none
// RETURNS:		nothing
//*******************************************************
function clearErrorMessage()
{
	objErrorDiv 				= document.getElementById("errorDiv");
	objErrorDiv.innerHTML		='';
	objErrorDiv.style.display 	= "none";
}
//*******************************************************

//**************************************************************************
// FUNCTION: PreparePostBackProcess
//**************************************************************************
// DESC:		Disguises the item to be bound
// PARAMS:		PostBackItem - The item to bind
//				VisibilityStatus - The visibility status of the bindable item
// RETURNS:		nothing
//**************************************************************************
function PreparePostBackProcess(PostBackItem,VisibilityStatus)
{
	var objPostBackItem = document.getElementById(PostBackItem);
	var objDIVCollection = objPostBackItem.getElementsByTagName("div")
	var objDIV1 = objDIVCollection.item(0);
	var objDIV2 = objDIVCollection.item(1);
		
	if (VisibilityStatus == "hidden")	{
		objDIV1.style.visibility = "hidden"
		objDIV2.style.visibility = "visible"
	}	else	{
		objDIV1.style.visibility = "visible"
		objDIV2.style.visibility = "hidden"
	}
}
//**************************************************************************

//**************************************************************************
// FUNCTION: select_onChange
//**************************************************************************
// DESC:		Build gofa URL and resets dropdown boxes were appropriate
// PARAMS:		none
// RETURNS:		nothing
//**************************************************************************

function select_onChange(ItemName)	{
	var PageForm 					= document.PCPSearchForm;
	var SelectedMake 				= PageForm.VehicleManufacturer;
	var SelectedModel 				= PageForm.VehicleModel;
	var SelectedDerivitive 			= PageForm.VehicleDerivative;
	var SelectedTerm				= PageForm.PlanTerm;
	var SelectedAnnualMileage 		= PageForm.AnnualMileage;
	var Gofa						= document.getElementById("iGopher");
	var TargetSrc					= "";
	var blnProceed					= true;
	var TargetBind;

	
	//** Build gofa URL string	
	TargetSrc 						= "PCPPostback.asp?RequestingItem=" + ItemName 
	TargetSrc += "&MakeID=" + SelectedMake.options[SelectedMake.selectedIndex].value; 
	TargetSrc += "&ModelID=" + SelectedModel.options[SelectedModel.selectedIndex].value; 
	TargetSrc += "&DerivitiveID=" + SelectedDerivitive.options[SelectedDerivitive.selectedIndex].value;
	TargetSrc += "&TermID=" + SelectedTerm.options[SelectedTerm.selectedIndex].value;		
	
	var ItemNameSelectedIndex;
	eval("ItemNameSelectedIndex = document.PCPSearchForm." + ItemName + ".selectedIndex")
	
	/// Check if the user has tried to reset the requesting select box	
	if (ItemNameSelectedIndex == 0)	{
		blnProceed			= false;
	}
	
	
	if (blnProceed == true)	{
		/// Rest dropdown lists accordingly	
		switch(ItemName)
		{
			case "VehicleManufacturer":
			{
				TargetBind = "PCPVehicleModel";
				break;
			}
			case "VehicleModel":
			{
				TargetBind = "PCPVehicleDerivative";
				break;
			}
			
			case "VehicleDerivative":
			{
				TargetBind = "PCPPlanTerm";
				break;
			}
			
			case "PlanTerm":
			{
				TargetBind = "PCPAnnualMileage";
				break;
			}
		}
		
		/// Empty and reset all select items on the page
		resetPostBackItems(TargetBind,"AnnualMileage",PageForm,true);
		
		/// If the dropdown change is a vehicle change then reset the deposit field to 0.00
		if (ItemName != "PlanTerm" && PageForm.DepositAmount.value != "0.00")	{
			PageForm.DepositAmount.value = "0.00";
		}
		
		/// Disguise the target bindable select box
		PreparePostBackProcess(TargetBind,"hidden");
		
		/// Invoke postback process from the IFRAME
		Gofa.src = TargetSrc;
	}	else	{
		/// If the user has tried to de-select the requesting select item, reset all selects
		resetPostBackItems(ItemName,"AnnualMileage",PageForm,true);
	}
}
//**************************************************************************


//**************************************************************************
// FUNCTION: resetPostBackItems
//**************************************************************************
// DESC:		Loops through bindable select boxes and empties or resets
//				accordingly
// PARAMS:		StartItem - The starting point of the loop
//				StopItem - The finishing point of the loop
//				objForm - The form object to loop through
//				blnClear - Boolean switch used to determine if we empty the select items
// RETURNS:		nothing
//**************************************************************************

function resetPostBackItems(StartItem,StopItem,objForm,blnClear)	{
	var objSelects 	= objForm.getElementsByTagName("select");
	var blnFoundFirst = false;
	StartItem = StartItem.replace("PCP","")
	for(i=0;i<objSelects.length;i++)	{
		objSelect = objSelects[i];
			
		if (blnFoundFirst == true)	{
			objSelect.options.selectedIndex 				= 0;
			if (blnClear == true)	{
				objSelect.options.length 					= 1
			}
		}
		
		if (objSelect.name == StartItem)	{
			blnFoundFirst = true;
		}
		
		if (objSelect.name == StopItem)	
			i = objSelects.length;
	}
}
//**************************************************************************

reCurrency = /^([0-9]{1,3},?)+(\.[0-9]{2})?$/

//**************************************************************************
// FUNCTION: submitForm
//**************************************************************************
// DESC:		Validation routine for the form
// PARAMS:		none
// RETURNS:		nothing
//**************************************************************************
function submitForm()	{
	objDoc = document.PCPSearchForm;
	
	if (objDoc.VehicleManufacturer.selectedIndex == 0)	{
		showErrorMessage("Choose a vehicle make");
		return false;
	}
	
	if (objDoc.VehicleModel.selectedIndex == 0)	{
		showErrorMessage("Choose a vehicle model");
		return false;
	}
	
	if (objDoc.VehicleDerivative.selectedIndex == 0)	{
		showErrorMessage("Choose a vehicle derivative");
		return false;
	}
	
	if (objDoc.PlanTerm.selectedIndex == 0)	{
		showErrorMessage("Choose a Personal Contract Plan Term");
		return false;
	}
	
	if (objDoc.AnnualMileage.selectedIndex == 0)	{
		showErrorMessage("Choose an agreed mileage");
		return false;
	}
	
	if (reCurrency.test(objDoc.DepositAmount.value) == false || objDoc.DepositAmount.value > 9999999) {
		showErrorMessage("Enter a deposit amount (£0.00 is valid)");
		return false;
	}
		
	if (objDoc.MaintenanceAgreement[0].checked == false && objDoc.MaintenanceAgreement[1].checked == false)	{
		showErrorMessage("You must state if you would like a maintnenance agreement.");
		return false;
	}
	
	//self.scroll(0, 0);
	return true;
}

//*******************************************************
// FUNCTION: helpPopup
//*******************************************************
// DESC:		Invokes help window and appends the helpID
//				to the querystring of the link
// PARAMS:		helpID
// RETURNS:		nothing
//*******************************************************
function helpPopup(helpID)
{
	var helpLink 			= "PCPHelp.asp?HelpID=" + helpID;
	var windowParams		= "width=300,height=135,resizable=yes,statusbar=no,status=no,toolbar=no,personalbar=no,directories=no,locationbar=no,scrollbars=no,left=200,top=100"
	window.open(helpLink,"helpWindow",windowParams);
}
//*******************************************************

//-->
