current_menu = "";
current_global_menu = "";
menu_on = 0;
global_menu_on = 0;

var debug_list = "";

function buildMenu2(menu_name, menu_array)
{
	// [0] - Background Color
	// [1] - Border Color
	// [2] - Highlight Color
	// [3] - Link Name
	// [4] - Link HREF
	// [5] - Link Target

	document.write("<span id=\"" + menu_name + "\" style=\"position: absolute; top: 100px; left: 100px; display: none;\" onMouseOver=\"stopTimer2();\" onMouseOut=\"startTimer2();\">\n");
	if (menu_name == "menu_quicktools") {
		document.write("<table border=0 cellpadding=0 cellspacing=0 style=\"background-color:FFFFFF\">\n");
	}
	else {
		document.write("<table border=0 cellpadding=0 cellspacing=0 style=\"background-color:FBFAEB\">\n");
	}
	
	for (i = 3; i < menu_array.length; i = i + 3)
	{
		if (menu_array[i] == "")
		{
			break;
		}
	
		document.write("<tr>\n");
	
		if (i == 3)
		{
			document.write("<td id=\"" + menu_name + i + "\" style=\"border: 1px solid #" + menu_array[1] + ";\">\n");
		}
		else
		{
			document.write("<td id=\"" + menu_name + i + "\" style=\"border-bottom: 1px solid #" + menu_array[1] + "; border-left: 1px solid #" + menu_array[1] + "; border-right: 1px solid #" + menu_array[1] + ";\"\n");
		}
		
		if(menu_array[i+1].indexOf("javascript:")==-1){
			document.write("<span onClick=\"goUrl('" + menu_array[i+1] + "', '" + menu_array[i+2] + "');\" onMouseOver=\"stopTimer2(), menuItemOn('" + menu_name + i + "', '" + menu_array[2] + "');\" onMouseOut=\"menuItemOff('" + menu_name + i + "', '" + menu_array[0] + "');\">\n");
		}
		else{
			document.write("<span onClick=\""+menu_array[i+1]+"\" onMouseOver=\"stopTimer2(), menuItemOn('" + menu_name + i + "', '" + menu_array[2] + "');\" onMouseOut=\"menuItemOff('" + menu_name + i + "', '" + menu_array[0] + "');\">\n");
		}
		
		document.write("<table width=\"100%\" border=0 cellpadding=0 cellspacing=0><tr><td class=\"dhtml_link_cell\" width=\"100%\" style=\"padding-top:4px;padding-bottom:4px\">\n");
		
		if (menu_array[i+2] == "")
		{
			if(menu_array[i+1].indexOf("javascript:")==-1){
				document.write("<a class=\"dhtml_link\" href=\"" + menu_array[i+1] + "\" >" + menu_array[i] + "</a>\n");
			}
			else{
				document.write("<a class=\"dhtml_link\" href=\"javascript:doNothing();\">" + menu_array[i] + "</a>\n");
			}	
			
		}
		else
		{
			document.write("<a class=\"dhtml_link\" href=\"javascript:doNothing();\">" + 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 buildParentLink(nav_font_color, nav_format, menu_counter, link_name, link_url)
{
	document.write("<tr>");
	
	document.write("<td>");
		document.write("<span id=\"parent_span_menu_" + menu_counter + "\" onMouseOver=\"stopTimer2(), showMenu('menu_" + menu_counter + "');\" onMouseOut=\"startTimer2();\">");
		document.write("<table id=\"parent_menu_" + menu_counter + "\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"115\">");
		document.write("<tr>");
		
		//document.write("<td valign=\"top\" width=\"5\"><img src=\"images/home_" + nav_format + "_arrow.gif\" width=\"5\" height=\"10\" hspace=\"0\" vspace=\"4\" alt=\"nav arrow\" border=\"0\" id=\"parent_arrow_menu_" + menu_counter + "\"/></td>");
		document.write("<td width=\"110\" class=\"dhtml_parent_cell\"><a href=\"" + link_url + "\" style=\"color: #" + nav_font_color + "; text-decoration: none; font-weight: bold; font-size: 13px;\" id=\"parent_link_menu_" + menu_counter + "\">" + link_name + "</a></td>");
		
		document.write("</tr>");
		document.write("</table>");
		document.write("</span>");
	
	document.write("</td>");
	
	document.write("</tr>");
}

function buildParentGlobalLink(nav_font_color, nav_format, menu_counter, link_name, link_url)
{
	if (link_url.search(/javascript\:/) == -1)
	{
		rtn_string = "<span id=\"parent_link_global_menu_" + menu_counter + "\"><a class=\"topnav\" href=\"" + link_url + "\" onMouseOver=\"stopTimer2(), showGlobalMenu('global_menu_" + menu_counter + "');\" onMouseOut=\"startTimer2();\">" + link_name + "</a></span> &nbsp;&nbsp;|&nbsp;&nbsp;";
	}
	else
	{
		rtn_string = "<span id=\"parent_link_global_menu_" + menu_counter + "\"><a class=\"topnav\" href=\"" + link_url + "\">" + link_name + "</a><span> &nbsp;&nbsp;|&nbsp;&nbsp;";
	}
	
	return rtn_string;
}

function menuItemOn(element_name, element_color)
{
	eval("document.getElementById(\"" + element_name + "\").style.background='#" + element_color + "'");
}

function menuItemOff(element_name, element_color)
{
	eval("document.getElementById(\"" + element_name + "\").style.background='#" + element_color + "'");
}

function showMenu2(menu_name)
{ 
	//document.getElementById("debug_menu_name").innerHTML = menu_name;
	//document.getElementById("debug_current_menu").innerHTML = current_menu;

	if (current_menu != "")
	{
		hideMenu2();
	}
	
	current_menu = menu_name;
	
	parentWidth = eval("document.getElementById(\"parent_" + menu_name + "\").offsetWidth");

	xPos = getAbsPos2("parent_" + menu_name)[0];
	yPos = getAbsPos2("parent_" + menu_name)[1];
	xPos += parentWidth;

	// 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'");

	
	//eval("document.getElementById(\"menu_1\").style.display='block'");
	
	// highlight parent link
//	eval("document.getElementById(\"parent_link_" + menu_name + "\").style.textDecoration='underline'");
	//eval("document.getElementById(\"parent_arrow_" + menu_name + "\").src=nav_arrow_on.src");
	//eval("document.getElementById(\"parent_" + menu_name + "\").style.background='#F8D294'");
	eval("document.getElementById(\"parent_" + menu_name + "\").style.backgroundImage = 'url(/discount_programs/images/leftnav_hover.gif)';");
}

function showGlobalMenu(menu_name)
{
	if (current_menu != "")
	{
		hideMenu2();
	}
	
	current_menu = menu_name;
	
	xPos = getAbsPos2("parent_link_" + menu_name)[0];
	yPos = getAbsPos2("parent_link_" + menu_name)[1];
	yPos += 16;
	xPos -= 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 hideMenu2()
{
	// hide menu
	eval("document.getElementById(\"" + current_menu + "\").style.display='none'");
	
	// un-highlight parent link
//	eval("document.getElementById(\"parent_link_" + current_menu + "\").style.textDecoration='none'");
//	if (eval("document.getElementById(\"parent_arrow_" + current_menu + "\")") != null)
//	{
//		eval("document.getElementById(\"parent_arrow_" + current_menu + "\").src=nav_arrow_off.src");
		eval("document.getElementById(\"parent_" + current_menu + "\").style.background=''");
//	}
	
	current_menu = "";
}

function startTimer2()
{
	menu_on = setTimeout("hideMenu2()", 500);
}

function stopTimer2()
{
	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 getAbsPos2(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);
} 

function underLine(learn_link){

	eval("document.getElementById(\"learn_"+learn_link+"\").style.textDecorationUnderline");

}

function removeU(learn_link){

	eval("document.getElementById(\"learn_"+learn_link+"\").style.textDecorationNone");

}

function showMenuSide(menu_name, side)
{
	if (current_menu != "")
	{
		hideMenu2();
	}
	
	current_menu = menu_name;
	
	parentWidth = eval("document.getElementById(\"parent_" + menu_name + "\").offsetWidth");
	parentHeight =  eval("document.getElementById(\"parent_" + menu_name + "\").offsetHeight");


	if (side == "left")
	{
		xPos = getAbsPos2("parent_" + menu_name)[0];
		yPos = getAbsPos2("parent_" + menu_name)[1];
		
//		xPos -= (eval("document.getElementById(\"" + menu_name + "\").offsetWidth"));
		xPos -= 152;
//		alert(menu_name);
//		yPos -= parentHeight;
	}
	
	if (side == "bottom")
	{
		xPos = getAbsPos2("parent_" + menu_name)[0];
		yPos = getAbsPos2("parent_" + menu_name)[1];
		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 loadContent(xml) {
  //alert (xml);
  var vbCode = "<%=pageTitle%>";
	alert(vbCode);
	//document.getElementById('content').innerHTML = xml + '<br>' + '<%buildContent("' + xml + '")%>'
	document.getElementById('content').innerHTML = vbCode
	
	//writeLayer('content','<%buildContent("nutrition.xml")%>');
}
*/

function writeLayer(layerID,txt){
	var ly
	if(document.all){
		ly=document.all[layerID]
		if(typeof(ly)=='object') ly.innerHTML=txt
		return;
	}
	if(document.getElementById){
		ly=document.getElementById(layerID) 
		if(typeof(ly)=='object') ly.innerHTML=txt
		return;
	}	
	if(document.layers){
		ly = document.layers[layerID]
		if(typeof(ly)=='object') {
			ly.document.open();
			ly.document.write(txt);
			ly.document.close();
		}
    }
}
