var newLineChar = String.fromCharCode(10);
var char34 = String.fromCharCode(34);
var LastMSMenu = "";
var IsMSMenu = true;
var IsMenuDropDown = true;
var HTMLStr;
var x = 0;
var y = 0;
var x2 = 0;
var y2 = 0;
var MSMenuWidth;
var ToolbarMinWidth;
var ToolbarMenu;
var ToolbarBGColor;
var ToolbarLoaded = false;
var aDefMColorTopBk = "#5A5A5A";
var aDefMColorTopTx = "#FFFFFF";
var aDefMColorTopTxSel = "#66FF66";
var aDefMColorItemBk = "#9A9A9A";
var aDefMColorItemBkSel = "#5A5A5A";
var aDefMColorItemTx = "#FFFFFF";
var aBorderItemStr = "BORDER-left:#5A5A5A 1px solid;BORDER-RIGHT:#5A5A5A 2px solid;BORDER-bottom:#5A5A5A 2px solid;";

var MSFontN;
var MaxMenu = 40;
var TotalMenu = 0;
var arrMenuInfo = new Array(40);
var PageWidth = 948;

document.write("<SPAN ID='StartMenu' STYLE='display:none;'></SPAN>");

document.write("<iframe id='msMenuiframe1'  src='./Images/WFBkgndTop1.gif' style='Z-INDEX:8; FILTER: Alpha(Opacity=0); VISIBILITY: hidden; POSITION: absolute;' marginWidth=0 marginHeight=0 src='' frameBorder=0 scrolling=no></iframe>");

HTMLStr = 
	"<DIV ID='idToolbar' STYLE='background-color:#5A5A5A;width:948'>" +
	"<DIV ID='idRow1' STYLE='position:relative;'>" + "<!--HEADER MENU-->" +
	"</DIV>" +
	"<DIV ID='idRow3' STYLE='position:relative;height:24;width:100%;'>" +
	"<DIV ID='idMSMenuPane' STYLE='position:absolute;top:0;left:0;height:24;' NOWRAP><table class='MenuTopTB' background='./Images/WFBkgndTop.gif'><tr> <!--MS_MENU_TITLES--> <td width=2%>&nbsp;</td></tr></table></DIV>" +
	"</DIV></DIV><SCRIPT TYPE='text/javascript'>" + 
	"   var ToolbarMenu = StartMenu;</SCRIPT><DIV WIDTH=100%>";
window.onresize  = resizeToolbar;
ToolbarBGColor = aDefMColorTopBk;

MSFontN  = " 8pt Verdana";

function drawToolbar()
{
	HTMLStr += "</DIV>";
	if (typeof(drawHeader)=='function')	HTMLStr	=	drawHeader(HTMLStr);
	if (typeof(appendMenuOpt)=='function') appendMenuOpt();
	document.write(HTMLStr); ToolbarLoaded = true;
	MSMenuWidth     = Math.max(idMSMenuPane.offsetWidth, (200+112));
	ToolbarMinWidth = (250+18);
	idToolbar.style.backgroundColor     = ToolbarBGColor;
	idMSMenuPane.style.backgroundColor  = aDefMColorTopBk;
	resizeToolbar();
	for (i = 0; i < TotalMenu; i++) {
		thisMenu = document.all(arrMenuInfo[i].IDStr);
		if (thisMenu != null){
			if (arrMenuInfo[i].IDStr == LastMSMenu && arrMenuInfo[i].type == "R"){
				arrMenuInfo[i].type = "A";
				arrMenuInfo[i].unit = 200;
			}
			if (arrMenuInfo[i].type == "A")
				thisMenu.style.width = arrMenuInfo[i].unit;
			else 
				thisMenu.style.width = Math.round(arrMenuInfo[i].width * arrMenuInfo[i].unit) + 'em';
		}
	}
}
function resizeToolbar()
{ 
	w =  Math.max(ToolbarMinWidth, PageWidth) - ToolbarMinWidth;	
	idMSMenuPane.style.width  = PageWidth;
}
function setSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
{
	var fFound = false;
	if (TotalMenu == MaxMenu){
		alert("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 = 180;
	}
	else{
		arrMenuInfo[i].type = (WidthType.toUpperCase().indexOf("ABSOLUTE") != -1)? "A" : "R";
		arrMenuInfo[i].unit = WidthUnit;
	}
}
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 addMSMenu(MenuIDStr, MenuDisplayStr, MenuHelpStr, MenuURLStr)
{ TargetStr = "_top"; tempID = "MS_" + MenuIDStr; addMenu(tempID, MenuDisplayStr, MenuHelpStr, MenuURLStr, TargetStr, false); LastMSMenu = tempID;}
function addMenu(MenuIDStr, MenuDisplayStr, MenuHelpStr, MenuURLStr, TargetStr, bCustomMenu)
{
	tagStr  = "<!--MS_MENU_TITLES-->"; MenuStr = newLineChar;
	MenuStr += "<A TARGET='" + TargetStr + "' TITLE='" + MenuHelpStr + "'" +
			   " ID='AM_" + MenuIDStr + "'";
	if (MenuURLStr != ""){MenuStr += " HREF='" + MenuURLStr + "'";}
	else MenuStr += " HREF='' onclick='window.event.returnValue=false;'";
	MenuStr += 	" onmouseout="  + char34 + "mouseMenuTop('out' ,'" + MenuIDStr + "'); hideMenu();" + char34 + 
				" onmouseover=" + char34 + "mouseMenuTop('over','" + MenuIDStr + "'); doMenu('"+ MenuIDStr + "');" + char34 + ">" +
				"<td width=124 valign=center STYLE='text-decoration:none;cursor:hand;'>&nbsp;<b>" + MenuDisplayStr + "</b></td></a>";
	MenuStr += tagStr; HTMLStr = HTMLStr.replace(tagStr, MenuStr);	
	setSubMenuWidth(MenuIDStr,"default",0);
}

function addMSSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr)
{TargetStr = "_top"; tempID = "MS_" + MenuIDStr; addSubMenu(tempID,SubMenuStr,SubMenuURLStr,TargetStr,false); }
function addSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr, TargetStr, bCustomMenu)
{
	cFont   = MSFontN;
	var MenuPos = MenuIDStr.toUpperCase().indexOf("MENU");
	if (MenuPos == -1) { MenuPos = MenuIDStr.length; }
	InstrumentStr = MenuIDStr.substring(0 , MenuPos) + "|" + SubMenuStr;
	URLStr        =  SubMenuURLStr;
	var LookUpTag  = "<!--" + MenuIDStr + "-->";
	var sPos = HTMLStr.indexOf(LookUpTag);
	if (sPos <= 0){
		HTMLStr += newLineChar + newLineChar +
				"<SPAN ID='" + MenuIDStr + "'" +
				" STYLE='display:none;position:absolute;width:160;background-color:" + aDefMColorItemBk + ";padding-top:0;padding-left:0;padding-bottom:3;z-index:9;" + aBorderItemStr + "'" +
				" onmouseout='hideMenu();'>";
		HTMLStr += "<HR  STYLE='position:absolute;left:0;top:0;color:" + aDefMColorTopBk + "' SIZE=1>";
		HTMLStr += "<DIV STYLE='position:relative;left:0;top:1;'>";
	}
	TempStr = newLineChar +
				"<A ID='AS_" + MenuIDStr + "'" +
				"   STYLE='text-decoration:none;padding-top:2;cursor:hand;width:100%;height=18;font:" + cFont + ";color:" + aDefMColorItemTx + "'" +
				"   HREF='" + URLStr + "' TARGET='" + TargetStr + "'" +
				" 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 addMSSubMenuLine(MenuIDStr){tempID = "MS_" + MenuIDStr;addSubMenuLine(tempID,false);}
function addSubMenuLine(MenuIDStr, bCustomMenu)
{
	var LookUpTag = "<!--" + MenuIDStr + "-->";
	var sPos = HTMLStr.indexOf(LookUpTag);
	if (sPos > 0){ cColor  = aDefMColorTopBk;
		TempStr = newLineChar + "<table width=100% border=0 cellpadding=0 cellspacing=0><tr bgcolor=" + char34 + cColor + char34 + " height=1><td  width=100%></td></tr></table>" +  LookUpTag ;
		HTMLStr = HTMLStr.replace(LookUpTag, TempStr);
	}
}
function mouseMenuTop(id, MenuIDStr) 
{
	IsMSMenu   = (MenuIDStr.toUpperCase().indexOf("MS_") != -1);
	IsMouseout = (id.toUpperCase().indexOf("OUT") != -1);
	if (IsMouseout){
		window.event.srcElement.style.color = aDefMColorTopTx;
	}
	else{
		window.event.srcElement.style.color = aDefMColorTopTxSel;
	}
}
function mouseMenu(id, MenuIDStr) 
{
	IsMSMenu   = (MenuIDStr.toUpperCase().indexOf("MS_") != -1);
	IsMouseout = (id.toUpperCase().indexOf("OUT") != -1);
	if (IsMouseout){
		window.event.srcElement.style.backgroundColor = aDefMColorItemBk;
	}
	else{
		window.event.srcElement.style.backgroundColor = aDefMColorTopBk;
	}
}

function doMenuExtra(thisMenu)
{
	var ifrm = document.getElementById("msMenuiframe1");
	ifrm.style.left = thisMenu.style.left;
	ifrm.style.top = thisMenu.style.top;
	ifrm.style.width = thisMenu.style.width;
	ifrm.style.height = thisMenu.scrollHeight + "px";
	ifrm.style.visibility = "visible";
}
function doMenu(MenuIDStr) 
{
	var thisMenu = document.all(MenuIDStr);
	if (ToolbarMenu == null || thisMenu == null || thisMenu == ToolbarMenu) {
		window.event.cancelBubble = true;
		return false;
	}
	window.event.cancelBubble = true;
	ToolbarMenu.style.display = "none";
	showElement("SELECT");
	showElement("OBJECT");
	ToolbarMenu = thisMenu;
	IsMSMenu = (MenuIDStr.toUpperCase().indexOf("MS_") != -1);
	x  = window.event.srcElement.offsetLeft +
	 	 window.event.srcElement.offsetParent.offsetLeft;
//	if (MenuIDStr == LastMSMenu) 
//		x += (window.event.srcElement.offsetWidth - thisMenu.style.posWidth);
	x2 = x + window.event.srcElement.offsetWidth;
	y  = idRow1.offsetHeight+idRow3.offsetHeight;
	thisMenu.style.top  = y;
	thisMenu.style.left = x;
	thisMenu.style.clip = "rect(0 0 0 0)";
	thisMenu.style.display = "block";
	doMenuExtra(thisMenu);
	window.setTimeout("showMenu()", 2);
	
	return true;
}
function showMenu() 
{
	if (ToolbarMenu != null){ 
		IsMenuDropDown = (IsMSMenu == false)? false : true;
		if (IsMenuDropDown == false)
		{
			y = (y - ToolbarMenu.offsetHeight - idRow3.offsetHeight);
			if (y < 0) y = 0;
			ToolbarMenu.style.top = y;
		}
		y2 = y + ToolbarMenu.offsetHeight;

		ToolbarMenu.style.clip = "rect(auto auto auto auto)";
	}
}

function hideMenu()
{
	if (ToolbarMenu != null && ToolbarMenu != StartMenu){
		cY = event.clientY + document.body.scrollTop;
		var cX=event.clientX + document.body.scrollLeft;
		var a = (cX >= (x+5)) && (cX <= (x + window.event.srcElement.offsetWidth))
		var b = (IsMenuDropDown == true)  && (cY > (y-10)) && (cY <= y2) 
		var c = (IsMenuDropDown == false) && (cY >= y) && (cY <= (y2+10))
		if ( (a && b)  || c)
		{
			window.event.cancelBubble = true;
			return; 
		}
		ToolbarMenu.style.display = "none";
		document.getElementById("msMenuiframe1").style.visibility = "hidden";
		ToolbarMenu = StartMenu;
		window.event.cancelBubble = true;
		showElement("SELECT");
		
	}
}
function hideElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++){
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;
		objLeft = obj.offsetLeft; objTop = obj.offsetTop; objParent = obj.offsetParent;
		while (objParent.tagName.toUpperCase() != "BODY"){
			objLeft  += objParent.offsetLeft; objTop   += objParent.offsetTop; objParent = objParent.offsetParent;
		}
		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){for (i = 0; i < document.all.tags(elmID).length; i++){	obj = document.all.tags(elmID)[i]; if (! obj || ! obj.offsetParent)	continue; obj.style.visibility = ""; } }
function ChangePage(FileName){var frm = document.frmMain; frm.szFileName.value = FileName; frm.submit();}
function makevisible(cur,which){if (which==0) cur.filters.alpha.opacity=100; else cur.filters.alpha.opacity=85;}
function IsReturnKey(){if (window.event.keyCode==13){window.event.keyCode=0;return true;}return false;}
function ChangeLanguage()
{
	var frm = document.frmMain;
	if( typeof(frm.szFileName_ME) != 'undefined' ){
		frm.szFileName.value = frm.szFileName_ME.value;
		frm.submit();
	}
	else
		alert('French version of this screen is under construction');
}

