//Set this to 1 later in code when you are using a .NET session in addition to ASP session makes sure both sessions timeout
var iASPXTrue = 0; 

//var ToolBar_Supported = false;
var Frame_Supported   = false;
var DoInstrumentation = false;

/*if (navigator.userAgent.indexOf("MSIE") != -1 &&
	navigator.userAgent.indexOf("Windows") != -1 &&
	navigator.appVersion.substring(0, 1) > 3) {
	ToolBar_Supported = true;
}*/

//if (true) {
	//****************************************************************************************
	// Timer functionality start                                                              
	//****************************************************************************************

	//Return value from setInterval call
	var iIntID;

	//Keeps track of how long we have been sitting on this page
	var iElapsedTime = 0;

	//Get our session timeout from cookie set on Login.asp
	var iBrowsingTime = GetCookie("SessionTimeout");
	//var iBrowsingTime = 10;

	//Set timeout notice threshold at 5 minutes before whatever our timeout is
	var iTimeOutNotice = iBrowsingTime - 300;
	//var iTimeOutNotice = iBrowsingTime - 5;	

	//****************************************************************************************
	// Timer functionality end                                                                
	//****************************************************************************************

	var LevelOneHeight = 45; //54; //60;
	var newLineChar = String.fromCharCode(10);
	var char34 = String.fromCharCode(34);
	var CurMLSWebMenu = "";
	var IsMenuDropDown = true;
	var LastMenu = false;
	var HTMLStr;
	var x = 0;
	var y = 0;
	var x2 = 0;
	var y2 = 0;
	var MLSWebMenuWidth;
	var ToolbarWidth = 760;
	var ToolbarMinWidth;
	var ToolbarMenu;
	var ToolbarBGColor;
	var ToolbarLoaded = false;
	var aDefMLSWebColor = new Array(3);
	var aCurMLSWebColor = new Array(3);
	var MLSWebFont;
	var MLSWebTitleFont;
	var MaxMenu = 30;
	var TotalMenu = 0;
	var arrMenuInfo = new Array(30);
	var LineURL = "http://" + domain + "/JavaScript/toolbar/images/white_line.gif";

	// Output style sheet and toolbar ID
	document.write("<SPAN id='StartMenu' STYLE='display:none;'></SPAN>");

	// Build toolbar template
	HTMLStr =
		"<DIV id='idToolbar'     STYLE='background-color:white;width:100%'>" +
		"<DIV id='idRow1' STYLE='position:relative; height:20px;'>" +
		"<DIV id='idMLSWebMenuPane' STYLE='position:absolute;top:0;left:0;height:20px;background-color:black;'><!--MLSWEB_MENU_TITLES--></DIV>" +
		"</DIV>" +
		"<DIV id=\"idRow2\" style=\"position: relative; height: " + LevelOneHeight + "px;\">" +
		"<DIV id='idMenuBanner'   STYLE='position:absolute;top:0;left:0;height:" + LevelOneHeight + "px;width:100%;overflow:hidden;vertical-align:top;'><!--BEG_MENU_BANNER--><!--END_MENU_BANNER--></DIV>" +
		"</DIV>" +
		"</DIV>" +
		"<SCRIPT TYPE='text/javascript'>" +
		"   var ToolbarMenu = document.getElementById('StartMenu');" +
		"</SCRIPT>" +
		"<DIV WIDTH=100%>";

	// Define event handlers
	window.onresize = resizeToolbar;

	// Intialize global variables
	ToolbarBGColor = "white"; 					// toolbar background color
	MLSWebFont = "bold xx-small Verdana";

	aDefMLSWebColor[0] = aCurMLSWebColor[0] = "#004000"; // bgcolor;
	aDefMLSWebColor[1] = aCurMLSWebColor[1] = "white"; // text font color
	aDefMLSWebColor[2] = aCurMLSWebColor[2] = "red"; 	// mouseover font color
//}


//************************************************************
//                    Only Functions Below Here               
//************************************************************

// The hard-coded numbers in functions - drawToolbar() & resizeToolbar()
// correspond to the dimension of the four gif files:
//		ICP_BANNER: 60h x 250w
//		ADS_BANNER: 40h x 200w
//		MSC_BANNER: 40h x 112w
//		Curve:	    20h x 18w

function drawToolbar()
{
	HTMLStr += "</DIV>";
	document.write(HTMLStr);
	ToolbarLoaded = true;

	MLSWebMenuWidth = Math.max(document.getElementById("idMLSWebMenuPane").offsetWidth, (300 + 112));

	//ToolbarMinWidth = (50+18) + MLSWebMenuWidth;
	ToolbarMinWidth = MLSWebMenuWidth;
	//alert("MLSWebMenuWidth = " + MLSWebMenuWidth);
	
	document.getElementById("idToolbar").style.backgroundColor = ToolbarBGColor;
	//idMSMenuPane.style.backgroundColor = aDefMSColor[0];
	document.getElementById("idMLSWebMenuPane").style.backgroundColor = aDefMLSWebColor[0];
	resizeToolbar();

	for (i = 0; i < TotalMenu; i++) 
	{
		thisMenu = arrMenuInfo[i].IDStr;
		if (thisMenu != null)
		{
			if (arrMenuInfo[i].IDStr == LastMenu && arrMenuInfo[i].type == "R")
			{
				//Last MSMenu has to be absolute width
				arrMenuInfo[i].type = "A";
				arrMenuInfo[i].unit = 200;
			}
			if (arrMenuInfo[i].type == "A")
			{
				//alert(arrMenuInfo[i].unit);
				//thisMenu.style.width = arrMenuInfo[i].unit;
				document.getElementById("AM_" + thisMenu).style.width = 200 + "px";
			}
			else
			{
				document.getElementById("AM_" + thisMenu).style.width = Math.round(arrMenuInfo[i].width * arrMenuInfo[i].unit) + 'em';
			}
		}
	}

	//If the page has requested that we show navagation, then show the timer as well
	if (ShowNavigation == true) {
	
		// Try to start the web page firing the browsingTime() function every second, controls our timeout popup
		try
		{
			iIntID = window.setInterval("browsingTime();", 1000);
		}
		catch (e)
		{
			//Do Nothing
		}	
	
	}	
}

function resizeToolbar()
{
	//if (ToolBar_Supported == false) return;
	w = Math.max(ToolbarMinWidth, document.body.clientWidth) - ToolbarMinWidth;
	document.getElementById("idMenuBanner").style.left = 0;
	document.getElementById("idMenuBanner").style.width = ToolbarWidth + "px"; //760; //document.body.clientWidth;

	document.getElementById("idMLSWebMenuPane").style.width = ToolbarWidth + "px"; //760; //ToolbarMinWidth + w;
}

function setToolbarBGColor(color)
{	
	ToolbarBGColor = color;
	if (ToolbarLoaded == true)
		idToolbar.style.backgroundColor = ToolbarBGColor;
}	

function setMLSWebMenuFont(sFont)
{	
	MLSWebFont = sFont;
}

function setDefaultMLSWebMenuColor(bgColor, fontColor, mouseoverColor)
{	
	if (bgColor   != "")	  aDefMLSWebColor[0] = bgColor;
	if (fontColor != "")	  aDefMLSWebColor[1] = fontColor;
	if (mouseoverColor != "") aDefMLSWebColor[2] = mouseoverColor;
}

//This function doesn't appear to be used as the only place it's called is from within itself.
/*function setMLSWebMenuColor(MenuIDStr, bgColor, fontColor, mouseoverColor)
{	
	if (ToolbarLoaded == false) return;

	// Reset previous MLSWeb Menu color if any
	if (CurICPMenu != "")
	{
		PrevID = CurMLSWebMenu.substring(4);
		CurMLSWebMenu = "";
		setMLSWebMenuColor(PrevID, aDefMLSWebColor[0], aDefMLSWebColor[1], aDefMLSWebColor[2]);
	}

	var id = "AM_" + "ICP_" + MenuIDStr;
	alert(document.all(id));
	var thisMenu = document.all(id);
	if (thisMenu != null)
	{
		CurMLSWebMenu = "MLSWEB_" + MenuIDStr;
		aCurMLSWebColor[0] = bgColor;
		aCurMLSWebColor[1] = fontColor;
		aCurMLSWebColor[2] = mouseoverColor;

		// Change menu color
		if (bgColor != "")
			thisMenu.style.backgroundColor = bgColor;
		if (fontColor != "")
			thisMenu.style.color = fontColor;

		// Change subMenu color
		id = "MLSWEB_" + MenuIDStr;
		thisMenu = document.all(id);
		if (thisMenu != null)
		{
			if (bgColor != "")
				thisMenu.style.backgroundColor = bgColor;
			
			if (fontColor != "")
			{
				i = 0;
				id = "AS_" + "MLSWEB_" + MenuIDStr;
				thisMenu = document.all.item(id,i);
				while (thisMenu != null)
				{
					thisMenu.style.color = fontColor;
					i += 1;
					thisMenu = document.all.item(id,i);
				}
			}
		}
	}
}*/

function setAds(Gif,Url,AltStr)
{	setBanner(Gif,Url,AltStr,"<!--BEG_ADS_BANNER-->","<!--END_ADS_BANNER-->");
}

function setMenuBanner(Gif,AltStr)
{	setBannerImage(Gif,AltStr,"<!--BEG_MENU_BANNER-->","<!--END_MENU_BANNER-->");
}

function setBannerImage(BanGif, BanAltStr, BanBegTag, BanEndTag)
{
	begPos = HTMLStr.indexOf(BanBegTag);
	endPos = HTMLStr.indexOf(BanEndTag) + BanEndTag.length;
	
	SubStr = HTMLStr.substring(begPos, endPos);
	SrcStr = "";
	SrcStr += "<table width=" + ToolbarWidth + " border=0 cellspacing=0 cellpadding=0 height='100%' background='" + BanGif + "'>";
	SrcStr += "<tr><td class=l valign='top' width='100%'>";
	SrcStr += "<font face='Verdana' color='" + aDefMLSWebColor[1] + "' size='5'>&nbsp;" + TitleText + "</font>"
	SrcStr += "</td></tr></table>"
	SrcStr = BanBegTag + SrcStr + BanEndTag;
	HTMLStr = HTMLStr.replace(SubStr, SrcStr);	
}

function setBanner(BanGif, BanUrl, BanAltStr, BanBegTag, BanEndTag)
{
	begPos = HTMLStr.indexOf(BanBegTag);
	endPos = HTMLStr.indexOf(BanEndTag) + BanEndTag.length;
	
	SubStr = HTMLStr.substring(begPos, endPos);
	SrcStr = "";
	if (BanUrl != "")
		SrcStr += "<A Target='_top' HREF='" + formatURL(BanUrl, BanGif) + "'>";
	SrcStr += "<IMG SRC='" + BanGif + "' ALT='" + BanAltStr + "' BORDER=0>";
	if (BanUrl != "")
		SrcStr += "</A>";
	SrcStr = BanBegTag + SrcStr + BanEndTag;
	HTMLStr = HTMLStr.replace(SubStr, SrcStr);	
}

function setMLSWebMenuWidth(Width)
{	
	ToolbarWidth=Width;
}

function setMLSWebSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
{	
	tempID = "MLSWEB_" + MenuIDStr;
	setSubMenuWidth(tempID, WidthType, WidthUnit);
}

function setSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
{
	var fFound = false;
	if (TotalMenu == MaxMenu)
	{
		alert("Unable to process menu. Maximum of " + MaxMenu + " reached.");
		return;
	}
	
	for (i = 0; i < TotalMenu; i++)
		if (arrMenuInfo[i].IDStr == MenuIDStr)
		{
			fFound = true;
			break;
		}

	if (!fFound)
	{
		arrMenuInfo[i] = new menuInfo(MenuIDStr);
		TotalMenu += 1;
	}

	if (!fFound && WidthType.toUpperCase().indexOf("DEFAULT") != -1)
	{
		arrMenuInfo[i].type = "A";
		arrMenuInfo[i].unit = 160;
	}
	else
	{
		arrMenuInfo[i].type = (WidthType.toUpperCase().indexOf("ABSOLUTE") != -1)? "A" : "R";
		arrMenuInfo[i].unit = WidthUnit;
	}
}

// This function creates a menuInfo object instance.
function menuInfo(MenuIDStr)
{
	this.IDStr = MenuIDStr;
	this.type  = "";
	this.unit  = 0;
	this.width = 0;
	this.count = 0;
}

function updateSubMenuWidth(MenuIDStr)
{
	for (i = 0; i < TotalMenu; i++)
		if (arrMenuInfo[i].IDStr == MenuIDStr)
		{
			if (arrMenuInfo[i].width < MenuIDStr.length) 
				arrMenuInfo[i].width = MenuIDStr.length;
			arrMenuInfo[i].count = arrMenuInfo[i].count + 1;
			break;
		}
}

function addMLSWebMenu(MenuIDStr, MenuDisplayStr, MenuHelpStr, MenuURLStr)
{ 	
	if (addMLSWebMenu.arguments.length > 4)
		TargetStr = addMLSWebMenu.arguments[4];
	else
		TargetStr = "_top";
	tempID = "MLSWEB_" + MenuIDStr;
	addMenu(tempID, MenuDisplayStr, MenuHelpStr, MenuURLStr, TargetStr, true); 
}

function addMenu(MenuIDStr, MenuDisplayStr, MenuHelpStr, MenuURLStr, TargetStr, bMLSWebMenu)
{
	cFont   = MLSWebFont;
	cColor0 = aDefMLSWebColor[0];
	cColor1 = aDefMLSWebColor[1];
	cColor2 = aDefMLSWebColor[2];
	tagStr  = "<!--MLSWEB_MENU_TITLES-->"

	MenuStr = newLineChar;
	if (bMLSWebMenu == false && LastMenu != "")
		MenuStr += "<SPAN STYLE='font:" + cFont + ";color:" + cColor1 + "'>|&nbsp;</SPAN>"; 
	MenuStr += "<A TARGET='" + TargetStr + "' TITLE='" + MenuHelpStr + "'" +
			   "   id='AM_" + MenuIDStr + "'" +
			   "   STYLE='text-decoration:none;cursor: pointer;font:" + cFont + ";background-color:" + cColor0 + ";color:" + cColor1 + ";'";
	if (MenuURLStr != "")
	{
		if (bMLSWebMenu)
			MenuStr += " HREF='" + formatURL(MenuURLStr, ("MLSWEB_" + MenuDisplayStr)) + "'";
		//else
			//MenuStr += " HREF='" + formatURL(MenuURLStr, ("MS_" + MenuDisplayStr)) + "'";
	}
	else
		MenuStr += " onclick='event.preventDefault();'";
	if(MenuDisplayStr.length<6)
		MenuDisplayStr = "&nbsp;&nbsp;" + MenuDisplayStr + "&nbsp;&nbsp;";
	if(MenuDisplayStr.length>=6 && MenuDisplayStr.length<10)
		MenuDisplayStr = "&nbsp;" + MenuDisplayStr + "&nbsp;";
	MenuStr += 	" onmouseout="  + char34 + "mouseMenu('out' ,'AM_" + MenuIDStr + "'); hideMenu(event);" + char34 + 
				" onmouseover=" + char34 + "mouseMenu('over','AM_" + MenuIDStr + "'); doMenu('"+ MenuIDStr + "', event);" + char34 + ">" +
				"" + MenuDisplayStr + "</a>";
	if (bMLSWebMenu)
		MenuStr += "<SPAN STYLE='font:" + cFont + ";color:" + cColor1 + "'>&nbsp;|</SPAN>";
	MenuStr += tagStr;
	
	HTMLStr = HTMLStr.replace(tagStr, MenuStr);	
	setSubMenuWidth(MenuIDStr,"default",0);
}

function addMLSWebSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr)
{	
	if (addMLSWebSubMenu.arguments.length > 3)
		TargetStr = addMLSWebSubMenu.arguments[3];
	else
		TargetStr = "_top";
	tempID = "MLSWEB_" + MenuIDStr;
	addSubMenu(tempID,SubMenuStr,SubMenuURLStr,TargetStr,true); 
}

function addMLSWebSubMenuTax(MenuIDStr, SubMenuStr, SubMenuURLStr)
{	
	if (addMLSWebSubMenuTax.arguments.length > 3)
		TargetStr = addMLSWebSubMenuTax.arguments[3];
	else
		TargetStr = "_new";
	tempID = "MLSWEB_" + MenuIDStr;
	addSubMenu(tempID,SubMenuStr,SubMenuURLStr,TargetStr,true); 
}

function addMLSWebMenuSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr)
{	
	if (addMLSWebSubMenu.arguments.length > 3)
		TargetStr = addMLSWebSubMenu.arguments[3];
	else
		TargetStr = "_top";
	tempID = "MLSWEB_" + MenuIDStr;
	addMenuSubMenu(tempID,SubMenuStr,SubMenuURLStr,TargetStr,true); 
}

function addSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr, TargetStr, bMLSWebMenu)
{
	cFont   = MLSWebFont;
	cColor0 = aDefMLSWebColor[0];
	cColor1 = aDefMLSWebColor[1];
	cColor2 = aDefMLSWebColor[2];
	
	var MenuPos = MenuIDStr.toUpperCase().indexOf("MENU");
	if (MenuPos == -1) { MenuPos = MenuIDStr.length; }
	InstrumentStr = MenuIDStr.substring(0 , MenuPos) + "|" + SubMenuStr;;
	URLStr        = formatURL(SubMenuURLStr, InstrumentStr);

	var LookUpTag  = "<!--" + MenuIDStr + "-->";
	var sPos = HTMLStr.indexOf(LookUpTag);
	if (sPos <= 0)
	{
		HTMLStr += newLineChar + newLineChar +
				"<span id='" + MenuIDStr + "'" +
				" style='border-top: 1px solid #FFF; display:none;position:absolute;width:200px;background-color:" + cColor0 + ";padding: 5px 0; z-index:9;'" +
				" onmouseout='hideMenu(event);'>";
		if (Frame_Supported == false || bMLSWebMenu == false)
		HTMLStr += "<div>";
	}
	
	if (SubMenuURLStr == "")
		{
		TempStr = newLineChar +
					"<DIV id='AS_" + MenuIDStr + "'" +
					"   STYLE='text-decoration:none;cursor: pointer;font:" + cFont + ";color:" + cColor1 + "'" +
					">" +
					"&nbsp;" + SubMenuStr + "</DIV>" + LookUpTag;
		}
	else
		{
		if(SubMenuStr.length<12)
			SubMenuStr += "&nbsp;&nbsp;&nbsp;&nbsp;"
		TempStr = newLineChar +
					"<A id='AS_" + MenuIDStr + "'" +
					"   STYLE='font: bold 13px Verdana, sans-serif; text-decoration: none; cursor: pointer; color:" + cColor1 + "'" +
					"   HREF='" + URLStr + "' TARGET='" + TargetStr + "'" +
					" onmouseout="  + char34 + "" + char34 +
					" onmouseover=" + char34 + "" + char34 + ">" +
					"&nbsp;" + SubMenuStr + "</A><br />" + LookUpTag;
		}
		
	if (sPos <= 0)
		HTMLStr += TempStr + "</div></span>";
	else
		HTMLStr = HTMLStr.replace(LookUpTag, TempStr);	

	updateSubMenuWidth(MenuIDStr);	
}

function addMenuSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr, TargetStr, bMLSWebMenu)
{
	cFont   = MLSWebFont;
	cColor0 = aDefMLSWebColor[0];
	cColor1 = aDefMLSWebColor[1];
	cColor2 = aDefMLSWebColor[2];
	
	var MenuPos = MenuIDStr.toUpperCase().indexOf("MENU");
	if (MenuPos == -1) { MenuPos = MenuIDStr.length; }
	InstrumentStr = MenuIDStr.substring(0 , MenuPos) + "|" + SubMenuStr;;
	URLStr        = formatURL(SubMenuURLStr, InstrumentStr);

	var LookUpTag  = "<!--" + MenuIDStr + "-->";
	var sPos = HTMLStr.indexOf(LookUpTag);
	if (sPos <= 0)
	{
		HTMLStr += newLineChar + newLineChar +
				"<SPAN id='" + MenuIDStr + "'" +
				" STYLE='display:none;position:absolute;width:160px;background-color:" + cColor0 + ";padding-top:0;padding-left:0;padding-bottom:20;z-index:9;'" +
				" onmouseout='hideMenu(event);'>";
		if (Frame_Supported == false || bMLSWebMenu == false)
			HTMLStr += "<HR  STYLE='position:absolute;left:0;top:0;color:" + cColor1 + "' SIZE=1>";
		HTMLStr += "<DIV STYLE='position:relative;left:0;top:8;'>";
	}

	TempStr = newLineChar +
				"&nbsp;" + SubMenuStr + "<br />" + LookUpTag;
	
	//TempStr = newLineChar +
	//			"<A id='AS_" + MenuIDStr + "'" +
	//			"   STYLE='text-decoration:none;cursor: pointer;font:" + cFont + ";color:" + cColor1 + "'" +
	//			" onmouseout="  + char34 + "mouseMenu('out' ,'" + MenuIDStr + "');" + char34 + 
	//			" onmouseover=" + char34 + "mouseMenu('over','" + MenuIDStr + "');" + char34 + 
	//			">" +
	//			"&nbsp;" + SubMenuStr + "</A><br />" + LookUpTag;
	
	if (sPos <= 0)
		HTMLStr += TempStr + "</DIV></SPAN>";
	else
		HTMLStr = HTMLStr.replace(LookUpTag, TempStr);	

	updateSubMenuWidth(MenuIDStr);	
}

function addMLSWebSubMenuLine(MenuIDStr)
{	
	tempID = "MLSWEB_" + MenuIDStr;
	addSubMenuLine(tempID,true);
}

function addSubMenuLine(MenuIDStr, bMLSWebMenu)
{
	var LookUpTag = "<!--" + MenuIDStr + "-->";
	var sPos = HTMLStr.indexOf(LookUpTag);
	if (sPos > 0)
	{
		cColor  = aDefMLSWebColor[1];
		TempStr = newLineChar + "<font size=1><HR STYLE='color:" + cColor + "' SIZE=1></font>" + LookUpTag;
		//TempStr ="<br /><img src=" + LineURL + " width=100% height=1>" + LookUpTag;
		HTMLStr = HTMLStr.replace(LookUpTag, TempStr);
	}
}

function mouseMenu(id, MenuIDStr)
{
	IsMSMenu = (MenuIDStr.toUpperCase().indexOf("MS_") != -1);
	IsMouseout = (id.toUpperCase().indexOf("OUT") != -1);

	if (IsMouseout)
	{
		color = aDefMLSWebColor[1];
		if (MenuIDStr == CurMLSWebMenu && aCurMLSWebColor[1] != "") 
			color = aCurMLSWebColor[1];
	}
	else
	{
		color = aDefMLSWebColor[2];
		if (MenuIDStr == CurMLSWebMenu && aCurMLSWebColor[2] != "") 
			color = aCurMLSWebColor[2];
	}
	document.getElementById(MenuIDStr).style.color = color;
}

function doMenu(MenuIDStr, evt)
{
	var thisMenu = document.getElementById(MenuIDStr);
	if (ToolbarMenu == null || thisMenu == null || thisMenu == ToolbarMenu) 
	{
		//This is essentially browser detection: If not IE.
		if (evt.stopPropagation)
		{
			evt.stopPropagation();
		}
		else {
			event.cancelBubble = true;
		}
		return false;
	}
	// Reset dropdown menu
	//window.event.cancelBubble = true;
	ToolbarMenu.style.display = "none";
	showElement("SELECT");
	showElement("OBJECT");
	ToolbarMenu = thisMenu;
	//IsMSMenu = (MenuIDStr.toUpperCase().indexOf("MS_") != -1);

	// Set dropdown menu display position
	x = document.getElementById("AM_" + MenuIDStr).offsetLeft +
	 	document.getElementById("AM_" + MenuIDStr).offsetParent.offsetLeft;
	if (MenuIDStr == LastMenu)
		x += (document.getElementById("AM_" + MenuIDStr).offsetWidth - thisMenu.style.posWidth);
	x2 = x + document.getElementById("AM_" + MenuIDStr).offsetWidth;
	y = (document.getElementById("idRow1").offsetHeight);
	document.getElementById(thisMenu.id).style.top = y + "px";
	document.getElementById(thisMenu.id).style.left = x + "px";
	document.getElementById(thisMenu.id).style.clip = "rect(0 0 0 0)";
	document.getElementById(thisMenu.id).style.display = "block";

	// delay 2 millsecond to allow the value of ToolbarMenu.offsetHeight be set
	window.setTimeout("showMenu()", 2);
	return true;
}

function showMenu() 
{
	if (ToolbarMenu != null) 
	{ 
		IsMenuDropDown = (Frame_Supported)? false : true;
		if (IsMenuDropDown == false)
		{
			y = (y - ToolbarMenu.offsetHeight - idRow2.offsetHeight);
			if (y < 0) y = 0;
			ToolbarMenu.style.top = y;
		}
		y2 = y + ToolbarMenu.offsetHeight;

		ToolbarMenu.style.clip = "rect(auto auto auto auto)";
		hideElement("SELECT");
		hideElement("OBJECT");
	}
}

function hideMenu(evt)
{
	if (ToolbarMenu != null && ToolbarMenu != document.getElementById("StartMenu")) 
	{
		// Don't hide the menu if the mouse move between the menu and submenus
		cY = evt.clientY + document.body.scrollTop;
		cX = evt.clientX + document.body.scrollLeft;
		if ( (cX >= (x+5) && cX <= x2) && ((IsMenuDropDown == true  && cY > (y-10) && cY < y2) || (IsMenuDropDown == false && cY >= y && cY <= (y2+10)) ))
		{
			//This is essentially browser detection: If not IE.
			if (evt.stopPropagation)
			{
				evt.stopPropagation();
			}
			else
			{
				event.cancelBubble = true;
			}
			return;
		}

		document.getElementById(ToolbarMenu.id).style.display = "none";
		ToolbarMenu = document.getElementById("StartMenu");
		
		//This is essentially browser detection: If not IE.
		if (evt.stopPropagation) {
			evt.stopPropagation();
		}
		else {
			event.cancelBubble = true;
		}

		showElement("SELECT");
		showElement("OBJECT");
	}
}

function hideElement(elmID)
{
	//This function hides select boxes
	//This is to correct an IE bug that prevents the menu from displaying above selectboxes.
	for (i = 0; i < document.getElementsByTagName(elmID).length; i++)
	{
		obj = document.getElementsByTagName(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;

		// Find the element's offsetTop and offsetLeft relative to the BODY tag.
		objLeft   = obj.offsetLeft;
		objTop    = obj.offsetTop;
		objParent = obj.offsetParent;
		while (objParent.tagName.toUpperCase() != "BODY")
		{
			objLeft  += objParent.offsetLeft;
			objTop   += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}
		// Adjust the element's offsetTop relative to the dropdown menu
		objTop = objTop - y;

		if (x > (objLeft + obj.offsetWidth) || objLeft > (x + ToolbarMenu.offsetWidth))
			;
		else if (objTop > ToolbarMenu.offsetHeight)
			;
		else if (IsMSMenu && (y + ToolbarMenu.offsetHeight) <= 80)
			;
		else
			obj.style.visibility = "hidden";
	}
}

function showElement(elmID)
{
	//This function was re-shows select boxes after they've been hidden by the hideElement Function
	//This is to correct an IE bug that prevents the menu from displaying above selectboxes.
	for (i = 0; i < document.getElementsByTagName(elmID).length; i++)
	{
		obj = document.getElementsByTagName(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;
		obj.style.visibility = "";
	}
}

function formatURL(URLStr, InstrumentStr)
{
	var tempStr = URLStr;

	if (DoInstrumentation && URLStr != "" )
	{
		var ParamPos1 = URLStr.indexOf("?");
		var ParamPos2 = URLStr.lastIndexOf("?");
		var ParamPos3 = URLStr.toLowerCase().indexOf("target=");
		var ParamPos4 = URLStr.indexOf("#");
		var Bookmark  = "";
		var URL = URLStr;
		if (ParamPos4 >= 0)
		{
		 	URL = URLStr.substr(0, ParamPos4);
			Bookmark = URLStr.substr(ParamPos4);
		}
		
		if (ParamPos1 == -1)
			tempStr = "?MSCOMTB=";
		else if (ParamPos1 == ParamPos2 && ParamPos3 == -1)	
			tempStr = "&MSCOMTB=";
		else if (ParamPos1 == ParamPos2 && ParamPos3 != -1)	
			tempStr = "?MSCOMTB=";
		else if (ParamPos1 < ParamPos2)
			tempStr = "&MSCOMTB=";

		tempStr = URL + tempStr + InstrumentStr.replace(" ","%20") + Bookmark;
	}
	return tempStr;
}

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//Opens a new window, lets you pass in whatever params you want
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function OpenNewWindow(sURL,sWindowName,sOptions)
{
	window.open(sURL,sWindowName,sOptions);
}

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

//**************************************
//  Put all timeout functionality here  
//**************************************

function browsingTime() {

	//increment elapsed time
	iElapsedTime++;
	
	//if elapsed time is equal to the timeout notice value, show our inactive message
	if (iElapsedTime==iTimeOutNotice) showInActiveMsg();

	//Check if elasped time is less than our timeout
	if (iElapsedTime < iBrowsingTime) {
		
		//How much time do we have left in seconds?
		var iTimeLeft = iBrowsingTime - iElapsedTime;
		
		//How many minutes are in iTimeLeft?
		var iMin = Math.floor(iTimeLeft / 60);
		
		//How many seconds are in iTimeLeft?
		var iSec = iTimeLeft - (Math.floor(iTimeLeft / 60) * 60);
		
		//Convert seconds to string so we can pad if need be
		var sSec = iSec.toString();
		if (sSec.length==1) sSec = "0" + sSec;
		
		//Set the browser window status
		window.defaultStatus = "Session Time Remaining... " + iMin + ":" + sSec;
	
	} else {
		//we have timed out, clear the status bar
		window.defaultStatus = "";
	}	

}

function showInActiveMsg() {

	//Set status bar to let user know they could be timing out
	window.defaultStatus = "Possibly Timing Out";
	
	//Set up info to pass to our pop up warninig
	var WinArgs = new Array();
	WinArgs[0]=iBrowsingTime - iElapsedTime;
	
	//Display our modal popup warning
	var myWin = window.showModalDialog("http://" + domain + "/Validation/SessionPopupTimer/SessionTimeoutReminder.htm", WinArgs,"status:no;center:yes;scroll:no;resizable:no;dialogWidth:320px;dialogHeight:200px;");

	//What happenned when the window closed?
	if (myWin==1){
		//It closed itself because we have timed out, notify the user
		top.location="http://" + domain + "/Validation/UserInvalid.asp?Sts=2";
	}
	else {
		//The user closed it, rest the timeout and go on our way
		fn_ResetTimeOut();
	}
}

function fn_ResetTimeOut() {	
	iElapsedTime = 0;	
}
