﻿function gID(x){
    return document.getElementById(x);
}
function toggle(x){
    var El=gID(x);
    El.style.display=(El.style.display=="none"||El.style.display=="")? "block" : "none";
}
function swapImg(img){
    // This function relies on normal/hover image names to be identical except for the 
    // suffix after the underscore (myImage_on.jpg, myImage_off.jpg)
    
    var strOver  = "_on";    // image to be used with mouse over ex: plus_on.jpg
    var strOff = "_off";     // normal image ex: plus_off.jpg
    var imgObject;
    
    // Deterimine if the parameter passed in was an object - swapImg(this) - 
    // or an id string - swapImg('imageId') and define the image object to be swapped
    imgObject=(typeof img!='string') ? img : gID(img);
    strImg=imgObject.src;
    
    // Define the new image source, if it's on turn it off, if it's off turn it on.
    imgObject.src = (strImg.search(/_on(.)+/g) != -1)? strImg.replace(strOver,strOff): strImg.replace(strOff,strOver);
}
function showDetail(x, e) {  // Function to show info boxes
    /*
    This function handles the more information popup and image toggling for the membership comparison table
    The function relies on the following markup in the image tag for the plus icon: 
       Important: The image tag must contain an id for the close X button to toggle it properly. 
    ---------
    <img id="plusMaps" src="/pathToImages/plus_off.gif" alt="More Information" onclick="showDetail('maps', event)" onmouseover="showDetail('maps', event)" onmouseout="showDetail('maps', event)"  />
    ---------
    
    For the close X in the detail popup, the following markup structure must be followed in the popup:
    Note: The click event is in the anchor here incase we decide to add the word 'close' next to the image.
    ---------
    <a href="javascript:void(0);" onclick="toggle('tow'); toggleImage('plusTow', 'close');" ><img src="/pathToImages/close_box_off.gif" alt="Close" /></a>
    ---------
    */
    var targ;
    var strOver  = "_on";    // image to be used with mouse over ex: plus_on.jpg
    var strOff = "_off";     // normal image ex: plus_off.jpg
    var strExp = "_exp";
    var xPos = 0;
	var yPos = 0;
	var dsBox = gID(x);
	
	// Establish browser event handling and event target
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode; // Safari bug
    var strImg=targ.src; 
    var targId=targ.id;  
   
   // Toggle the detail box open if it's a click event
   if(e.type=="click"){
   
   		// switch the plus image to the expanded state
  		toggleImage(targId);
        // Turn off any currently opened boxes & Plus images toggled to expanded status except the ones that are going to be toggled  
 
        var allBoxes = $('#infoBoxes table');
        var allPluses = $('#membershipBenefitsTable img');
        
        for(i=0;i<allBoxes.length; i++){
            if(allBoxes[i]!=dsBox) allBoxes[i].style.display='none';
        }
        for(i=0;i<allPluses.length; i++){
        
            if(allPluses[i].id!=targ.id) {
                if(allPluses[i].src.search(/_exp(.)+/g) != -1){
                	openPlus = gID(allPluses[i].id);
                	//setTimeout used to fix IE6 image swap bug
                	setTimeout(function(){openPlus.src = openPlus.src.replace(strExp,strOff);}, 50);
                	
                	
                	//alert(openPlus.src);
                }else{
                	//gID(allPluses[i].id).src=allPluses[i].src.replace(strExp,strOn);
                }
            }
        }
        // Determine if NS or IE, then find the mouse coordinates of the click
        
	    if (e.pageX || e.pageY){
		    xPos = e.pageX;
		    yPos = e.pageY;
	    }
	    else if (e.clientX || e.clientY){
		    xPos = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		    yPos = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	    }
        dsBox.style.left = (xPos + 20) + 'px';
        dsBox.style.top = (yPos + 20) + 'px';
        
        // Toggle the selected box to visible
        toggle(x);
		
    }
    // Normal image swap function fires if the event is a mouseover or mouseout. Happens only if the expanded image is not present (ex. plus_exp.jpg)
    if(e.type=="mouseover"){
        if(strImg.search(/_off(.)+/g) != -1 && strImg.search(/_exp(.)+/g) == -1) targ.src=strImg.replace(strOff,strOver);
    }
    if(e.type=="mouseout"){
        if(strImg.search(/_on(.)+/g) != -1 && strImg.search(/_exp(.)+/g) == -1) targ.src=strImg.replace(strOver,strOff);
    }
}

function toggleImage(x){
    // The this function handles the toggling of the plus images to expanded/non-expanded states
    // for the more information popups in the select membership box
    // Set Timout functions used to fix IE6 image swap bug
    var strOver  = "_on";    // image to be used with mouse over ex: plus_on.jpg
    var strOff = "_off";     // normal image ex: plus_off.jpg
    var strExp = "_exp";
    var strImg=gID(x).src;
    var targ = gID(x);
    
    if(strImg.search(/_exp(.)+/g)!= -1){
    	setTimeout(function(){targ.src=(arguments[1])?strImg.replace(strExp,strOver):strImg.replace(strExp,strOff)}, 50);
    }else{
    	setTimeout(function(){targ.src=(strImg.search(/_on(.)+/g) != -1) ? replaceImage(strImg,strOver,strExp) : replaceImage(strImg,strOff,strExp)}, 50); 
    }
}
function replaceImage(x,y,z){
	return x.replace(y,z);
}

function tooltip2(x,e){
alert(x);
gID(x).style.display="block";
}
function tooltip(x, e){
    // Establish browser event handling
	if (!e) var e = window.event;
	theDiv=gID(x);
    
    gID(x).style.display=(gID(x).style.display=="none"||gID(x).style.display=="")? "block" : "none";
    
    
    // Determine if NS or IE, then find the mouse coordinates of the click
	if (e.pageX || e.pageY){
		xPos = e.pageX;
		yPos = e.pageY;
	}
	else if (e.clientX || e.clientY){
		xPos = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		yPos = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}   
	    if(document.getElementById('iframeshim')!=null){
	        ifrm=document.getElementById('iframeshim');
	        ifrm.width=theDiv.offsetWidth;
		    ifrm.height=theDiv.offsetHeight;
		    ifrm.style.left = xPos + 10 + 'px';
		    ifrm.style.top = yPos - theDiv.offsetHeight + 'px';
		    if(theDiv.style.visibility!='visible'){
		        ifrm.style.display='block';
	        }else{
		        ifrm.style.display='none';
	        }
	    }
        theDiv.style.left = xPos + 10 + 'px';
        theDiv.style.top = yPos - theDiv.offsetHeight + 'px';    
}
function sizeTaskBar(){
    var TB=document.getElementById('processNav').getElementsByTagName('li');
    //divWidth=document.getElementById('processNav').offsetWidth;
    var RightMargin = 4;
    for (i=0;i<TB.length;i++){
        TB[i].style.width=Math.floor((98/TB.length))+ "px";
        TB[i].style.marginRight=(i==TB.length-1)? 0 + "px" : RightMargin + "px";
    }
    
}

// Print Preview Functions
var printPreviewWin = 'height=700,width=700,scrollbars=yes,location=no,menubar=no,resizable=yes';
var searchString='PrintPreview';
function printPreview() {
	previewURL=self.location+'#'+searchString;
	win = window.open(previewURL, 'popup', printPreviewWin);
}
function styleWizard() {
	var urlString = document.URL;
	var url_check = urlString.indexOf(searchString);
	if ( url_check != -1 ) {
		for (i=0;i<document.styleSheets.length;i++){
			document.styleSheets[i].disabled=true;
		}
		loadPrintCss("/Style%20Library/css/OnlineBillPay/OBP_Print.css");
		loadPrintCss("/Style%20Library/css/OnlineMembership/OLM_Print.css");
	}
}

function loadPrintCss(filename){
  	var fileref=document.createElement("link");
  	fileref.setAttribute("rel", "stylesheet");
  	fileref.setAttribute("type", "text/css");
  	fileref.setAttribute("href", filename);

	if (typeof fileref!="undefined")
 	 document.getElementsByTagName("head")[0].appendChild(fileref);
}
// End Print Preview 

function autoTab(el,cID){
    if (el.value.length < el.getAttribute('maxlength')) return;
    var c = document.getElementById(cID).getElementsByTagName('input');
    
    if(c==null) return;
    for(i=0; i < c.length; i++) {
        
        var curEl = c[i];
        var nextEl = null;
        if(el==curEl) nextEl = c[i+1];
            
        if(nextEl!=null) {
           nextEl.focus(); // focus regardless of the focus state of next el
        }
    }
}

function getNumTasks(o){
    var cells = document.getElementById(o).getElementsByTagName('td');
    
    // default master page: 720px This will need to change when the final masterpage is implemented
    var cellWidth = 720 / cells.length;
    for (var i=0; i<cells.length;i++ ){
        cells[i].width = cellWidth;
        // fix for IE ignoring CSS styling on disabled anchor tags
        switch(cells[i].className){
            case 'current': cells[i].getElementsByTagName('a')[0].disabled=0;
                            break;
            case 'inactive': cells[i].getElementsByTagName('a')[0].disabled=0;
                             cells[i].getElementsByTagName('a')[0].style.cursor = 'default';
                             break;
        }
    }
}
function taskbarHover(o, e){
    if (!e) var e = window.event;
    var cell = o.parentNode;
    if(cell.className == 'active'){
        if(e.type == 'mouseover'){
            cell.style.borderBottom = '2px solid #9cb207';
        }else{
            cell.style.borderBottom = '2px solid #003466';
        }
    }
}

function clr(o) 
{
    if(o==null) return;
    if(o.value==arguments[1]){
        o.value='';
    }
    //o.style.color="#333";
}

function unfocus(o){
	if(o.value==''){ 
	    o.value=arguments[1];
	    //o.style.color="#999";
	}
}
function getFAQ(x, y, z){

	//x: named anchor
	//y: site varitation
	//z: page/section paramemter

	var targetURL;
	var winWidth = 500;
	switch(z){
	case "Privacy" : targetURL = "/"+y+"/about/pages/privacy.aspx";
		winWidth = 900;
		break;
	case "Security" : targetURL = "/"+y+"/information/privacy/";
		break;
	case "OLM" : targetURL = "/"+y+"/information/faq/pages/online-membership.aspx#"+x;
		break;
	case "OBP" : targetURL = "/"+y+"/information/faq/pages/online-bill-pay.aspx#"+x;
		break;
	case "OLQ" : targetURL = "/"+y+"/information/faq/pages/online-quote.aspx#"+x;
		break;
	case "OLQ_Auto" : targetURL = "/"+y+"/information/faq/pages/online-quote-auto.aspx#"+x;
		break;
	case "OLQ_Home" : targetURL = "/"+y+"/information/faq/pages/online-quote-home.aspx#"+x;
		break;
	}
    win = window.open(targetURL, 'popup', 'height=700,width='+winWidth+',scrollbars=yes,location=no,menubar=no,resizable=yes');
	win.focus();
}

function hideRows(x){
    var tblBenefits = document.getElementById('planFeatures');
    var tblBenefitDisclaimer = document.getElementById('memTableDisclaimer');
    if(x == "Driving Resources"){
    	tblBenefits.className = tblBenefits.className + " LOBDrivingResources"
    }
    if(x != "OLM"){
    	tblBenefitDisclaimer.className = tblBenefitDisclaimer.className + " showDisclaim";
    }
}

function setIQQSummaryTitle(x){
	var titleContainer = document.getElementById("summaryTitleIDIQQ");
	var newTitle = "Owners";
	if(titleContainer != null){
		switch(x){
			case "REOwnerInfo" : newTitle = "Tenants";
		}
		titleContainer.innerHTML = newTitle;
	}
}
function homeIQQCurrentStep(x){
	switch(x){
		case "HOConfirmationInfo" : 
			document.getElementById("HOConfirmationInfo4").className="current";
			break;
		case "HOCoverageDiscountInfo" : 
			document.getElementById("HOCoverageDiscountInfo3").className="current";
			break;
		case "HOPropertyInfo" : 
			document.getElementById("HOPropertyInfo2").className="current";
			break;
		case "HOOwnerInfo" : 
			document.getElementById("HOOwnerInfo1").className="current";
			break;
		case "COConfirmationInfo" : 
			document.getElementById("COConfirmationInfo4").className="current";
			setDinHeader('Condo');
			break;
		case "COCoverageDiscountInfo" : 
			document.getElementById("COCoverageDiscountInfo3").className="current";
			setDinHeader('Condo');
			break;
		case "COPropertyInfo" : 
			document.getElementById("COPropertyInfo2").className="current";
			setDinHeader('Condo');
			break;
		case "COOwnerInfo" : 
			document.getElementById("COOwnerInfo1").className="current";
			setDinHeader('Condo');
			break;
		case "REConfirmationInfo" : 
			document.getElementById("REConfirmationInfo4").className="current";
			setDinHeader('Renters');
			break;
		case "RECoverageDiscountInfo" : 
			document.getElementById("RECoverageDiscountInfo3").className="current";
			setDinHeader('Renters');
			break;
		case "REPropertyInfo" : 
			document.getElementById("REPropertyInfo2").className="current";
			setDinHeader('Renters');
			break;
		case "REOwnerInfo" : 
			document.getElementById("REOwnerInfo1").className="current";
			setDinHeader('Renters');
			break;
	}
}
function autoIQQCurrentStep(x){
	var cells = document.getElementById("processNav").getElementsByTagName('td');
	if(cells.length == 5){
	    document.getElementById(x+"5").getElementsByTagName("span")[0].innerHTML = "4";
	    document.getElementById(x+"6").getElementsByTagName("span")[0].innerHTML = "5";
	}
	switch(x){
		case "Driver" : 
			document.getElementById("Driver3").className="current";
			break;
		case "Vehicle" : 
			document.getElementById("Vehicle2").className="current";
			break;
		case "GeneralInfo" : 
			document.getElementById("GeneralInfo1").className="current";
			break;
		case "Assignments" : 
			document.getElementById("Assignments4").className="current";
			break;
		case "Coverages" : 
			document.getElementById("Coverages5").className="current";
			break;
		case "Confirmation" : 
			document.getElementById("Confirmation6").className="current";
			break;
	}
}
function setDinHeader(x){
    //alert(x);
    var theDin = document.getElementById("ctl00_PlaceHolderMain_ctl01__ControlWrapper_RichImageField").getElementsByTagName("img")[0];
    if(theDin == null) return;
    switch(x){
        case "Condo" :
            theDin.src = "/SiteCollectionImages/titles/page-headers/GetInsurance/header_getinsurance_getcondoquote_136x22.png";
            break;
        case "Renters" :
            theDin.src = "/SiteCollectionImages/titles/page-headers/GetInsurance/header_getinsurance_getrentersquote_150x22.png";
            break;
    }
}
function hidePxlTag(){
	// Just incase we need to hide a pxl tag on the front end
    var imageArray = document.getElementsByTagName("img");
    for(i=0;i<imageArray.length;i++){
        if(imageArray[i].src.indexOf("convergetrack.com")>0){
            //imageArray[i].style.display="none"; 
            //alert('found one');
        }
    }
}
function isIE(){
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
