/* Section_tree will normally have been included via Act_section_tree.js */

var	MAX_ROWS = 19;

function generateMenu(section_tree)
{
	var	result = "";
	var	count = 0;

	result += "<table>";

	result += "<tr><td colspan='100'><img src='close.png' onclick='popup_menu(170, 153, false, false);' align='right' /><img src='dddundee-product-menu-text.png' /><span style='font-size:75%'><br /><br /></span></td></tr>";
	
	result += "<tr><td class='menucolumn'>";
	result += "<table class='menutable'>";

	for (var i = 1; i <= section_tree.length; ++i) {
		var	elm = section_tree[i];

		if (elm.sName.toLowerCase() != 'discontinued') {
			result += "<tr><td><b><a class='menumainentry' href='" + elm.sURL + "'>" + elm.sName + "</b></td></tr>";
			++count;

			result += "<tr><td class='menusubentry'>";
			if (elm.pChild  &&  (elm.pChild.length > 0)) {
				for (var j = 1; j <= elm.pChild.length; ++j) {
					var	subElm = elm.pChild[j];

					result += "<a href='" + subElm.sURL + "'>" + subElm.sName + "</a><br />";
					++count;
				}
			}
			result += "</td></tr>";

			if (count > MAX_ROWS) {
				result += "</table></td><td class='menucolumn'><table class='menutable_next_col menutable'>";		/* End column, start new column; this will not split a top-level section even if it's too long */
				count = 0;
			}
		}
	}

	result += "</table>";
	result += "</td></tr></table>";

	return result;	
}
