﻿// JScript File
var page = new PageQuery(window.location.search);
var genericQuery;

function RequestDART(inCat)
{
    var axel = Math.random()+"";
    var aRandomNumber = axel * 10000000000000;
    var dartElement = document.createElement("IFRAME");
    //dartElement.src = "https://fls.doubleclick.net/activityi;src=1886972;type=first303;cat=" + inCat + ";ord="+ aRandomNumber + "?";
    //Amit 09/11/2008 sUSD#7699206 Extra tag num added into url
    dartElement.src = "https://fls.doubleclick.net/activityi;src=1886972;type=first303;cat=" + inCat + ";ord=1;num="+ aRandomNumber + "?";
    dartElement.style.display = "none"; 
    //dartElement.id = "dartFrame" + aRandomNumber;  //may need this in case of pageless design where events may need to be tracked.  
    var targetElement = document.getElementsByTagName('body')[0];
    targetElement.appendChild(dartElement);
}

/**************** Query String parsing Utility ***************************/
function PageQuery(q) 
{
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if(q) 
    {
        for(var i=0; i < this.q.split("&").length; i++) 
        {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) 
    {
        for(var j=0; j < this.keyValuePairs.length; j++) 
        {
            if(this.keyValuePairs[j].split("=")[0] == s)
            return this.keyValuePairs[j].split("=")[1];
        }
        return false;
    }
    this.getParameters = function() 
    {
        var a = new Array(this.getLength());
        for(var j=0; j < this.keyValuePairs.length; j++) 
        {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key)
{
    return unescape(page.getValue(key)); 
}

//This function creates a new object to store an array of delimited query params.
function ParseAWSQueryString(query)
{
    genericQuery = new PageQuery(query);
}

//This function gets a param based on the key passed in.
function GetQueryStringParam(key)
{
    return unescape(genericQuery.getValue(key));
}

/*********** IE/FireFox cross-browser compatibility functions *********************/
function setInnerText(obj, text) { (obj.innerText != null) ? obj.innerText = text : obj.textContent = text; }
function getInnerText(obj) { return (obj.innerText != null) ? obj.innerText : obj.textContent; }

// "target" for Mozilla, Netscape, Firefox et al. ; "srcElement" for IE
function getEventElement(evt) { return evt["target"] ? evt["target"] : evt["srcElement"]; }
function cancelBubble(evt)
{
    var e=(evt)?evt:window.event; // browser compatibility code for cancel bubble
    (window.event) ? e.cancelBubble=true : e.stopPropagation(); 
}

function attachClickEvent(obj, method)
{
    if(window.addEventListener){ // Mozilla, Netscape, Firefox
        obj.addEventListener('click', method, false);
    } 
    else { // IE
        obj.attachEvent('onclick', method);
    }
}

function detachClickEvent(obj, method)
{
    if(window.removeEventListener){ // Mozilla, Netscape, Firefox
        obj.removeEventListener('click', method, false);
    } 
    else { // IE
        obj.detachEvent('onclick', method);
    }
}

// removes mulitple instances of the same handler from an element
function removeMultipleHandlers(element, eventName, handler)
{
    if(element._events)
    {
        var eventCache = element._events[eventName];
        if(eventCache)
        {
            for(var i=0; i<eventCache.length; i++)
            {
                if(eventCache[i].handler == handler) { $removeHandler(element, eventName, handler); }
            }
        }
    }
}

function handlerExists(element, eventName, handler)
{
    if(element._events)
    {
        var eventCache = element._events[eventName];
        if(eventCache)
        {
            for(var i=0; i<eventCache.length; i++)
            {
                if(eventCache[i].handler == handler) { return true; }
            }
        }
    }
    return false;
}

/**************** Navigation functions **********************/
function showNav(a) {
    //2E009 - BackBrowser
    //enabling back browser button functionality
    needToConfirmUnload = false;
    var ul = a.getElementsByTagName("ul")[0];
    if (ul.childNodes.length > 0) {
        ul.style.display = "inline";
    }
}

function hideNav(a) {
    //2E009 - BackBrowser
    //enabling back browser button functionality
    needToConfirmUnload = true;
    var ul = a.getElementsByTagName("ul")[0];
    ul.style.display = "none";
}


/*************** SUB- NAVIGATION *************************/

function reIndexNode(node, index)
{
    node.id = node.id.replace(/INDEX/g, index);
    node.innerHTML = node.innerHTML.replace(/INDEX/g, index);
}

function reIndexExistingNode(node, index)
{
    node.id = node.id + '~' + index;
    // re-index child nodes
    // labels
    var spanNodes = node.getElementsByTagName('SPAN');
    for(var i=0; i<spanNodes.length; i++)
    {
        var id = spanNodes[i].id;
        if(id.indexOf('Index') != -1){ setInnerText(spanNodes[i], '0' + index); }
        var parsedId = getParsedId(id);
        spanNodes[i].id = parsedId + '~' + index;
    }
    // images
    var imgNodes = node.getElementsByTagName('IMG');
    for(var j=0; j<imgNodes.length; j++)
    {
        var parsedImgId = getParsedId(imgNodes[j].id);
       imgNodes[j].id = parsedImgId + '~' + index;
    }
    // inputs
    var inputNodes = node.getElementsByTagName('INPUT');
    for(var k=0; k<inputNodes.length; k++)
    {
       var parsedInputId = getParsedId(inputNodes[k].id);
       inputNodes[k].id = parsedInputId + '~' + index;
    }
}


function removeSubNavElement(strElement)
{
    var divDel = $get(strElement);
    
    
    if(navigator.userAgent.indexOf("MSIE")!=-1){
        divDel.outerHTML = "  "; // modified code to fix IE6/IE7 bug: http://support.microsoft.com/default.aspx?scid=kb;EN-US;925014
    }
    else
    {
        var parent = divDel.parentNode;
        divDel = parent.removeChild(divDel);  
    }
    divDel == null;
}

function getParsedId(strId)
{
    var _last = strId.lastIndexOf('~');
    return (_last == -1) ? strId : strId.substring(0, _last);
}

/******************** MOUSE OVER/OUT EFFECTS *************************/

function addMouseOver(evt)
{
    var imgAdd = getEventElement(evt);
    imgAdd.src = "images/"+ language +"/btn_add_over.gif"
}

function addMouseOut(evt)
{
    var imgAdd = getEventElement(evt);
    imgAdd.src = "images/"+ language +"/btn_add_on.gif"
}

function backMouseOver(evt)
{
    var imgBack = getEventElement(evt);
    imgBack.src = "images/"+ language +"/btn_back_over.gif"
}

function backMouseOut(evt)
{
    var imgBack = getEventElement(evt);
    imgBack.src = "images/"+ language +"/btn_back_on.gif"
}

function nextMouseOver(evt)
{
    var imgNext = getEventElement(evt);
    imgNext.src = "images/"+ language +"/btn_next_over.gif"
}

function nextMouseOut(evt)
{
    var imgNext = getEventElement(evt);
    imgNext.src = "images/"+ language +"/btn_next_on.gif"
}

function setPopup(contentGuid, targetID, event)
{
    //template is the panel which will be dynamically cloned for the popup
    var template = $get('contentDiv');
    var theBody = document.getElementsByTagName("body");
    
    var toolTip = $get("toolTip_" + targetID);
    //if the tool tip is not already on the page, create it
    if ( toolTip == null )
    {
        if (! template )
        {
            template = document.createElement("div");
            template.id = 'contentDiv';
            template.className = 'TootTipEditable';
            theBody[0].appendChild(template);
        }
           
        //Clone the popup panel dynamically
        var popUpClone = template.cloneNode(true);

        //Set the text to be displayed
        popUpClone = setText( template, contentGuid);
        popUpClone.id = targetID + '_Popup';
                    
        //Add the clone to the page.
        var cloneContainer = document.createElement('div');
        cloneContainer.id = 'toolTip_' + targetID;
        cloneContainer.style.position = 'absolute';
        
        var topLeftCornerDiv = document.createElement('div');
        topLeftCornerDiv.id = targetID + '_ToolTipTopLeftCorner';
        topLeftCornerDiv.className = 'ToolTipTopLeftCorner';
        cloneContainer.appendChild(topLeftCornerDiv);
        
        var topMiddleDiv = document.createElement('div');
        topMiddleDiv.id = targetID + '_ToolTipTopMiddle';
        topMiddleDiv.className = 'ToolTipTopMiddle';
        cloneContainer.appendChild(topMiddleDiv);    
        
        var topRightCornerDiv = document.createElement('div');
        topRightCornerDiv.id = targetID + '_ToolTipTopRightCorner';
        topRightCornerDiv.className = 'ToolTipTopRightCorner';
        cloneContainer.appendChild(topRightCornerDiv);
        
        //content div
        cloneContainer.appendChild(popUpClone);
        //
        
        var bottomLeftCornerDiv = document.createElement('div');
        bottomLeftCornerDiv.id = targetID + '_ToolTipBottomLeftCorner';
        bottomLeftCornerDiv.className = 'ToolTipBotLeftCorner';
        cloneContainer.appendChild(bottomLeftCornerDiv);    
        
        var bottomMiddleDiv = document.createElement('div');
        bottomMiddleDiv.id = targetID + '_ToolTipBottomMiddle';
        bottomMiddleDiv.className = 'ToolTipBotMiddle';
        cloneContainer.appendChild(bottomMiddleDiv);
        
        var bottomRightCornerDiv = document.createElement('div');
        bottomRightCornerDiv.id = targetID + '_ToolTipBottomRightCorner';
        bottomRightCornerDiv.className = 'ToolTipBotRightCorner';
        cloneContainer.appendChild(bottomRightCornerDiv);    
        
        //attach the formatted div to the body
        theBody[0].appendChild(cloneContainer);
        var toolTipClone = $get(cloneContainer.id);
        
        if (event != null && event.type == 'mouseover')
            {
                setPopUpPosition(toolTipClone, event)
            }
        else
            {
                toolTipClone.style.visibility = 'hidden';        
            }
    }
    else
    {
        //if tool tip has already been created on the page and the onmouseover 
        //event occurs then we need to set the placement of the hover
        if (event != null && event.type == 'mouseover')
        {
            setPopUpPosition(toolTip, event)
        }        
    }
}

function setPopUpPosition(item, event)
{
    var thisClientX = 0;
    var thisClientY = 0;
    var thisScrollTop = 0;
    var thisScrollLeft = 0;
    var offsetY = 0;
    var offsetX = 0;
    
    thisClientX = event.clientX;
    thisClientY = event.clientY;
    thisScrollTop = document.documentElement.scrollTop;
//    item.style.top = (thisClientY + thisScrollTop + 10 + offsetY) + "px";
//    item.style.left = (thisClientX + 10 + offsetX) + "px";
//    item.style.zIndex = "100102";
//    item.style.visibility = 'visible';  
    var loc = new Sys.UI.Point((thisClientX + 10 + offsetX), (thisClientY + thisScrollTop + 10 + offsetY));
    setAdjustedPopupLocation(item, event, loc)  
}

function hideThisToolTip (e)
{
    var thisElement = e;
    var thisElementParent = thisElement.target.parentNode;
    thisElementParent.style.visibility = "hidden";
    
}


function createPopUp(popUpElement,targetID)
{
    var path = "<%= this.ApplicationInstance.Context.Request.Path%>";
    var extenderID = 'HoverMenuExtender_' + targetID
    $create(AjaxControlToolkit.HoverMenuBehavior, {"DynamicServicePath":path,"HoverCssClass":"popupHover","id":extenderID,"OffsetX":0,"OffsetY":0,"popupElement":popUpElement}, null, null, $get( targetID ));

}
function setText( divNode, elementID )
{
    //Still need to determine how text will be retrieved and displayed 	
    var text = ClientContent.GetToolTip(elementID);
    divNode.innerHTML = text;
    return divNode;
}

function HTMLDecode(nText) {
  var newValue = nText.replace(/&lt;/g, "<")
                      .replace(/&gt;/g, ">")
                      .replace(/&quot;/g, "\"")
                      .replace(/&apos;/g, "'")
                      .replace(/&amp;/g, "&");
  return newValue
}

//this is for specifially defining offsets on the (?)
function showToolTipOffset(event, target, offsetX, offsetY)
{
    var thisClientX = 0;
    var thisClientY = 0;
    var thisScrollTop = 0;
    var thisScrollLeft = 0;
    
    var popupTarget = $get(target);
    var toolTip = $get("toolTip_" + target);
    if ( toolTip == null )
    {
        toolTip = createToolTip(popupTarget.innerHTML);
        toolTip.id = "toolTip_" + target;
    }
    toolTip.style.visibility = 'visible';
    
    thisClientX = event.clientX;
    thisClientY = event.clientY;
    thisScrollTop = document.documentElement.scrollTop; 

    toolTip.style.top = (thisClientY + thisScrollTop + offsetY) + "px";
    toolTip.style.left = (thisClientX + offsetX) + "px";
    toolTip.style.zIndex = "100102";    
       
}

//if the offsets are null then then do normal stuff
//if the offset is not null these are for matrix rollovers
function showToolTip(event,target,offsetX,offsetY)
{
    var thisClientX = 0;
    var thisClientY = 0;
    var thisScrollTop = 0;
    var thisScrollLeft = 0;
    
    if ( offsetX == null )
    {
        offsetX = 0;
    }
    if ( offsetY == null )
    {
        offsetY = 0;
    }
    var popupTarget = $get(target);
    var toolTip = $get("toolTip_" + target);
    if ( toolTip == null )
    {
        toolTip = createToolTip(popupTarget.innerHTML);
        toolTip.id = "toolTip_" + target;
    }
//    toolTip.style.visibility = 'visible';
    
    
    if (offsetX == 0)
        thisClientX = event.clientX;
    if (offsetY == 0)
    {
        thisClientY = event.clientY;
        thisScrollTop = document.documentElement.scrollTop;
    }
//    thisScrollLeft = document.documentElement.scrollLeft;
//    c=431;

    var loc = new Sys.UI.Point((thisClientX + 10 + offsetX), (thisClientY + thisScrollTop + 10 + offsetY));
//    if(loc.x + toolTip.clientWidth > $common.getClientBounds().width) { loc.x = ($common.getLocation($get(event.target.id)).x - toolTip.clientWidth) - 10; }
//    if(loc.y + toolTip.clientHeight > $common.getClientBounds().height) { loc.y = ($common.getLocation($get(event.target.id)).y - toolTip.clientHeight) - 10; }
//    
//    $common.setLocation(toolTip, loc);
//    toolTip.style.zIndex = "100102";
    setAdjustedPopupLocation(toolTip, event, loc)
}

function setAdjustedPopupLocation(toolTip, event, point)
{
    // browser compatibility code
    var element = (event.srcElement == null) ? event.target : event.srcElement;

    if(point.x + toolTip.clientWidth > $common.getClientBounds().width) { point.x = ($common.getLocation(element).x - toolTip.clientWidth) - 10; }
    if(point.y + toolTip.clientHeight > $common.getClientBounds().height) { point.y = ($common.getLocation(element).y - toolTip.clientHeight) - 10; }
    
    $common.setLocation(toolTip, point);
    toolTip.style.zIndex = "100102";
    toolTip.style.visibility = 'visible';
}

function hideToolTip(target)
{
    var popupTarget = $get("toolTip_" + target);
    popupTarget.style.visibility = 'hidden';
}

function hideAndDestroyToolTip(target)
{
    var target = $get("toolTip_" + target);
    if (target != null)
    {
        target.style.visibility = 'hidden';
        target.parentNode.removeChild(target);
    }
}

function createToolTip(text)
{
    var toolTip = $get("toolTipClone");
    //Add the clone to the page.
    var theBody = document.getElementsByTagName("body");
    var popUpClone = document.createElement('div');

    var cloneContainer = document.createElement('div');
    cloneContainer.id = '_ToolTip';
    cloneContainer.style.position = 'absolute';
    
    var topLeftCornerDiv = document.createElement('div');
    topLeftCornerDiv.id = '_ToolTipTopLeftCorner';
    topLeftCornerDiv.className = 'ToolTipTopLeftCorner';
    cloneContainer.appendChild(topLeftCornerDiv);
    
    var topMiddleDiv = document.createElement('div');
    topMiddleDiv.id = '_ToolTipTopMiddle';
    topMiddleDiv.className = 'ToolTipTopMiddle';
    cloneContainer.appendChild(topMiddleDiv);
    
    var topRightCornerDiv = document.createElement('div');
    topRightCornerDiv.id = '_ToolTipTopRightCorner';
    topRightCornerDiv.className = 'ToolTipTopRightCorner';
    cloneContainer.appendChild(topRightCornerDiv);
    
    //content div
    popUpClone.innerHTML = text;
    popUpClone.className = 'TootTipEditable';
    cloneContainer.appendChild(popUpClone);
    //
    
    var bottomLeftCornerDiv = document.createElement('div');
    bottomLeftCornerDiv.id = '_ToolTipBottomLeftCorner';
    bottomLeftCornerDiv.className = 'ToolTipBotLeftCorner';
    cloneContainer.appendChild(bottomLeftCornerDiv);
    
    var bottomMiddleDiv = document.createElement('div');
    bottomMiddleDiv.id = '_ToolTipBottomMiddle';
    bottomMiddleDiv.className = 'ToolTipBotMiddle';
    cloneContainer.appendChild(bottomMiddleDiv);
    
    var bottomRightCornerDiv = document.createElement('div');
    bottomRightCornerDiv.id = '_ToolTipBottomRightCorner';
    bottomRightCornerDiv.className = 'ToolTipBotRightCorner';
    cloneContainer.appendChild(bottomRightCornerDiv);    
    
    //attach the formatted div to the body
    theBody[0].appendChild(cloneContainer);

    return cloneContainer;
}

    //figures out the top left coordinates in the page of the element
    // that the mouse event occured on
    function getOffset(element)
    {
        var e = element;
        elementOffsetX = 0;
        elementOffsetY = 0;
        
        //Checks to see if offsetParent is not supported supported (Firefox)
        if (e.offsetParent == null)
        {
            while (e)
            {
                if (e.id == 'BODY')
                    break;
                elementOffsetX += e.offsetLeft;
                elementOffsetY += e.offsetTop;
                
                if (e.offsetParent == null)
                    e = e.parentNode;
                else
                    e = e.offsetParent;   
            }  
        }
        //else do this for IE6 or browser that supports IE6
        else 
        {       
            while (e)
            {
                elementOffsetX += e.offsetLeft;
                elementOffsetY += e.offsetTop;
                
                e = e.offsetParent;   
            }
        }    
    } 

//We want to assure that the hbx script has rendered before we call the 
//_hbPageView function.  If not rendered yet let the page move on without error.
// Below method is a commonmethod used by AET to capture HBX measurements.If language is Spanish, the tag is prefixed by "/spanish"
// item 1 is first argument of _hbPageView function and item2 is second argument. Eg _hbPageView('cancel_zip.aspx','/auto/overlay')

function Innovations_hbPageView(item1, item2)
{
    try
    {
        var LOB = 'AU';
        var hbxState;
        var item2languageAware = item2
        var hbxZipCode;
        
        //prefix item2 with /spanish to capture hispanic measurements
        if(language == 'ESPANOL')
        {
            item2languageAware = "/"+ "spanish" + item2;
        }
        
        if (typeof GeoState != 'undefined')//Entry page stores state code in this variable
            var hbxState = GeoState;
        else if (typeof data != 'undefined' && typeof data.State != 'undefined')//The rest of configurator stores state code in this object
            var hbxState = data.State;
        else 
            hbxState = '';        

        if (typeof zip != 'undefined')//Entry page stores zip code in this variable
            var hbxZipCode = zip + '|' + territory; //8E042: Adding HBX Tag to include selected territory code
        else 
            hbxZipCode = '';    
        
        parent._hbSet('cv.c9', LOB);
        parent._hbSet('cv.c4', hbxState); 
        parent._hbSet('cv.c15', hbxZipCode);       
        parent._hbPageView(item1, item2languageAware);
    }
    catch(err)
    {
        //do nothing
    }       
}

    //prevents onmouseout function from firing in situation 2
    //--------------
    //| Layer      |.onmouseout = doSomething;
    //| --------   |
    //| | Link | ----> Fires here
    //| |      |   |
    //| --------   |
    //| --------   |
    //| | Link |   |
    //| |    <--- | 2) but not here
    //| --------   |
    //--------------
    //
    //---->: mouse movement
    //
    function fireMouseOut(e,checkNames) 
    {
        var stop = new Boolean(false);
	    if (!e) 
	        var e = window.event;
    	    
	    //e.srcElement works in IE, e.target works in Mozilla
	    var target = (window.event) ? e.srcElement : e.target;
	    for (var name in checkNames)
	    {
	        if (target.id == checkNames[name])
	        {
	            stop = false;
	        }    	        
	    }
    	
	    //if name not found abort
	    if (stop) 
	        return;
    	
	    //e.relatedTarget works in Mozilla, e.toElement works in IE    
	    var relatedTarget = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	    while (relatedTarget != target && relatedTarget.nodeName != 'BODY')
		    relatedTarget = relatedTarget.parentNode
        
        //went into a child node, dont fire
	    if (relatedTarget == target) 
	        return false;
	    // Mouseout took place when mouse actually left layer
	    // Handle event
	    return true;
    }
    
    function goToLink(url)
    {
        top.window.location.href = url;    
    }
    
    function sendSummaryMouseOver(evt)
    {
        var imgSendSummary = getEventElement(evt);
        imgSendSummary.src = "images/" + language + "/button_sendmysummary_over.gif"
    }

    function sendSummaryMouseOut(evt)
    {
        var imgSendSummary = getEventElement(evt);
        imgSendSummary.src = "images/" + language + "/button_sendmysummary_on.gif"
    }

    
    var AllstateBlueMatrix;
    var AllstateBlueSummary;
    var AllstateBlueModal;
    var IndemnityHeader;
    var isAllstateBlue;
    var AllstateBlueMatrixTop;
    
    /* For BudgetSmart */
    var AllstateBlueShortSummary;    
    var ValueLine10;        
    var ValueLine19;       
    var ValueAllstateBlue; 
    var BudgetSmart;        

    function showAllstateBlue()
    {
        isAllstateBlue = document.getElementById(matrixClientID + "hidIsAllstateBlue").value;
        AllstateBlueMatrix = document.getElementById(matrixClientID + "AllstateBlueMatrixPanel");
        AllstateBlueSummary = document.getElementById("AllstateBlueSummaryDiv");
        AllstateBlueModal = document.getElementById("AllstateBlueModalDiv");
        IndemnityHeader = document.getElementById(matrixClientID + "IndemnityHeader");
        AllstateBlueMatrixTop = document.getElementById("topNonYCAHeader");
       
        AllstateBlueMatrix.style.display = 'none';
        AllstateBlueSummary.style.display = 'none';
        AllstateBlueModal.style.display = 'none';
      
        if ( isAllstateBlue == 'True' )
        {
            AllstateBlueMatrix.style.display = 'block';
            AllstateBlueSummary.style.display = 'block';
            AllstateBlueModal.style.display = 'block';
            IndemnityHeader.style.display = 'none';
            
            AllstateBlueMatrixTop.className = 'AllstateBlueTop';
        }
        else
        {
            IndemnityHeader.style.display = 'block'; 
        }
    }

if (Sys && Sys.Application) { Sys.Application.notifyScriptLoaded(); }
