<!--
//****************************************************************************
// Copyright.........: © MATTHEWS SOFTWARE INC.
// ..................: Licensed by Agreement to Ford Motor Co.
//
//***************************************************************************

var BOSS = false,
	m_flashSettings = {}

try {
	jQuery.noConflict();
} catch (errorObject) {
	//
}

function isIE() {
	return !!(window.attachEvent && !window.opera);
}
function isIE6(){
	if(document.all && !window.opera && !window.XMLHttpRequest){
		return true;
	}
}

//document.write('<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">'); // TSH: 12-8-2008 : This will cache out the browser
//document.write('<META HTTP-EQUIV="Pragma" CONTENT="no-cache">'); // TSH: 12-8-2008 : This will cache out the browser
document.write('<LINK REL="shortcut icon" HREF="../favicon.ico" />'); // TSH : 12-2-2008 : Adds Bookmark Icon to the URL Bar

//--------------------------------------------------------------------------------
// LAYOUT FUNCTIONS
// These functions write the header and are called from every page.
// FUNCTION NAMES:
//		StandardLayoutStart()
//		StandardLayoutEnd()
//--------------------------------------------------------------------------------

function StandardLayoutStart(isWdUser, isValidUser, userName, lineCount, orderTotal, canPlaceOrder, isMediaUser, isCatalogUser, isCallCenterUser, isSpecial, useWmode) {
/* --------------------------------------------------------------------------------
Description........: These parameters are not used, but I've preserved their default
...................: values in case we do decide to use them again...
...................:	isWdUser = (isWdUser === undefined ? 0 : isWdUser);
...................:	userName = (userName === undefined ? "" : userName);
...................:	lineCount = (lineCount === undefined ? 0 : lineCount);
...................:	orderTotal = (orderTotal === undefined ? "$0.00" : orderTotal);
...................:	canPlaceOrder = (canPlaceOrder === undefined ? 0 : canPlaceOrder);
...................:	isMediaUser = (isMediaUser === undefined ? 0 : isMediaUser);
...................:	isCatalogUser = (isCatalogUser === undefined ? 0 : isCatalogUser);
-------------------------------------------------------------------------------- */
	var bannerCookie;
	
	m_flashSettings.isValidUser = (isValidUser === undefined ? 0 : isValidUser);
	m_flashSettings.isSpecial = (isSpecial === undefined ? "MainImage" : isSpecial);
	m_flashSettings.bannerCookie = (GetCookieNumeric("frbannerVisible", 0) == 0 ? 0 : 1);
	m_flashSettings.useWmode = 1; //useWmode;

	document.write('<div id="TopPageContent" class="ContentTop">');
	document.write('</div>');
	
	document.write('<div id="MiddlePageContent" class="content-background-middle2">');
	
	
};

function writeFlashContent() {
	var objectElement,
		useWmode;

	if (m_flashSettings.useWmode == 0) {
		useWmode = '<embed src="../include/flash/NewNav2.swf?specialSWF='+ m_flashSettings.isSpecial + '&IsValidUser=' + m_flashSettings.isValidUser + '&fr_bannerVisible=' + m_flashSettings.bannerCookie + '" quality="best" bgcolor="#000000" width="896" height="276" name="NewNav2" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	} else {
		useWmode = '<param name="wmode" value="transparent" />' +
			'<embed src="../include/flash/NewNav2.swf?specialSWF='+ m_flashSettings.isSpecial + '&IsValidUser=' + m_flashSettings.isValidUser + '&fr_bannerVisible=' + m_flashSettings.bannerCookie + '" quality="best" wmode="transparent" bgcolor="#000000" width="896" height="276" name="NewNav2" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
	}

	objectElement = '' +
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="896" height="276" id="NewNav2" align="middle">' +
		'<param name="allowScriptAccess" value="sameDomain" />' +
		'<param name="allowFullScreen" value="false" />' +
		'<param name="movie" value="../include/flash/NewNav2.swf?specialSWF='+ m_flashSettings.isSpecial + '&IsValidUser=' + m_flashSettings.isValidUser + '&fr_bannerVisible=' + m_flashSettings.bannerCookie + '" />' +
		'<param name="quality" value="best" />' +
		'<param name="bgcolor" value="#000000" />' +
		useWmode +
	'</object>';

	document.getElementById("TopPageContent").innerHTML = objectElement;
}

function MoveContent() {
	try {
		document.getElementById("MiddlePageContent").className = "content-background-middle2";
		document.getElementById("BottomPageContent").className = "content-background-bottom2";
		SetBannerCookie(0);
	} catch (errorObject) {
		alert("MoveContent");
	}
}

function HidePageContent(){
	try {
		document.getElementById("MiddlePageContent").className = "content-background-middle3";
	} catch (errorObject) {
		alert("HidePageContent");
	}
}

function ShowPageContent(){
	try {
		document.getElementById("MiddlePageContent").className = "content-background-middle2";
	} catch (errorObject) {
		alert("ShowPageContent");
	}
}

function MoveContentBack(){
	try {
		document.getElementById("MiddlePageContent").className = "content-background-middle";
		document.getElementById("BottomPageContent").className = "content-background-bottom";
		SetBannerCookie(1);
	} catch (errorObject) {
		alert("MoveContentBack");
	}
}

function SetBannerCookie(value){
	document.cookie = "frbannerVisible=" + escape(value) + ";path=/";
}

function StandardLayoutEnd(IsWdUser) {
	document.write('</div>');
	document.write('<div id="BottomPageContent" class="content-background-bottom"></div>');	
	document.write("<TABLE align='center'>");
	// ----------------------------------------------------------------------------------------------------
	document.write("<TR>");
		document.write("<TD VALIGN='bottom' ALIGN='left'>");
			// ----------------------------------------------------------------------------------------------------
			// Asterisk row
			document.write("<TABLE CELLSPACING='0px' CELLPADDING='0px' align='center' CLASS='std-text-white'>");
				document.write("<TR>");
					document.write("<TD ALIGN='center'>* Not legal for sale or use on pollution-controlled motor vehicles.</TD>");
					document.write("<TD STYLE='padding-top:3px' STYLE='padding-left:5px; padding-right:5px' ALIGN='center' >&nbsp;&middot;&nbsp;</TD>");
					document.write("<TD ALIGN='center'>** Direct replacement part.</TD>")
				document.write("</TR>");
			document.write("</TABLE>");
			// ----------------------------------------------------------------------------------------------------
			// Tech line row
			document.write("<TABLE CELLSPACING='0px' CELLPADDING='0px' align='center' CLASS='std-text-white'>");
				document.write("<TR>");
					document.write("<TD ALIGN='right'><A HREF='../home/SiteMap.asp'><font color='white'>Site Map</font></A></TD>");
					document.write("<TD STYLE='padding-top:3px' STYLE='padding-left:5px; padding-right:5px' ALIGN='center' >&nbsp;&middot;&nbsp;</TD>");
					
					document.write("<TD ALIGN='right'><A HREF='../home/privacy.asp'><font color='white'>Privacy Policy</font></A></TD>");
					document.write("<TD STYLE='padding-top:3px' STYLE='padding-left:5px; padding-right:5px' ALIGN='center' >&nbsp;&middot;&nbsp;</TD>");
					document.write("<TD ALIGN='right'><A HREF='../home/termsofuse.asp'><font color='white'>Terms Of Use</font></A></TD>");
					document.write("<TD STYLE='padding-top:3px' STYLE='padding-left:5px; padding-right:5px' ALIGN='center' >&nbsp;&middot;&nbsp;</TD>");
					document.write("<TD ALIGN='right'><A HREF='http://www.ford.com/go/privacy' TARGET='_blank'><font color='white'>Your California Privacy Rights</font></A></TD>");
					document.write("<TD STYLE='padding-top:3px' STYLE='padding-left:5px; padding-right:5px' ALIGN='center' >&nbsp;&middot;&nbsp;</TD>");
					document.write("<TD ALIGN='right'><a href='../announcements/news47.asp'><font color='white'>Warranty &amp; Use Information</font></a></TD>");
					document.write("<TD STYLE='padding-top:3px' STYLE='padding-left:5px; padding-right:5px' ALIGN='center' >&nbsp;&middot;&nbsp;</TD>");
					document.write("<TD ALIGN='left'>" + GetTechHotLinePhone(IsWdUser) + "</TD>");
				document.write("</TR>");
			document.write("</TABLE>");
			// ----------------------------------------------------------------------------------------------------
			// Copyright row
			document.write("<TABLE CELLSPACING='0px' CELLPADDING='0px' WIDTH='100%' CLASS='std-text-white'>");
				document.write("<TR><TD COLSPAN='3' ALIGN='center'>Copyright &#169; :: Information - Ford Motor Company; Application Software - Matthews Software, Inc. 1986-2009</TD></TR>");
			document.write("</TABLE>");
		document.write("</TD>");
	document.write("</TR>");
	// ----------------------------------------------------------------------------------------------------
	document.write("</TABLE>"); // End the main table.
	window.setTimeout(writeFlashContent, 100);
	//writeFlashContent();
};

function GetTechHotLinePhone(IsWdUser) {
	if(IsWdUser) {
		return "Tech Support (800) FORD788";
	} else {
		return "Tech Support (800) FORD788";
	}
};

function WriteLeavingSite() {
	/*
		C-00287
		CSF : 10-26-2005
	*/
	var strImageFileName = "../images/default/leavingsite.gif";
	var strLegalText = "Clicking on the referenced link will cause you to exit this Ford Motor Company web site.  New business terms and personal privacy policy may apply on the site to which you transfer.";
	document.write("<a href='../home/privacy.asp'><img style='border:none' src='" + strImageFileName + "' style='margin:0px 5px 0px 2px' title='" + strLegalText + "' align='middle'/></a>");
}

//--------------------------------------------------------------------------------
// LOGIN/OUT FUNCTIONS
// Initiates logging in and out.  It is event driven whenever the user clicks the
// log in/out button on the main menu.  It is essentially called from every page.
// FUNCTION NAMES:
//		logoutuser_onclick()
//--------------------------------------------------------------------------------

function logoutuser_onclick() {
	try {
		if(GetCookieNumeric("validuser") == 1) {
			window.location.href = "../include/serverscripts/logout_post.asp";
		} else {
			window.location.href = "../home/login.asp"
		}
	} catch(errorObject) {
	}
}

//--------------------------------------------------------------------------------
// COMMON FUNCTIONS
// FUNCTION NAMES:
//		SetStandardStartupFocus()
//		ScrollToTop()
//		ShowGroup()
//		removeBlanks()
//		GetCookieNumeric()
//		GetCookieString()
//		GetQueryStringNumeric()
//		MakeUpperCase()
//--------------------------------------------------------------------------------

function SetStandardStartupFocus() {
	try {
		document.getElementsByTagName("body")[0].focus();
	} catch(errorObject) {
	}
}

function ScrollToTop() {
	try {
		window.scrollTo(0, 0);
	} catch(errorObject) {
	}
}

function checkIE(){
	var appID;
	if(navigator.appName == "Microsoft Internet Explorer"){
		return true;
	}else{
		return false;
	}
}

function showPolicy(ElementID) {
	var srcElem = ElementID;
	//
	if(srcElem.rows[1].style.display == "none"){
		if(checkIE() == true){
			srcElem.rows[1].style.display = "inline";
		}else{
			srcElem.rows[1].style.display = "table-row";
		}
		srcElem.rows[0].cells[0].innerHTML = "<img language='JavaScript' border='0' width='15px' height='15px' src='../images/Home_New/Minus.gif'>";
	}else{
		srcElem.rows[1].style.display = "none";
		srcElem.rows[0].cells[0].innerHTML = "<img language='JavaScript' border='0' width='15px' height='15px' src='../images/Home_New/Plus.gif'>";
	}
}
function ShowGroup(GroupDescription, isThis) {
	var srcElem = isThis;
	//
	while (srcElem.tagName != "TABLE")
		srcElem = srcElem.parentNode;
	//
	if(srcElem.rows[1].style.display != "none") {
		srcElem.rows[1].style.display = "none";
		srcElem.rows[0].cells[0].className = 'PartsCat_itemClosed';
		srcElem.rows[0].cells[0].innerHTML = "+ <font class='fontSpace'>" + GroupDescription + "</font>"
		document.cookie = GroupDescription + "=0;path=/";
	} else {
		srcElem.rows[1].style.display = "";
		srcElem.rows[0].cells[0].className = 'PartsCat_itemOpen';
		srcElem.rows[0].cells[0].innerHTML = "-  <font class='fontSpace2'>" + GroupDescription + "</font>"
		document.cookie = GroupDescription + "=1;path=/";
	}
}

function removeBlanks(s) {
	var temp = "";
	for (var i=0; i < s.length; ++i) {
		var c = s.charAt(i);
		if (c != " ") temp += c;
	}
	return temp;
}

function GetCookieNumeric(value, defaultValue) {
	s = removeBlanks(document.cookie);
	var pairs = s.split(";");
	for (var i=0; i<pairs.length; ++i) {
		var pairSplit = pairs[i].split("=");
		if (pairSplit[0] == value) {
			if (pairSplit.length > 1) {
				return pairSplit[1];
			} else {
				return 0;
			}
		}
	}
	if (defaultValue !== undefined) {
		return defaultValue;
	} else {
		return 0;
	}
}

function GetCookieString(value) {
	s = document.cookie;
	s = removeBlanks(s);
	var pairs = s.split(";");
	for (var i=0; i<pairs.length; ++i) {
		var pairSplit = pairs[i].split("=");
		if (pairSplit[0] == value) {
			if (pairSplit.length > 1) {
				return pairSplit[1].replace(/~/g, " ");
			} else {
				return "";
			}
		}
	}
	return "";
}

function GetQueryStringNumeric(value) {
	var s = new String(document.URL);
	s = removeBlanks(s.substring(s.indexOf("?") + 1, s.length));
	var pairs = s.split("&");
	for (var i=0; i<pairs.length; ++i) {
		var pairSplit = pairs[i].split("=");
		if (pairSplit[0] == value) {
			if (pairSplit.length > 1) {
				return pairSplit[1];
			} else {
				return 0;
			}
		}
	}
	return 0;
}

function GetQueryString(value) {
	var s = new String(document.URL);
	s = removeBlanks(s.substring(s.indexOf("?") + 1, s.length));
	var pairs = s.split("&");
	for (var i=0; i<pairs.length; ++i) {
		var pairSplit = pairs[i].split("=");
		if (pairSplit[0] == value) {
			if (pairSplit.length > 1) {
				return unescape(pairSplit[1]);
			} else {
				return "";
			}
		}
	}
	return "";
}

function MakeUpperCase() {
	var strConvert = String.fromCharCode(window.event.keyCode);
	strConvert = strConvert.toUpperCase();
	window.event.keyCode = strConvert.charCodeAt(0);
}

//--------------------------------------------------------------------------------
// MAIN MENU GOTO SCRIPTS
// FUNCTION NAMES:
//		Goto_Home()
//		Goto_WtbHome()
//		Goto_MailingList()
//--------------------------------------------------------------------------------

function Goto_Home() {
	window.location.href = "../home/home.asp"
}

function Goto_WtbHome() {
	window.location.href = "../wheretobuy/main.asp"
}

function Goto_MailingList() {
	window.location.href = "../mailinglist/mailinglist.asp"
}

// --------------------------------------------------------------------------------
// FOCUS WORLD LINKS
// FUNCTION NAMES:
//		GoTo_FocusStep4()
//--------------------------------------------------------------------------------

function GoTo_FocusStep4() {
	/*
	10-12-2004 : Currently only referenced by...
		focus\xsl\main-1step.xsl

		This function called from main-1step.asp.  The drop down list values must be greater than
		or equal to zero. If the value is -1, then the drop down still says ":: SELECT ::".  If
		the value is 0, then the user selected "All".  Anything greater than zero is an actual specific
		selection.
	*/
	if ((document.getElementById("optB").checked == false) && (document.getElementById("optC").checked == false))	{
		alert('Please Select The Type of Focus You Currently Own   [Step 1]');
	}
	else {
		window.location.href = "../Focus/Main-S4.asp?vehicleid=" + GetVehicleId();
	}
}

//--------------------------------------------------------------------------------
// PART GOTO SCRIPTS
// FUNCTION NAMES:
//		Goto_CategoryForWheels()
//--------------------------------------------------------------------------------

function Goto_CategoryForWheels() {
	/*
	10-12-2004 : Currently only referenced by...
		include\templates\leftcolumn.xsl
		
		This opens the part category page specifically for wheels.  It is called
		from several places.  All categories come from the DB, however, this one
		is created artificially for the categories section of the part pages left
		column.
	*/
	window.location.href = "../parts/category.asp?catID=25&catdesc=Wheels";
}

/* --------------------------------------------------------------------------------
POSTING
-------------------------------------------------------------------------------- */

function RSExecute2() {
	var strParameters = "";
	var objAjax;

	for (var i=1; i<arguments.length; i++) {
		if(i > 1) {
			strParameters = strParameters + "&";
		}
		strParameters = strParameters + "par" + i + "=" + escape(arguments[i]);
	}
		
	if(typeof(arguments[arguments.length-1]) === "function") {
		objAjax = new Ajax.Request( arguments[0], { method:'post', parameters:strParameters, asynchronous:true, onComplete: arguments[arguments.length-1] } );
	} else {
		objAjax = new Ajax.Request( arguments[0], { method:'post', parameters:strParameters, asynchronous:false } );
		return objAjax.transport.responseText;
	}
}

try {
	Element.addMethods("select", {
		/* ----------------------------------------------------------------------------
		Add three new methods to all SELECT elements.
		---------------------------------------------------------------------------- */
		addOption: function(element, innerHTML, value){
			var oOption;

			element = $(element);
			oOption = document.createElement("OPTION");
			element.options.add(oOption);
			oOption.innerHTML = innerHTML;
			oOption.value = value;
			return element;
		},

		selectOption: function(element, value){
			var arOptions;

			element = $(element);
			arOptions = element.options;
			for(var c=0, length=arOptions.length; c<length; c++) {
				if(arOptions[c].value == value) {
					arOptions[c].selected = true;
				}
			}
			return element;
		},

		selectedRow: function(element){
			var arOptions;

			element = $(element);
			arOptions = element.options;
			for(var c=0, length=arOptions.length; c<length; c++) {
				if(arOptions[c].selected === true) {
					return c;
				}
			}
			return element;
		}
	});
} catch(errorObject) {
	//
}

function getXmlNodeValue(xmlNode, ElementName) {
	try {
		var strNodeValue = "";
	
		if(ElementName.substr(0, 1) == "@") {
			strNodeValue = xmlNode.getAttribute(ElementName.substr(1, (ElementName.length - 1)));
		} else {
			var taggedNode = xmlNode.getElementsByTagName(ElementName)[0];
			if(taggedNode === undefined) {
				taggedNode = xmlNode.getElementsByTagName(ElementName.split(":")[1])[0];
			}
	
			strNodeValue = taggedNode.text;
			if(strNodeValue === undefined) {
				strNodeValue = taggedNode.textContent;
			}
		}
	} catch(errorObject) {
		strNodeValue = null;
	}
	return strNodeValue;
}

function writeRightColumn(defaultMenuOption) {
	var htmlStr = "";
	htmlStr = htmlStr + "<td class='newRightColumn' align='right' valign='top'><div style='position:relative; left:0px;'>";
		htmlStr = htmlStr + "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='220' height='400' id='Right_Column_4' align='middle'>";
			htmlStr = htmlStr + "<param name='allowScriptAccess' value='sameDomain' />";
			htmlStr = htmlStr + "<param name='allowFullScreen' value='false' />";
			htmlStr = htmlStr + "<param name='movie' value='RC/Right_Column_5.swf?defaultMenuOption=" + defaultMenuOption + "' />";
			htmlStr = htmlStr + "<param name='quality' value='high' /><param name='wmode' value='opaque' /><param name='bgcolor' value='#ffffff' />";
			htmlStr = htmlStr + "<embed src='RC/Right_Column_5.swf?defaultMenuOption=" + defaultMenuOption + "' quality='high' wmode='opaque' bgcolor='#ffffff' width='220' height='400' name='Right_Column_4' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
		htmlStr = htmlStr + "</object>";
	htmlStr = htmlStr + "</div></td>";
	
	return htmlStr
}

function writeTextColumn(defaultTextID) {
	// TSH : 8-13-2008
	// This function writes the flash object for the "Remarks" Text box on the Mustang/HeroCard pages
	return "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='200' height='230' id='Mustang HeroCard Text Holder2' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='allowFullScreen' value='false' /><param name='movie' value='flash/Mustang HeroCard Text Holder2.swf?DefaultTxtID=" + defaultTextID + "' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='flash/Mustang HeroCard Text Holder2.swf?DefaultTxtID=" + defaultTextID + "' quality='high' bgcolor='#ffffff' width='200' height='230' name='Mustang HeroCard Text Holder2' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}

// TSH: 02-02-2009
// This function writes the Right Column on Most Pages
function writeMainRightColumn(defaultMenuOption) {
	return "<script>writeMainRightColumn2(" + defaultMenuOption + ")</script>";
}

function writeMainRightColumn2(defaultMenuOption){	// Need this function because IE7 is retarded
	var htmlStr = '';
		htmlStr = htmlStr + '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="190" height="600" id="Right_Column_Global" align="middle">';
			htmlStr = htmlStr + '<param name="allowScriptAccess" value="sameDomain" />';
			htmlStr = htmlStr + '<param name="allowFullScreen" value="false" />';
			htmlStr = htmlStr + '<param name="movie" value="../include/Flash/Right_Column_Global.swf?defaultMenuOption=' + defaultMenuOption + '" />';
			htmlStr = htmlStr + '<param name="quality" value="high" />';
			htmlStr = htmlStr + '<param name="wmode" value="transparent" />';
			htmlStr = htmlStr + '<param name="bgcolor" value="#ffffff" />';
			htmlStr = htmlStr + '<embed src="../include/Flash/Right_Column_Global.swf?defaultMenuOption=' + defaultMenuOption + '" quality="high" wmode="transparent" bgcolor="#ffffff" width="190" height="600" name="Right_Column_Global" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		htmlStr = htmlStr + '</object>';
	document.write(htmlStr);
}

function setSelectedRC(source, menuId) {
	document.cookie = "rc_" + source + "=" + menuId + ";path=/";
}

function trimString(TrimThis){
	while(TrimThis.charAt(0) == (" ")) TrimThis = TrimThis.substring(1);
	while(TrimThis.charAt(TrimThis.length - 1) == " ") TrimThis = TrimThis.substring(0, TrimThis.length - 1);
	return String(TrimThis);
}
