/* 
	List Menu Helper
	----------------
	
	js functions that help with menus that are built around list items like
	those found in the Management Team pages.
	
	depends on: util.js
	
 */
 

/*  ------------------------------------------
	checkMenuForSelected
	------------------------------------------ 
	For each menu item, check it to see if you need to prepend "selected" to
	the list item class (if the anchor matches the current page).  It
	assumes each list item has only one anchor.
	------------------------------------------ */

	function checkMenuForSelected(id) {
	
		// Get the span/div element.
		var menuSpanList = document.getElementById(id);
		if (menuSpanList == undefined) return false;

		var listItems = menuSpanList.getElementsByTagName("li");
		if (listItems == undefined) return false;

		// For each menu item, check to see if it needs to be "selected".
		for (var i = 0; i < listItems.length; i++) {
			var bSelected = false;
			var className = listItems[i].className;

			// Check the first anchor for href value.
			var anchors = listItems[i].getElementsByTagName("a");
			if (anchors != undefined && anchors.length > 0) {
				var href = anchors[0].getAttribute("href");

				// If that href corresponds to this page, make it selected.
				if (isURIMe(href, 1)) {
					bSelected = true;
					var innerText = document.createElement("span");
					innerText.innerHTML = anchors[0].innerHTML;
					listItems[i].replaceChild(innerText, anchors[0]);
				} // if
			} // if
			
			// Change the listItem class name.
			if (bSelected) {
				className = "selected " + className;
				listItems[i].className = className;
			} // if
		} // for

	} // checkMenuForSelected
	

/*  ------------------------------------------
	checkMenuForDeleted
	------------------------------------------ 
	For each menu item, check it to see if you need to delete an item from
	the list (if the anchor matches the current page).  It assumes each list
	item has only one anchor.
	------------------------------------------ */

	function checkMenuForDeleted(id) {
	
		// Get the span/div element.
		var menuSpanList = document.getElementById(id);
		if (menuSpanList == undefined) return false;

		var listItems = menuSpanList.getElementsByTagName("li");
		if (listItems == undefined) return false;

		// For each menu item, check to see if it needs to be "deleted".
		for (var i = 0; i < listItems.length; i++) {
			// Check the first anchor for href value.
			var anchors = listItems[i].getElementsByTagName("a");
			if (anchors != undefined && anchors.length > 0) {
				var href = anchors[0].getAttribute("href");

				// If that href corresponds to this page, make it deleted.
				if (isURIMe(href, 1)) {
					listItems[i].parentNode.removeChild(listItems[i]);
				} // if
			} // if
		} // for

	} // checkMenuForDeleted
