var ToolBar_Supported = false;
var Frame_Supported   = false;

if (navigator.userAgent.indexOf("MSIE")    != -1 && 
   ((navigator.userAgent.indexOf("Windows") != -1) || (navigator.userAgent.indexOf("Mac") != -1)) && 
   navigator.appVersion.substring(0,1) > 3)
{
	ToolBar_Supported = true;
}

if (ToolBar_Supported)
{
	var newline = String.fromCharCode(10);
	var dblquot = String.fromCharCode(34);
	var LastMenu= "";
	var CurrentMenu = "";
	var IsMenuDropDown = true;
	var HTMLStr;
	var TBLStr;
	var x = 0;
	var y = 0;
	var x2 = 0;
	var y2 = 0;
	var x3 = 0;
	var ToolbarMinWidth;
	var ToolbarMenu;
	var ToolbarLoaded = false;
	var MenuBGColor;	
	var MenuTextColor;
	var MenuMouseOverColor;
	var CurMenuBGColor;
	var CurMenuTextColor;
	var CurMenuMouseOverColor;
	var MenuFont;
	var MaxMenu = 30;
	var TotalMenu = 0;
	var arrCreateMenuInfo = new Array(30);
	var MenuBGColor	= "black";	// bgcolor;
	var MenuTextColor = "white";	// text font color
	var MenuMouseOverColor = "red";		// mouseover font color

	// Output style sheet and toolbar ID
	document.write("<SPAN ID='StartMenu' style='display:none;'></SPAN>");

	// Build toolbar template
	TBLStr  = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR style='height:20;vertical-align:middle'><!--MENU_TITLES--></TR></TABLE>";
	HTMLStr = 
		"<div id='idToolbar'     style='background-color:white;width:100%'>" +
		"<div id='idRow1'        style='position:relative;height:60;'>" +
		"<div id='idSiteLogo'    style='position:absolute;top:0;left:0;height:60;width:120;overflow:hidden;vertical-align:top;'><!--BEG_SITE_LOGO--><!--END_SITE_LOGO--></div>" +
		"<div id='idPageLogo'    style='position:absolute;top:0;left:0;height:60;width:200;vertical-align:center;overflow:hidden;'><!--BEG_PAGE_LOGO--><!--END_PAGE_LOGO--></div>" +
		"<div id='idPageTitle'   style='position:absolute;top:15;left:320;height:60;vertical-align:center;overflow:hidden;'><!--BEG_PAGE_TITLE--><!--END_PAGE_TITLE--></div>" +
		"</div>" +
		"<div id='idRow2' style='position:relative;height:20;width:100%'>" +
		"<div id='idMenuPane' style='position:absolute;top:0;left:0;height:20;color:white;background-color:black;' NOWRAP><!--MENU_TITLES--></div>" +
		"</div>" +
		"</div>" +
		"<script for=idToolbar event=onresize>ResizeToolbar();</script>" +
		"<script for=idToolbar event=onmouseover>HideMenu();</script>" +
		"<script TYPE='text/javascript'>" + 
		"   var ToolbarMenu = StartMenu;" + 
		"</script>" + 
		"<DIV WIDTH=100%>";

	// Intialize global variables
	MenuFont = "bold xx-small Courier";
	
	MenuBGColor	= CurMenuBGColor = "black";	        // bgcolor;
	MenuTextColor = CurMenuTextColor = "white";	        // text font color
	MenuMouseOverColor = CurMenuMouseOverColor = "red";		// mouseover font color
}

// The hard-coded numbers in functions - drawToolbar() & ResizeToolbar()
// correspond to the dimension of the four gif files:
//		32_16 logo: 60h x 120w
//		page_logo: 60h x 200w 

function DrawToolbar()
{
	HTMLStr += "</div>";
	document.write(HTMLStr);
	ToolbarLoaded = true;
	ToolbarMinWidth = 320;

	idMenuPane.style.backgroundColor = MenuBGColor;
	idMenuPane.style.color			= MenuTextColor;
	ResizeToolbar();

	for (i = 0; i < TotalMenu; i++) 
	{
		thisMenu = document.all(arrCreateMenuInfo[i].IDStr);
		if (thisMenu != null)
		{
			if (arrCreateMenuInfo[i].type == "A")
				thisMenu.style.width = arrCreateMenuInfo[i].unit;
			else 
				thisMenu.style.width = Math.round(arrCreateMenuInfo[i].width * arrCreateMenuInfo[i].unit) + 'em';
		}
	}
}

function ResizeToolbar()
{
	if (ToolBar_Supported == false) return;

	w = Math.max(ToolbarMinWidth, document.body.clientWidth) - ToolbarMinWidth;
	
    idPageLogo.style.left = 120;
    // center Title
	idPageTitle.style.left    = 330;

	idMenuPane.style.width = ToolbarMinWidth + w;
}

function SetPageTitle(TitleStr)
{
    begTag = "<!--BEG_PAGE_TITLE-->";
    endTag = "<!--END_PAGE_TITLE-->";
    begPos = HTMLStr.indexOf(begTag);
    endPos = HTMLStr.indexOf(endTag) + begTag.length;;
    
    SubStr = HTMLStr.substring(begPos, endPos);
    SrcStr = "";
    SrcStr += "<h2>" + TitleStr + "</h2>";
    SrcStr = begTag + SrcStr + endTag;
    HTMLStr = HTMLStr.replace(SubStr, SrcStr);
}

function SetPageLogo(Gif,Url,AltStr)
{	
    SetImage(Gif,Url,AltStr,"<!--BEG_PAGE_LOGO-->","<!--END_PAGE_LOGO-->");
}

function SetSiteLogo(Gif,Url,AltStr)
{	
    SetImage(Gif,Url,AltStr,"<!--BEG_SITE_LOGO-->","<!--END_SITE_LOGO-->");
}

function SetImage(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='" + BanUrl + "'>";
	SrcStr += "<IMG SRC='" + BanGif + "' ALT='" + BanAltStr + "' BORDER=0>";
	if (BanUrl != "")
		SrcStr += "</A>";
	SrcStr = BanBegTag + SrcStr + BanEndTag;
	HTMLStr = HTMLStr.replace(SubStr, SrcStr);	
}

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 (arrCreateMenuInfo[i].IDStr == MenuIDStr)
		{
			fFound = true;
			break;
		}

	if (!fFound)
	{
		arrCreateMenuInfo[i] = new CreateMenuInfo(MenuIDStr);
		TotalMenu += 1;
	}

	if (!fFound && WidthType.toUpperCase().indexOf("DEFAULT") != -1)
	{
		arrCreateMenuInfo[i].type = "A";
		arrCreateMenuInfo[i].unit = 160;
	}
	else
	{
		arrCreateMenuInfo[i].type = (WidthType.toUpperCase().indexOf("ABSOLUTE") != -1)? "A" : "R";
		arrCreateMenuInfo[i].unit = WidthUnit;
	}
}

function CreateMenuInfo(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 (arrCreateMenuInfo[i].IDStr == MenuIDStr)
		{
			if (arrCreateMenuInfo[i].width < MenuIDStr.length) 
				arrCreateMenuInfo[i].width = MenuIDStr.length;
			arrCreateMenuInfo[i].count = arrCreateMenuInfo[i].count + 1;
			break;
		}
}

function AddSiteMenu(MenuIDStr, MenuDisplayStr, MenuHelpStr, MenuURLStr)
{ 	
	if (LastMenu == "") HTMLStr = HTMLStr.replace("<!--MENU_TITLES-->", TBLStr);

	if (AddSiteMenu.arguments.length > 4)
		TargetStr = AddSiteMenu.arguments[4];
	else
		TargetStr = "_top";
	tempID = "ICP_" + MenuIDStr;
	AddMenu(tempID, MenuDisplayStr, MenuHelpStr, MenuURLStr, TargetStr, true); 
	LastMenu = tempID;
}

function AddMenu(MenuIDStr, MenuDisplayStr, MenuHelpStr, MenuURLStr, TargetStr, bICPMenu)
{
	cStyle  = "font:" + MenuFont + ";background-color:" + MenuBGColor + ";color:" + MenuTextColor + ";";
	tagStr  = "<!--MENU_TITLES-->";
	
	if (MenuHelpStr == "") MenuHelpStr = MenuDisplayStr;
	MenuStr = newline;
	MenuStr += "<TD style='" + cStyle + "' ID='AM_" + MenuIDStr + "' NOWRAP>";

	MenuStr += "<A style='text-decoration:none;cursor:hand;font:" + MenuFont + ";color:" + MenuTextColor + ";'" +
			   "   TARGET='" + TargetStr + "'" +
			   "   TITLE=" + dblquot + MenuHelpStr + dblquot;
	if (MenuURLStr != "")
		MenuStr += " HREF='" + MenuURLStr + "'";
	else
		MenuStr += " HREF='' onclick='window.event.returnValue=false;'";
	MenuStr += " onmouseout="  + dblquot + "MouseMenu('out' ,'" + MenuIDStr + "'); HideMenu();" + dblquot + 
			   " onmouseover=" + dblquot + "MouseMenu('over','" + MenuIDStr + "'); DoMenu('"+ MenuIDStr + "');" + dblquot + ">" +
			   "&nbsp;" + MenuDisplayStr + "&nbsp;</a>";
	MenuStr += "&nbsp;</TD><TD style='" + cStyle + "'>|</TD>";

	MenuStr += tagStr;
	HTMLStr = HTMLStr.replace(tagStr, MenuStr);	
	SetSubMenuWidth(MenuIDStr,"default",0);
}

function AddSiteSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr)
{	
	if (AddSiteSubMenu.arguments.length > 3)
		TargetStr = AddSiteSubMenu.arguments[3];
	else
		TargetStr = "_top";
	tempID = "ICP_" + MenuIDStr;
	AddSubMenu(tempID,SubMenuStr,SubMenuURLStr,TargetStr,true); 
}

function AddSubMenu(MenuIDStr, SubMenuStr, SubMenuURLStr, TargetStr, bICPMenu)
{
	
	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 += newline + newline +
				"<SPAN ID='" + MenuIDStr + "'" +
				" style='display:none;position:absolute;width:160;background-color:" + MenuBGColor + ";padding-top:0;padding-left:0;padding-bottom:20;z-index:9;'" +
				" onmouseout='HideMenu();'>";
		if (Frame_Supported == false || bICPMenu == false)
			HTMLStr += "<HR  style='position:absolute;left:0;top:0;color:" + MenuTextColor + "' SIZE=1>";
		HTMLStr += "<DIV style='position:relative;left:0;top:8;'>";
	}

	TempStr = newline +
				"<A ID='AS_" + MenuIDStr + "'" +
				"   style='text-decoration:none;cursor:hand;font:" + MenuFont + ";color:" + MenuTextColor + "'" +
				"   HREF='" + URLStr + "' TARGET='" + TargetStr + "'" +
				" onmouseout="  + dblquot + "MouseMenu('out' ,'" + MenuIDStr + "');" + dblquot + 
				" onmouseover=" + dblquot + "MouseMenu('over','" + MenuIDStr + "');" + dblquot + ">" +
				"&nbsp;" + SubMenuStr + "</A><BR>" + LookUpTag;
	if (sPos <= 0)
		HTMLStr += TempStr + "</div></SPAN>";
	else
		HTMLStr = HTMLStr.replace(LookUpTag, TempStr);	

	UpdateSubMenuWidth(MenuIDStr);	
}

function AddSiteSubMenuLine(MenuIDStr)
{	
	tempID = "ICP_" + MenuIDStr;
	AddSubMenuLine(tempID,true);
}

function AddSubMenuLine(MenuIDStr, bICPMenu)
{
	var LookUpTag = "<!--" + MenuIDStr + "-->";
	var sPos = HTMLStr.indexOf(LookUpTag);
	if (sPos > 0)
	{
		TempStr = newline + "<HR style='color:" + MenuTextColor + "' SIZE=1>" + LookUpTag;
		HTMLStr = HTMLStr.replace(LookUpTag, TempStr);
	}
}

function MouseMenu(id, MenuIDStr) 
{
	IsMouseout = (id.toUpperCase().indexOf("OUT") != -1);

	if (IsMouseout)
	{
		color = MenuTextColor;
		if (MenuIDStr == CurrentMenu && CurMenuTextColor != "") 
			color = CurMenuTextColor;
	}
	else
	{
		color = MenuMouseOverColor;
		if (MenuIDStr == CurrentMenu && CurMenuMouseOverColor != "") 
			color = CurMenuMouseOverColor;
	}
	window.event.srcElement.style.color = color;
}

function DoMenu(MenuIDStr) 
{
	var thisMenu = document.all(MenuIDStr);
	if (ToolbarMenu == null || thisMenu == null || thisMenu == ToolbarMenu) 
	{
		window.event.cancelBubble = true;
		return false;
	}
	// Reset dropdown menu
	window.event.cancelBubble = true;
	ToolbarMenu.style.display = "none";
	ShowElement("SELECT");
	ShowElement("OBJECT");
	ShowElement("IFRAME");
	ToolbarMenu = thisMenu;

	// Set dropdown menu display position
	x  = window.event.srcElement.offsetLeft +
	 	 window.event.srcElement.offsetParent.offsetLeft;
	y  = (idRow1.offsetHeight + idRow2.offsetHeight);

	// Get main menu width
	x2 = x + (MenuIDStr == window.event.srcElement.offsetWidth);
	// Get dropdown menu width
	x3 = x + 160;
	for (i = 0; i < TotalMenu; i++)
		if (arrCreateMenuInfo[i].IDStr == MenuIDStr)
		{
			x3 = x+ arrCreateMenuInfo[i].unit;
			break;
		}
	thisMenu.style.top  = y;
	thisMenu.style.left = x;
	thisMenu.style.clip = "rect(0 0 0 0)";
	thisMenu.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;
		}
		// Get dropdown menu height
		y2 = y + ToolbarMenu.offsetHeight;

		ToolbarMenu.style.clip = "rect(auto auto auto auto)";
		HideElement("SELECT");
		HideElement("OBJECT");
		HideElement("IFRAME");
	}
}

function HideMenu()
{
	if (ToolbarMenu != null && ToolbarMenu != StartMenu) 
	{
		var cX = event.clientX + document.body.scrollLeft;
		var cY = event.clientY + document.body.scrollTop;
		var bHideMenu = true;

		if (IsMenuDropDown == true)
		{
			if (cY >= (y - idRow2.offsetHeight+10) && cY < y)
			{
				if (cX >= (x+5) && cX <= x2) bHideMenu = false;
			}
			else if (cY >= y && cY <= y2)
			{
				if (cX > (x+5) && cX <= x3) bHideMenu = false;
			}
		}
		else
		{
			if (cY >= y2 && cY < (y2 + idRow2.offsetHeight))
			{
				if (cX >= (x+5) && cX <= x2) bHideMenu = false;
			}
			else if (cY >= y && cY <= y2)
			{
				if (cX > (x+5) && cX <= x3) bHideMenu = false;
			}
		}

		if (! bHideMenu) 
		{
			window.event.cancelBubble = true;
			return; 
		}

		ToolbarMenu.style.display = "none";
		ToolbarMenu = StartMenu;
		window.event.cancelBubble = true;

		ShowElement("SELECT");
		ShowElement("OBJECT");
		ShowElement("IFRAME");
	}
}

function HideElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(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 ((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 NewItem(ExpDateStr, NewStr)
{
	endDate = new Date(ExpDateStr)
	if (Date.parse(Date()) < Date.parse(endDate))
	{
		document.write('<img src="../images/new.gif" width="30" height="15" border="0" alt="' + NewStr + '">')
	}
}

function UpdatedItem(ExpDateStr, NewStr)
{
	endDate = new Date(ExpDateStr)
	if (Date.parse(Date()) < Date.parse(endDate))
	{
		document.write('<img src="../images/updated.gif" width="50" height="15" border="0" alt="' + NewStr + '">')
	}
}

function InsertSponsor()
{
	document.write('<a href="http://www.yesweareontheweb.com"><img border="0" src="../images/adlogo.gif" alt="never knowingly understood" width="120" height="30"><br>');
	document.write('Visit our sponsor.</a>');
	document.write('<hr width="100" align="center" height="1" color="red">');
}