﻿//
// JScript file use in the call-back data from the incentive web service
// The scripts below manipulate the classes of the rendered html.
// this file will work as long as incentive.css is included.

/***********************************************************/
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;

    try {
        document.getElementById("loading").style.visibility = "visible";
    } catch (e) { }

}
function Anthem_PostCallBack() {
    _endTime = new Date();
    _processingTime = _endTime - _startTime;

    if (anthemState < 2) {
        anthemState = 0;
        clearTimeout(timeoutId);
    }
    try {
        document.getElementById("loading").style.visibility = "hidden";
    } catch (e) { }
}

//
function ShowOffer(sOfferID) {
	var oDiv = document.getElementById(sOfferID);
	var oElements = document.getElementsByTagName("div");	
    // Walk page div's and hide open campaigns
    for(var i = 0; i < oElements.length; i++) {
        switch (oElements[i].className) {
            case "hide_offer" :
	            oElements[i].className = "hide_offer";
	            break;
            case "show_offer" :
	            oElements[i].className = "hide_offer";
	            break;
        }
    }
    // Show user selected campaign
    oDiv.className = "show_offer";
}

function HighlightOffer(sOfferID) {
    var oTab = document.getElementById('tab_'+sOfferID);
	var oElements = document.getElementsByTagName("a");
	//alert("oElements = " + oElements.length);
	//alert("OfferId = " + sOfferID);
    for(var i = 0; i < oElements.length; i++) {
        switch (oElements[i].className) {
            case "tab_inactive" :
	            oElements[i].className = "tab_inactive";
	            break;
            case "tab_active" :
	            oElements[i].className = "tab_inactive";
	            break;
        }
    }
    // Show user selected campaign
    oTab.className = "tab_active";

}

function closeMe() {
    try {
        document.forms["GetSweepstakes"].cboVehicle.style.display = "block";
    } catch(e) { }
    document.getElementById("shadow-container").style.display = "none";
    document.getElementById("container").innerHTML = "";
}

function DrawIncentiveAsset(sAssetPath, sAssetName, sAssetHeight, sAssetWidth) {
	if(sAssetName.indexOf(".x-shockwave-flash") > 0) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" height="' + sAssetHeight + '" width="' + sAssetWidth + '">');
		document.write('	<param name="allowScriptAccess" value="sameDomain" />');
		document.write('	<param name="movie" value="'+sAssetPath+'">');
		document.write('	<param name="quality" value="high">');
		document.write('	<param name="play" value="true">');
		document.write('	<param name="id" value="flashmovie">');
		document.write('	<param name="wmode" value="transparent">' );
		document.write('	<param name="bgcolor" value="#ffffff">');
		document.write('	<embed bgcolor="#ffffff" height="' + sAssetHeight + '" pluginspage="http://www.macromedia.com/go/getflashplayer" src="' + sAssetPath + '" type="application/x-shockwave-flash" width="' + sAssetWidth + '" allowScriptAccess="sameDomain" quality="high" wmode="transparent" play="true">');
		document.write('</object>');
	} else {
		document.write('<img src="' + sAssetPath + '" width="' + sAssetWidth + '" height="' + sAssetHeight + '" alt="' + sAssetName +'" border="0"/>');
	}
}



function SubmitToIncentives(sLandingPage) {
    /*********************************************************
    Version: 1.0
    Date: 12-10-2006
    Desc: Function used for submiting LMDA region incentives
    ***********************************************************/
    
    /**************************************
    Begin: Async call to incentives
    **************************************/
    async.get('transform.aspx?sMake=' + sMake + '&sModel=' + sVehicle + '&sModelYear=' + sYear + '&sZipcode=' + sZipcode + '&sReferringSite=' + sGlobalLandingPage + '&eProgramType=1&iNumOfOffers=-1&eOfferType=0');
    /**************************************
    End: Async call to incentives      
    **************************************/
}

