function expandMenuItem(menu_id) {
	//  Then show the child item
	document.getElementById('ID-'+menu_id).className = 'visible';
}
function collapseMenuItem(menu_id) {
	//  Then hide the child item
	document.getElementById('ID-'+menu_id).className = 'hidden';
}

function collapse(menu_id) {
	//  Check for valid 'menu_id'
	if (menu_id != null && menu_id > 0) {
		//  Check for hidden or visible sub-menu and show/hide accordingly
		if (document.getElementById('ID-'+menu_id).className == 'menuTable') {
			document.getElementById('ID-'+menu_id).className = 'hidden';
		}
	}
}

function expand(menu_id) {
	//  Check for valid 'menu_id'
	if (menu_id != null && menu_id > 0) {
		//  Check for hidden or visible sub-menu and show/hide accordingly
		if (document.getElementById('ID-'+menu_id).className == 'hidden') {
			document.getElementById('ID-'+menu_id).className = 'menuTable';
		}
	}
}

function collapseOrExpand(menu_id) {
	//  Check for valid 'menu_id'
	if (menu_id != null && menu_id > 0) {
		//  Check for hidden or visible sub-menu and show/hide accordingly
		if (document.getElementById('ID-'+menu_id).className == 'hidden') {
			expandMenuItem(menu_id);
		}
		else {
			collapseMenuItem(menu_id);
		}
	}
}

function expandAllMenus() {
/*
	This function is solely for the "expand" link at the top of the page.

	All we have to do is loop through all the <UL> elements and set
	className to 'visible'
*/
	var els = document.getElementsByTagName('ul');
	for (i=0; i<els.length; i++) {
		var tmp = els[i].getAttribute('id');
		if (tmp != null) {
			if (tmp.substr(0,3) == 'ID-') {
				if (tmp.substr(3) > 0) {
					expandMenuItem(tmp.substr(3));
				}
			}
		}
	}
}

function collapseAllMenus() {
/*
	The following code loops through every <UL>
	in this document and checks for an ID property
	that matches the IDs we use here ('ID-#') and
	calls the shrink/expand function to hide it
*/
	var els = document.getElementsByTagName('ul');
	for (i=0; i<els.length; i++) {
		var tmp = els[i].getAttribute('id');
		//  Make sure the ID attribute exists
		if (tmp != null) {
			//  Make sure it starts with 'ID-'
			if (tmp.substr(0,3) == 'ID-') {
				//  Make sure it's not 'ID-0'
				if (tmp.substr(3) > 0) {
					collapseMenuItem(tmp.substr(3));
				}
			}
		}
	}
}

/*
	Fire off a function to collapse all the menus from the start
	We could just put "class=hidden" in the code to start with but
	browsers with JavaScript turned off would have no way to show
	the menus again!
*/
window.onload = collapseAllMenus;
