﻿// JScript File
var zip;
var territory;
var GeoState;
var GlobalAllianceData;
var GlobalValidationResult;
var GlobalAgentID = "";
var AWSzipCodeChanged = false;
var GlobalLicensedStates;
var IsAgentLicensed = true;
var GlobalAgentName="";
var GlobalZip="00000";
var invalidZipFlag = false;
var urlArray = [null,null];
var zipCodeLiterals;
var pageName;
var validZip;

/****************DART Tag javascript Iteration 4 *************************/
function ProcessZipEntry(txtValue)
{ 
    var charCount = txtValue.value.length;
    
    if (charCount == 5){ 
        invalidZipFlag = false;
        if (zip != txtValue.value){
          //hide the AWS message
            $get('AWSZipCodeChangedMessage').style.display = "none";
         //User entered a five number zip code and it is not identical to the previous entry.
         zip = txtValue.value;
         //if user comes from AWS, set flag that zipcode changed.
         if (GlobalAgentID != "")
         {
            AWSzipCodeChanged = true;         
         }
        /*START FOR USD #6911089,6976742,6964667 FIX*/
        
        //Set the value to 0 if the zip code is changed
        self.parent.changedZipCode = 0;
        
        /*END FOR USD #6911089,6976742,6964667 FIX*/ 
        
        //Call GeoService to get state code for this zip.
        CallGeoService(zip);
        }
    }
}

function buildZipCodeChangedMessage(link)
{
    //sets up the zipcode
    $get("AWSZipCode").innerHTML = zip;
    
    //sets up the Agent Name
    $get("AWSAgentName").innerHTML = GlobalAgentName;
    
    //sets up the state string
    var GlobalLicensedStateArray = new Array();
    
    GlobalLicensedStateArray = GlobalLicensedStates.split(/,/);

    var length = GlobalLicensedStateArray.length;

    if (length > 2) //more than two states
    {
        var formattedStatesArray = new Array();

        var dupeStateFlag = new Boolean();
        dupeStateFlag = false;
        
        //prime the loop
        newState = GlobalLicensedStateArray.pop();
        formattedStatesArray.push(newState);
        length = length-1;
        //loop through remaining states if they are not duplicate then add to the array
        for (x=length; x >= 1; x--)
        {
            newState = GlobalLicensedStateArray.pop();
            for (y=formattedStatesArray.length; y >= 0; y--)
            {
                if (newState == formattedStatesArray[y])
                {    
                    dupeStateFlag = true;
                    break;
                }
            }
            if (dupeStateFlag == false) 
                formattedStatesArray.push(newState);
                
            dupeStateFlag = false;

        }

        var lastState = formattedStatesArray.pop();

        var stateString = formattedStatesArray.join(", ");
    
        $get("AWSAgentStates").innerHTML = stateString + " and " + lastState;        
    }
    else if (length == 2)//two states
    {
        var firstState = GlobalLicensedStateArray.pop();
        var secondState = GlobalLicensedStateArray.pop();
        
        if (firstState == secondState)
            $get("AWSAgentStates").innerHTML = firstState;
        else
            $get("AWSAgentStates").innerHTML = firstState + " and " + secondState;
    }
    else //one state
    {
        $get("AWSAgentStates").innerHTML = GlobalLicensedStateArray.pop();
    }
   
    //sets up the link
    $get("agentLocatorLink").href = link + "?ZipCode=" + zip;
}

function buildALRlink(link)
{ 
    //sets up the link
    $get("AlocatorLink").href = link + "?ZipCode=" + zip;

}

function CallGeoService(strZipCode)
{
    zip = strZipCode;
    //PageMethods.GetGeoZip(zip, ProcessGeoServiceResponse, processGeoAllianceError);
    PageMethods.GetGeoZip(zip, ProcessGeoServiceResponse, processError);
}

function ParseAgentQuery(query)
{
    //parse through query and set results into array delimited by '&'
    //This function is found in UIHelper.js
    //ParseAWSQueryString(query);
    //Once querystring is parsed and set to an object of key/value pair array,
    //look through parsed array to find licensed states and set results to Global variable
    GlobalLicensedStates = GetParamFromAgentQuerystring('LState');
    
    verifyAgentLicenseState();  
    
    GlobalAgentName = GetParamFromAgentQuerystring('AgentName');
    
    PageMethods.GetAgentLocatorLink(buildZipCodeChangedMessage, processError);
}

function CheckForAgentQuery()
{
     //get query string from session and return results to parseAgentQuery()
     //1st param is name of function that will get called upon sucess of PageMethod
     //the data returned from the PageMethod will get passed into the "success function" as a param.
    PageMethods.GetAgentQuery(ParseAgentQuery, processError);
   
}

function verifyAgentLicenseState()
{
    //if states are avail, verify that state of current zipcode is found in license state list.
    if(GlobalLicensedStates != 'false')
    {
        //parse through license states and compare with state returned from GEO service
        //3rd param is function name called on success of page method.
        PageMethods.IsAgentLicensed(GeoState, GlobalLicensedStates, SetIsAgentLicensed, processError);
            
        //display the message
       
    }
    else //compare to state of AWS page.
    {
        var awsState = GetParamFromAgentQuerystring('State');
        if (awsState != false)
        {
            if (awsState == GeoState)
            {
                SetIsAgentLicensed(true);
            }
            else
            {
                SetIsAgentLicensed(false);
            }
        }
    }
}

function SetIsAgentLicensed(flag)
{
    IsAgentLicensed = flag;
    //user entered zip code to an unlicensed state
    if (flag == false && invalidZipFlag == false)
    {
     $get('AWSZipCodeChangedMessage').style.display = "";
     self.parent.changedZipCode = zip;
    }
    //user entered a zip code to a licensed state.
    else
    {
        /*START FOR USD #6911089,6976742,6964667 FIX*/
        
        //self.parent.changedZipCode = null;
        self.parent.changedZipCode = 0;
        
        /*END FOR USD #6911089,6976742,6964667 FIX*/ 

    }
}


//if we came from AWS and changed zip code to a state that the agent is not licensed in
//we need to ensure that the stream type stays out of AWS from this point on
//SetIsAgentLicensed(flag) changes the value of changedZipCode
//
//this function is added to select button as an eventlistener in addTerrSelectOnClickEvent()
//it resets the AWSzipCodeChanged to false and globalAgentID to empty string
//resetting the AWSzipCodeChanged prevents AWS functionality in ZipCodeModal.js 
//from happening on subsequent calls to the entry page
function setStreamType()
{
    if (self.parent.changedZipCode != null)
    {
        AWSzipCodeChanged = false;
        GlobalAgentID = "";
        //$get('Entry1800Message').style.display = "block";   
    }
}

function GetParamFromAgentQuerystring(key)
{
    //Function found in UIHelper.js
    var param = entryQueryString(key);
    if (param != null)
    {
       return param;
    }
    else
    {
        return null;
    }
}


function ProcessGeoServiceResponse(ValidationResult)
{
    GeoState = ValidationResult.sGeoState;
    GlobalValidationResult = ValidationResult.sStateInfo;
    validZip = ValidationResult.validZip;    
    
    //Check flag for whether zipcode coming from AWS was changed.
    //if user doesn't come from AWS, flag is set to 'false' by default
    if (AWSzipCodeChanged == true)
    {
        //If yes, verify new zipcode is a state in which agent is licensed
        CheckForAgentQuery();
    }
    
    if(ValidationResult.Territory != null)
    {
        resetZipMsg();
        ProcessValidState(ValidationResult.Territory);
    }
//    else if (GeoState == 'CA' || GlobalValidationResult != 'CallAlliance')
    else if(GlobalValidationResult != 'CallAlliance')
    {
        ProcessInactiveStates(GlobalValidationResult);
    }
    else if (GeoState == 'MA' || GeoState == '')
    {
        //Massachusetts or no state returned from GeoService for the zip code the user entered.
        //Display appropriate message based on what was returned. 
        ProcessNULLMassachusetts(GeoState);   
    }    
    else if (validZip == false)
    {
        DisplayInvalidZipCodeMessage(GeoState);
    }
}
function DisplayInvalidZipCodeMessage(GeoState)
    {
        modalBackImage = "url(images/1_2-entryPage-zipcodeNot_SideBorder.gif)";
        $get('ZipCodeModalWrapper').style.backgroundImage = modalBackImage;
        $get('pnlZipCode').style.backgroundImage = modalBackImage;
        $get('ZipCodeModalMultipleTerritories').style.display = 'none';
        $get('ZipCodeModalValidTerritory').style.display = 'none';
        $get('ZipCodeModalInvalidTerritory').style.display = 'block';
        $get('ZipCodeModalWhiteBody').style.marginBottom = '0px';
        $get('ZipCodeModalWrapper').style.backgroundColor = '#DDBB49';
        
        //hide Where do you live div, display We're sorry and inelgible zip message
        $get('IneligibleZIP').style.display = 'block';
        $get('WereSorry').style.display = 'block';
        $get('WhereDoYouLive').style.display = 'none';
        
        var divItem = $get('SelectAreaWrapper');
        divItem.style.display = 'block';
        divItem.style.paddingBottom = '0px';
       
        PageMethods.GetAgentLocatorLink(buildALRlink, processError);


    }


function ProcessNULLMassachusetts(stateCode){
    modalBackImage = "url(images/1_2-entryPage-zipcodeNot_SideBorder.gif)";
    $get('ZipCodeModalWrapper').style.backgroundImage = modalBackImage;
    $get('pnlZipCode').style.backgroundImage = modalBackImage;
    $get('ZipCodeModalMultipleTerritories').style.display = 'none';
    $get('ZipCodeModalValidTerritory').style.display = 'none';
    $get('ZipCodeModalInvalidTerritory').style.display = 'block';
    $get('ZipCodeModalWhiteBody').style.marginBottom = '0px';
    $get('ZipCodeModalWrapper').style.backgroundColor = '#DDBB49';
    $get('CancelMessageArea').style.color = '#A95343';
    var divItem = $get('SelectAreaWrapper');
    divItem.style.display = 'block';
    divItem.style.paddingBottom = '0px';
       
    if (stateCode == 'MA')
    {
        $get('CancelMessageArea').className = 'ZipCodeInvalid';
        var CancelMessageObj = $get('lblCancelMessage');
        var CancelMessageText = zipCodeLiterals.sorryNotOffered;        
        setInnerText(CancelMessageObj, CancelMessageText); 
    }
    //This gets triggered when Alliance cannot return territories for the zipcode entered.  ie: PO boxes.
    else if (stateCode == 'NA')
    {
        $get('CancelMessageArea').className = 'ZipCodeNotFound';
        var CancelMessageObj = $get('lblCancelMessage');
        var CancelMessageText = zipCodeLiterals.sorryZipNotFound;        
        setInnerText(CancelMessageObj, CancelMessageText); 
    }

    //This gets triggered when the Geoservice cannot find the zipcode that was entered by the user.  ie: zipcode = 00000
    else
    {   
        $get('CancelMessageArea').className = 'ZipCodeInvalid';
        var CancelMessageObj = $get('lblCancelMessage');
        var CancelMessageText = zipCodeLiterals.invalidZip;        
        setInnerText(CancelMessageObj, CancelMessageText);
        invalidZipFlag = true;
    }       
}

function ProcessValidState(AllianceData){
    //Set AllianceData JSON object
    setGlobalAllianceData(AllianceData);
    
    //If Geo returned a state but Alliance did not return any territories for that zip 
    //and state combo then that means we do not offer insurance in that zip, i.e. 12345.
    //12345 is a NY zip but no territories returned.
    if (GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories == null || GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory.length<1)
    {
        ProcessNULLMassachusetts('NA');
        return;   
    }
    
    //We want to make sure all the sibling nodes that may have been created via node
    //cloning are removed before we display the results of the users next zip search.
    //Doing this assures that the screen will display accordingly and empty divs will 
    //not be hanging on the screen.
    var node = $get('ValidStateTemplate');
    removeSiblingNodes(node);
    
    var divItem = $get('SelectAreaWrapper');
    divItem.style.display = 'block';
    //Hide invalid territory div
    $get('ZipCodeModalInvalidTerritory').style.display = 'none';
    //Show valid territory div
    $get('ZipCodeModalValidTerritory').style.display = 'block';
    $get('ZipCodeModalWhiteBody').style.marginBottom = '0px';

    //If more than one territory is returned from Alliance we want to
    //do multiple things.  Display a div that gives instructions to select one
    //of the multiple territories displayed on the screen, fix padding for display
    //purposes and set height and overflow properties of the area where the 'Select'
    //buttons appear.  We want multiple territories to appear in a scrollable area
    //to preserve the layout of the modal popup.
    if (GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory.length>1)
    {
        $get('ZipCodeModalMultipleTerritories').style.display = 'block';
        $get('ZipCodeModalSelect').style.marginBottom = '0px';
        $get('ZipCodeModalValidTerritory').style.height = '84px';//Sets height of scrollable area
        $get('ZipCodeModalValidTerritory').style.overflow = 'auto';//Creates scrollable area
    }
    else
    {
        $get('ZipCodeModalMultipleTerritories').style.display = 'none';
        $get('ZipCodeModalValidTerritory').style.height = '';
    }

    //Loop through all the territories returned and build div's that display
    //the city and state in addition to ta 'Select' button for each.    
    //for (var i=0; i<GlobalAllianceData.Territories.length; i++)
    
    if(GlobalAllianceData.StateCode != "CA")
    {
        for (var i=0; i<GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory.length; i++)
        {       
            
            //We know there is a territory but if the territory node has children nodes that are null
            //or blank the data is deemed incomplete and potentially incorrect, show special message.
            if (GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CityName == null || GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CityName == '')
             {
                ProcessNULLMassachusetts('NA');
                return;   
             }
                  
            var city;
            //Trim spaces off of city name
            city = GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CityName.replace(/^\s*|\s*$/g,"");
                    
            //Clone div
            cloneDIV('ZipCodeModalSelect', 'CloneContainer', i); 
            
            //Add click event to each select button that is displayed for each of the
            //territories.
            addTerrSelectOnClickEvent(i);       
         
            var StateMessageObj = $get('lblStateMessage' + '~' + i);
            //Need to append inside/outside city limits and county name if more than one
            //territory returned
            if (GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory.length>1 && GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CountyName != null)
            {
                var StateMessageText = city + ', ' 
                   + GlobalAllianceData.StateCode + ' (' + GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CityLimitInd + ' City Limits) '
                        + GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CountyName + ' COUNTY';
            }
            else if (GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory.length>1 && GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CountyName == null)
            {
                var StateMessageText = city + ', ' 
                    + GlobalAllianceData.StateCode + ' (' + GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CityLimitInd + ' City Limits)';                        
            }
            else
            {
                var StateMessageText = city + ', ' + GlobalAllianceData.StateCode;        
            }
            setInnerText(StateMessageObj, StateMessageText);                 
       } //end for
   }
   else //CA specific logic
   {
       for (var i=0; i<GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory.length; i++)
            {       
                
                  
                var county;
                //Trim spaces off of city name
                county = GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[i].CountyName.replace(/^\s*|\s*$/g,"");
                                
                //Clone div
                cloneDIV('ZipCodeModalSelect', 'CloneContainer', i); 
                
                //Add click event to each select button that is displayed for each of the
                //territories.
                addTerrSelectOnClickEvent(i);       
             
                var StateMessageObj = $get('lblStateMessage' + '~' + i);
                //For CA Alliance only returns County Names, not City Names
                var StateMessageText = county + " COUNTY, " + GlobalAllianceData.StateCode;
                setInnerText(StateMessageObj, StateMessageText);                 
           } //end for      
       
   }
   
    modalBackImage = "url(images/1_2-entryPag-zipcod-2return-sideBorder.gif)";
    $get('ZipCodeModalWrapper').style.backgroundImage = modalBackImage;
    $get('ZipCodeModalWrapper').style.backgroundColor = '#66B329';
    $get('pnlZipCode').style.backgroundImage = modalBackImage;
        
}

function ProcessInactiveStates(stateName){

    i=0;
    
    //Set AllianceData JSON object
    //setGlobalAllianceData(AllianceData);    
    
    var divItem = $get('SelectAreaWrapper');
    divItem.style.display = 'block';
    
    //We want to make sure all the sibling nodes that may have been created via node
    //cloning are removed before we display the results of the users next zip search.
    //Doing this assures that the screen will display accordingly and empty divs will 
    //not be hanging on the screen.
    var node = $get('ValidStateTemplate');
    removeSiblingNodes(node);
     
    //Hide invalid territory div
    $get('ZipCodeModalInvalidTerritory').style.display = 'none';
    $get('ZipCodeModalMultipleTerritories').style.display = 'none';
    $get('ZipCodeModalWhiteBody').style.marginBottom = '0px'; 
    $get('ZipCodeModalValidTerritory').style.height = '';
    //Show valid territory div
    $get('ZipCodeModalValidTerritory').style.display = 'block';
    
    
    
    //Clone div
    cloneDIV('ZipCodeModalSelect', 'CloneContainer', i);
    
    //Add click event to the select button
    addTerrSelectOnClickEvent(i);
    
    var StateMessageObj = $get('lblStateMessage' + '~' + i);
    var StateMessageText = stateName;
    
    setInnerText(StateMessageObj, StateMessageText);                 
      
    modalBackImage = "url(images/1_2-entryPag-zipcod-2return-sideBorder.gif)";
    $get('ZipCodeModalWrapper').style.backgroundImage = modalBackImage;
    $get('ZipCodeModalWrapper').style.backgroundColor = '#66B329'; 
    $get('pnlZipCode').style.backgroundImage = modalBackImage;
}

function removeSiblingNodes(node)
{
    while (node != null)
    {
        var sibling = node.nextSibling;
        
        if(sibling == undefined &&
            sibling == null)
        {
            return;
        }   
        
        if(navigator.userAgent.indexOf("MSIE")!=-1){
            sibling.outerHTML="  "; // modified code to fix IE6/IE7 bug: http://support.microsoft.com/default.aspx?scid=kb;EN-US;925014
        }
        else
        {
            sibling.parentNode.removeChild(sibling);
        }
    }
}

function CancelZipModal(){
    Innovations_hbPageView('cancel_zip.aspx','/auto/overlay');//Call HitBox function to submit action
        
    //Start of fix for IM44077
    modalBackImage = "url(images/1_2-entryPag-zipcod-2return-sideBorder.gif)";
    $get('ZipCodeModalWrapper').style.backgroundImage = modalBackImage;
    $get('ZipCodeModalWrapper').style.backgroundColor = '#66B329';
    $get('ZipCodeModalInvalidTerritory').style.display = 'none';
    $get('ZipCodeModalWhiteBody').style.marginBottom = '0px';
    $get('pnlZipCode').style.backgroundImage = modalBackImage;
    var txtBoxZipCode = $get('txtBoxZipCode');
    txtBoxZipCode.value = "";
    txtBoxZipCode.focus();
    resetZipMsg();
}

function resetZipMsg(){
        $get('IneligibleZIP').style.display = 'none';
        $get('WereSorry').style.display = 'none';
        $get('WhereDoYouLive').style.display = '';
}

function processError(error, response){
    top.window.location=urlHomeErrorPage;  //variable defined in Entry Page.  This takes the web.config appSettings urlAllstate
}

function processGeoAllianceError(error, response)
{
    if(error !== null) { alert(error.get_message()); }
}

function cloneDIV(templateDIV, parentDIV, index){
    var template = $get(templateDIV);
    var newNode = template.cloneNode(true);
    reIndexExistingNode(newNode, index);
    var divZipModal = $get(parentDIV);
    divZipModal.appendChild(newNode);
 }

function cancelSubmit(){
    return false;
}

function cancelEnterKey(){
    var panelDiv =  $get('pnlZipCode');
    var selectDiv = $get('SelectAreaWrapper');

    if (panelDiv.style.display != 'none' && selectDiv.style.display == 'none')
    {
        return false;
    }
    else
    {        
        return true;
    }
}

function setTerritoryValues(evt){

    var btnIndex = getEventElement(evt);
    index = btnIndex.value;
    
    if(GlobalValidationResult == 'CallAlliance')
    {    
        PageMethods.SetSessionItems(index, GlobalAllianceData,IsAgentLicensed, GlobalAgentID, processAlternateEntry, processError);
        //8E042: Adding HBX Tag c15 to include selected territory code
        territory = GlobalAllianceData.selectResponse.selectTerrResponse.selectTerritories.selectTerritory[index].TerritoryCode;
    } 
     else
    {
        PageMethods.SetStateZipSession(zip, GeoState, processAlternateEntry, processError);
    }
    
    Innovations_hbPageView('select_zip.aspx','/auto/overlay');//Call HitBox function to submit action   
       
    RequestDART('quoti792');
}
    
    //4E025
function processAlternateEntry()
{    
    //qQuote is either 'PQ' or null comes from querystring via Entrypage variable
    PageMethods.GetPersonalQuoteState( zip, GeoState, qQuote, handleURL, sinkNonErrors );
}

//setTerritoryValues
/*Fix to capture javascript/async error that Firefox3 produces.  
The error returned is 0 which is not a valid http status code
200 is valid okay code.*/
function sinkNonErrors( error, response )
{
    var statusCode = error.get_statusCode();

    if ( !( statusCode == 0 || stateCode == 200 ) || error.get_timedOut() )
    {
        processError( error, response );
    }
    //Firefox3 successful TODO: handle a success of GetPersonalQuoteState calling pagemethod to retrieve urlArray for handleURL
}

//successful PageMethod event for setTerritoryValues
function handleURL(inUrlArray)
{
    urlArray = inUrlArray;
    // (DEST = ‘WQB or DCI2)
    if (urlArray[0] == "WQB" || urlArray[0] == "DCI2")
        top.window.location.href = urlArray[1];
    //Else (DEST =’AET’)
    else if (urlArray[0] == "AET")
    {
        //window.location.href = urlArray[1];  this is causing js popup errors. to test this locally use your machine name
        //http://machine-name/ConfiguratorFrame.aspx?Quote=PQ .... seems to be doing a pageload before leaving, and then when config loads
        //appears to not be able to find top (iframe)
        top.URLDestination = "AET";
        submitPage();
    }
    else
        submitPage();
        
}


function submitPage(){
    
    document.forms[0].submit();
    
}

function setGlobalAllianceData(AllianceData){
    GlobalAllianceData = AllianceData;
}

function addTerrSelectOnClickEvent(index){
    var submitBtn = $get('imgBtnSelect' + '~' + index);
    submitBtn.value = index;
    if(window.addEventListener){ // Mozilla, Netscape, Firefox
        submitBtn.addEventListener('click', setTerritoryValues, false);
        submitBtn.addEventListener('click', setStreamType, false);
    } 
    else { // IE
        submitBtn.attachEvent('onclick', setTerritoryValues);
        submitBtn.attachEvent('onclick', setStreamType);
    } 
}   


if (Sys && Sys.Application) { Sys.Application.notifyScriptLoaded(); }

// Below function is called by switchLangModalExtender on EntryPageHeader.ascx to capture HBX measurements for Toggle link.

     function callHBXOnCancel(callingPage)
     {
         pageName = callingPage;  
         PageMethods.GetLanguage(onCancelSucceeded,null);    
           
     }
     
     // This function is called by setNewLang()method on ConfiguratorPage.master
     function callHBXOnContinue(callingPage)
     {
         pageName = callingPage;    
         PageMethods.GetLanguage(onContinueSucceeded,null);    
         
     }
      
     function onCancelSucceeded(result)
     {  
        var x = pageName;
        if(result == "ESPANOL")
        {
           item1 = "cancel_toggle_to_english";
           item2 = "/"+ pageName;
        }
        else
        {
           item1 = "cancel_toggle_to_spanish";
           item2 = "/" + pageName;
        }  
                   
        Innovations_hbPageView(item1,item2);   
     } 
        

     function onContinueSucceeded(result)
     {
        if(result == "ESPANOL")
        {
           item1 = "continue_toggle_to_english";
           item2 = "/"+ pageName;
        }
        else
        {
           item1 = "continue_toggle_to_spanish";
           item2 = "/" + pageName;
        }      
               
        Innovations_hbPageView(item1,item2);            
    }
    
     //Below two functions are called by contPersonalQuoteExtender_Matrix and contPersonalQuoteExtender_Summary Ajax extenders
    function callHBXOnNQ2Cancel(callingPage)
     {
         pageName = callingPage;  
         PageMethods.GetLanguage(onNQ2CancelSucceeded,null);  
     }
     
    function onNQ2CancelSucceeded(result)
    {
        var item1, item2;
        item1 = "no_NQ2";
        if(language == "ESPANOL")
        {
          item2 = "/"+ pageName;
        }
        else
        {
          item2 = "/" + pageName;
        }      
               
        Innovations_hbPageView(item1,item2);
     }
     
    function callHBXOnNQ2Continue(callingPage)
     {
         PageMethods.GetLanguage(onNQ2ContinueSucceeded,null);    
         pageName = callingPage; 
     }
     
    function onNQ2ContinueSucceeded(result)
    {
        var item1, item2;
        item1 = "continue_NQ2";
        if(language == "ESPANOL")
        {
           item2 = "/"+ pageName;
        }
        else
        {
           item2 = "/" + pageName;
        }      
               
        Innovations_hbPageView(item1,item2);
     }
