//BEGIN BUTTON SECTION
//Note: This section is for all the buttons that have rollovers that are common throughout the site.

img_backtotop_On = new Image();
img_backtotop_Off = new Image();
img_closewindow_On = new Image();
img_closewindow_Off = new Image();
img_downloadnow_On = new Image();
img_downloadnow_Off = new Image();
img_go_On = new Image();
img_go_Off = new Image();
img_readmore_On = new Image();
img_readmore_Off = new Image();
img_requestnow_On = new Image();
img_requestnow_Off = new Image();
img_search_On = new Image();
img_search_Off = new Image();
img_searchevent_On = new Image();
img_searchevent_Off = new Image();
img_submit_On = new Image();
img_submit_Off = new Image();
img_continue_On = new Image();
img_continue_Off = new Image();
img_cancel_On = new Image();
img_cancel_Off = new Image();
img_accept_On = new Image();
img_accept_Off = new Image();
img_decline_On = new Image();
img_decline_Off = new Image();

img_backtotop_On.src = '/assets/images/buttons/button_backtotop_on.gif';
img_backtotop_Off.src = '/assets/images/buttons/button_backtotop_off.gif';
img_closewindow_On.src = '/assets/images/buttons/button_closewindow_on.gif';
img_closewindow_Off.src = '/assets/images/buttons/button_closewindow_off.gif';
img_downloadnow_On.src = '/assets/images/buttons/button_downloadnow_on.gif';
img_downloadnow_Off.src = '/assets/images/buttons/button_downloadnow_off.gif';
img_go_On.src = '/assets/images/buttons/button_go_on.gif';
img_go_Off.src = '/assets/images/buttons/button_go_off.gif';
img_readmore_On.src = '/assets/images/buttons/button_more_on.gif';
img_readmore_Off.src = '/assets/images/buttons/button_more_off.gif';
img_requestnow_On.src = '/assets/images/buttons/button_requestnow_on.gif';
img_requestnow_Off.src = '/assets/images/buttons/button_requestnow_off.gif';
img_search_On.src = '/assets/images/buttons/button_search_on.gif';
img_search_Off.src = '/assets/images/buttons/button_search_off.gif';
img_searchevent_On.src = '/assets/images/buttons/button_search_on.gif';
img_searchevent_Off.src = '/assets/images/buttons/button_search_off.gif';
img_submit_On.src = '/assets/images/buttons/button_submit_on.gif';
img_submit_Off.src = '/assets/images/buttons/button_submit_off.gif';
img_continue_On.src = '/assets/images/buttons/button_continue_on.gif';
img_continue_Off.src = '/assets/images/buttons/button_continue_off.gif';
img_cancel_On.src = '/assets/images/buttons/button_cancel_on.gif';
img_cancel_Off.src = '/assets/images/buttons/button_cancel_off.gif';
img_accept_On.src = '/assets/images/buttons/button_accept_on.gif';
img_accept_Off.src = '/assets/images/buttons/button_accept_off.gif';
img_decline_On.src = '/assets/images/buttons/button_decline_on.gif';
img_decline_Off.src = '/assets/images/buttons/button_decline_off.gif';

function CheckHTMLSwitch(){
	if (getCookieValue("html") == "true" && document.location.href.indexOf("v=") <= 0){
		if(document.location.href.indexOf("?") > 0){
			document.location = document.location.href + "&v=html";
		}else{
			document.location = document.location.href + "?v=html";
		}
	}	
}

function gotoFlash(){

	//If they 'actually' don't have flash, go to the get flash page
	if(getCookieValue("html") == "" || !canPlayFlash()){
		document.location = "/getflash/?url=" + document.location.href.replace("?v=html","");
	
	//if they are just pretending to not have flash, go to the flash version
	}else{
		strURL = document.location.href.replace("?v=html","");
		strURL = strURL.replace("&v=html","");
		SetCookieValue("html","false",1);
		document.location = strURL;
	}
}
function gotoHTML(){
	SetCookieValue("html","true",1);
	if(document.location.href.indexOf("?") > 0){
		document.location = document.location + "&v=html";
	}else{
		if(document.location.href.indexOf("v=html") <= 0){
			document.location = document.location + "?v=html";
		}
	}
}

function getBuildPriceLink(){
	var strURL;
	strURL = "/ExternalRedirects.asp?site=http://www.forddirect.com/FordVehicles.jsp?partner=" + getCookieValue("partner") + "&target=Config"; 
	window.parent.location = strURL;
}

function getPriceQuote(){
	var strURL; 
	strURL = "/ExternalRedirects.asp?site=http://quickquote.forddirect.com/FordVehicles.jsp?partner=" + getCookieValue("partner"); 
	window.parent.location = strURL;
}

function popupPageWithNav(loc, name, width, height) {
	window_options = "'toolbar=yes,location=yes,buttons=yes;directories=yes,status=yes,menubar=yes,toolbar=yes,resizable=yes,scrollbars,copyhistory=yes,height=" + height + ",width=" + width + ",screenX=100,screenY=100'";
	nwn = window.open(loc,name,window_options);
	nwn.focus();
} 

function openNewWindow(theURL,winName,features) {
	var newWin;
	var locationString = '';
	if (newWin && ieX){
		locationString = locationString + newWin.location;
		if (locationString != ''){
			newWin.location.href = theURL;
		} else {
			newWin = window.open(theURL,winName,features);
			}
	} else {
		newWin = window.open(theURL,winName,features);
		}
}

function FIPWin(nPopupID){
	window.open("/asp/popups/fippopup.asp?nPopupID=" + nPopupID,"fip","toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,copyhistory=no,width=350,height=430,top=0,left=50,screenX=50,screenY=0");
}

function popOutside(sURL) {
	if( confirm( "You are linking to a non-Ford website.  Your browsing and interaction are subject to the rules and policies of that site.  Please read over the site's rules and policies before proceeding." ) ) 
	{
		n = window.open(sURL, 'n', 'width=700,height=555,location=yes,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		n.focus();

	} else {
		// Don't Leave Site
	}
}


//BEGIN COOKIE SPECIFIC SECTION
//Note: This section is used to maintain all querystring values passed in to fordvehicles.com.
function SetTrackingCookie(){
	var _cimage = new Image();
	_cimage.src = "/asp/util/cookie.asp" + location.search.toLowerCase();
}
SetTrackingCookie();


function SetLastVehicleVisited(nVehAbstID){
	//This function is used on the homepage of fordvehicles.
	//Sets the last visited vehicle.
	if(nVehAbstID.length > 0){
		SetCookieValue("LastVehicleVisited",nVehAbstID,30)
	}
	 
};

function SetCookieValue(name,val,nDays) {
	var objtoday = new Date();
	var objexpire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	objexpire.setTime(objtoday.getTime() + 3600000*24*nDays);
	document.cookie = name+"="+escape(val)+ ";path=/;expires="+objexpire.toGMTString();
	
}

function TurnOnImage(oElement){	
	img = eval(oElement + "On.src");
	document [oElement].src = img;
}
	
function TurnOffImage(oElement){
	img = eval(oElement + "Off.src");
	document [oElement].src = img;
}	

function IsInCookie(ckie,nme)
{
   var splitValues;
   var i;
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=");
      if (splitValues[0]==nme) return true;
   }
   return false;
}
function removeBlanks(strng)
{
   var result="";
   var i;
   var chrn;
   for (i=0;i<strng.length;++i) {
      chrn=strng.charAt(i);
      if (chrn!=" ") result += chrn;
   }
   return result;
}
function getValue(ckie,nme)
{
   var splitValues;
   var i;
   for(i=0;i<ckie.length;++i) {
      splitValues=ckie[i].split("=");
      if(splitValues[0]==nme) return splitValues[1];
   }
   return "";
}
function getCookieValue(cname) {   
   var cookie=document.cookie;    
   var chkdCookie=removeBlanks(cookie);   
   var nvpair=chkdCookie.split(";");
   var tvalue = "";
   if(IsInCookie(nvpair,cname));  
   {   
      tvalue=getValue(nvpair,cname);   
    }
	return tvalue;    
}
//END COOKIE CODE

function openNewWindowWithFeatures(theURL,winName,features) {
	newWin = window.open(theURL,winName,features);
}

function fGetPage(loc, name, width, height) {
	window_options = "'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars,copyhistory=no,height=" + height + ",width=" + width + ",screenX=100,screenY=100'";
	var sWin = window.open(loc,name,window_options);
	sWin.focus();
} 

function popFullFunc( window_http, window_name, nW, nH ) {
	var	window_left = 140; 
	var window_top = 150;
		
	window_options = "'toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes,height=" + nH + ",width=" + nW + ",left=" + window_left + ",screenX=" + window_left + ",top=" + window_top + ",screenY=" + window_top + "'";
	window.open( window_http, window_name, window_options );
}

/**************************************************
	T O W I N G   M O D U L E  - START
***************************************************/

function FV_openBrWindow(theURL,winName,features) { 
  window.name = "towingWindow";
  window.open(theURL,winName,features);
}

function FV_openTowingModle( type, vehicle, cab ) {
	window.name = "towingWindow";
	self.name = "towingWindow";
	 
	if( cab == "" ) {
		FV_openBrWindow('http://' + window.location.host + '/towing/popup.asp?type='+ type +'&uid=' + vehicle + '' ,'TowingGuide','width=725,height=581,resizable=1');
	} else {
		FV_openBrWindow('http://' + window.location.host + '/towing/popup.asp?type='+ type +'&uid=' + vehicle + '&cid=' + cab + '' ,'TowingGuide','width=725,height=581,resizable=1');
	}
}
 
// Spelling correction that doesn't break the original
function FV_openTowingModule(type,vehicle,cab) { 
  FV_openTowingModle( type, vehicle, cab );
}


/**************************************************
	T O W I N G   M O D U L E  - END
***************************************************/

function goTo(strLoc){	
 if (strLoc.substring(0,1) == '/')
  	window.parent.location = "http://" + window.location.host + strLoc;		
  else
  	window.parent.location = strLoc;		
 }

function leftNavOn(obj, bgNumber){
				obj.className = "leftNavOn" + bgNumber;
}
function leftNavOff(obj,bgNumber){
	obj.className = "leftNavOff" + bgNumber;
}

function bottomleftNavOn(obj, bgNumber){
				obj.className = "bottomleftNavOn" + bgNumber;
}
function bottomleftNavOff(obj,bgNumber){
	obj.className = "bottomleftNavOff" + bgNumber;
}


//Popup Survey
function goexternal(sURL){
	if( confirm( "You are linking to a non-Ford website. When you click ‘OK’, you are subject to the terms and conditions of that site. Please read over the site’s terms and conditions and privacy policy.") ) {
		// Leave Site - linking code goes here
		document.location = sURL;
	} else {
		// Don't Leave Site
	}
}

function popOutside(sURL) {
	if( confirm( "You are linking to a non-Ford website. When you click ‘OK’, you are subject to the terms and conditions of that site. Please read over the site’s terms and conditions and privacy policy.") ) {
		n = window.open(sURL, 'n', 'width=700,height=555,location=yes,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		n.focus();

	} else {
		// Don't Leave Site
	}
}
	

//All of this is For the Popup Survey****************************************************BEGIN POPUP SURVEY
var browser = navigator.appName,
	isMSIE = "Microsoft Internet Explorer",
	isNS = "Netscape",
	isAMac = navigator.platform;
var min_visits = 2
if (!(isAMac == "MacPPC" || browser == isNS)){
	var mockImage = new Image( 1, 1 );
	mockImage.src = "/asp/util/aspInc_new.asp";	//This page increments a counter by one. 
}

function fGetPage(loc, name, width, height) {
	window_options = "'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars,copyhistory=no,height=" + height + ",width=" + width + ",screenX=100,screenY=100'";
	var sWin = window.open(loc,name,window_options);
	sWin.focus();
} 



	
function fGetCookie(cookieName){
	var cookieValue = "",
		cookieObj = document.cookie,
		cookieID = cookieName + "=",
		cookieExists = cookieObj.indexOf(cookieID);
		if (cookieExists != -1){
			var valStart = cookieExists + cookieID.length;
			var valEnd = cookieObj.indexOf(";",valStart);
			if (valEnd == -1) valEnd = cookieObj.length;
			cookieValue = unescape(cookieObj.substring(valStart,valEnd));
			return cookieValue;
			}
		}


function fSetCookie(name, value, expire){
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + ";path=/"
	}

function fFlashClickHandler(sURL){
	window.onunload = null;
	location.href = sURL;
	}

function fChangeHandler(e){
	//var vehicleElement = document.forms['VehicleSelect'].elements['aVehicle'];
	window.onunload = null;
	//window.location.href = vehicleElement[vehicleElement.selectedIndex].value;
	redirectAccessor(document.forms['VehicleSelect']);
	return true;
}

var aURLs = new Array();
	aURLs[0] = "www.dongdugroup.com";
	aURLs[1] = "www.dongdugroup.com";
	aURLs[2] = "www.dongdugroup.com";
	aURLs[3] = "www.dongdugroup.com";
	aURLs[4] = "www.dongdugroup.com";
	aURLs[5] = "www.dongdugroup.com";
	aURLs[6] = "javascript";
	aURLs[7] = "www.dongdugroup.com";
	aURLs[8] = "www.dongdugroup.com";
	aURLs[9] = "www.dongdugroup.com";
	aURLs[10] = "www.dongdugroup.com";
	aURLs[11] = "www.dongdugroup.com";
	
	
function fClickHandler(e){
	var oEventSource,
		bContinue = 1;
	if (browser == isMSIE){
		oEventSource = event.srcElement;
		src = new String(event.srcElement);
	} else {
		oEventSource = e.target;
		src = new String(e.target);
	}

	if (src == "[object]") bContinue = 0;
 
	if (oEventSource.href && (new String(oEventSource.href)).indexOf("/images/2003/EN/sitenav/g_myford_on.gif")>=0) bContinue = 1;
	if(oEventSource.target && new String(oEventSource.target) == "_new") bContinue = 0;
	if (oEventSource.name){
		if (document.images[oEventSource.name]){
			src = new String( document.images[oEventSource.name].parentElement );
		}
	}
	for (var i = 0; i < aURLs.length; i++){
		if (src.indexOf(aURLs[i]) >= 0){
			bContinue = 0;
		}
	}
			
	var cVal_FVSurveyLaunched = fGetCookie("FVsurveyLaunched");
	if (bContinue && cVal_FVSurveyLaunched != "TRUE"){
		launchSurvey();
	}
	 
	window.onunload = null;
	return true;
}

function fGetPage(loc, name, width, height) {
	window_options = "'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars,copyhistory=no,height=" + height + ",width=" + width + ",screenX=100,screenY=100'";
	var sWin = window.open(loc,name,window_options);
	sWin.focus();
} 

function fGetPageNoScroll(loc, name, width, height) {
	window_options = "'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,copyhistory=no,height=" + height + ",width=" + width + ",screenX=100,screenY=100'";
	window.open(loc,name,window_options);
} 


	
function fPageUnload(){
	var cVal_FVSurveyLaunched = fGetCookie("FVsurveyLaunched");
	var cVal_visited =  fGetCookie("counter");
		
	if(cVal_visited!="")
		cVal_visited = parseInt(cVal_visited);
	else
		cVal_visited = 0;
	
	// only when the popup survey hasn't popuped and the user visited more than
	// two pages, the popup survey shows up
	if (cVal_FVSurveyLaunched != "TRUE" && cVal_visited>=min_visits){
		launchSurvey();
	}
}

function fAddHandlers(o){
	o.onclick = fClickHandler;
	o.onchange = fChangeHandler;
	o.onsubmit = fSubmitHandler;
}


function fSubmitHandler(e) {
	window.onunload = null;
	return true;
}

function fDefineHandlers(){
	//for (var i = 0; i < document.links.length; i++ ) fAddHandlers(document.links[i]);
	//alert(document.links.length);
	
	for (var i = 0; i < document.links.length; i++ ) 
	{
	 
	 if(!isSpecialLink(new String(document.links[i])))
	 	fAddHandlers(document.links[i]);
	}
	
	
	
	if ((isAMac != "MacPPC") || (browser != isNS))
	{
	  divArray = document.all.tags('DIV')

      //alert("divArray.length=" + divArray.length);
	  for(var i=0; i<divArray.length; i++)
	  {
	  	  
	  	linkArray = divArray[i].all.tags('A');
	  
		  for(var j=0; j<linkArray.length; j++)
		  {
		    //alert(linkArray[j].innerHTML);
		    fAddHandlers(linkArray[j]);
		  }
	  }

	}
	
	window.onunload = fPageUnload;
	
	var formArr = document.forms;
	//////////////////////
	if( document.forms ) {
		for( iCounter = 0; iCounter < document.forms.length; iCounter++ ) {
			if( document.forms[iCounter].action.indexOf("www.fordvehicles.com") >= 0 || document.forms[iCounter].action.indexOf("qa.fv50.jwtdigital.com") >= 0 || document.forms[iCounter].action.indexOf("/") == 0 || document.forms[iCounter].action.length == 0 || document.forms[iCounter].action.indexOf("/") == -1) {
				fAddHandlers( document.forms[iCounter] );
			}
		}
	}
	//////////////////////
	if (formArr && formArr['VehicleSelect'] && formArr['VehicleSelect'].elements['aVehicle']) fAddHandlers(formArr['VehicleSelect'].elements['aVehicle']);
}


function launchSurvey(){
	if (screen.width > 800){
		fGetPage("/asp/util/FVPopup.htm", "popupsurvey", 500, 400);
	} else {
		fGetPage("/asp/util/FVPopup.htm", "popupsurvey", 600, 400);
		}
	fSetCookie("FVsurveyLaunched","TRUE");
}


var cVal_FVSurvey = fGetCookie("FVsurvey");

if (cVal_FVSurvey == "TRUE"){

	// count the pages this user visited
	var visits = fGetCookie("counter");

	// if the cookie was not found, this is your first visit
	if (isNaN(parseInt(visits))) {
	  visits = 1; // the value for the new cookie
	} else {
	  // increment the counter
	  visits = parseInt(visits) + 1;
	}
	
	// set the new cookie
	fSetCookie("counter", visits);
	//count end
}


function isSpecialLink(strLink)
{
  strLink = strLink.toLowerCase();
  
   if(strLink=="javascript://")
   return true;
   
   else if(strLink.indexOf("/features/harley/vehicle_imgs.asp")!=-1 && strLink.indexOf("#")!=-1)
   return true;
   
   else if(strLink.indexOf("/features/harley/img_gallerys.asp")!=-1 && strLink.indexOf("#")!=-1)
   return true;
   
   else
   return false;
}

function loadSurvey()		//This is the function that is called on all of the web pages on fordvehicles.com.
{
	if ((isAMac != "MacPPC") || (browser != isNS)){
	  	if (cVal_FVSurvey == "TRUE")
			fDefineHandlers();
	}
}
//END POPUP SURVEY
