current_menu = "";
menu_on = 0;

function buildMenu(menu_name, menu_array)
{
	// [0] - Link Name
	// [1] - Link HREF
	// [2] - Link Target

	if(menu_array[3]!=""){
	document.write("<span id=\"" + menu_name + "\" style=\"position: absolute; top: 100px; left: 100px; display: none;\" onMouseOver=\"stopTimer();\" onMouseOut=\"startTimer();\">\n");
	
	//check if quicktools menu.  if so set table width = 120
	if(menu_name.indexOf("quick")==-1){	
		document.write("<table border=0 cellpadding=0 cellspacing=0 background=\"images/trans.gif\" class=\"dhtml_table\">\n");
	}
	else{	
		document.write("<table border=0 cellpadding=0 cellspacing=0 background=\"images/trans.gif\" width=\"140\" class=\"dhtml_table\">\n");
	}
	
	for (i = 0; i < menu_array.length; i = i + 3)
	{
		if (menu_array[i] == "")
		{
			break;
		}
	
		document.write("<tr>\n");
	
		if (i+3 == menu_array.length)
		{
			document.write("<td class=\"dhtml_cell_bottom\">\n");
		}
		else
		{
			document.write("<td class=\"dhtml_cell\">\n");
		}
		
		document.write("<span onClick=\"goUrl('" + menu_array[i+1] + "', '" + menu_array[i+2] + "');\" onMouseOver=\"stopTimer(), menuItemOn('" + menu_name + i + "');\" onMouseOut=\"menuItemOff('" + menu_name + i + "');\">\n");
		document.write("<table width=\"100%\" border=0 cellpadding=0 cellspacing=0><tr><td class=\"dhtml_link_cell\" width=\"100%\" id=\"" + menu_name + i + "\">\n");
		
		if (menu_array[i+2] == "")
		{
			document.write("<a class=\"dhtml_link\" href=\"" + menu_array[i+1] + "\">" + menu_array[i] + "</a>\n");
		}
		else
		{
			document.write("<a class=\"dhtml_link\" href=\"" + menu_array[i+1] + "\" target=\"" + menu_array[i+2] + "\">" + menu_array[i] + "</a>\n");
		}
		
		document.write("</td></tr></table>\n");
		document.write("</span>\n");
		document.write("</td>\n");
		
		document.write("</tr>\n");
	}
	
	document.write("</table>\n");
	document.write("</span>\n");
	}
}

function menuItemOn(element_name)
{
	eval("document.getElementById(\"" + element_name + "\").className = 'dhtml_link_cell_on'");
}

function menuItemOff(element_name)
{
	eval("document.getElementById(\"" + element_name + "\").className = 'dhtml_link_cell'");
}

function showMenu(menu_name)
{
	if (current_menu != "")
	{
		hideMenu();
	}
	
	current_menu = menu_name;
	
	parentWidth = eval("document.getElementById(\"parent_" + menu_name + "\").offsetWidth");
	parentHeight =  eval("document.getElementById(\"parent_" + menu_name + "\").offsetHeight");

	xPos = getAbsPos("parent_" + menu_name)[0];
	yPos = getAbsPos("parent_" + menu_name)[1];
//	xPos += parentWidth;
	yPos += parentHeight + 2;
	
	// show menu
	eval("document.getElementById(\"" + menu_name + "\").style.left='" + xPos + "'");
	eval("document.getElementById(\"" + menu_name + "\").style.top='" + yPos + "'");
	eval("document.getElementById(\"" + menu_name + "\").style.display='block'");
}

function hideMenu()
{
	// hide menu
	eval("document.getElementById(\"" + current_menu + "\").style.display='none'");
	current_menu = "";
}

function startTimer()
{
	menu_on = setTimeout("hideMenu()", 500);
}

function stopTimer()
{
	if (menu_on != 0)
	{
		clearTimeout(menu_on);
	}
}

function goUrl(go_url, go_target)
{
	if (go_url != "")
	{
		if (go_target != "")
		{
			window.open(go_url);
		}
		else
		{
			location.href = go_url;
		}
	}
}

function getX(el) 
{ 
	xPos = el.offsetLeft; 
	tempEl = el.offsetParent; 
	while (tempEl != null) 
	{ 
		xPos += tempEl.offsetLeft; 
		tempEl = tempEl.offsetParent; 
	} 
	return xPos; 
} 

function getY(el) 
{ 
	yPos = el.offsetTop; 
	tempEl = el.offsetParent; 
	
	while (tempEl != null) 
	{ 
		yPos += tempEl.offsetTop; tempEl = tempEl.offsetParent; 
	} 
	
	return yPos; 
} 

function getAbsPos(id) 
{ 
	var el = document.all ? document.all(id) : document.getElementById ? document.getElementById(id) : null; 
	
	if (el) 
	{ 
		var trueX = getX(el); 
		var trueY = getY(el); 
	} 
	
	return new Array(trueX, trueY);
} 