var isID = 0;
var isAll = 0;
var isLayers = 0;
var isMenuActive = 0;
var isSubActive = 0;
var onMenu;
var onSub;
var timeOn = null;
var timeSub = null;

if (document.getElementById){isID=1;}
if (document.layers){isLayers=1;}
if (document.all){isAll=1;}

function menus()
{		
	this.length = 0;				
	this.addMenu = addTopLevelMenu;		
}

function menu(desc,caption,menuURL,menuWidth)
{		
	this.ref = desc			
	this.text = caption;			
	this.href = menuURL;			
	this.itemCount = 0;				
	this.addItem = addMenuItem;	
	this.menuWidth = menuWidth;
}

function menuItem(caption,itemURL,hasLine)
{	
	this.text = caption;			
	this.href = itemURL;			
	this.hasLine = hasLine;			
	this.subMenuExists = 0;			
	this.addSubMenu = addSubMenu;
	this.subRef = "";
}

function addTopLevelMenu(desc,caption,menuURL,menuWidth)
{			
	this.length++;				
	this["menu" + this.length] = new menu(desc,caption,menuURL,menuWidth);	
}

function addMenuItem(caption,itemURL,hasLine)
{	
	this.itemCount++;				
	this["menuItem" + this.itemCount] = new menuItem(caption,itemURL,hasLine)	
}

function addSubMenu(subRef)
{				
	this.subMenuExists = 1;			
	this.subRef = subRef;
	this.subMenu = new menu("",""); 	
}


function drawTopLevelMenu(barWidth)
{		
	var itemWidth = 70; //100.0 / mainMenu.length;
	
	content = "<div id=\"menu\">\n";
	content += "<table cellspacing=\"0\" border=\"0\" align=\"left\" cellpadding=\"2\">\n";
	content += "<tr>\n";
	
	for (i=1; i <= mainMenu.length; i++)
	{
		thisMenu = mainMenu['menu' + i]
		if (!isLayers)
		{
			if (thisMenu.itemCount > 0)
			{
				content += "<td width=\"" + itemWidth + "\" onmouseover=\"showMenu('" + thisMenu.ref + "Menu','main'); window.status='" + thisMenu.text + "'\" ";
				content += "onmouseout=\"menuTimer(); window.status=''\"><span style=\"cursor:default;\" class=\"menuCaption\">" + thisMenu.text + "</td>\n";
			}
			else
				content += "<td class=\"menuItem\" width=\"" + itemWidth + "\">" + "<a class=\"menuCaption\" href=\"" + thisMenu.href + "\">" + thisMenu.text + "</a></td>\n";
		}
		else  
		{
			if (thisMenu.itemCount > 0)
			{
				content += "<td width=\"" + itemWidth + "\">";
				content += "<a class=\"menuCaption\" href=\"\" "
				content += "onmouseover=\"showMenu('" + thisMenu.ref + "Menu','main'); window.status='" + thisMenu.text + "'\" "
				content += "onmouseout=\"menuTimer(); window.status=''\">" + thisMenu.text + "</a></td>\n"
			}
			else
				content += "<td class=\"menuItem\" width=\"" + itemWidth + "\">" + "<a class=\"menuCaption\" href=\"" + thisMenu.href + "\">" + thisMenu.text + "</a></td>\n";
		}


	}
			
	content += "</tr></table></div>"
	document.write (content)
//	confirm(content);	

}


function drawMainMenus(){		

	var content = "";
	var subcontent = "";
	
	for (i=1; i <= mainMenu.length; i++)
		{
	
		thisMenu = mainMenu['menu' + i];
	
		content += "\n<div id=\"" + thisMenu.ref + "Menu\">\n";
		content += "<table border=\"0\" class=\"submenu\" cellpadding=\"2\" cellspacing=\"0\">\n";
		
		
		for (j=1; j <= thisMenu.itemCount; j++)
		{
		
			thisItem = thisMenu['menuItem' +j];
		
			content += "<tr>\n";
			
			if (!isLayers)
			{		
				tdid = 'menu' + i + 'Item' + j;
				content += "<td id=\"" + tdid + "\" width=\"" + thisMenu.menuWidth + "\" onmouseout=\"menuOut('" + tdid + "');";
				
				if (thisItem.subMenuExists)
					content += "subTimer()";
				
				content += "\" onmouseover=\"menuOver('" + tdid + "');";
				
				if (thisItem.subMenuExists)
					content += "showMenu('" + thisItem.subRef + "','sub')";
				
				content += "\" onclick=\"location.href='" + thisItem.href + "'\"><a class=\"menuItem\" href=\"" + thisItem.href + "\">&nbsp;";
				content += thisItem.text + "&nbsp;</a>";
				content += "</td>\n";
				
			} 
			else 
			{
				content += "<td width=\"" + thisMenu.menuWidth + "\"><a class=\"menuItem\" href=\"" + thisItem.href + "\" onmouseout=\"menuOut();";
				
				if (thisItem.subMenuExists)
					content += "subTimer()";
				
				content += "\" onmouseover=\"menuOver();";
				
				if (thisItem.subMenuExists)
					content += "showMenu('" + thisItem.subRef + "','sub')";
				
				content += "\">&nbsp;";
				content += thisItem.text + "&nbsp;</a>";
				content += "</td>\n";
			}
			
			content += "</tr>\n";
		
			
			if(thisItem.subMenuExists)
				subcontent += drawSubMenu(thisItem)
			
			if (thisItem.hasLine)
				content += "<tr><td align=\"center\"><img src=\"/images/structure/borderline_bk.gif\" width=\"105\" height=\"1\" border=\"0\"></td></tr>";		
		}
	
		content += "</table>\n";
		content += "</div>\n\n";
	}

//	prompt("dogs", content);
//	confirm(content);
	document.write(content)		
	document.write(subcontent)	
	
}

function drawSubMenu(menuItem)
{	
	var content = "";

	content += "<div id=\"" + menuItem.subRef + "\">\n";
	content += "<table border=\"0\" class=\"submenu\" cellpadding=\"2\" cellspacing=\"0\">\n";

	subMenu = menuItem.subMenu;

	for (k=1; k <= subMenu.itemCount; k++)
	{
		subItem = subMenu['menuItem' + k];
		tdid = menuItem.text + 'menuItem' + k;
		content += "<tr>\n";	
		if (!isLayers)
		{		
			content += "<td id='" + tdid +"' onmouseout=\"subOut('" + tdid + "')\" onmouseover=\"subOver('" + tdid + "')\"";
			content += " onclick=\"location.href='" + subItem.href + "'\">";
			content += "<a class=\"menuItem\" href=\"" + subItem.href + "\">&nbsp;";
			content += subItem.text + "&nbsp;</a>"
			if (subItem.hasLine) 
				content += "<hr>";
			content += "</td>\n";
		} 
		else 
		{
			content += "<td>";
			content += "<a class=\"menuItem\" href=\"" + subItem.href + "\"";
			content += " onmouseout=\"subOut()\" onmouseover=\"subOver()\">&nbsp;";
			content += subItem.text + "&nbsp;</a>";
			if (subItem.hasLine)
				content += "<hr>";
			content += "</td>\n";		
		}
		
		content += "</tr>\n";
		
	}

	content += "</table>\n";
	content += "</div>\n\n";
//	prompt("dogs", content);
//	confirm(content);

return content
	
}



function drawMenuBar()
{		
	document.write("<tr><td colspan=2 class=\"menu\">");
	drawTopLevelMenu(100)
//	drawMainMenus();		// NETSCAPE!
	document.write("</td></tr>");
}


function drawFooter()
{
	document.write("<p class=\"copyright\">");
	document.write("Copyright &copy; Tynemarch Systems Engineering Ltd, 2010 All Rights Reserved.");
}


function showMenu(menuName,menuType)
{
	if (menuType=="sub")
	{
		if (timeSub != null) 
		{
			clearTimeout(timeSub)
			hideSub(onSub)
		}
			
	}
	else
	{
		if (timeOn != null) 
		{
			clearTimeout(timeOn)
			hideMenu(onMenu)
		}
	}

	setVisibility(menuName,'visible')

	if (menuType=="sub")
		onSub = menuName
	else 
		onMenu = menuName
}


function menuTimer() 
{
	timeOn = setTimeout("btnOut()",600)
}

function btnOut() 
{
	if (isMenuActive == 0) 
		hideMenu(onMenu)
}

function setVisibility(menuName,state)
{
	if (isID)
		document.getElementById(menuName).style.visibility = state;
	else if (isLayers)
		document.layers[menuName].visibility = state;
	else 
		document.all[menuName].style.visibility = state;
}


function menuOver(tdel) 
{
	if (timeSub != null) 
	{
		clearTimeout(timeSub)
		hideSub(onSub)
	}
	clearTimeout(timeOn)
	isMenuActive = 1

	selectTD(tdel);
}

function menuOut(tdel) 
{
	isMenuActive = 0
	timeOn = setTimeout("hideMenu(onMenu)", 600)

	clearTD(tdel);
}

function subOver(tdel) 
{
	isSubActive = 1
	clearTimeout(timeSub)
	clearTimeout(timeOn)
	isMenuActive = 0

	selectTD(tdel);
}

function subOut(tdel) 
{
	isSubActive = 0
	timeSub = setTimeout("hideSub(onSub)", 400)
	timeOn = setTimeout("hideMenu(onMenu)", 400)

	clearTD(tdel);
}

function menuItemOut()
{
	if (isSubActive == 0) 
		hideSub(onSub)
}

function subTimer()
{
	timeSub = setTimeout("menuItemOut()",400)
}


function hideMenu(menuName)
{
 	if (isMenuActive == 0) 
 	{
		setVisibility(menuName,'hidden')
		if (onSub)
			hideSub(onSub)
 	}
}


function hideSub(menuName)
{
 	if (isSubActive == 0) 
		setVisibility(menuName,'hidden')
}

function selectTD(tdel)
{
	if (isID)
	{
		var t = document.getElementById(tdel);
		if (t == null) return;
		t.className = "tdselected";
	}
}

function clearTD(tdel)
{
	if (isID)
	{
		var t = document.getElementById(tdel);
		if (t == null) return;
		t.className = "";
	}
}