// JavaScript Document: LM Configurator:
/***************************************************************/
var userAgent = " " + navigator.userAgent.toLowerCase();
nn = userAgent.indexOf("mozilla") > 0;
if( userAgent.indexOf("compatible") > 0 )
    nn = false;
ie = userAgent.indexOf("msie") > 0;
mac = userAgent.indexOf("mac") > 0;
if(ie && !mac)
	{
	var vb= "";	
      	vb += '<SCR' + 'IPT LANGUAGE=VBScript\> \n';
		vb += 'Function VBFlash() \n';
        vb += 'on error resume next \n';
        vb += 'Dim C \n';
        vb += 'set C = vbNull \n';
        vb += 'Dim tver \n';
        vb += 'set tver = 0 \n';
		vb += 'Dim svr \n';
        vb += 'svr = "ShockwaveFlash.ShockwaveFlash" \n';
        vb += 'set C = CreateObject(svr) \n';
        vb += 'if (IsObject(C)) then \n';
		vb += 'Dim mVer \n';
        vb += 'Dim sVer \n';
        vb += 'Dim cVer \n';
        vb += 'cVer = C.FlashVersion() \n';
        vb += 'mVer = int(cVer / 65536) \n';
        vb += 'sVer = cVer mod 65536 \n';
        vb += 'if (sVer < 100) then sVer = "0" + CStr(sVer) \n';
        vb += 'if (sVer < 10)  then sVer = "0" + CStr(sVer) \n';
        vb += 'tver = CStr(mVer) + ".0" + CStr(sVer) \n';
        vb += 'end if \n';
        vb += 'VBFlash = tver \n';
        vb += 'End Function \n';
      	vb += 'Function VBGetFlashTE \n';
        vb += 'on error resume next \n';
        vb += 'Dim C \n';
        vb += 'set C = vbNull \n';
        vb += 'Dim svVer \n';
        vb += 'set svVer = 0 \n';
        vb += 'For i = 10 To 1 Step -1 \n';
        vb += 'Dim svr \n';
        vb += 'svr = "ShockwaveFlash.ShockwaveFlash." + CStr(i) \n';
        vb += 'set C = CreateObject(svr) \n';
        vb += 'if (IsObject(C)) then \n';
        vb += 'svVer = i \n';
        vb += 'Exit For \n';
        vb += 'end if \n';
        vb += 'Next \n';
        vb += 'VBGetFlashTE = svVer \n';
        vb += 'End Function \n';
	vb += '</SCR' + 'IPT\> \n';
	document.write(vb);
	}
    if(ie && !mac)
		{
	      	var fVer = VBFlash() || 0;
		if (fVer == 3.0008){var svVer = VBGetFlashTE();
        	if (svVer > fVer){fVer = 4.0000;}}
		else if (!fVer){fVer = VBGetFlashTE() || 0;}
		else if (fVer == 4){fVer = 4.0015;}}
    else{var fVer=0;}
      function setF()
      {arr = navigator.plugins;arrl = arr.length;
        for (var i=0; i < arrl; i++){plug = arr[i];desc   = plug.description;
          if (desc.indexOf("Shockwave Flash ") != -1){var vLoc = desc.indexOf("Shockwave Flash ");
            var vStr = desc.substring(vLoc + 16,desc.length);var sVer;var mVer;vLoc = vStr.indexOf(" r");
            if (vLoc != -1){mVer = vStr.substring(0,vLoc);sVer = vStr.substring(vLoc + 2,vStr.length);
            fnVer = parseFloat(mVer + (sVer < 100 ? "0" : "") + (sVer < 10 ? "0" : "") + sVer);}
            else{fnVer = parseFloat(vStr);}}}}
var fnVer = 0;
setF();
var myFlash;
if(!fVer || fVer==0){myFlash=fnVer;}
else{myFlash=fVer;}
function hasFlash(bVer){if(myFlash<bVer){return false;}else{return true;}}
flashEnabled = hasFlash(7);
/****************************************************************/

var anthemState = 0;


function ClearTextBox(oTextBox, sFlag) {
    /***********************************************************
	Version 1.0
	Date: 05-31-06
	Description: Clears any text box.
	************************************************************/	
    if(sFlag == "zipcode") {
        if((oTextBox.value == "Enter Zipcode") || (oTextBox.value == "C. P.")) { 
            var s;
            s = cookieGet('zipcode');
            if (s == null) s = '';
            oTextBox.value = s; 
        }
    }
    if(sFlag == "search") {
        if(oTextBox.value == "City, State or Zip") {
            var s;
            s = cookieGet('zipcode');
            if (s == null) s = '';
            oTextBox.value = s; 
        }
    }
    if(sFlag == "footer") {
        if((oTextBox.value == "Search") || (oTextBox.value == "Buscar en el sitio")) {
            oTextBox.value = "";
        }
    }
}

function SetTextBox(oTextBox, sFlag) {
    /***********************************************************
	Version 1.0
	Date: 05-31-06
	Description: Resets any textbox.
	************************************************************/	
    if(sFlag == "zipcode") {
        if(oTextBox.value == "") { 
            oTextBox.value = "C. P."; 
        }
    }
    if(sFlag == "search") {
        if(oTextBox.value == "") {
            oTextBox.value = "Ciudad, estado o c\363digo postal";
        }
    }
    if(sFlag == "footer") {
        if(oTextBox.value == "") {
            oTextBox.value = "Buscar en el sitio";
        }
    }
}
function rollMe(imgEle,parentEle) {
           if (parentEle)
                imgEle = parentEle.getElementsByTagName("img")[0];
            
           var src = imgEle.src;
           try {
	            imgEle.src = (/_on/.test(src)) ? src.replace('_on', '_off') : src.replace('_off', '_on');
	       } catch(e) {
	            var src = imgEle.innerHTML;
	            imgEle.innerHTML = (/_on/.test(src)) ? src.replace('_on', '_off') : src.replace('_off', '_on');
	       }
        
            
        }   
          
        

function DisplayNotable() 
{  
	var scrollY = 0;
	if (window.pageYOffset) 						scrollY = window.pageYOffset;
	else if (document.documentElement.scrollTop)	scrollY = document.documentElement.scrollTop;
	if (scrollY > 30) scrollY -= 30;
    document.getElementById("notable").style.marginTop = scrollY + 'px';

    document.getElementById("notablebg").style.height = (document.body.offsetHeight + 10) + "px";
    document.getElementById("notablebg").style.display = 'block';
    document.getElementById("notablebg").style.visibility = 'visible';
    document.getElementById("nota_continue_buttons").innerHTML = document.getElementById("notablebuffer").innerHTML;
    document.getElementById("notable").style.display = 'block';
    document.getElementById("notable").style.visibility = 'visible';
}   


function popHelp() {
	/***********************************************************
	Version 1.0
	Date: 05-28-05
	Description: Pops the help window.
	************************************************************/
	var winWidth = 475;
	var winHeight = 325;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open('http://espanol.lincoln.com/configurator/help.aspx','HelpWin','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=no,resizable=yes');
}
	

function popWhyZip() {
	/***********************************************************
	Version 1.0
	Date: 05-28-05
	Description: Pops the why we need your zip window.
	************************************************************/
	var winWidth = 300;
	var winHeight = 250;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open('http://espanol.lincoln.com/configurator/whyZipCode.aspx','WhyZip','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=no,resizable=yes');
}

function popPrivacy(sBrand) {
    /***********************************************************
	Version 1.0
	Date: 05-28-05
	Description: Pops the lincoln mercury privacy policy.
	************************************************************/
	var winWidth = 662;
	var winHeight = 625;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	var sURL = "http://espanol.lincoln.com/dlincolnvehicles/privacy.asp"
	window.open(sURL,'PopPrivacy','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=yes,resizable=no');
}

function popPayEst(sBrand, sZip, sModelYear, sModelBrand, sModelName, sModelPrice, sModelCode) {
    /***********************************************************
	Version 1.0
	Date: 07-10-06
	Description: Pops the Ford Credit Payment Estimator window.
	************************************************************/
	var sBrandCode = '';
	var winWidth = 800;
	var winHeight = 500;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	if(sBrand=='Lincoln') { 
	    sBrandCode='LV';
	} else {    
	    sBrandCode='MV';
	}
	window.open('https://www.onlinevehiclefinancing.com/aaui?ATD_SERVLET_ACTION=PE&ATD_SERVLET_PAGE_CLASS=AAExternal&SourceOfData=' + sBrandCode + '&DealerFullFax=&paFullZipCode=' + sZip + '&ModelKey=' + sModelYear + '|' + sModelBrand + '|' + sModelCode + '&ModelName=' + sModelName + '&ModelPrice=' + sModelPrice + '&NewUsedIndicator=N','PayEst','height='+winHeight+',width='+winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=yes,resizable=yes');
}

function popTradeIn(sBrand) {
     /***********************************************************
	Version 1.0
	Date: 07-12-06
	Description: Pops the Ford Credit Payment Estimator window.
	************************************************************/
	var winWidth = 540;
	var winHeight = 520;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	var sDealerId = '';
	if(sBrand == 'lincoln') {
	    sDealerId = '3052001';
	} else {
	    sDealerId = '3053001';
	}
	try {
        window.open('http://www.intelliprice.com/intellipricedealer/start.htm?dealerid=' + sDealerId,'PopIntelliprice','height='+winHeight+',width='+winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=yes,resizable=yes');
    } catch(e) { }
}
	
function popTellMeMore() {
	/***********************************************************
	Version 1.0
	Date: 05-28-05
	Description: Pops the tell me more window.
	************************************************************/
	var winWidth = 600;
	var winHeight = 400;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open('http://espanol.lincoln.com/configurator/more.aspx','TellMore','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=no,resizable=yes');
}
	
function popLiveChat(brandIdentifier) {
	/***********************************************************
	Version 1.0
	Date: 05-28-05
	Description: Pops the Live Chat window.
	************************************************************/
	var winWidth = 472;
	var winHeight = 420;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	s_prop5 = brandIdentifier + ': config: chatnow';
	sendAnalyticsEvent('');
	window.open('http://server.iad.liveperson.net/hc/LPford_ford3/?cmd=file&file=visitorWantsToChat&site=LPford_ford3&offlineURL=http://www.lincolnmercury.com/livechat/chatroom_closed.asp&referrer='+document.location,'chatLPford_ford3','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=no,resizable=no');
}

function popMSRPHelp() {
	/***********************************************************
	Version 1.0
	Date: 05-28-05
	Description: Pops the MSRP Help window.
	************************************************************/
	var winWidth = 500;
	var winHeight = 300;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open('http://espanol.lincoln.com/configurator/msrp.aspx','MSRPHelp','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=no,resizable=yes');
}

function popWindowSticker(sVIN, sOrgId) {
    /***********************************************************
	Version 1.0
	Date: 07-06-06
	Description: Pops the new 'View Window Sticker' window.
	************************************************************/
    var winWidth = 690;
	var winHeight = 500;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open('http://fordlabels.webview.biz/webviewhybrid/WindowSticker.aspx?vin='+sVIN+'&ref=VL&localeid=1033&orgid='+sOrgId,'WindowSticker','menubar=yes,toolbar=no,location=no,scrollbars=yes,directories=no,resizable=yes,height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft);
    
}

function popCompareModels() {
    /***********************************************************
	Version 1.0
	Date: 07-06-06
	Description: Pops the new 'Help Me Choose' window.
	************************************************************/
    var winWidth = 700;
	var winHeight = 450;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open('http://espanol.lincoln.com/configurator/CompareModel.aspx','HelpMeChoose','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=yes,resizable=yes');
}

function popDirections(sMap) {
    /***********************************************************
	Version 1.0
	Date: 05-28-05
	Description: Pops the Dealer Driving Directions window.
	************************************************************/
    var winWidth = 720;
	var winHeight = 520;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open(sMap,'MMMap','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=yes,resizable=yes');
}

function testLocateCompare(sPaCode) {
     /***********************************************************
	Version 1.0
	Date: 07-24-06
	Description: Tests inventory compare checkboxes.
	************************************************************/
	var oElems = document.getElementsByName("chkCompare");
	var iCount = 0;
	var sVIN = "";
	
	for (var intIndex = 0; intIndex < oElems.length; intIndex++) {
		if (eval("oElems[" + intIndex  + "].checked") == true) {
		    iCount++
			sVIN = sVIN + "&vin" + iCount + "=" + oElems[intIndex].value;
			if (iCount == 2) {
                var sParam = "?pacode=" + sPaCode + sVIN
                popLocateCompare(sParam);
                clearLocateCompare();
            }
		}
	}
}

function popLocateCompare(sCompareParameters) {
    /***********************************************************
	Version 1.0
	Date: 07-24-06
	Description: Pops the new Locate Compare window.
	************************************************************/
	var winWidth = 740;
	var winHeight = 450;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open('http://espanol.lincoln.com/configurator/InventorySearchCompare.aspx' + sCompareParameters,'LocateCompare','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=yes,resizable=yes');
}

function clearLocateCompare() {
    /***********************************************************
	Version 1.0
	Date: 07-26-06
	Description: Clears the Inventory checkboxes.
	************************************************************/
    var oElems = document.getElementsByName("chkCompare");
    for (var intIndex = 0; intIndex < oElems.length; intIndex++) {
        oElems[intIndex].checked = false;
    }
}

function popPrint() {
	/***********************************************************
	Version 1.0
	Date: 05-28-05
	Description: Pops print window.
	************************************************************/
	var winWidth = 760;
	var winHeight = 450;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	window.open('http://espanol.lincoln.com/configurator/printSummary.aspx','PrintSummary','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=yes,resizable=yes');
}
	
function ValidateForm(theForm) {
	/**************************************************************************************
	Version 1.0
	Date: 05-28-05
	Description: Validates any form
	**************************************************************************************/
	var objElements = theForm.elements;
	var strMessage = "<b>Corrige los siguientes errores identificados en rojo:</b>";
	
	for(var i=0; i<objElements.length; i++) {
		if((objElements[i].className == "validate") && (objElements[i].value == "")) {
			strMessage = strMessage + "<br /> - " + objElements[i].alt;
		}
	}
	if(strMessage == "<b>Please correct the errors identified in red below:</b>") {
		document.getElementById("submit_command").style.visibility = "hidden";
		document.getElementById("contact_submit").innerHTML = "<h4>Por favor, ten paciencia mientras procesamos tu solicitud...</h4>";
		return true;
	} else {
		document.getElementById("error").style.visibility = "visible";
		document.getElementById("error").innerHTML = strMessage;
		return false;
	}
}


/*
    ========================================================================    
    IMAGE RESIZE ANIMATION CODE
    L. Felarca v1.0
*/

    // these variables are dependent on vehicle layout type
    var INTWIDTHWIDE;
    var INTWIDTHNARROW;
    var NUMSTEPS;
    var STEPSIZE;
    
    var FPS = 45;
    var FPSINTERVAL = 1000 / FPS;

    var isSmall = false;
    var isAnimating = false;

    var timer;
    var stepNum = 0 ;

    function ReplaceImageExterior(imgcontrol, replaceimage, imgsmallcontrol, replaceimagesmall, txtcontrol, replacetext) {
        if (isSmall) 
        {
            document.getElementById("exterior_piccy").src = replaceimagesmall;
        }
        else
        {
            document.getElementById("exterior_piccy").src = replaceimage;            
        }

        // imgcontrol.value = replaceimage
        txtcontrol.innerHTML = replacetext
    }
    
    function ReplaceImageInterior(imgcontrol, replaceimage, txtcontrol, replacetext) {

        document.getElementById("interior_piccy").src = replaceimage;

        // imgcontrol.value = replaceimage
        txtcontrol.innerHTML = replacetext
    }


    function PreLoadImage(imageurl) {
        //img = new Image;
        //img.src = imageurl
    }

    function navInit() {

        if ( document.getElementById("brand").innerHTML == "Mercury" )
        {
            // mercury
            INTWIDTHWIDE = 372;
            INTWIDTHNARROW = 168;
            NUMSTEPS = 25;
        }
        else
        {
            // lincoln
            INTWIDTHWIDE = 333;     
            INTWIDTHNARROW = 166;   
            NUMSTEPS = 20;          
        }
        STEPSIZE = (INTWIDTHWIDE - INTWIDTHNARROW) / NUMSTEPS;        

	    finishAnim();

        // set images	    
        
        setImages();
       	    
	    // set interior pic to narrow
	    document.getElementById("interior_pic").style.left = (INTWIDTHNARROW - INTWIDTHWIDE) + "px";
    }
    
    function setImages() {
        if(isSmall == false) {
            document.getElementById("exterior_piccy").src = document.getElementById("ctl00_ContentPlaceHolder1_ViewLargeImageExterior").value;
        } else {
            document.getElementById("exterior_piccy").src = document.getElementById("ctl00_ContentPlaceHolder1_ViewSmallImageExterior").value;
        }
        document.getElementById("interior_piccy").src = document.getElementById("ctl00_ContentPlaceHolder1_ViewLargeImageInterior").value
    }
    

    function startAnim( dummyParam, targetState ) {

	    if (isAnimating) { return; }

	    if (targetState==isSmall ) { return; } /* shouldn't happen */
    	
	    isSmall = targetState;
	    isAnimating = true;			
	    timer = setInterval("animTick()", FPSINTERVAL);
	    stepNum = 0;
    	
    }


    function animTick() {

	    stepNum++;
    	
	    var direction, divWidth, imgOffset;
    	
	    if (isSmall) { 
		    // expand
		    divWidth = INTWIDTHNARROW + Math.floor(stepNum * STEPSIZE);
		    imgOffset = Math.floor( (NUMSTEPS - stepNum) * -STEPSIZE );
	    }
	    else { 
		    // shrink
		    divWidth = INTWIDTHWIDE - Math.floor(stepNum * STEPSIZE); 
		    imgOffset = Math.floor(stepNum * -STEPSIZE); 
		    imgOffset++; // (minor alignmnet kludge)
	    }
    	
	    document.getElementById("interior_container").style.width = divWidth + "px"; 
	    document.getElementById("interior_pic").style.left = imgOffset + "px"; 
    	
	    if (stepNum >= NUMSTEPS) { finishAnim(); }
    }


    function finishAnim() {

	    clearInterval(timer);
	    isAnimating = false;
    	
	    // exchange buttons & swap car image
	    if (isSmall) {
		    document.getElementById("btn_makelarge").style.display = "none";
		    document.getElementById("btn_makesmall").style.display = "block";

            document.getElementById("exterior_piccy").src = document.getElementById("ctl00_ContentPlaceHolder1_ViewSmallImageExterior").value;

	    }
	    else {
		    document.getElementById("btn_makelarge").style.display = "block";
		    document.getElementById("btn_makesmall").style.display = "none";
            document.getElementById("exterior_piccy").src = document.getElementById("ctl00_ContentPlaceHolder1_ViewLargeImageExterior").value;

		    document.getElementById("interior_pic").style.left = (Math.floor(stepNum * -STEPSIZE) + 0) + "px";  // minor alignment kludge
	    }
	    
	    // alert( document.getElementById("interior_pic").style.left );
    }

/*
    IMAGE RESIZE ANIMATION CODE -- END
    ========================================================================
*/

    function openAIC() {
        window.open('http://www.autosite.com/');
    }


function popDetailedSpecs(Model)
{
	//Version 1.0, L.Felarca
	//Date: 08-14-2006
	//Description: Popup Detailed Specs page (print version) from brand site using brandsite js fn

    var u = "";
    var sModel = Model.toLowerCase();
    
    if (document.getElementById("brand").innerHTML == "Lincoln")
    {
        u += "http://espanol.lincoln.com/" + sModel + "/models_print.asp";
        popWindow(u, 'print_specs', 530, 500, 1, 1, 1, 0, 0, 0); 
    }
    else
    {
        u += "http://espanol.lincoln.com/" + sModel + "/specs_print.asp";
        popWindow(u,'print_specs','650','650','1','','','','','');
    }
}


var timeoutId;
// var _startTime;
// var _endTime;
// var _processingTime;

function anthem_PreCallBack()
{
   // _startTime = '';
   // _endTime = ''
   // _processingTime = ''
    
    
   // _startTime = new Date();
   
    // starts a 1-second delay
    anthemState = 1;
    timeoutId = setTimeout( "anthem_PreCallBackShow()", 1000 );
    
}

function anthem_PreCallBackShow() {

    if (anthemState < 1) return;

    anthemState = 2;

    var winWidth = 200;
    var winHeight = 50;

    var winLeft = (780/2) - (winWidth / 2);
    var winTop = 280; // (document.height - winHeight) / 2;

	var loading = document.getElementById("loading");
	
	loading.style.top = winTop + "px";
	loading.style.left = winLeft + "px";
	loading.style.height = winHeight + "px";
	loading.style.width = winWidth + "px";
    loading.style.visibility = 'visible';

}


function anthem_PostCallBack() {
   // _endTime = new Date();
    
   // _processingTime = _endTime - _startTime;
    
   // document.getElementById("callbackTime").innerHTML = 'this callback took ' + _processingTime + ' milliseconds to process';
    
    if (anthemState < 2) 
    {
        anthemState = 0;
        clearTimeout(timeoutId);
    }

    document.getElementById("loading").style.visibility = 'hidden';
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+";domain=;path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}