/*************************************************************
  writeMenu() written 1/17/04 by Nancy Brauer  
  Last modified 1/22/06
  If you reuse this code, please include this comment block.
  Thanks!
*************************************************************/

// Some images we'll use multiple times
var arrow = new Image;
var arrow_down = new Image;
var arrow_select = new Image;

function writeMenu(strSelect, intLevels)
{
	var strReturn = "";

	// Before going any further, make sure we got valid two arguments.
	if ((strSelect.length > 0) && (intLevels >= 0))
	{
		// We're good to go.  Declare and initialize variables.
		var bItemSelected = false;

		// Define the background color for the selected row in the menu.
		var strSelectBGcolor = "#FEFDCA";

		// Default the relative path string to the current directory.
		var strPath = "./";

		// Declare the arrays of menu titles, items, and links.
		var arrayTitles = Array("Home","Regions","Members &amp; Officers","Bylaws","Certification Programs","Training","Events","Forms &amp; Registrations","Legislative News","Open Forum","Newsletters","Links");
		var arrayItems = Array("index","regions","members","bylaws","cert","training","conferences","forms","leg","forum","newsletters","links");
		var arrayLinks = Array("index","regions/index","members/index","bylaws","certification/index","training/index","conferences/index","forms","legislative","forum","newsletters","links");

		// If intLevels > 0, set strPath appropriately.
		if (intLevels > 0)
		{
			strPath = "";
			for (var i = 0; i < intLevels; i++) {
					strPath = strPath + "../";
			}
		}

		// Set the sources for the images.
		arrow.src = strPath + "graphics/arrow.gif";
		arrow_down.src = strPath + "graphics/arrow_down.gif";
		arrow_select.src = strPath + "graphics/arrow_select.gif";

		// Begin the menu table.
		strReturn = strReturn + "<table width='100%' border=0 cellpadding=4 cellspacing=0>\n";

		for (var i = 0; i < arrayItems.length; i++) {
			// Reinitialize bItemSelected.
			bItemSelected = false;

			// Start the table row.
			strReturn = strReturn + "<tr";

			// Should the current menu item be selected?
			if (arrayItems[i] == strSelect)
			{
				bItemSelected = true;
				// Write the background color.
				strReturn = strReturn + " bgcolor='"+strSelectBGcolor+"'";	
			}

			// Close the table row.
			strReturn = strReturn + ">\n";
			
			// Start the table cell.
			strReturn = strReturn + "<td valign='middle'>";

			if (bItemSelected)
			{
				// Selected
				strReturn = strReturn + "<img src='"+strPath+"graphics/arrow_select.gif' border=0></td>\n";
				// Start the next table cell.
				strReturn = strReturn + "<td valign='middle' class='menu_select'>"+arrayTitles[i]+"</td>\n";

			} else {
				// Not selected
				// Write the image and link.
				strReturn = strReturn + "<a href='"+strPath+arrayLinks[i]+".htm' onMouseOver='document.images[\""+arrayItems[i]+"\"].src=arrow.src' onMouseOut='document.images[\""+arrayItems[i]+"\"].src=arrow_down.src'><img src='"+strPath+"graphics/arrow_down.gif' name='"+arrayItems[i]+"' border=0></a></td>\n";

				// Start the next table cell.
				strReturn = strReturn + "<td valign='middle'>";
				strReturn = strReturn + "<a href='"+strPath+arrayLinks[i]+".htm' class='menu' onMouseOver='document.images[\""+arrayItems[i]+"\"].src=arrow.src' onMouseOut='document.images[\""+arrayItems[i]+"\"].src=arrow_down.src'>"+arrayTitles[i]+"</a></td>\n";
			}

			// Close the table row.
			strReturn = strReturn + "</tr>\n";
		} // end for

		// Begin the menu table.
		strReturn = strReturn + "</table>\n";

	} else {
		// Didn't get two valid arguments.  
		strReturn = strReturn + "Error:  One or more invalid arguments were passed to writeMenu.\n";

		// for debugging
		//alert (strSelect);
		//alert (strSelect.length);
		//alert(intLevels);

	} // end if

	return strReturn;

} // end function writeMenu