﻿/***************************************************************/
// JavaScript Document: Flashpoint Inventory Search
/***************************************************************/
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 == "Zip Code")) { 
            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 == "Search Site")) {
            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 = "Zip Code"; 
        }
    }
    if(sFlag == "search") {
        if(oTextBox.value == "") {
            oTextBox.value = "City, State or Zip";
        }
    }
    if(sFlag == "footer") {
        if(oTextBox.value == "") {
            oTextBox.value = "Search Site";
        }
    }
}

   
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('whyZipCode.aspx','WhyZip','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=no,resizable=yes');
}
	
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('more.aspx','TellMore','height='+winHeight+',width='+ winWidth+',top='+winTop+',left='+winLeft+',directories=0,toolbar=0,scrollbars=no,resizable=yes');
}
	
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('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 = 600;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	if (sOrgId == '') {
	    sOrgId = '8229';
	}
	window.open('http://services.forddirect.fordvehicles.com/inventory/WindowSticker.pdf?vin='+ sVIN, '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('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('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('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>Please correct the errors identified in red below:</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>Please be patient while we process your request...</h4>";
		return true;
	} else {
		document.getElementById("error").style.visibility = "visible";
		document.getElementById("error").innerHTML = strMessage;
		return false;
	}
}


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';
}
