/* This first inline block is to replace browser hawk with client-side browser detection.*/
var BROWSER_ISMAC = (navigator.appVersion.indexOf("Windows") == -1);
var BROWSER_ISPC = (navigator.appVersion.indexOf("Windows") != -1);
var PLATFORMNAME = "";
var BROWSER_NAME = navigator.appName.toLowerCase();
var IS_IE6 = (navigator.appVersion.indexOf("MSIE 6") != -1);
var IS_IE7 = (navigator.appVersion.indexOf("MSIE 7") != -1);
var gIVI_section = "";
var isIE=navigator.appName=="Microsoft Internet Explorer";

var urlParts=document.location.toString().split("/");
var creativeVersion=urlParts[3];
var testingVersion=urlParts[4];
var getVars=getUrlVars();

if(BROWSER_NAME == "microsoft internet explorer"){
	BROWSER_NAME = "explorer";
}

if(BROWSER_ISPC){
	PLATFORMNAME = "pc";
}else if(BROWSER_ISMAC){
	PLATFORMNAME = "mac";
}else{
	PLATFORMNAME = "unix";
}

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=750,height=555,location=yes,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		n.focus();
	}
}

function openWin( html, name, wval, hval, scroll) {
	var features;
	
	if (wval != '' && hval != '' && wval != undefined && hval != undefined)  {
		features = 'width='+wval+',height='+hval+',toolbar=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no';
	} else {
		features = 'width=940,height=620,toolbar=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no';
	}
	
	var nW = window.open(html, name, features);
	
}

function openFullScreenWin( html, name, scroll) {
	var features;
	features = 'width='+ screen.width +',height='+ screen.height + ',top=0,left=0,toolbar=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no';
	var n=window.open( html, name, features);
}

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);
	}
	return newWin;
}

function TurnOnImage(oE){
	var img = eval(oE + "On.src");
	document [oE].src = img;
}

function TurnOffImage(oE){
	var img = eval(oE + "Off.src");
	document [oE].src = img;
}

function roll(ele) {
	var img = ele.getElementsByTagName("img")[0];
	var src = img.src;
	img.src = (/_on/.test(src)) ? src.replace('_on', '_off') : src.replace('_off', '_on');
}

function rollit(ele){
	var obj = document.getElementById(ele);
	var src = obj.getAttribute("src");
	obj.setAttribute("src",(/_on/.test(src)) ? src.replace('_on', '_off') : src.replace('_off', '_on'));
}

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 fGetColorPopupPage(loc, name) {

	if(navigator.appName != "Microsoft Internet Explorer") {
		iWindowLeft = window.screenX
		iWindowTop = window.screenY
	} else {
		iWindowLeft =window.screenLeft
		iWindowTop =window.screenTop
	}

 	mytop =iWindowTop 
	myleft =iWindowLeft + 140

	window_options = "'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,copyhistory=no,height=318,width=714,top=" + mytop +",left=" +myleft + ",screenX=100,screenY=100'";
	var sWin = window.open(loc,name,window_options);

	sWin.focus();
}

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.") ) {
		document.location = sURL;
	}
}

/* WRAPPER FUNCTIONS - deprecated, but used by 3rd party templates */

function showObject(name){
	if (document.getElementById(name)) document.getElementById(name).style.display="block";
}

function hideObject(name){
	if (document.getElementById(name)) document.getElementById(name).style.display="none";
}



function stripHTML(oldString) {

  return oldString.replace(/<&#91;^>&#93;*>|\n|\t/g, "");
  
}

/********************************************************
	Generic layer visibility function
	layerName -- identifies the div layer being affected
********************************************************/

// show layer
function divShow( divName ){
	document.getElementById( divName ).style.display='block';
}

// hide layer
function divHide( divName ){
	document.getElementById( divName ).style.display='none';
}

// show layer visible
function divVisible( divName ){
	document.getElementById( divName ).style.visibility='visible';
}

// hide layer hidden
function divHidden( divName ){
	document.getElementById( divName ).style.visibility='hidden';
}

function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}

	return vars;
}

//Usage: onmouseout='if (isMouseLeaveOrEnter(event, this)) YourActionHere();' onmouseover='if (isMouseLeaveOrEnter(event, this)) YourOtherActionHere();'
function isMouseInOrOut(e, handler) {
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget :
	e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}

function findPos(obj) {
	var curleft = curtop = 0;
	while( obj != null)
	{
		curleft += obj.offsetLeft ;
		curtop += obj.offsetTop ;
		obj = obj.offsetParent ;
	}
	
	return [curleft,curtop];
}

function findPos_n(oObj, bUseParent){
    if(typeof(oObj) == "string") oObj = document.getElementById(oObj)
    var b = document.getElementsByTagName("body")[0]
    var sl = document.documentElement.scrollLeft
    var st = document.documentElement.scrollTop
    if(document.getBoxObjectFor){
        var r = document.getBoxObjectFor(oObj)
        var rect = {l:r.x,t:r.y,r:r.width+r.x,b:r.y+r.height}
    } else{
        if(oObj.getBoundingClientRect){
	        var r = oObj.getBoundingClientRect()
	        var rect = {l:r.left-2+sl,t:r.top-2+st,r:r.right-2+sl,b:r.bottom-2+st}
        } else {
	        var l = oObj.offsetLeft
	        var t = oObj.offsetTop
	        var rect = {l:l,t:t,r:l+oObj.offsetWidth,b:t+oObj.offsetHeight}
	        var p = oObj.offsetParent
	        if(bUseParent) p = oObj.parentNode
	        while(p){
		        l = p.offsetLeft
		        t = p.offsetTop
		        if(l){
		        	rect.l += l
		        	rect.r += l
		        }
		        if(t){
		        	rect.t += t
		        	rect.b += t
		        }
		        if(bUseParent){
		        	p = p.parentNode
		        } else {
		        	p = p.offsetParent
		        } 
	        }
        }
    }
    return rect
}

function findMousePos(e) {
	var posx = 0;var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return [posx, posy];
}

function rollClass(ele) {
	ele.className = (/_on/.test(ele.className)) ? ele.className.replace('_on', '_off') : ele.className.replace('_off', '_on');
}

function getPositionLeft(This){
	var el = This;var pL = 0;
	while(el){pL+=el.offsetLeft;el=el.offsetParent;}
	return pL
}
function getPositionTop(This){
	var el = This;var pT = 0;
	while(el){pT+=el.offsetTop;el=el.offsetParent;}
	return pT
}

function isInBox(sName,evt) {
	var oBox = document.getElementById(sName);
	
	var boxCoord = findPos(oBox);
	var mouseCoord = findMousePos(evt);

	if ((mouseCoord[1]>=boxCoord[1] || mouseCoord[1]<=(boxCoord[1] + oBox.offsetHight)) 
		&& (mouseCoord[0]>=boxCoord[0] || mouseCoord[0]<=(boxCoord[0] + oBox.offsetWidth)) )
	{	return true; }
	else
	{	return false; }
		
	
}

 
 function showDebug(sShow) {
	if (document.getElementById("status"))
		document.getElementById("status").innerHTML = sShow;
 }
 
 
function hover(el) {
	return;
	if (el.src.indexOf('off')==-1){
		el.src=el.src.replace('on','off');
	}else{
		el.src=el.src.replace('off','on');
	}
}

var inishScript = {
	run:[
	
	],
	inish:function(oSelf){
		for(var i = 0; i<oSelf.run.length; i++) oSelf.run[i].inish()
		oSelf.run = 0
	}
}

