<!--Modify for Divisional Content-->
var multiBrandEnabled = false;  //required ONLY for cross-divisional sites, for divisional sites update to true
<!---->

//Fuctions required to fill the states, mile and proximity combo boxes

function initLocateDealer() {
	LoadStateValues();
	LoadMileValues();
	if (multiBrandEnabled == true){LoadBrand();}
}

function initLocate() {
	LoadStateValues();
	LoadMileValues();
	LoadMileUpdate();
	LoadSelectedValues();
}

//function required to display different Headers
function displayHeaders(){
	if(toolName == "VL"){
		document.getElementById('pageTitle').style.backgroundImage = "url(/images/bp/vlws/header_locate_vehicle.gif)";
		document.getElementById('pageTitle').style.backgroundRepeat = "no-repeat";
		document.getElementById('pageTitle').style.backgroundPosition = "668px 14px";		
		document.getElementById('pageTitle').innerHTML += "Locate Vehicle";
		document.getElementById('step1').innerHTML += "<span class=\"gHidden\">Step 1: Select Search Area</span>";
		document.getElementById('step2').innerHTML += "<span class=\"gHidden\">Step 2: Select A Vehicle</span>";
		document.getElementById('step3').innerHTML += "<span class=\"gHidden\">Step 3: Inventory Results</span>";
		document.title = "Locate Vehicle";
		}else if (toolName == "RAQ"){
			//document.getElementById('pageTitle').innerHTML += "Request A Quote";
			document.getElementById('pageTitle').style.backgroundImage = "url(/images/bp/messaging/header_request_quote.gif)";
			document.getElementById('pageTitle').style.backgroundRepeat = "no-repeat";
			document.getElementById('pageTitle').style.backgroundPosition = "668px 14px";			
			document.getElementById('step1').innerHTML += "<span class=\"gHidden\">Step 1: Select A Dealer</span>";
			document.getElementById('step2').innerHTML += "<span class=\"gHidden\">Step 2: Select A Vehicle</span>";
			document.getElementById('step3').innerHTML += "<span class=\"gHidden\">Step 3: Request A Quote</span>";
			document.getElementById('step3').style.backgroundImage = "url(/images/bp/messaging/top_nav_step3_off.gif)";
			//document.getElementById('compareMainTabs').style.marginBottom = "23px";
			document.title = "GMC | 2008 New Vehicles: Request a Quote from a GMC Dealer";
			}else if(toolName == "RAT"){
				document.getElementById('pageTitle').innerHTML += "Schedule A Test Drive";
				document.getElementById('step1').innerHTML += "Step 1: Select A Dealer";
				document.getElementById('step2').innerHTML += "Step 2: Select A Vehicle";
				document.getElementById('step3').innerHTML += "Step 3: Schedule A Test Drive";
				document.title = "Schedule A Test Drive";
				}else if (toolName == "DL"){
					//document.getElementById('pageTitle').innerHTML += "Locate Dealer";
					document.getElementById('pageTitle').style.backgroundImage = "url(/images/bp/dealerlocator/hdr_locate_dealer.gif)";
					document.getElementById('pageTitle').style.backgroundRepeat = "no-repeat";
					document.getElementById('pageTitle').style.backgroundPosition = "685px 14px";	
					document.getElementById('compareMainTabs').style.visibility = 'hidden';
					document.getElementById('compareMainTabs').style.display = 'none'
					document.getElementById('step1').style.visibility = 'hidden';
					document.getElementById('step1').style.display = 'none';
					document.getElementById('step2').style.visibility = 'hidden';
					document.getElementById('step2').style.display = 'none';
					document.getElementById('step3').style.visibility = 'hidden';
					document.getElementById('step3').style.display = 'none';
					document.getElementById('step4').style.visibility = 'hidden';
					document.getElementById('step4').style.display = 'none';					
					document.title = "Locate Dealer";	
		}
}
//funtion required to display the selection drop down only for GMC
function showDealerSelection(){
	displayDealer = true;
	displayBrandSelection();
	hideMDCDLabel();
	document.getElementById('BCD').style.fontWeight = 'bold';
}

//funtion required to hide the selection drop down only for GMC
function hideDealerSelection(){
	displayDealer = false;
	//displayLocateDGMC();
	hideBradD();
	hideBrandSelection();
	hideOptionalValues();
	mediumDutyDealers();
	document.getElementById('MDCM').style.fontWeight = 'bold';
	document.getElementById('BCD').style.fontWeight = 'normal';
}

//funtion required to display the brand selection drop down
function displayBrandSelection(){
	//display the brand drop down for cross-divisional sites
	if(((brandId == "FLEET")||(brandId == "GM")||(brandId == "CUV"))){
		displayBSelection();
		hideLocateDGMC();
		hideOptionalValues();
		hideMDCDLabel();
		//display the dealer selection only for Chevrolet and GMC
		}else if(brandId == "CHEVROLET"){
			hideBradD();
			hideLocateDGMC();
			hideOptionalValues();
			hideMDCDLabel();
			}else if(brandId == "GMC"){
				//displayLocateDGMC();
				hideBradD();
				hideBrandSelection();
				hideOptionalValues();
				hideMDCDLabel();
					if(displayDealer == true){
						hideBradD();
						displayBSelection();
						document.getElementById('optionalValues').style.visibility = 'visible';
						document.getElementById('optionalValues').style.display = 'block';
						hideMDCDLabel();
					}
				}else{
					hideBrandSelection();
					hideLocateDGMC();
					hideOptionalValues();
					hideMDCDLabel();
		}	
}

//funtion to hide the Medium Duty Commercial Dealers label
function hideMDCDLabel(){
	document.getElementById('MDCM').style.fontWeight = 'normal';
}

//function to display the brand dropdown
function displayBSelection(){
	document.getElementById('brandSelection').style.visibility = 'visible';
	document.getElementById('brandSelection').style.display = 'block';
}

//function to display the Locate Dealer for GMC
function displayLocateDGMC(){
	document.getElementById('LocateDGMC').style.visibility = 'visible';
	document.getElementById('LocateDGMC').style.display = 'block';
}

//function to hide the Locate GMC Commercial Dealers for GMC
function hideLocateDGMC(){
	document.getElementById('LocateDGMC').style.visibility = 'hidden';
	document.getElementById('LocateDGMC').style.display = 'none';
}

//function to hide the optionalValues dropdown for GMC
function hideOptionalValues(){
	document.getElementById('optionalValues').style.visibility = 'hidden';
	document.getElementById('optionalValues').style.display = 'none';
}

//function to hide the brandSelection dropdown
function hideBrandSelection(){
	document.getElementById('brandSelection').style.visibility = 'hidden';
	document.getElementById('brandSelection').style.display = 'none';
}

//funtion to hide the brand dropdown
function hideBradD(){
	document.getElementById('brandD').style.visibility = 'hidden';
	document.getElementById('brandD').style.display = 'none';
}

//Function to load the values for Retail Dealer, Medium Duty Dealer and Business Central Dealer for cross-divisional sites
function setRadioValue(){
	var RD =  document.getElementById("RetailDealer").checked;
	var MDD = document.getElementById("MediumDutyDealer").checked;
	var BCD = document.getElementById("BusinessCDealer").checked;
	if (RD == true){dTypeCode = document.getElementById("RetailDealer").value; }
	if (MDD == true){dTypeCode = document.forms["brandsDL"].MediumDutyDealer.value; agreementTypeCode = "SLS";}
	if (BCD == true){
		dTypeCode = document.forms["brandsDL"].BusinessCDealer.value; 
		agreementTypeCode = "SLS";
		document.forms["SearchByZipCode"].programCode.value = "csv";
		document.forms["SearchBycityState"].programCode.value = "csv";
		document.forms["SearchByDealer"].programCode.value = "csv";
	}
}

//Function for Medium Duty Commercial Dealers
function mediumDutyDealers(){
	document.forms["SearchByZipCode"].ProgramICON.value = "bpo";
	document.forms["SearchBycityState"].ProgramICON.value = "bpo";
	document.forms["SearchByDealer"].ProgramICON.value = "bpo";
	document.forms["SearchByZipCode"].dealerTypeCode.value = "M";
	document.forms["SearchBycityState"].dealerTypeCode.value = "M";
	document.forms["SearchByDealer"].dealerTypeCode.value = "M";
}

//function to load the brand dropdown
function LoadBrand(){
	document.forms["brandsDL"].brandD.options[0] = new Option("Select a Brand","Select a Brand");
	for(var i=0; i< brandObjectArray.length; i++){
			document.forms["brandsDL"].brandD.options[i+1] = new Option(brandObjectArray[i].name, brandObjectArray[i].abbreviation);
		}
}

//functions to fill the state and miles dropdowns automatically
function LoadStateValues(){
	document.forms["SearchBycityState"].SearchByCityStateStateName.options[0]= new Option("Select A State","0");
	document.forms["SearchByDealer"].SearchByVendorStateName.options[0]= new Option("Select A State","0");
	for(var i=0; i< stateObjectArray.length; i++){
			document.forms["SearchBycityState"].SearchByCityStateStateName.options[i+1]= new Option(stateObjectArray[i].name, stateObjectArray[i].abbreviation);
			document.forms["SearchByDealer"].SearchByVendorStateName.options[i+1]= new Option(stateObjectArray[i].name, stateObjectArray[i].abbreviation);
		}
}

function LoadMileValues(){
	document.forms["SearchBycityState"].SearchByCityStateProximity.options[0]= new Option("Within 5 Miles","5");
	document.forms["SearchByZipCode"].SearchByPostalCodeProximity.options[0]= new Option("Within 5 Miles","5");
	for(var i=0; i< mileObjectArray.length; i++){
			document.forms["SearchBycityState"].SearchByCityStateProximity.options[i+1]= new Option(mileObjectArray[i].name, mileObjectArray[i].abbreviation);
			document.forms["SearchByZipCode"].SearchByPostalCodeProximity.options[i+1]= new Option(mileObjectArray[i].name, mileObjectArray[i].abbreviation);
		}
	selectMileLocateDealer();
	selectMileZipCode();
}

function LoadMileUpdate(){
	document.forms["SearchRangeDL"].LoadMileUpdate.options[0]= new Option("Within 5 Miles","5");
	for(var i=0; i< mileObjectArray.length; i++){
			document.forms["SearchRangeDL"].LoadMileUpdate.options[i+1]= new Option(mileObjectArray[i].name, mileObjectArray[i].abbreviation);
		}
	selectMile();
}

//Load the values from the dealersearch.jsp 
function LoadSelectedValues(){
	readAllSBToolsCookies();
	if (!isEmptyString(sbToolsCookies['sbtzipcode']) && !isEmptyString(sbToolsCookies['sbtzipproximity'])) {
		document.forms["SearchByZipCode"].SearchByPostalCodePostalCode.value = sbToolsCookies['sbtzipcode'];
		document.forms["SearchByZipCode"].SearchByPostalCodeProximity.value = sbToolsCookies['sbtzipproximity'];
	}
	
	if ((!isEmptyString(sbToolsCookies['sbtcityname']) && !isEmptyString(sbToolsCookies['sbtcitystate']) && !isEmptyString(sbToolsCookies['sbtcityproximity']))) {
		document.forms["SearchBycityState"].SearchByCityStateCityName.value = sbToolsCookies['sbtcityname'];
		document.forms["SearchBycityState"].SearchByCityStateStateName.value = sbToolsCookies['sbtcitystate'];
		document.forms["SearchBycityState"].SearchByCityStateProximity.value = sbToolsCookies['sbtcityproximity'];
	}
	
	if ((!isEmptyString(sbToolsCookies['sbtsearchdealername']) && !isEmptyString(sbToolsCookies['sbtcitynamedealer']) && !isEmptyString(sbToolsCookies['sbtcitystatedealer']))) {
		document.forms["SearchByDealer"].SearchByVendorVendorName.value = sbToolsCookies['sbtsearchdealername'];
		document.forms["SearchByDealer"].SearchByVendorCityName.value = sbToolsCookies['sbtcitynamedealer'];
		document.forms["SearchByDealer"].SearchByVendorStateName.value = sbToolsCookies['sbtcitystatedealer'];		
	}
}


//Functions to select the default mile
function selectMile(){
	if(document.forms["SearchRangeDL"].LoadMileUpdate.options[2].value == "25"){
			document.forms["SearchRangeDL"].LoadMileUpdate.options[2].selected = true;
		}
}

function selectMileLocateDealer(){
	if(document.forms["SearchBycityState"].SearchByCityStateProximity.options[2].value == "25"){
			document.forms["SearchBycityState"].SearchByCityStateProximity.options[2].selected = true;
		}
}

function selectMileZipCode(){
	if(document.forms["SearchByZipCode"].SearchByPostalCodeProximity.options[2].value == "25"){
			document.forms["SearchByZipCode"].SearchByPostalCodeProximity.options[2].selected = true;
		}
	}

// Submit the form with the current position "recordBegin , recordEnd" of the paging
function submitForm(recordBegin, recordEnd, PCProx, CSProx, result){
	document.forms["SearchRangeDL"].recordBegin.value = recordBegin;
	document.forms["SearchRangeDL"].recordEnd.value   = recordEnd;
	AssignProximityPaging(PCProx, CSProx);
	if(result == 'viewall'){
		document.forms["SearchRangeDL"].ShowAllresults.value = 'yes';
		}else{
			document.forms["SearchRangeDL"].ShowAllresults.value = 'no';
		}
	document.forms["SearchRangeDL"].submit();	
}

function AssignProximityPaging(PCProx, CSProx){
	if(PCProx != null){
		document.forms["SearchRangeDL"].PCProximity.value = PCProx;
		document.forms["SearchRangeDL"].CSProximity.value = "null";
	}else if (CSProx != null){
		document.forms["SearchRangeDL"].PCProximity.value = "null";
		document.forms["SearchRangeDL"].CSProximity.value = CSProx;
		}else if((PCProx == null)&&(CSProx == null)){
			document.forms["SearchRangeDL"].PCProximity.value = "null";
			document.forms["SearchRangeDL"].CSProximity.value = "null";
			}
}

function SearchBoxResize(){
	var str = navigator.appVersion;
	if(str.indexOf("MSIE 8.0") > -1){
		document.getElementById('SearchAgainSection').style.paddingLeft="15px";
	}
}