var menubgcolor='#C18429'
var dd_menuwidth='243px' //default menu width
var dd_menuwidth2='300px' //width specific for GI Life

/****** === MUST INCLUDE THE BELOW CODE === ******
Insert 1 of these document.write lines for EACH separate menu style required 
for the site created on the .CSS file.  Ensure that the ID tag for each is unique.
******/
var ie4=document.all
var ns6=document.getElementById&&!document.all
if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+dd_menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')



//Contents for menu 1
var menu1=new Array()
var menuloc1=new Array(0,0)

if (lang=="E") {
	menu1[0]='<a href="/Can/affinity/affinity.nsf/public/cml">Term Life</a>'
	menu1[1]='<a href="/Can/affinity/affinity.nsf/public/cml_fml">FollowMe Life</a>'
	menu1[2]='<a href="/Can/affinity/affinity.nsf/public/cml_gilife">Guaranteed Issue</a>'
} else {
	menu1[0]='<a href="/Can/affinity/affinity.nsf/public/f_cml">Assurance-vie temporaire</a>'
	menu1[1]='<a href="/Can/affinity/affinity.nsf/public/f_cml_fml">Emporte-moi Assurance-vie</a>'
}


//===== Marketing cookie code =====//
function getQueryString(variable) {
  var query = window.location.search.substring(1);
  query = query.toLowerCase();
  variable = variable.toLowerCase();
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}
function setMktPath(){
  var expires = new Date();
  expires.setTime (expires.getTime() + 1000 * 60 * 60 * 24 * 90); //set expiry date 90 days in the future
  var expiryDate = expires.toGMTString();
  var path = "/";  
  var mpath = getQueryString("mpath");
  if (mpath){
      document.cookie='%mpath=' + mpath + '%; path=' + path + '; expires=' + expiryDate; 
  } else {
     //-- SP(30-Mar-06): Add further check for "mkt=", in the event the user followed an e-mail campaign 
     //-- link that does not use a redirection url.
     var mkt = getQueryString("mkt");
     if (mkt){
        document.cookie='%mkt=' + mkt + '%; path=' + path + '; expires=' + expiryDate; 
     } 
  }
}
setMktPath();


//===== Miscellaneous Functions =====//
function openWindow( url, winWidth, winHeight, winName, openFullWindow) {
	var winTop = (screen.height / 2) - (winHeight / 2);
	var winLeft = (screen.width / 2) - (winWidth / 2);
	var winNM = winName? winName:"win";
	if ( openFullWindow && openFullWindow !="") {
		winFeatures = "";
	} else {
		winFeatures ="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=" + winLeft + ",top=" + winTop + ",width=" + winWidth + ",height=" + winHeight;
	}       
	win = window.open(url, winNM, winFeatures);
	win.focus();
}

function getPageInfo(op){
	try { 
		var rtn	
		switch (op) {
		case "asso":
			rtn = associationName;
			break;
		case "assoS":
			rtn = associationNameS;
			break;
		case "lang":
			rtn = lang;
			break;
		case "pageId":
			rtn = pageId;
			break;
		case "pageType":
			rtn = pagetype;
			break;
		case "prdType":
			rtn = prdType;
			break;
		default:
			rtn = eval(op);
			break;
		}
		return rtn;	
	} catch (e) { return '' }
}
function cLang(langCode){ //--- change lang
	var EWDB = 'affinity.nsf';
//1. get current page info : path, pagename, type and langCode
	var curURL = window.location.href;
	
	//-FIX FOR '&MPATH='.  If this parameters is contained in the query string, then remove it
	//-prior to flipping the language...
	var pos_mpath = curURL.toLowerCase().indexOf("&mpath=");
	if (pos_mpath != -1){
		// Extract everything BEFORE and AFTER the mpath part....
		var mpath = curURL.substring(pos_mpath + 1, curURL.length);
		var mpathBegin = curURL.substring(0, pos_mpath);

		var mpathEnd = "";
		var pos_mpathEnd = mpath.indexOf("&");
		
		if (pos_mpathEnd != -1){
			mpathEnd = mpath.substring(pos_mpathEnd, mpath.length);
		}
		
		curURL = mpathBegin + mpathEnd
	}
	//-END OF FIX FOR &MPATH=
	
	var p
	p = curURL.lastIndexOf('/');
	var curPath = curURL.substring(0, p);
	var curType = (curPath.toLowerCase().indexOf(EWDB)>0)? 'EW':'Form';
	var curPageReq = curURL.substring(p+1, curURL.length);
	p = curPageReq.indexOf('?');
	var curPage = (p>=0)? curPageReq.substring(0, p):curPageReq;
	var curReq = (p>=0)? curPageReq.substring(p+1, curPageReq.length): (curType=='EW')?'':'Open';
	var curLang, formLangP;
	var curAnchor='';
	switch (curType) {
	case 'EW':
		p = curPage.indexOf('#');
		if (p>=0) {
			curAnchor = curPage.substring(p, curPage.length);
			curPage = curPage.substring(0,p);
		}
		curLang = curPage.substring(0, 2)
		curLang = (curLang.toLowerCase() == 'f_')? 'F':'E';
		break;
	case 'Form':
		formLangP = curReq.toLowerCase().indexOf('&lang=');
		if (formLangP>=0) {
			curLang = curReq.substring(formLangP+6, formLangP+7);
			curLang = ( (curLang != 'E')&& (curLang !='F') )?'E':curLang;
		} else {			
			curLang = document.forms[0].lang.value;
		}
		break;
	}
//2. change page lang
	if (!langCode) langCode = (curLang=='F')?'E':'F';
	if (langCode == curLang) return 0; //no change
	
	switch (curType) {
	case 'EW':
		curPage = (langCode=='F')? 'f_' + curPage:curPage.substring(2, curPage.length);
		
		//----New stuff for assocation name flip: Start ----
		// Attemp to get as code from query string first, otherwise use default assoCode....
		var qAsso = getQueryString("as");
		if (qAsso==null | qAsso==""){
			curAsso = associationName;
		} else {
		   curAsso = qAsso;
		}
		
		if (langCode=="E"){
		   if (curAsso.substring(0,2)=="f_"){
		      curAsso = curAsso.substring(2,curAsso.length);
		   }
		} else {
		   if (curAsso.substring(0,2) != "f_"){
		      curAsso = "f_" + curAsso
		   }
		}
		
		curReq = "open&as=" + curAsso;
		//----New stuff for assocation name flip: End ----
		
		break;
	case 'Form':

		//-- New method for handling language flip while in applications (CI, TL, GI).  If on the first 
		//-- page of the application process, then allow to flip back n' forth between languages.  However,
		//-- once the application process has been started (QueryString contains 'ParentUNID'), then reroute
		//-- back to site's homepage and flip language.
		curAsso = associationName;
		curPage = curAsso;
	
		if (langCode=="E"){
		   if (curAsso.substring(0,2)=="f_"){
		      curAsso = curAsso.substring(2,curAsso.length);
		      curPage = curAsso;
		   }
		} else {
		   if (curAsso.substring(0,2) != "f_"){
		      curAsso = "f_" + curAsso;
		      curPage = curAsso;
		   }
		}
		

		//==Start of DSP12-Jul-06: New coding for lanugage flip in applications....
		var flipType = ((curURL.toLowerCase().indexOf("parentunid")>0) | (curURL.toLowerCase().indexOf("/apply/")>0))? 'home':'flip';
        if (flipType=='flip'){
        	//-- First page of any automated form -- it's OK to flip language here.  Remove the as= from 
        	//-- the query string.  
        	var pos = curURL.toLowerCase().indexOf("&as=");
        	if (pos != -1){
        		var qsBegin = curURL.substring(0, pos);
        		var qsAsso = curURL.substring(pos+1, curURL.length);
        		var qsEnd = ""
        		pos = qsAsso.indexOf("&");
        		if (pos != -1){
        			qsEnd = qsAsso.substring(pos, qsAsso.length);
        		}
        	}
        	qsNew = qsBegin + qsEnd;
        	
        	//-- Now, extract the path, page & parms into seperate variables...
			curPath = qsNew;
        	var pos = qsNew.toLowerCase().indexOf(".nsf");
			if (pos != -1){
        		curPath = qsNew.substring(0, pos+4);
			}
			
        	var posEnd = qsNew.toLowerCase().indexOf("?");
        	var curReq = "";
        	if (posEnd != -1){
        		curReq = qsNew.substring(posEnd+1, qsNew.length);
        		//-- Remove the '#' from the end of the qs...
        		if (curReq.substring(curReq.length-1, curReq.length) == "#"){
        			curReq = curReq.substring(0, curReq.length-1);
        		}

				curPage = qsNew.substring(pos+5,posEnd);
        	}
			curReq = curReq + "&as=" + curAsso;        	

        } else {
            //--- already within application process - reroute back to home page of site...
			curPath = "/Can/affinity/affinity.nsf/Public";
			curReq = "open&as=" + curAsso;
        }
		//==end of DSP12-Jul-06: New coding for lanugage flip in applications....
		
		//break;
	}
//	alert(curPath + '\n' + curPage + '\n'+ curReq + '\n'+ curType + '\n'+ curLang);
//	alert( "New page URL:" + curPath+'/'+curPage+ ((curReq=='')? '': ('?'+curReq)) + curAnchor );
	window.location = curPath+'/'+curPage+ ((curReq=='')? '': ('?'+curReq)) + curAnchor;
}

//============ SPECIALIZED FUNCTIONS FOR "WEB LOGIC - HEALTH & DENTAL" LINKING ==============//
function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function getMktCode(){
	var mktCode = getQueryString("mkt");
	if (mktCode==null | mktCode==""){
		mktCode = Get_Cookie( "mkt" );
		if (mktCode==null | mktCode==""){
			// mktCode = defaultMktCode;
		} else {
			if (mktCode.substring(mktCode.length-1,mktCode.length)=="%"){
				mktCode = mktCode.substring(0,mktCode.length-1);
			}
		}
	}
	return mktCode;
}
function RequestBrochure(planType){
	var defaultMktCode = "";

    //-- UAT --> var hdURL = "https://devsecure.lhplans.com/LH/CoverMe/Consumer/ObtainBrochure1.jsp?module=P"
	var hdURL = "https://secure.lhplans.com/LH/CoverMe/Consumer/ObtainBrochure1.jsp?module=P"

	// Get the current URL (which will help determine planType)
	var curURL = window.location.href;
	curURL = curURL.toLowerCase();
	
	// Get the current marketing code (if any).  If none assigned, use default 'life'.
    mktCode = getMktCode();
    if (mktCode == null | mktCode == ""){
    	mktCode = defaultMktCode;
    }
    
	// If no planType was passed as a parameter, then determine the planType by examing the query string.
	// QS will contain the string '_fml' for FollowMe, or '_gilife' for GI.  Otherwise, default to LIFE.
	if (planType == null | planType==""){
    	if (curURL.indexOf("cml_fml")>-1 | curURL.indexOf("pd=fl")>-1){
			planType = "FL";
    	} else {
		    if (curURL.indexOf("cml_gilife")>-1 | curURL.indexOf("pd=gi")>-1){
		    	planType = "GL";
		    } else {
		    	planType = "LF";
		    }
    	}
    }
	
	var newURL = hdURL + "&lang=" + lang + "&planType=" + planType + "&MKT=" + mktCode.toUpperCase();
	window.location = newURL;
}
function op_Mkt( newURL ){
	defaultMktCode = "";

	var mktCode = getMktCode();
	if (mktCode==null | mktCode==""){
		mktCode = defaultMktCode;
	}

	var checkURL = newURL.toLowerCase();
	if (checkURL.indexOf(".nsf") != -1){
		if (checkURL.indexOf("?open") == -1){
			newURL = newURL + "?open"
		}
		newURL = newURL + "&mkt=" + mktCode.toUpperCase();
   } else {
   		if (checkURL.indexOf("?") == -1){
			if (checkURL.indexOf(".htm") == -1){
   				if (checkURL.substring(checkURL.length-1,checkURL.length)=="/"){
   					newURL = newURL + "?";
   				} else {
   					newURL = newURL + "/?";
   				}
   			} else {
   				newURL = newURL + "?";
   			}
   		} else {
   			newURL = newURL + "&";
   		
   		}
   		newURL = newURL + "MKT=" + mktCode.toUpperCase();
	}   

    parent.location = newURL;
}
//===========================================================================================//


//=================================== OBSOLETE FUNCTIONS ===================================//
// Provided by Delvinia but replaced by standard openWindow() function above. Keeping for now.
function showPopUp2(url, target){
	window.open(url, target,
      "titlebar=no, toolbar=no,scrollbars=yes,menubar=no,status=no,resizable=yes");
}
//==========================================================================================//
