/**
 *
 * AXASPACE Scripts
 *
 */

// Preload images
var imgPreLoad = "/images/nav-home-over.jpg,/images/nav-home-on.jpg,/images/nav-about-us-over.jpg,/images/nav-about-us-on.jpg,/images/nav-how-it-works-over.jpg,/images/nav-how-it-works-on.jpg,/images/nav-learning-center-over.jpg,/images/nav-learning-center-on.jpg,/images/nav-contact-us-over.jpg,/images/nav-contact-us-on.jpg".split(",");
var tempImg = [];
for (var imgInc=0; imgInc<imgPreLoad.length; imgInc++) {
	tempImg[imgInc] = new Image();
	tempImg[imgInc].src = imgPreLoad[imgInc];
}
 
// Trim White Space 
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

 
 
// CSS Modification Functions 
function getCSSRule(ruleName,deleteFlag){ruleName=ruleName.toLowerCase();if(document.styleSheets){for(var i=0;i<document.styleSheets.length;i++){var styleSheet=document.styleSheets[i];var ii=0;var cssRule=false;do{if(styleSheet.cssRules){cssRule=styleSheet.cssRules[ii]}else{cssRule=styleSheet.rules[ii]}if(cssRule){if(cssRule.selectorText.toLowerCase()==ruleName){if(deleteFlag=='delete'){if(styleSheet.cssRules){styleSheet.deleteRule(ii)}else{styleSheet.removeRule(ii)}return true}else{return cssRule}}}ii++}while(cssRule)}}return false}function killCSSRule(ruleName){return getCSSRule(ruleName,'delete')}function addCSSRule(ruleName){if(document.styleSheets){if(!getCSSRule(ruleName)){if(document.styleSheets[0].addRule){document.styleSheets[0].addRule(ruleName,null,0)}else{document.styleSheets[0].insertRule(ruleName+' { }',0)}}}return getCSSRule(ruleName)}

// Hide dependent form groups and health conditions matrix
var hideConditions = addCSSRule("#healthProfileConditions");
var hideDependents = addCSSRule(".dependentForm");
hideConditions.style.display = "none";
hideDependents.style.display = "none";

// Make Pop Ups
function makePopUp(whereTo,winWidth,winHeight) {
	var remote=window.open("","remotewin","width="+winWidth+",height="+winHeight+",menubar=0,toolbar=no,scrollbars=yes");
	remote.location.href=whereTo;
	remote.focus();
	return false;
}



// Pop Info
var popElem;
var popTimer;
var popInfo = function() {
	var content;
	var selectElemOverlay = false;
	var addLoadEvent = function(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
			
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			};
		}
	};
	var addInfoPops = function () {
		for(var i=0; i<content.length; i++) {
			var popUp = document.createElement("div");
			var popUpContent ="";
			popUp.className = "popUp";
			popUp.style.display = "none";
			popUp.id = content[i].target + "_popUp";
			if(content[i].title!="") {
				popUpContent = "<h2>"+content[i].title+"</h2>"
			}
			popUpContent += content[i].content;
			popUp.innerHTML = popUpContent;
			document.body.appendChild(popUp);
			if(document.getElementById(content[i].target)) {
				document.getElementById(content[i].target).onmouseover = showPop;
				document.getElementById(content[i].target).onmouseout = hidePop;
				popUp.onmouseover = continuePop;
				popUp.onmouseout = hidePopInfo;
			}
			
		}
	};
	// Binding for showing the InfoPop
	var showPop = function() {
		addSelectElemOverlay();
		this.alt="";
		this.style.cursor="help";
		showPopInfo(document.getElementById(this.id+"_popUp"), this);
		(document.body.scrollWidth);
	};
	// Binding for hiding the InfoPop
	var hidePop = function() {
		hidePopInfo(document.getElementById(this.id+"_popUp"));
	};
	
	// Shows the InfoPop
	var showPopInfo = function(element, target) {
		if(popElem&&popTimer) {
			if(popElem!=element) {
				clearTimeout(popTimer);
				if(popElem) {
					popElem.style.display = "none";
				}
			}
			else if(popElem==element) {
				clearTimeout(popTimer);
			}
		}
		popElem = element;
		element.style.display ="block";
		var x = getAbsolutePosition(target).x + 12;
		if(document.body.scrollWidth<=x+330) {
			x = document.body.scrollWidth - 330;
		}
		element.style.top = getAbsolutePosition(target).y + target.offsetHeight + "px";
		element.style.left = x + "px";
	};
	
	// Hides the InfoPop
	var hidePopInfo = function() {
		popTimer = setTimeout(terminatePop, 500);
	};
	var terminatePop = function() {
		toggleIframeDisplay("none");
		if(popElem) {
			popElem.style.display = "none";
		}
	};
	// Cancel the Pop Timer
	var continuePop = function(element) {
		this.style.cursor="help";
		clearTimeout(popTimer);
	};
	
	/* Determine the absolute position for an element on the page*/
	var getAbsolutePosition = function(element) {
		var r = { x: element.offsetLeft, y: element.offsetTop };
		if (element.offsetParent) {
			var tmp = getAbsolutePosition(element.offsetParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	};
	/* Add iframes over the select elements in IE 6*/
	var addSelectElemOverlay = function() {
		if(checkForInternetExplorer()&&!selectElemOverlay) {
			selectElemOverlay = true;
			var selectElems = document.getElementsByTagName("select");
			for(var i=0; i<selectElems.length; i++) {
				var iframeElem = document.createElement("iframe");
				iframeElem.className = "selectElemOverlay";
				iframeElem.style.width = selectElems[i].offsetWidth + "px";
				iframeElem.style.height = selectElems[i].offsetHeight +  "px";
				iframeElem.style.left = getAbsolutePosition(selectElems[i]).x;
				iframeElem.style.top = getAbsolutePosition(selectElems[i]).y;
				document.body.appendChild(iframeElem);
			}
		}
		else if(checkForInternetExplorer()) 
		{
			toggleIframeDisplay("block");
		}
	};
	var toggleIframeDisplay = function (displayMode) {
		var selectElems = document.getElementsByTagName("iframe");
		for(var i=0; i<selectElems.length; i++) {
			if(selectElems[i].className == "selectElemOverlay") {
				selectElems[i].style.display = displayMode;
			}
		}
	};
	
	/* Check for older versions of Internet Explorer */
	var checkForInternetExplorer = function() {
		if(navigator.appVersion.indexOf("MSIE")!=-1) {
			return  parseFloat(navigator.appVersion.split("MSIE")[1])<=6 ? true : false;
		}
		else {
			return  false;
		}
	};
	return {
		add: function(input) {
			content = input;
			addLoadEvent(addInfoPops);
		}
	}
}();







var popInfoContent = [
	{target: "healthProfileQuestion", title: "Why do we need this info?", content: "<p>This information is used to provide you with an accurate insurance quote. Your insurance premium is based on a number of factors, including your height and weight, your age, and your overall health status.</p>"},
	{target: "aboutYouQuestion", title: "Why do we need this info?", content: "<p>This information is used to show you quotes for health plans available where you live. It is also used to match you with licensed agents who will contact you with free, personalized quotes.</p>"},
	{target: "secureForm", title: "", content: "<p>The information you provide using this form will be sent to our secure servers using Secure Sockets Layer (SSL) encryption to protect your privacy.</p>"},
	{target: "healthConditionsQuestion", title: "", content: "<p>Have you been diagnosed or treated for any of the following health conditions?</p>"},
	{target: "bcbsInfo", title: "", content: "<p>Blue Cross Blue Shield of AZ</p><p>Blue Cross of CA</p> <p>Blue Shield of CA </p> <p>Anthem Blue Cross Blue Shield CO </p> <p>Anthem Blue Cross Blue Shield CT </p> <p>Blue Cross Blue Shield of GA </p> <p>Blue Cross of ID </p> <p>Blue Cross Blue Shield of IL </p> <p>Anthem Blue Cross Blue Shield IN </p> <p>Anthem Blue Cross Blue Shield KY </p> <p>Blue Cross Blue Shield of LA </p> <p>Blue Cross Blue Shield of MI </p> <p>Anthem Blue Cross Blue Shield MO </p> <p>Blue Cross Blue Shield of NM </p> <p>Anthem Blue Cross Blue Shield NV </p> <p>Anthem Blue Cross Blue Shield OH </p> <p>Blue Cross Blue Shield of TN </p> <p>Blue Cross Blue Shield of TX </p> <p>Anthem Blue Cross Blue Shield VA </p> <p>Anthem Blue Cross Blue Shield WI </p>"}
];
popInfo.add(popInfoContent);


