//Common Javascript Code 
//new js
var lwdivids=new Array('div_lw_addon','div_lw_productcomparison','div_lw_alert','div_lw_emailquote','div_lw_security','div_lw_appprocesschart','div_lw_contact','div_lw_needlife','div_lw_viewbrochure','div_lw_aboutprovider','div_lw_policysummary','div_lw_disclaimer','div_lw_specialoffer','div_lw_subscribenl','div_lw_tvad');
var timetoanimate1=1000;
var timetoanimate2=500;
var numberlwindows=0;
var isanimating=false;
var iscallingback=false;
var calcwindow=null;
var partnerwindow=null;
var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}
function checkIEImage(){
	if(Browser.Version()<7){
		var elem=null;
		//div bg images
		for(var i=1;i<20;i++){
			elem=document.getElementById('ie_pngimage'+i);
			if(elem)
				elem.style.backgroundImage=elem.style.backgroundImage.replace(/\.png/,'.gif');
		}
		//img element
		for(var i=101;i<120;i++){
			elem=document.getElementById('ie_pngimage'+i);
			if(elem)
				elem.src=elem.src.replace(/\.png/,'.gif');
		}
		//td bg images
		var tds = document.getElementsByTagName('td');
		for (var i=0;i<tds.length;i++){
			var bgimg=tds[i].style.backgroundImage;
			if(bgimg.indexOf(".png")>=0&&(bgimg.indexOf("images/lw_")>=0||bgimg.indexOf("images/addon_")>=0)){
				tds[i].style.backgroundImage=bgimg.replace(/\.png/,'.gif');
			}
		}
		//health addon element
		for(var i=1;i<4;i++){
			elem=document.getElementById('div_addon'+i);
			if(elem)
				elem.style.backgroundImage=elem.style.backgroundImage.replace(/\.png/,'.gif');
		}
	}
}
document.onkeydown=checkKeycode;
function checkKeycode(e){
	var keycode;
	if(window.event) 
		keycode=window.event.keyCode;
	else if(e) 
		keycode=e.which;
	if(keycode==13){
		if(document.getElementById('div_lw_alert'))
			closePopUp('div_lw_alert');
		else
			void(0);
	}
}
function isValidEmail(string) {
	return (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);
}
function loadimages(webpath){
	if(document.images){
		var img1= new Image();
		var img2= new Image();
		img1.src=webpath+'images/build_addon_selectbg_selected.jpg';
		img2.src=webpath+'images/build_addon_selected.png';
		
		/*img4.src=webpath+'images/calc_hover.png';
		img5.src=webpath+'images/addsign_hover.png';
		img6.src=webpath+'images/backbtn_hover.png';
		img7.src=webpath+'images/nextbtn_hover.png';
		img8.src=webpath+'images/emailquote_hover.png';
		img9.src=webpath+'images/PolicyComparison_hover.png';
		img10.src=webpath+'images/btnmenu0.png';
		img13.src=webpath+'images/healthtab_selected.jpg';
		img14.src=webpath+'images/lifetab.jpg';
		img15.src=webpath+'images/liveonlinehelp_hover.jpg';
		img16.src=webpath+'images/tick_hover.png';
		img17.src=webpath+'images/cross_hover.png';
		img18.src=webpath+'images/topmenuitem_sub_center.png';
		img19.src=webpath+'images/btnApply_hover.png';
		img20.src=webpath+'images/btnmenu1_active.png';
		img21.src=webpath+'images/btnmenu1_health.png';
		img22.src=webpath+'images/btnmenu1_health_active.png';
		img23.src=webpath+'images/btnmenu2_active.png';
		img24.src=webpath+'images/btnmenu3_active.png';
		img25.src=webpath+'images/btnmenu4_active.png';
		img26.src=webpath+'images/detailedcomparison_hover.png';
		img27.src=webpath+'images/qmarkover_bottom.png';
		img28.src=webpath+'images/qmarkover_bottom2.png';
		img29.src=webpath+'images/qmarkover_middle.png';
		img30.src=webpath+'images/qmarkover_middle2.png';
		img31.src=webpath+'images/qmarkover_top.png';
		img32.src=webpath+'images/qmarkover_top2.png';
		img33.src=webpath+'images/topmenuitem_sub_bottom.png';*/
	}
}
//----------query string method start------------
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 '';
}
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){
var page = new PageQuery(window.location.search);
return unescape(page.getValue(key));
}
//----------query string method end------------
function AddFieldValue(FieldName, FieldValue){
	var clientInput = '';
	clientInput = '<ClientDetail>';
	clientInput = clientInput + '<FieldName>';
	clientInput = clientInput + FieldName;
	clientInput = clientInput + '</FieldName>';
	clientInput = clientInput + '<FieldValue>';
	clientInput = clientInput + FieldValue;
	clientInput = clientInput + '</FieldValue>';
	clientInput = clientInput + '</ClientDetail>';
	return clientInput;
}
function alertNew(msg){
	showPopUp('div_lw_alert');
	document.getElementById('div_alertmessage').innerHTML=msg;
}
function ShowMyDiv(div_id) {
	var elem=document.getElementById(div_id);
	if(elem)
		elem.style.display = 'block';
}
function HideMyDiv(div_id) {
	var elem=document.getElementById(div_id);
	if(elem)
		elem.style.display = 'none';
}
function ShowHideDiv(div_id){
	var elem=document.getElementById(div_id);
	if(elem){
		if(elem.style.display=='block')
			elem.style.display='none';
		else
			elem.style.display='block';
	}
}
var viewportwidth = getWindowWidth();
var viewportheight = getWindowHeight();
function getWindowWidth(){
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if(typeof window.innerWidth != 'undefined'){
		return window.innerWidth;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if(typeof document.documentElement!='undefined'&&typeof document.documentElement.clientWidth!='undefined' && document.documentElement.clientWidth!=0){
		return document.documentElement.clientWidth;
	}
	// older versions of IE
	else{
		return document.getElementsByTagName('body')[0].clientWidth;
	}
}
function getWindowHeight(){
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if(typeof window.innerWidth != 'undefined'){
		return window.innerHeight;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if(typeof document.documentElement!='undefined'&&typeof document.documentElement.clientWidth!='undefined' && document.documentElement.clientWidth!=0){
		return document.documentElement.clientHeight;
	}
	// older versions of IE
	else{
		return document.getElementsByTagName('body')[0].clientHeight;
	}
}
function closePopUp(elemid) {
	var cvr = document.getElementById("cover");
	var lw = document.getElementById(elemid);
	if(lw){
		lw.style.display = "none";
		numberlwindows=numberlwindows-1;
	}
	if(cvr&&!hasPopUp()){
		cvr.style.display = "none";
		document.getElementById('iframe_cover').style.display = "none";
		//document.body.style.overflow='auto';
		document.documentElement.style.overflow="auto";
	}
}
function isdisplayblock(id){
	var elem=document.getElementById(id);
	if(elem)
		if(elem.style.display=='block')
			return true;
	return false;
}
function hasPopUp(){
	for(var i=0;i<lwdivids.length;i++){
		if(isdisplayblock(lwdivids[i]))
			return true;
	}
	return false;
}
function closePopUpAll(){
	for(var i=0;i<lwdivids.length;i++){
		closePopUp(lwdivids[i]);
	}
	numberlwindows=0;
}
function showPopUp(elemid) {
	var cvr = document.getElementById("cover");
	var lw = document.getElementById(elemid);
	if(cvr){
		cvr.style.display = "block";
		cvr.style.height = "100%";
		cvr.style.width = "100%";
		cvr.style.overflow="hidden";
		document.getElementById('iframe_cover').style.display = "block";
		//document.body.style.overflow='hidden';
		document.documentElement.style.overflow="hidden";
	}
	if(lw){
		numberlwindows=numberlwindows+1;
		lw.style.display = "block";
		var leftval = Math.max((viewportwidth-lw.offsetWidth)/2-25,0)+numberlwindows*10;
		if(leftval<0) leftval=0;
		lw.style.left = String(leftval)+"px";
		lw.style.top = String(Math.max((viewportheight-lw.offsetHeight)/2-25,0)+numberlwindows*10)+"px";
		scroll(0,0);
	}
}
function GetOpacity(divid){
	var elem=document.getElementById(divid)
	var flt=elem.style.filter;
	if(flt){
		var alp=flt.alpha;
		if(alp){
			if(alp.opacity){
				return Math.round(parseFloat(alp.opacity));
			}
		}
	}
	if(elem.style.opacity)
		return Math.round(parseFloat(elem.style.opacity)*100);
	if(elem.style.mozOpacity)
		return Math.round(parseFloat(elem.style.mozOpacity)*100);
	if(elem.style.khtmlOpacity)
		return Math.round(parseFloat(elem.style.khtmlOpacity)*100);
	return 100;
}
function showProductComparisonWindow(producttypeid){
	showPopUp('div_lw_productcomparison');
	var clientInput = '<ResultSet>';
	clientInput += AddFieldValue('ProductTypeID',producttypeid);
	clientInput += '</ResultSet>';
	pageShowProductComparison_MainCB.Callback(clientInput);
}
function showViewBrochureWindow(producttypeid,providerid){
	showPopUp('div_lw_viewbrochure');
	var clientInput = '<ResultSet>';
	clientInput += AddFieldValue('ProductTypeID',producttypeid);
	clientInput += AddFieldValue('ProviderID',providerid);
	clientInput += '</ResultSet>';
	pageShowViewBrochure_MainCB.Callback(clientInput);
}
function showAboutProviderWindow(providerid){
	showPopUp('div_lw_aboutprovider');
	var clientInput = '<ResultSet>';
	clientInput += AddFieldValue('ProviderID',providerid);
	clientInput += '</ResultSet>';
	pageShowAboutProvider_MainCB.Callback(clientInput);
}
function showPolicySummaryWindow(producttypeid,providerid){
	showPopUp('div_lw_policysummary');
	var clientInput = '<ResultSet>';
	clientInput += AddFieldValue('ProductTypeID',producttypeid);
	clientInput += AddFieldValue('ProviderID',providerid);
	clientInput += '</ResultSet>';
	pageShowPolicySummary_MainCB.Callback(clientInput);
}
function setupMenu(){
	document.getElementById('div_quotemenu').className='topmenuitem0';
	document.getElementById('div_lifemenu').className='topmenuitem1';
	document.getElementById('div_healthmenu').className='topmenuitem1_health';
	document.getElementById('div_insurermenu').className='topmenuitem2';
	document.getElementById('div_insurermenu_health').className='topmenuitem2';
	document.getElementById('div_servicemenu').className='topmenuitem3';
	document.getElementById('div_servicemenu_health').className='topmenuitem3';
	var pagename=String(window.location.pathname);
	var isHealth=false;
	if(pagename.indexOf('life-insurance')>=0)
		document.getElementById('div_lifemenu').className='topmenuitem1_active';
	else if(pagename.indexOf('health-insurance')>=0){
		document.getElementById('div_healthmenu').className='topmenuitem1_health_active';
		isHealth=true;
	}
	else if(pagename.indexOf('our-insurers')>=0){
		document.getElementById('div_insurermenu').className='topmenuitem2_active';
		document.getElementById('div_insurermenu_health').className='topmenuitem2_active';
	}
	else if(pagename.indexOf('our-service')>=0){
		document.getElementById('div_servicemenu').className='topmenuitem3_active';
		document.getElementById('div_servicemenu_health').className='topmenuitem3_active';
	}
	else
		document.getElementById('div_quotemenu').className='topmenuitem0_active';
	if(queryString('product')=='health'||isHealth)
		switchHealth(null,1);
	else
		switchLife(null,1);
}
function chkStartQuoteBtn(stepid){
	if(stepid==1)
		document.getElementById('div_quotemenu').className='topmenuitem0_active';
	else
		document.getElementById('div_quotemenu').className='topmenuitem0';
}
function showSpecialOfferWindow(product){
	showPopUp('div_lw_specialoffer');
	var clientInput = '<ResultSet>';
	clientInput += AddFieldValue('Product',product);
	clientInput += '</ResultSet>';
	pageShowSpecialOffer_MainCB.Callback(clientInput);
}
function opencalc(url,isaddon){
	var errorMsg = '';
	var psmoker=0;
	var pgender=0;
	var page=0;
	var smoker=0;
	var gender=0;
	var age=0;
	var idstr='';
	var addqstr='';
	if(isaddon==true) //health page, life addon, use health fields
		idstr='_Health';
	if(document.getElementById("div_quote")){
		if(document.getElementById("optSmoker_Partner"+idstr+"_0").checked)
			psmoker=1;
		else if(document.getElementById("optSmoker_Partner"+idstr+"_1").checked)
			psmoker=2;
		if(document.getElementById("optGender_Partner"+idstr+"_0").checked)
			pgender=1;
		else if(document.getElementById("optGender_Partner"+idstr+"_1").checked)
			pgender=2;
		page=document.getElementById("optAge_Partner"+idstr).value;
		if(page=='') page='0';
		if(String(page)=='0'&&isaddon==true)
			addqstr='&noperson2=1';
		if(document.getElementById("chkPartner"+idstr).checked==true){
			if(psmoker==0)
				errorMsg='Please enter partner\'s Smoker Status.';
			if(pgender==0)
				errorMsg='Please enter partner\'s Gender.';
			if(page=='0')
				errorMsg='Please enter partner\'s Age.';
		}
		if(document.getElementById("optSmoker"+idstr+"_0").checked)
			smoker=1;
		else if(document.getElementById("optSmoker"+idstr+"_1").checked)
			smoker=2;
		if(document.getElementById("optGender"+idstr+"_0").checked)
			gender=1;
		else if(document.getElementById("optGender"+idstr+"_1").checked)
			gender=2;
		age=document.getElementById("optAge"+idstr).value;
		if(age=='') age='0';
		if(smoker==0)
			errorMsg='Please enter your Smoker Status.';
		if(gender==0)
			errorMsg='Please enter your Gender.';
		if(age=='0')
			errorMsg='Please enter your Age.';
		if(errorMsg!=''){
			alertNew(errorMsg);
			return;
		}
	}
	calcwindow=window.open(url+'?age='+age+'&gender='+gender+'&smoker='+smoker+'&page='+page+'&pgender='+pgender+'&psmoker='+psmoker+addqstr,'_newwin','width=980,height=650,toolbar=0,status=0');
}
function subscribeNewsletter(){
	var emailadd=document.getElementById("pageSitemap_pageShowSubscribeNL_txtEmailAddress").value.replace(/ /g,'');
	var name=document.getElementById("pageSitemap_pageShowSubscribeNL_txtName").value.replace(/\&/g,'and').replace(/\'/g,'&prime;');
	if(emailadd==''){alertNew('Please enter an email address');return;}
	if(!isValidEmail(emailadd)){alertNew('Please enter a valid email address');return;}
	if(name==''){alertNew('Please enter your name');return;}
	var clientInput = '<ResultSet>';
	clientInput += AddFieldValue('Name',name);
	clientInput += AddFieldValue('EmailAddress',emailadd);
	clientInput += '</ResultSet>';
	pageSitemap_pageShowSubscribeNL_MainCB.Callback(clientInput);
}


//old js
function fn_copy(objFrom, objTo){
	document.getElementById(objTo).value = document.getElementById(objFrom).value;
}
function ShowDiv(div_id, option_name) {
	if (document.getElementById(option_name).checked == true){
		document.getElementById(div_id).style.display = 'block';
	}
	else{
		document.getElementById(div_id).style.display = 'None';
	}
}
function setCookie(c_name,value,expiredays){
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
function CngBG(obj,nc){
	obj.nc=obj.className;
	obj.className=nc;
}
function popUp(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + "');");
}
