/*	Name: 			mibankJsLib.js
	Author: 		Michael T Venturella Jr (MTV)
	Created:		05-Oct-05
	
	Revision Notes:
		1.1 	05-Oct-05	MTV		Original version.	
		1.2 	12-Apr-06	alk		modifying tagline portion for Commercial, which has no tagline
		1.3 	03-AUG-06	AWW		added OK,MO and KS to switch/case in showState()
		1.4 	05-Sep-06	MTV		added new code to handle the new font size change logic, using unique style sheets.
									The code must be un-commented to work.  Around 630-ish
		1.5 	15-Sep-06	MTV		Enabled the font change stuff.
		1.6		08-MAR-07	AWW		modified locationChange to accommodate _hbLink call.
		1.7		30-MAY-07	AWW		added getToken and streamlined getCookieValue
		1.8		02-AUG-07	AWW		commented _hblink in locationChange in pre-HBX. it was a problem for MVNT
        1.9     23-JAN-08       AWW     Added Indiana to showState()
		1.11		24-JAN-08	AWW		modified verbiage used in setEdit() and tagline() according to issue 2112 (Set/Edit vs. Customize/Update)
        1.12    28-FEB-08   AWW     fixed the "null" link problem on universal apply page
        1.21	28-May-08	MTV		Updated for multi-bank and all states.  Updated function showState() to show correct state no matter what state is chosen.
*/
//some handy vars to have (AMS) SAM 12-May-04. Ported 07-Feb-06.
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();

// *** BROWSER VERSION ***

var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);

// Note: On IE, start of appVersion return 3 or 4
// which supposedly is the version of Netscape it is compatible with.
// So we look for the real version further on in the string

var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
   is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
   is_major = parseInt(is_minor);
}

// Netscape6 is mozilla/5 + Netscape6/6.0!!!
// Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
var nav6Pos = agt.indexOf('netscape6');
if (nav6Pos !=-1) {
   is_minor = parseFloat(agt.substring(nav6Pos+10))
   is_major = parseInt(is_minor)
}

var is_getElementById   = (document.getElementById) ? "true" : "false"; // 001121-abk
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false"; // 001127-abk
var is_documentElement = (document.documentElement) ? "true" : "false"; // 001121-abk

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                      (agt.indexOf("; nav") != -1)) );
var is_nav6   = (is_nav && is_major==6);    // new 010118 mhp
var is_nav6up = (is_nav && is_minor >= 6) // new 010118 mhp

var is_nav5   = (is_nav && is_major == 5 && !is_nav6); // checked for ns6
var is_nav5up = (is_nav && is_minor >= 5);

var is_ie   = (iePos!=-1);
var is_ie3  = (is_ie && (is_major < 4));

var is_ie4   = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5   = (is_ie && is_major == 5);
var is_ie5up = (is_ie && is_minor >= 5);

var is_iframes = (is_ie4up || is_nav6) ? "true" : "false";
//END vars. SAM 07-Feb-06.

function getToken(str, delim, idx) { // very simple non-robust, getToken function
	try { return str.split(delim)[idx]; }
	catch(err) { return ""; }
}

//more vars.  MTV 01-Mar-06
var cookieName="CFCLIENT_MIBANKNEW";
var miBankNewRoot = "/mibanknew/";
var miBankNewImagePath = "/mibanknew/images/";
//END MTV vars

//retrieves a cookie's values by their name.
function getCookie(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 = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

//calls getCookie, and looks for the value specified
//returns the value, or 'false' if not found
function getCookieValue(c, v) {
	var cookieString=getCookie(c.toUpperCase())
	if (cookieString != null) {
		// the client cookie is split by "#" on the outside and "=" on the inside
		var outside = cookieString.split("#");
		for( var i = 0; i < outside.length; i++) {
			if( getToken(outside[i], "=", 0) == v )
				return getToken(outside[i], "=", 1)
		}
	}
	return false; /// if it hasnt returned by now, then the cookie value was not found, so return false.
	/*
	// this is the old getCookieValue prior to 5/30/07. keep around for awhile
	cookieString=getCookie(c.toUpperCase())	
	if (cookieString != null) {
		lValues=cookieString.replace(/#/gi, ',')
		if( lValues ) {
			var paramPos=lValues.indexOf(v.toUpperCase())
			if (paramPos >=0) {
				var valuePos=lValues.indexOf('=', paramPos)
				if (valuePos >=0) {
					var delimPos=lValues.indexOf(',', valuePos)
					if (delimPos >=0) {
						return lValues.substr(valuePos+1, delimPos-valuePos-1)
					}else return false
				}else return false
			}else return false
		} else return false
	} else return false
	*/
}

//used for redirecting to your preferred homepage
function preferedHome(fileName) {
	//first, use CFML to figure out what homepage to go to.
	var blineValue=getCookieValue(cookieName, "BLINE")
	switch (blineValue) {
		case "1":
			home="personal";
			break;
		case "2":
			home="smallbusiness";
			break;
		case "3":
			home="commercial";
			break;
		case "4":
			home="wealthmanagement";
			break;
		default:
			home="homepage";
	}
	if (home != "homepage") {
		goToLoc="subsections.cfm?pagename="+home
		if (fileName.indexOf("index") != -1) {
			location.href=goToLoc;
		} else if (fileName.indexOf("homepage") != -1) {
			location.href=goToLoc;
        }
	}
    setDefaultStateDDLB();
 
}

function setDefaultStateDDLB() {
   // add code here to default the state ddlb stuff
    var stCookie = getCookie("MIBANKNEW_STATE");
    var stVal = (stCookie) ? stCookie : "";
    var bFound=false;

    if( document.getElementById("SLAPIFORM") ) { // document.SLAPIFORM.stateIdDDLB
//    alert("YAR!");
        if( stVal.length ) {
            for( var i  = 0; i < document.SLAPIFORM.stateIdDDLB.length; i++) {
                if( document.SLAPIFORM.stateIdDDLB[i].value == stVal ) {
                    document.SLAPIFORM.stateIdDDLB.selectedIndex = i;
                    document.SLAPIFORM.stateId.value = stVal;

                    bFound=true;
                    break;
                }
            }
        }
        document.getElementById("stateIdDDLB").disabled = bFound;
        document.getElementById("divChangeAcctLoc").style.display = (bFound) ? "inline" : "none";
        document.getElementById("divChangeAcctLoc").checked=false;
    }
}



//used with headers to show the curently selected business line (area of interest).
function showBline() {
	var blineValue=getCookieValue(cookieName, "BLINE")
	switch (blineValue) {
		case "1":
			theBline="Personal";
			break;
		case "2":
			theBline="Small Bus.";
			break;
		case "3":
			theBline="Commercial";
			break;
		case "4":
			theBline="Wealth Mgmt";
			break;
		default:
			theBline="Select";
	}
	document.write(theBline)
}

//used with headers to define the home link.
function callHome(linkText) {
	var blineValue=getCookieValue(cookieName, "BLINE")
	switch (blineValue) {
		case "1":
			home="personal";
			break;
		case "2":
			home="smallbusiness";
			break;
		case "3":
			home="commercial";
			break;
		case "4":
			home="wealthmanagement";
			break;
		default:
			home="homepage";
	}
	if (linkText) {
		document.write("<a class='bodytextboldblue' href='subsections.cfm?pagename="+home+"'>"+linkText+"</a>")
	} else {	
	document.write("<a class='bodytextboldblue' href='subsections.cfm?pagename="+home+"'>Home</a>")
	}
}

//used with headers to switch between the tag line, or the setpreferences in the BLIB
function tagLine(tag, width) {
	var state=getCookieValue(cookieName, "STATE");
	if(state=='1' || state==false) {
		document.write('<td width="'+width+'" class="tagline"><A href="preferences.cfm" class="bodytextorange">Customize Preferences</A></td>');
	} else {
		if (tag.length)
			document.write('<td width="'+width+'" class="tagline">'+tag+'</td>');
		else
			document.write('<td width="'+width+'" class="tagline">&nbsp;</td>');
	}
}

//used with headers to show set or edit infront of preferences.
function setEdit() {
	var state=getCookieValue(cookieName, "STATE")
	if(state=='1' || state==false) document.write("Customize")
	else document.write("Update")
	
}

//used with headers to show the curently selected state.
function showState() {
//	var state=getCookieValue(cookieName, "STATE");
    var stCookie = getCookie("MIBANKNEW_STATE");
    var state = (stCookie) ? stCookie : getCookieValue(cookieName, "STATE");
    var bFound=false;
	if (state==false) stateAbbrev="Select";
	else {
		switch (state) {
			case "1": stateAbbrev="Select";break;
			case "2": stateAbbrev="WI";break;
			case "3": stateAbbrev="MN";break;
			case "4": stateAbbrev="AZ";break;
			case "5": stateAbbrev="NV";break;
			case "6": stateAbbrev="FL";break;
			case "7": stateAbbrev="FSB";break;
			case "8": stateAbbrev="MO";break;
			case "9": stateAbbrev="KS";break;
			case "10": stateAbbrev="OK";break;
			case "11": stateAbbrev="IN";break;
			case "12": stateAbbrev="AK";break;
			case "13": stateAbbrev="AL";break;
			case "14": stateAbbrev="AR";break;
			case "15": stateAbbrev="CA";break;
			case "16": stateAbbrev="CO";break;
			case "17": stateAbbrev="CT";break;
			case "18": stateAbbrev="DC";break;
			case "19": stateAbbrev="DE";break;
			case "20": stateAbbrev="GA";break;
			case "21": stateAbbrev="HI";break;
			case "22": stateAbbrev="IA";break;
			case "23": stateAbbrev="ID";break;
			case "24": stateAbbrev="IL";break;
			case "25": stateAbbrev="KY";break;
			case "26": stateAbbrev="LA";break;
			case "27": stateAbbrev="MA";break;
			case "28": stateAbbrev="MD";break;
			case "29": stateAbbrev="ME";break;
			case "30": stateAbbrev="MI";break;
			case "31": stateAbbrev="MS";break;
			case "32": stateAbbrev="MT";break;
			case "33": stateAbbrev="NC";break;
			case "34": stateAbbrev="ND";break;
			case "35": stateAbbrev="NE";break;
			case "36": stateAbbrev="NH";break;
			case "37": stateAbbrev="NJ";break;
			case "38": stateAbbrev="NM";break;
			case "39": stateAbbrev="NY";break;
			case "40": stateAbbrev="OH";break;
			case "41": stateAbbrev="OR";break;
			case "42": stateAbbrev="PA";break;
			case "43": stateAbbrev="RI";break;
			case "44": stateAbbrev="SC";break;
			case "45": stateAbbrev="SD";break;
			case "46": stateAbbrev="TN";break;
			case "47": stateAbbrev="TX";break;
			case "48": stateAbbrev="UT";break;
			case "49": stateAbbrev="VA";break;
			case "50": stateAbbrev="VT";break;
			case "51": stateAbbrev="WA";break;
			case "52": stateAbbrev="WV";break;
			case "53": stateAbbrev="WY";break;
			
			/* 28-May-08 MTV 
			   If promoting this before June 11, comment out the case statements above and uncomment the ones below.
			case "1":
				stateAbbrev="Select";
				break;
			case "2":
				stateAbbrev="WI";
				break;
			case "3":
				stateAbbrev="MN";
				break;
			case "4":
				stateAbbrev="AZ";
				break;
			case "5":
				stateAbbrev="NV";
				break;
			case "6":
				stateAbbrev="FL";
				break;
			case "8":
				stateAbbrev="MO";
				break;
			case "9":
				stateAbbrev="KS";
				break;
			case "10":
				stateAbbrev="OK";
				break;
			case "11":
				stateAbbrev="IN";
				break; 
			default:
				stateAbbrev="FSB";*/
		}
	}
	document.write(stateAbbrev);
}

//Used with drop down menus of links.  Takes customer to destination. Not a pop-up window.
function locationChange(list) {
	var loc=list[list.selectedIndex].value;
	var index;
	var hbxName="";	
	if (loc=="null" || loc.indexOf("null|") == 0 ) { // 28-FEB-08   AWW     added "loc.indexOf("null|") == 0" 
		loc="";
		list.selectedIndex=0;
	}
	if (loc) {
	
		if( loc.indexOf("|") >= 0 ) {
			// NEW - The HBX way
			var hbxURL=0;
			var hbxPN=1;
			var hbxLOC=2;
			var hbxVars = loc.split("|");
			index=hbxVars[hbxURL].indexOf('~');
			//alert(hbxVars[hbxURL] + "\r\n" + hbxVars[hbxPN] + "\r\n" + hbxVars[hbxLOC]);
			// for HBX, replace " " w/ "+" and "&amp;" with "", and any any non-alpha-numeric (exluding "-", "_", "+" and "\") with ""
			_hbLink(hbxVars[hbxPN],hbxVars[hbxLOC]); /// let HBX know that a "link" was clicked
			if (index<0) {
					// didn't find the '~'
				location.href=hbxVars[hbxURL];
				//loc="";
				list.selectedIndex=0;
			} 
			else
				window.open(hbxVars[hbxURL].substr(0,hbxVars[hbxURL].length-2),'newWindow'); // ~ indicates pop into seperate window. don't forget to strip ~ out of URL
		}
		else
		{
			// The pre-HBX way
			index=loc.indexOf('~');
			// for HBX, replace " " w/ "+" and "&amp;" with "", and any any non-alpha-numeric (exluding "-", "_", "+" and "\") with ""
			hbxName = list[list.selectedIndex].text.replace(" ", "+", "g");
			hbxName = hbxName.replace("&amp;", "", "g");
			hbxName = hbxName.replace(/[^\d\w_\+\/-]/g, "");
			//alert(hbxName);
			//_hbLink(list[list.selectedIndex].text,'dropDownMenu'); /// let HBX know that a "link" was clicked
			if (index<0) {
					// didn't find the '~'
				location.href=loc;
				//loc="";
				list.selectedIndex=0;
			} 
			else
				window.open(loc.substr(0,loc.length-2),'newWindow'); // ~ indicates pop into seperate window. don't forget to strip ~ out of URL
		}
	}
}

//used by dhtml access accounts box.
function hideBlocks(selection) {
	if (selection == "personal") {
		perSelect.className="bodytextbold"
		sbSelect.className="bodytextboldlight"
		comSelect.className="bodytextboldlight"
		wmSelect.className="bodytextboldlight"
		perBlock1.style.display="block"
		perBlock2.style.display="block"
		sbBlock1.style.display="none"
		comBlock1.style.display="none"
		wmBlock1.style.display="none"
	}
	if (selection == "sb") {
		perSelect.className="bodytextboldlight"
		sbSelect.className="bodytextbold"
		comSelect.className="bodytextboldlight"
		wmSelect.className="bodytextboldlight"
		perBlock1.style.display="none"
		perBlock2.style.display="none"
		sbBlock1.style.display="block"
		comBlock1.style.display="none"
		wmBlock1.style.display="none"
	}
	if (selection == "com") {
		perSelect.className="bodytextboldlight"
		sbSelect.className="bodytextboldlight"
		comSelect.className="bodytextbold"
		wmSelect.className="bodytextboldlight"
		perBlock1.style.display="none"
		perBlock2.style.display="none"
		sbBlock1.style.display="none"
		comBlock1.style.display="block"
		wmBlock1.style.display="none"
	}
	if (selection == "wm") {
		perSelect.className="bodytextboldlight"
		sbSelect.className="bodytextboldlight"
		comSelect.className="bodytextboldlight"
		wmSelect.className="bodytextbold"
		perBlock1.style.display="none"
		perBlock2.style.display="none"
		sbBlock1.style.display="none"
		comBlock1.style.display="none"
		wmBlock1.style.display="block"
	}
}
	
function hideBlocks2(selection) {
	var perRadio=document.getElementById('perRadio')
	var sbRadio=document.getElementById('sbRadio')
	var comRadio=document.getElementById('comRadio')
	var wmRadio=document.getElementById('wmRadio')
	var perSelect=document.getElementById('perSelect')
	var sbSelect=document.getElementById('sbSelect')
	var comSelect=document.getElementById('comSelect')
	var wmSelect=document.getElementById('wmSelect')
	var perBlock1=document.getElementById('perBlock1')
	var perBlock2=document.getElementById('perBlock2')
	var sbBlock1=document.getElementById('sbBlock1')
	var comBlock1=document.getElementById('comBlock1')
	var wmBlock1=document.getElementById('wmBlock1')
	
	if (selection == "personal") {
		perRadio.checked=1
		sbRadio.checked=0
		comRadio.checked=0
		wmRadio.checked=0
		perSelect.className="bodytextbold"
		sbSelect.className="bodytextboldlight"
		comSelect.className="bodytextboldlight"
		wmSelect.className="bodytextboldlight"
		perBlock1.style.display="block"
		perBlock2.style.display="block"
		sbBlock1.style.display="none"
		comBlock1.style.display="none"
		wmBlock1.style.display="none"
		var pUserName = document.getElementById("username")
		if( pUserName )
			pUserName.focus();
	}
	else if (selection == "sb") {
		perRadio.checked=0
		sbRadio.checked=1
		comRadio.checked=0
		wmRadio.checked=0
		perSelect.className="bodytextboldlight"
		sbSelect.className="bodytextbold"
		comSelect.className="bodytextboldlight"
		wmSelect.className="bodytextboldlight"
		perBlock1.style.display="none"
		perBlock2.style.display="none"
		sbBlock1.style.display="block"
		comBlock1.style.display="none"
		wmBlock1.style.display="none"
	}
	else if (selection == "com") {
		perRadio.checked=0
		sbRadio.checked=0
		comRadio.checked=1
		wmRadio.checked=0
		perSelect.className="bodytextboldlight"
		sbSelect.className="bodytextboldlight"
		comSelect.className="bodytextbold"
		wmSelect.className="bodytextboldlight"
		perBlock1.style.display="none"
		perBlock2.style.display="none"
		sbBlock1.style.display="none"
		comBlock1.style.display="block"
		wmBlock1.style.display="none"
	}
	else if (selection == "wm") {
		perRadio.checked=0
		sbRadio.checked=0
		comRadio.checked=0
		wmRadio.checked=1
		perSelect.className="bodytextboldlight"
		sbSelect.className="bodytextboldlight"
		comSelect.className="bodytextboldlight"
		wmSelect.className="bodytextbold"
		perBlock1.style.display="none"
		perBlock2.style.display="none"
		sbBlock1.style.display="none"
		comBlock1.style.display="none"
		wmBlock1.style.display="block"
	}
}
	
// Throw in all the bells, whistles.
function changeCursor() {
	if(document.body.style.cursor == "pointer") {
		document.body.style.cursor = "auto";
	} else {
		document.body.style.cursor = "pointer";
	}
}

//	Description: 	D/HTML Javascript that makes detail tabs on the profile pages change


var initialtab=[1, "sc1"];
var currTab = 1;
var previoustab="";
var tabCount = 20;

// Special changeTabCursor function for tabs since requirement essentially restricts
// mouse cursor/pointer to arrow if tab is selected.
function changeTabCursor(tab) 
{
	if(document.body.style.cursor == "pointer" || currTab == tab) {
		document.body.style.cursor = "auto";
	} else {
		document.body.style.cursor = "pointer";
	}
}

function getStyleObject(objectId) {
    	// cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	    // W3C DOM
    	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	    // MSIE 4 DOM
	    return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
    	// NN 4 DOM.. note: this won't find nested layers
    	return document.layers[objectId];
    } else {
	    return false;
    }
} // getStyleObject

function detailsProductSwapOn(tab) 
{
	var ltCellTop;
	var i;

	for(  i = 1; i<=tabCount; i++)
	{
		ltCellTop=getStyleObject('LT_'+i);
		if( !ltCellTop) 
			return; 
		if( i.toString() == tab )
		{
			ltCellImg=getStyleObject('LT_'+tab+'_img').src= miBankNewImagePath + "rates_left_blue.gif";
			rtCellImg=getStyleObject('RT_'+tab+'_img').src= miBankNewImagePath + "rates_right_blue.gif";

			ltCellTop.className="detailtabson";
			ltCellLeft=getStyleObject('LCL_'+tab).className="backgroundblue";
			ltCellRight=getStyleObject('LCR_'+tab).className="detailtabson";
			ctCellTop=getStyleObject('CT_'+tab).className="backgroundblue";
			ctCellCenter=getStyleObject('CC_'+tab).className="detailtabson";
			ctCellBottom=getStyleObject('CB_'+tab).className="detailtabson";
			ctCellBottomPad=getStyleObject('CBB_'+tab).className="detailtabson";
			rtCellTop=getStyleObject('RT_'+tab).className="detailtabson";
			rtCellLeft=getStyleObject('RCL_'+tab).className="detailtabson";
			rtCellRight=getStyleObject('RCR_'+tab).className="backgroundblue";
			botCellLeft=getStyleObject('BC_'+tab).className="backgroundwhite";
			document.body.style.cursor = "auto";
		}
		else
		{
			if( getStyleObject('LT_'+tab+'_img').src.indexOf("rates_left_blue") != -1)
				detailsProductSwapOff(i);
		}
	}
}
function detailsProductSwapOff(tab) 
{
	var ltCellTop;

	if( currTab != tab )
	{
		ltCellTop=getStyleObject('LT_'+tab);
		if(ltCellTop)
		{
			getStyleObject('LT_'+tab+'_img').src= miBankNewImagePath + "rates_left_gold.gif";
			getStyleObject('RT_'+tab+'_img').src= miBankNewImagePath + "rates_right_gold.gif";

			ltCellTop.className="detailtabsoff"
			getStyleObject('LCL_'+tab).className="backgroundgold";
			getStyleObject('LCR_'+tab).className="detailtabsoff";
			getStyleObject('CT_'+tab).className="backgroundgold";
			getStyleObject('CC_'+tab).className="detailtabsoff";
			getStyleObject('CB_'+tab).className="detailtabsoff";
			getStyleObject('CBB_'+tab).className="detailtabsoff";
			getStyleObject('RT_'+tab).className="detailtabsoff";
			getStyleObject('RCL_'+tab).className="detailtabsoff";
			getStyleObject('RCR_'+tab).className="backgroundgold";
			getStyleObject('BC_'+tab).className="backgroundblue";
		}
	}	
}
			
function expandcontent(tabid)
{
	if (previoustab!="")
		getStyleObject(previoustab).style.display="none";

	getStyleObject(tabid).style.display="block";
	if( previoustab != tabid )
	{
		previoustab=tabid;
		currTab = tabid.substr(2,1);
		detailsProductSwapOn(currTab);
	}
}
function setInitTab(tabno)
{
	initialtab[0] = tabno;
	initialtab[1] = "sc" + tabno;
}
function initDetailTabs()
{
	if( !getStyleObject(initialtab[1]) )
	{
		initialtab[0] = 1;
		initialtab[1] = "sc1";
	}
	expandcontent(initialtab[1]); 

}
/*  ********************** DETAIL TAB STUFF DONE ****************************  */

// 2nd level tab stuff. sam 07-nov-05, mtv 08-Nov-05
//these functions use the id property - LEVEL 2 NAVIGATION

function detailsTabSwapOn(tab) {
	tlCell=document.getElementById('TL_' + tab)
	tcCell=document.getElementById('TC_' + tab)
	trCell=document.getElementById('TR_' + tab)
	llCell=document.getElementById('LL_' + tab)
	lcCell=document.getElementById('LC_' + tab)
	lrCell=document.getElementById('LR_' + tab)
	bpCell=document.getElementById('BP_' + tab)
	blCell=document.getElementById('BL_' + tab)
		
	tlCell.className="level2onnav"
	tcCell.className="level2onnav"
	trCell.className="level2onnav"
	llCell.className="level2onnav"
	lcCell.className="level2onnav"
	lrCell.className="level2onnav"
	bpCell.className="level2onnav"			
	blCell.className="level2onnav"
}

function detailsTabSwapOff(tab) {
	tlCell=document.getElementById('TL_' + tab)
	tcCell=document.getElementById('TC_' + tab)
	trCell=document.getElementById('TR_' + tab)
	llCell=document.getElementById('LL_' + tab)
	lcCell=document.getElementById('LC_' + tab)
	lrCell=document.getElementById('LR_' + tab)
	bpCell=document.getElementById('BP_' + tab)
	blCell=document.getElementById('BL_' + tab)
		
	tlCell.className="level2nav"
	tcCell.className="level2nav"
	trCell.className="level2nav"
	llCell.className="level2nav"
	lcCell.className="level2nav"
	lrCell.className="level2nav"
	bpCell.className="level2nav"			
	blCell.className="backgroundblue"
}
// end 2nd level tab stuff. sam 07-nov-05, mtv 08-Nov-05

//this will change locations.  Only for use by tabs where the destination is internal.
function tabHref(page) {
	var loc='subsections.cfm?pagename=' + page
	location.href=loc
}
//SAM 07-Feb-06. AMS.
function getState() {
	var stateVal=getCookieValue(cookieName, "STATE")
	if (stateVal==false) return("1")
	else return(stateVal)
}

function setCookie(name, value, duration, bRedirect) {
//alert(name);
  var curCookie = name + "=" + escape(value) + ";" + ((duration =="") ? "" : " expires=" + escape(duration)) + "; path=/; ";
  document.cookie = curCookie;
  if( bRedirect )
  	window.location.href = window.location.href;
}

function appendCookie(name, value, duration, bRedirect) {
	var tempCookie = getCookie(name);
	tempCookie = ( !tempCookie || tempCookie == "undefined" ) ? "" : tempCookie;

	if( tempCookie.indexOf(value) == -1)	{
		var val = ( tempCookie == "" ) ? value : tempCookie + "," + value;
		setCookie(name, val, duration, bRedirect);
		return true; // cookie had to be appended, so return true
	}
	else
		return false; // cookie did not need to be appended, so return false 
}

//this will dynamically change the font size when a user changes their font size selection.
function changeFontSize(fntsize) {
	setCookie('fntsize',fntsize,'Wed, 11-Nov-2050 12:00:00 GMT','1');
}

/* function cycleFontSize() {
	if (getCookie('fntsize') == null) {
		var fntsize = 10;
	} else {
		var fntsize = getCookie('fntsize');
	}
	if (fntsize == 10)
		changeFontSize(12);
	if (fntsize == 12)
		changeFontSize(14);
	if (fntsize == 14)
		changeFontSize(10);
}*/

//The following are rewritten to take advantage of the three style sheet method

//cycles through the font sizes - new method using indexes.
function cycleFontSize() {
	if (getCookie('fntsize') == null) {
		var fntsize = 1;
	} else {
		var fntsize = getCookie('fntsize');
	}
	if (fntsize == 1)
		changeFontSize(2);
	if (fntsize == 2)
		changeFontSize(3);
	if (fntsize == 3)
		changeFontSize(1);
}

//this will generate the link tag for a stylesheet
function swapCSS(cssName, cssNumber) {
	if (cssName && cssNumber)
		document.write("<link type='text/css' rel='stylesheet' href='"+cssName+cssNumber+".css'>");
	else
		document.write("<link type='text/css' rel='stylesheet' href='mibank1.css'>");
}

//end font change stuff

		
function memberme(_form) {
	if( _form ) 	{
		if( _form.rememberMe && _form.username ) 		{
			var sid = ( _form.rememberMe.checked ) ? _form.username.value : "";
			setCookie( "slapiuserid", sid, "", false);
		}
	}
}

function initSLAPIID() {
	if( document.SLAPIFORM ) {
		var uid = getCookie("slapiuserid");
		document.SLAPIFORM.username.value = ( !uid || uid == "undefined" ) ? "" : uid;
		document.SLAPIFORM.rememberMe.checked = (document.SLAPIFORM.username.value.length) ? true : false;
	}
	
}

//Secondary pop-up windows
function popUpWindow(contentUrl){
	var newWin= window.open(contentUrl,"tool", "HEIGHT=525,WIDTH=780,TOP=5,LEFT=5,resizable=yes,scrollbars=yes,menubar=no,toolbar=yes,status=yes,location=no");
}

function popSLAPIMsg(msg) {
		var w = 430;
		var h = 140;
		var winl = (screen.width - w)/2;
		var wint = (screen.height - h)/2;
		var newWin= window.open("slapimsg.cfm?msg=" + msg,"HomepageLogin", "HEIGHT=" + h + ",WIDTH=" + w + ",TOP=" + wint + ",LEFT=" + winl + ",resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no");
		newWin.focus();
}

function popDisclosure(toID, w, h)
{
	var tempCookie = getCookie("popupID");
	if( tempCookie ) {
		if( tempCookie != "undefined" && tempCookie != toID ) 	{
			var wDisclosure;
			var winl = (screen.width-w)/2;
			var wint = (screen.height-h)/2;
			var sObjID = (toID == "MIBANK") ? tempCookie : toID;
			var direction = (toID == "MIBANK") ? "G" : "C"; // coming or going ?
	
			if( toID != "MIBANK" ) { // Remove this IF statement if Marketing decides they need a popup 			//disclosure when Leaving Marshall Funds, too.
				wDisclosure = window.open( miBankNewRoot + "subsections.cfm?objectID=" + sObjID + "&dir=" + direction, "disclosure", "HEIGHT=" + h + ",WIDTH=" + w + ",TOP=" + wint + ",LEFT=" + winl + ",resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=yes,location=no");
				wDisclosure.focus();
			}
		}
	}
	setCookie("popupID", toID, "", false);

}

var signOnCount = 0;
function submitSignOn(_pn,_mlc) {
	if (signOnCount > 0)
		return false; // this will prevent the form submission from occurring.

    var SF = document.SLAPIFORM;
//    alert("*" + SF.stateId.value + "*");
    if( (SF.userId.value.length < 4 ||  SF.userId.value.length > 32) &&  SF.stateId.value == "" ) {
        document.getElementById("spLoginMsg").innerHTML="<b>Sign on unsuccessful</b>";
        SF.userId.focus();
        alert("Please re-enter your User ID and select the state in which your account resides.  If you need assistance, please call 1-800-642-2657.");
        return false;
    } 
    else if( (SF.userId.value.length < 4 ||  SF.userId.value.length > 32) ) {
        document.getElementById("spLoginMsg").innerHTML="<b>Sign on unsuccessful</b>";
        SF.userId.focus();
        alert("We did not recognize your User ID.  Please re-enter your User ID.  If you need assistance, please call 1-800-642-2657.");
        return false;
    }
    else if( SF.stateId.value == "" ) {
        document.getElementById("spLoginMsg").innerHTML="<b>Sign on unsuccessful</b>";
        SF.stateIdDDLB.focus();
        alert("Please select the state in which your account resides.  If you need assistance, please call 1-800-642-2657.");
        return false;
    }  else {
    	signOnCount++;
    	try{ _hbLink(_pn, _mlc); } catch(e) {} // call hblink, but do not react adversely if there is a problem (i.e. if pn or mlc werent passed). we dont want the customer to not be able to login just because of hbx.
    	return true; // this will allow the form submission to proceed
    }
    return false;
}
