var insideBar;
var noChangeImg;
var customerCenterLocation = "/igpinfo/clients/";
var associateInsurerLocation = "/igpinfo/associate/";
var IGPOnlyLocation = "/igpinfo/igp_only/";

var names = new Array('home','pAnds','advant','igp','country','cont');

//dim the rest of the images except the image name notThis
function dimRest(notThis) {

	for (var i = 0; i < names.length; i++) {
	
		if (notThis != names[i] && names[i] != noChangeImg) {
			img1 = eval("document." + names[i]);
			img1.src = "images/" + names[i] + "_roll.gif";
		}
	}

}


//restore the dimmed images once the mouse is out of the navbar
function restoreRest(notThis) {
	
	if (insideBar == 0) {

		for (var i = 0; i < names.length; i++) {
		
			if (notThis != names[i] && names[i] != noChangeImg) {
				img1 = eval("document." + names[i]);
				img1.src = "images/" + names[i] + "_idle.gif";
			}
	
		}
	
	}

}


function swapimgrestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function preloadimages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadimages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}


function swapimage() { //v3.0
  var i,j=0,x,a=swapimage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function processLogin() {

	var logInSelect = document.getElementById("select_login");
	var logInType = "";
	var loginLocation = "";
			
	if (logInSelect != null) {

		logInType = logInSelect.options[logInSelect.selectedIndex].value;

		if (logInType == 1) { //Client Sites
		
			if (getCookie("customer_id")) {
				loginLocation = customerCenterLocation + getCookie("customer_id") + "/index.html";
			} else {
				loginLocation = "/igpinfo/log_in.html";
			}
	
		} 			
		else if (logInType == 2 ) { //AI Client
			
			if (getCookie("customer_id")) {
				loginLocation = associateInsurerLocation + getCookie("customer_id") + "/index.html";
			} else {
				loginLocation = "/igpinfo/ai_log_in.html";
			}
			
		}
		window.location = loginLocation;
	
	}
}

function processLogin_NetworkOffice() {

	var logInSelectNO = document.getElementById("select_login");
	var logInTypeNO = "";
	var loginLocationNO = "";
			
	if (logInSelectNO != null) {

		logInTypeNO = logInSelectNO.options[logInSelectNO.selectedIndex].value;

		if (logInTypeNO == 1) { //Client Sites
		
			if (getCookie("customer_id")) {
				loginLocationNO = customerCenterLocation + getCookie("customer_id") + "/index.html";
			} else {
				loginLocationNO = "/igpinfo/log_in.html";
			}
	
		} 		
		else if (logInTypeNO == 2 ) { //IGP Office
			
			if (getCookie("customer_id")) {
				loginLocationNO = IGPOnlyLocation + getCookie("customer_id") + "/index.html";
			} else {
				loginLocationNO = "/igpinfo/igp_only/index.html";
			}
			
		}
		else if (logInTypeNO == 3 ) { //AI Client
			
			if (getCookie("customer_id")) {
				loginLocationNO = associateInsurerLocation + getCookie("customer_id") + "/index.html";
			} else {
				loginLocationNO = "/igpinfo/ai_log_in.html";
			}
			
		}
		window.location = loginLocationNO;
	
	}
}

			

function getCustomerCenter() {

	var customerId = "";
	
	if (document.getElementById("customer_id") != null) {
		customerId = document.getElementById("customer_id").value.toLowerCase();
	}
	
	if (customerId != "") {

		if (document.cookie) setCookie("customer_id",customerId);
		document.forms["log_in"].action = customerCenterLocation + customerId + "/index.html";

	} else {

		alert("Please enter your Customer ID.");
		return false;
		
	}
	
		return true;
}

function getAssociateInsurer(){

	var customerId = "";
	
	if (document.getElementById("customer_id") != null) {
		customerId = document.getElementById("customer_id").value.toLowerCase();
	}
	
	if (customerId != "") {

		if (document.cookie) setCookie("customer_id",customerId);
		document.forms["log_in"].action = associateInsurerLocation + customerId + "/index.html";

	} else {

		alert("Please enter your Customer ID.");
		return false;
		
	}
	
		return true;

}
		


/* Portions of the cookie functions are derived from code by Bill Dortch */

// Use this function to save a cookie.
function setCookie(name, value) {
	document.cookie = name + "=" + escape(value) + "; path=/";
}

// Use this function to delete a cookie.
function delCookie(name) {
	document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

// Use this function to retrieve a cookie.
function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie;             
    
	if (dc.length > 0) {              
    	
		begin = dc.indexOf(cname);       
        
		if (begin != -1) {           
	        begin += cname.length;       
    	    end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    
	}
	
	return null;
}


function showSelectedReport(selectObject) {

	var selectedReport = selectObject.options[selectObject.selectedIndex].value;

	if (selectedReport != "") {
		window.location = selectedReport;	
	}	
	
	return true;

}

function openPopR(pg,wt,ht) {
//alert("Entering openpopR");
//alert(pg);
//alert(wt);
//alert(ht);
	//var centerWidth = getWindowWidth()/2 - wt/2;
	var centerWidth = 100;
	//alert(centerWidth);
	//var centerHeight = getWindowHeight()/2 - ht/2;
	var centerHeight = 14;
	//alert(centerHeight);
	
	var str="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+wt+",height="+ht+",left="+centerWidth+",top="+centerHeight+"";
//var str="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+wt+",height="+ht+",left="600",top="800"";
//alert(str);
	pop=window.open(pg,"JohnHancockR",str);
	pop.focus();
}

function getWindowWidth() {
	return window.innerWidth ? window.innerWidth : document.body.offsetWidth;
}

function getWindowHeight() {
	return window.innerHeight ? window.innerHeight : document.body.offsetHeight;
}