/*
 * Email obfuscator
 */
function generateEmail(hostname, username) {
    var atSign = "&#64;";
    var email = username + atSign + hostname;
    document.write("<" + "a" + " " + "href" + "=" + "mail" + "to:" + email + ">" + email + "<\/a>");
}

/*
 * Function to initialise the menu by setting the class of all li's to empty.
 */
function initialiseMenu() {
	var menuLevel1 = $('menuLevel1');
	if (menuLevel1 == null)
		return;
	//var liTags = menuLevel1.getElementsByTagName("li");
	var liTags = $$('li');
	if (liTags != null) {
		for (var i = 0; i < liTags.length; i++) {
			if (liTags[i].getAttribute("class") == "selected")
				liTags[i].setAttribute("class", "");
			// Toggle selected unselect
			liTags[i].onclick = function() {
					if (this.className == "selected")
						this.className = "";
					else
						this.className = "selected";
			}
		}
	}
}

/*
function toggleMenuItem(section) {
	if (section != null) {
		if (section.getAttribute("class") == "selected")
			section.setAttribute("class", "");
		else
			section.setAttribute("class", "selected");
	}
}

function toggleMenuItem(section) {
	if (section != null) {
		if (section.className == "selected")
			section.className = "";
		else
			section.className = "selected";
	}
}
*/

/*
 * Extracts the menu id from the uri and then hilights the menu item.
 */
function selectMenuItem(menuItemId) {
	initialiseMenu();
	if (menuItemId == null || menuItemId.trim() == "")
		return;
	var menuItem = $(menuItemId);
	var parentLi = findParentLi(menuItem);
	if (parentLi != null)
		parentLi.className = "selected";
	if (menuItem != null)
		menuItem.className = "selected";
}

/*
 * Find the parent menu tag
 */
function findParentLi(obj) {
    var testObj = obj.parentNode;
    while(testObj != null && testObj.nodeName.toLowerCase() != "li") {
        testObj = testObj.parentNode;
    }
    return testObj;
}