window.onload = function(){
    MM_preloadImages("../images/bContactOver.jpg","../images/bSearchOver.jpg");
}

var menutimer;

function MM_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=MM_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_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 MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_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 RunFlashContent(){
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js. In Flash, run \"Apply Active Content Update\" in the Commands menu to copy AC_RunActiveContent.js to the HTML output folder.");
	} else {
		AC_FL_RunContent(
			'codebase', 'https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0',
			'width', '750',
			'height', '50',
			'src', '../swf/MENU6Access',
			'quality', 'high',
			'pluginspage', 'https://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'MENU6Access',
			'bgcolor', '#ffffff',
			'name', 'MENU6Access',
			'menu', 'true',
			'allowScriptAccess','sameDomain',
			'movie', '../swf/MENU6Access',
			'salign', ''
			); //end AC code
	}
}

function dropDownNav(oSelect){
	try{
		var idx = oSelect.selectedIndex;
		var url = oSelect.options[idx].value;
		if(url && url != "#")
			window.location = url;
	}catch(e){}
}


function popUp(URL) 
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=0,width=360,height=460');");
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function show(id) {
    clearTimeout(menutimer);
	if (document.getElementById) {
		document.getElementById(id).style.display="block";
	} else if (document.all) {
		document.all[id].style.display="block";
	} else if (document.layers) {
		document.layers[id].display="block";
	}
}
 
function hide(id) {
    if (document.getElementById) {
    	document.getElementById(id).style.display="none";
    } else if (document.all) {
    	document.all[id].style.display="none";
    } else if (document.layers) {
    	document.layers[id].display="none";
    }
}

function hide_grp(id1, id2, id3, id4) {
    hide(id1);
    hide(id2);
    hide(id3);
    hide(id4);
}

function fixit(id) {
    menutimer = setTimeout('hide("'+id+'")',3000);
}

var Cookie = {
	set: function (name, value, expires, path, domain, secure) {
		var c = name + "=" + escape(value);
		if(expires)
			c += "; expires=";
			if(typeof expires == "string" || typeof expires == "number")
				expires = new Date(expires);
			c += expires.toGMTString();
		if(path)
			c += "; path=" + path;
		if(domain)
			c += "; domain=" + domain;
		if(secure)
			c += "; secure";
		document.cookie = c;
	}
	, get: function (name) {
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1) {
			begin = dc.indexOf(prefix);
			if (begin != 0)
				return null;
		} else {
			begin += 2;
		}
		var end = dc.indexOf(";", begin);
		if (end == -1) {
			end = dc.length;
		}
		return unescape(dc.substring(begin + prefix.length, end));
	}
	, remove: function (name, path, domain) {
		if (Cookie.get(name)) {
			Cookie.set(name, "", 0, path, domain);
		}
	}
}

/**** Login Form Code ****/
var LOGIN_PREFIX;
function disableEnter(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	return keyCode != 13;
}
function userTypeChange(oSelect, fieldsId){
    var selectedUserType = oSelect.options[oSelect.selectedIndex].text;
    if(selectedUserType.toLowerCase() == "policyholder"){
        if(SECURE)
		    document.getElementById(fieldsId).className = "loginFields_selected";
	    else
            window.location = SECURE_URL + "?P=2";
    } else { 
	    document.getElementById(fieldsId).className = "loginFields";
    }
}
function keepRadio(form, args){
	var KEEP_RADIO_PREFIX = "keepradio-";
	var DAYS_TO_KEEP = 10;
	for(var i=1; i<arguments.length; i++){
		var name = arguments[i];
		var radios = form[name];
		var value = Cookie.get(KEEP_RADIO_PREFIX + name);
		for(var j=0; j < radios.length; j++){
			var radio = radios[j];
			radio.onclick = function(){
				var d = new Date();
				Cookie.set(KEEP_RADIO_PREFIX + this.name, this.value, d.setDate(d.getDate() + DAYS_TO_KEEP));
			}
			if(radio.value == value){
				radio.click();
			}
		}
	}
}
function doLogin(selectId){
    try{
		var oSelect = document.getElementById(selectId);
		var selectedUserType = oSelect.options[oSelect.selectedIndex].text;
		var companies = document.frmLogin.LoginCompany;
		var company = "";
		for(var i=0; i<companies.length; i++){
			if(companies[i].checked){
				company = companies[i].value.toLowerCase();
				break;
			}
		}
		if(company == ""){
			alert("Please select a company.");
			return false;
		}

		var policyholder = (selectedUserType.toLowerCase() == "policyholder");
		
		var url = LOGIN_PREFIX;

		switch(company){
			case "galic" : 
				if(policyholder)
					url += ".secure.gafri.com/PolicyValuesWeb/PHRLogin.aspx";
				else
					url += ".secure.gafri.com/aagis/";
				break;
			case "ailic" : 
				if(policyholder)
					url += ".annuityinvestors.com/VAailicClient/PolicyList.aspx";
				else
					url += ".secure01.gafri.com/ailic/";
				break;
			case "loyal" : 
				if(policyholder)
					url += ".secure.gafri.com/PolicyValuesWeb/PHRLogin.aspx";
				else
					url += ".sec.gafri.com/loyal/";
				break;
		}

		if (document.getElementById("txtUserName").value == "" && document.getElementById("txtPassword").value == ""){
			window.location = url;
		}else{
			document.getElementById("txtURL").value = url;
			document.frmLogin.submit();
		}
		return false;
	} finally {
	    return false;
	}
}

/* Flash Replacement Ajax */
function makeRequest(idName, content) {
  var url = "flash_rep.aspx"
  url = url+"?input="+content;
  changeTabs(content);

  var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }

  if (!http_request) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
  }
  http_request.onreadystatechange = function() { alertContents(http_request, idName); };
  http_request.open('GET', url, true);
  http_request.send(null);
}

function alertContents(http_request, idName) {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      document.getElementById(idName).innerHTML=http_request.responseText;
    } else {
      alert('There was a problem with the request.');
    }
  }
  else {
    document.getElementById(idName).innerHTML="<img src='../images/slide_loadjpg.jpg'>"
  }
}

function changeTabs(num) { // assumes 3 tabs, needs to be changed whenever the number of tabs changes
    switch(num) {
        case 1:
            document.getElementById('tab1_l').className = 'act_left';
            document.getElementById('tab1_c').className = 'current';
            document.getElementById('tab1_r').className = 'act_right';

            document.getElementById('tab2_l').className = 'ina_left';
            document.getElementById('tab2_c').className = '';
            document.getElementById('tab2_r').className = 'ina_right';

            document.getElementById('tab3_l').className = 'ina_left';
            document.getElementById('tab3_c').className = '';
            document.getElementById('tab3_r').className = 'ina_right';

            break;
        case 2:
            document.getElementById('tab1_l').className = 'ina_left';
            document.getElementById('tab1_c').className = '';
            document.getElementById('tab1_r').className = 'ina_right';

            document.getElementById('tab2_l').className = 'act_left';
            document.getElementById('tab2_c').className = 'current';
            document.getElementById('tab2_r').className = 'act_right';

            document.getElementById('tab3_l').className = 'ina_left';
            document.getElementById('tab3_c').className = '';
            document.getElementById('tab3_r').className = 'ina_right';
            
            break;
        case 3:
            document.getElementById('tab1_l').className = 'ina_left';
            document.getElementById('tab1_c').className = '';
            document.getElementById('tab1_r').className = 'ina_right';

            document.getElementById('tab2_l').className = 'ina_left';
            document.getElementById('tab2_c').className = '';
            document.getElementById('tab2_r').className = 'ina_right';

            document.getElementById('tab3_l').className = 'act_left';
            document.getElementById('tab3_c').className = 'current';
            document.getElementById('tab3_r').className = 'act_right';

            break;
        default:
            document.getElementById('tab1_l').className = 'act_left';
            document.getElementById('tab1_c').className = 'current';
            document.getElementById('tab1_r').className = 'act_right';

            document.getElementById('tab2_l').className = 'ina_left';
            document.getElementById('tab2_c').className = '';
            document.getElementById('tab2_r').className = 'ina_right';

            document.getElementById('tab3_l').className = 'ina_left';
            document.getElementById('tab3_c').className = '';
            document.getElementById('tab3_r').className = 'ina_right';
            
            break;
    }
}
