

function gnLoad_EventHandler() {
  	if(menuType == "modelHome" && document.all) {
		AttachEvent(getElemRefs("gmcVehicles"), "mouseover", vehicles_onMouseover);
		AttachEvent(getElemRefs("gmcVehicles"), "mouseout", vehicles_onMouseout);
	}
	/* dont want to toggle s&b menu any longer ... commenting for jd power in case they want functionality to return 
  	if(menuType == "modelHome") {
		AttachEvent(getElemRefs("shopAndBuyHeader"), "click", toggleShopBuy);
	}*/
}
  
function vehicles_onMouseover() {
	getElemRefs("gmcVehiclesList").style.display = "block";
	getElemRefs("gmcVehiclesHeader").style.backgroundImage = "url('/images/nav/leftNav_vehicles_over.gif')";
}  
function vehicles_onMouseout() {
	getElemRefs("gmcVehiclesList").style.display = "none";
	getElemRefs("gmcVehiclesHeader").style.backgroundImage = "url('/images/nav/leftNav_vehicles.gif')";
}

//this function is being called in the left nav's flash.
function locateDealerLeftNav(zipCodeVal, params){
		if(document.getElementById("locateInputTxt") != null){
			frmInput = document.getElementById("locateInputTxt");
			frmInput.value = zipCodeVal;
			if (typeof(params) == "string"){	//if there is a set of parameters it processes them by adding hidden input fields.
				var paramArray = params.split('&');
	
				for (var i = 0; i < paramArray.length; i++){	//iterates on each parameter
					var v = paramArray[i].split('=');
					if (v.length > 1){
						var el = document.createElement("input");	//we create a new input field in the form
						el.setAttribute("type", "hidden");
						el.setAttribute("name", v[0]);
						el.setAttribute("value", v[1]);
						document.locateDealerFormLeftNav.appendChild(el);
					}
				}
			}
		}

	if(document.getElementById("flashReplaced") != null){
		window.location.href= "/locatedealer/cntrl?WEBSITEID=GC&BRANDID=GC&FILEPATH=%2Fgmc%2F&BPLINK=Y&mapLink=true&drivingLink=true&urlForward=true&searchSelected=ByPostalCode&SearchType=ByPostalCode&ProgramICON=bpo&desiredCount=10&level=1&width=425&height=250&request=dealerlocate&originatingBrand=DIVISIONAL&model=&SearchByPostalCodeProximity=50&SearchByCityStateCityName=City&SearchByCityStateStateName=&SearchByCityStateProximity=50&SearchByVendorVendorName=Dealer+Name&SearchByVendorCityName=City&SearchByVendorStateName=State&x=0&y=0&dealerTypeCode=R&SearchByPostalCodePostalCode=" + zipCodeVal;
	}else{
		document.locateDealerFormLeftNav.submit();
	}
}


function flashLink(url, flashSection) {
	
	if (typeof hasFlash == "undefined") {
	// hasFlash is not defined, therefore this page does not have sifr or some other flash-related js
		return true;	
	}
	
	if (hasFlash == true) {
			
		if (isFlashReady) {
			if (flashProxy != null) {
				flashProxy.call('updateMainContent', flashSection);
				setActiveNavState(url)
				return false;
			} 
		}
	}
	return true;
}


function currentVehicleLink(fileUrl) {
	var url = new String();	
	// currently we only have specs for the 1500
	if ((brand == "sierra900") && (fileUrl.indexOf("specs") == 0)){
		url = "/sierra900/1500/" + fileUrl;
	} else {
		url = "/" + brand +"/"+ vehicle +"/" + fileUrl;
	}
	window.location.href = url;	
}

function validateZipOnSubmit(domObj){
	var str = domObj.value;
	if(str.length != 5){
		alert('Zip code must have 5 numbers.');	
		return false;
	}
	else{
		return true;	
	}
}

function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
	 
	 
function vld5()
{	
   txt = document.locateDealerFormLeftNav.SearchByPostalCodePostalCode;
   if (txt.value != " Enter ZIP")
      txt.setAttribute('maxLength', 5);
   else
      txt.setAttribute('maxLength', 10);
}
	function empty(str)  
	  {    
	  	var is_empty; 
	  	if(str.length != 5){
		is_empty = true;
		return (is_empty);
		}
		var text = " \n\t" + String.fromCharCode(13);                            
		var i;                                                
		for(i = 0, is_empty = true; (i < str.length) && is_empty; i++) 
		  is_empty = text.indexOf(str.charAt(i)) != - 1;  
		 return(is_empty);	
	  }  
	  function Fields(form)  
	  {  
	   if(empty(form.locateInputTxt.value)){
		 alert("Zip code must have 5 numbers.");  
		 return (false);   
	   }else{  
	   return (true);  
	   }
	   }  

/*function SetZipFieldLength(pEvent)
{
   mZip= document.getElementById("zip");
   if (pEvent=="focus")
   {
      mZip.setAttribute('maxLength', 5);
      mZip.value="";
   }
   else
   {
      mZip.setAttribute('maxLength', 10);
      mZip.value="Enter ZIP";
   }
}*/

function setActiveNavState(url) {

	if( document.getElementById && document.getElementsByTagName ){
		if( document.getElementById( 'activeModel' ) ){
			var modelStuff = document.getElementById( 'activeModel' );
			var links = modelStuff.getElementsByTagName( 'a' );

			for( var i=0; i < links.length; i++ ){
				if (links[i].href == url) {
					links[i].className = "gnActive";
				} else {
					links[i].className = "";
				}
			}
		}
	}
}

/* this function is no longer needed as toggling isn't desired. am leaving in code because it might
return someday -- dtw */

var itemStatus = new Array();
function toggleMenu(area, id, page) {
	// First, find the button image and the menu
	var image = document.getElementById("openClose" + id);
	var menu = document.getElementById("subMenu" + id);
	
	if (image == undefined || menu == undefined) return false;
	id = area + "-" + id;
	if ((itemStatus[id] == undefined && page=="gmcHome") || (itemStatus[id] == undefined && page=="modelHome"))itemStatus[id] = true;
	if (itemStatus[id] == undefined && page!="gmcHome")itemStatus[id] = false;
	// Toggle the button image
	itemStatus[id] = !itemStatus[id];	
	image.className =  (itemStatus[id] ? "closeButton" : "openButton");	
	menu.style.display = (itemStatus[id] ? "inline" : "none");
	return false;
}
function toggleLineUp(idImage, idItems) {
	var image = document.getElementById(idImage);
	var divItems = document.getElementById(idItems);
	
	if(divItems.style.display=="none"){
		divItems.style.display="block";
	}else{
		divItems.style.display="none";
	}
	if(image.src=="/images/nav/vehicle_lineup_on.gif"){
		image.src="/images/nav/vehicle_lineup_on.gif";
	}else{
		image.src="/images/nav/vehicle_lineup_on.gif";
	}
	return true;
}

function show(id){
	document.getElementById(id).style.display="block";
	document.getElementById('gmcVLU').src='/images/nav/vehicle_lineup_on.gif';
}
function hide(){
	document.getElementById('itemsLU').style.display="none";
	document.getElementById('gmcVLU').src='/images/nav/leftNav_vehicleLineRight.jpg';
}
function toggleShopBuy() {
	var shopSubMenu = getElemRefs("shopSubMenu");
	var shopDiv = getElemRefs("shopDiv");
	if(shopDiv.className == "") {
		shopDiv.className = "expand";
		shopSubMenu.style.display = "block";
	} else {
		shopDiv.className = "";
		shopSubMenu.style.display = "none";
	}
}
  
	 function setOmniture(omniture){
   //Set omniture sprop2 variable with value from left nav
	   sprop2Aux = omniture;
	   sprop2="";
	 }
  
AttachEvent(window, "load", gnLoad_EventHandler);

