if (document.getElementById){

	// toggle menus visibility 
	function toggle( menuID, targetId ){
			var menu;
			var target;

			menu = document.getElementById( menuID );
			target = document.getElementById( targetId );
				if (target.style.display == ""){
	
					for(i=1; (a = menu.getElementsByTagName("ul")[i]); i++) {
						var subMenuID = menuID + "SM" + i;
						document.getElementById( subMenuID ).style.display = "none";
					}
					
					var LastsubMenuID = menuID + "SM" + i;
					var LastsubMenuEle;
					LastsubMenuEle = document.getElementById( LastsubMenuID )
					if (LastsubMenuEle == "undefined" || LastsubMenuEle == null) {
						//nothing
					} else {
						LastsubMenuEle.style.display = "none";
						target.style.display = "block";
						target.parentNode.parentNode.style.display = "block";
						target.parentNode.parentNode.parentNode.parentNode.style.display = "block";
					}


				} else if (target.style.display == "none"){
					
					for(i=1; (a = menu.getElementsByTagName("ul")[i]); i++) {
						var subMenuID = menuID + "SM" + i ;
						//alert( subMenuID );	
						document.getElementById( subMenuID ).style.display = "none";
					}

					var LastsubMenuID = menuID + "SM" + i;
					document.getElementById( LastsubMenuID ).style.display = "none";

					target.style.display = "block";
					target.parentNode.parentNode.style.display = "block";
					target.parentNode.parentNode.parentNode.parentNode.style.display = "block";
				} else {
					target.style.display = "none";
				}
	}


	function expand( menuID, targetId ){
			var menu;
			var target;

			menu = document.getElementById( menuID );
			target = document.getElementById( targetId );
			if (target != null) {
				if ( target.style.display == "none" || target.style.display == "") {
					toggle(menuID,targetId);
				}
			}

	}

	function dohref(newurl, menubase, menupostfix) {
		window.location.href=newurl;

	}


}


function CreateDynamicMenu(menuID, top, left, backColor) {
//just return the relevant menu
	var menu;
	menu = document.getElementById( menuID );

	//we can also shoot through here to locate the url to autoopen
	if (true) {
		autoOpenMenu(menuID);
	}

	return menu;
}

function autoOpenMenu(menuID) {
	var menu;
	menu = document.getElementById( menuID );
	var arr;
	try {
		arr = menu.getElementsByTagName("a")
	} catch(e) {return;}
	try {
		var menuFound = false;
		var hasQueryString = document.URL.indexOf('?');
		var testUrl;
		var testQS = "";
		testUrl = window.location.pathname.toUpperCase();
		if( hasQueryString > -1 ) {
			testQS = document.URL.substring(hasQueryString, document.URL.length).toUpperCase();
		}
		var menuurl;
		for(i=0; (a = arr[i]); i++) {
			menuurl = arr[i].href.toUpperCase();
			if (menuurl.indexOf(testUrl+testQS)>-1 && (arr[i].href.indexOf("#") == -1) ) {
				arr[i].style.color = "#336";
				arr[i].style.fontWeight = "bold";
				//now locate the nearest UL parent
				targetID = arr[i].parentNode.parentNode.id;
				try {
					if( document.getElementById(arr[i].id).parentNode.getElementsByTagName("ul").length > 0 )
					{
						var submenus;
						submenus = document.getElementById(arr[i].id).parentNode.getElementsByTagName("ul");
						expand( menuID, submenus[0].id);
					}
				}
				catch (e) {
					//void
				}
				expand(menuID,targetID);

				//only opens to first match
				menuFound = true;
				break;
			} 
		}

		//no menu found - try stubs
		if (!menuFound) {
		for(i=0; (a = arr[i]); i++) {
			menuurl = arr[i].href.toUpperCase();
			if (menuurl.indexOf(testUrl)>-1 && (arr[i].href.indexOf("#") == -1) ) {
				arr[i].style.color = "#336";
				arr[i].style.fontWeight = "bold";
				//now locate the nearest UL parent
				try {
					targetID = arr[i].parentNode.parentNode.id;
					try {
						if( document.getElementById(arr[i].id).parentNode.getElementsByTagName("ul").length > 0 )
						{
							var submenus;
							submenus = document.getElementById(arr[i].id).parentNode.getElementsByTagName("ul");
							expand( menuID, submenus[0].id);
						}
					} 
					catch(e) {
						//void
					}

					expand(menuID,targetID);
				} catch(e) {}
				//only opens to first match
				break;
			} 
		}
		}



	}
	catch(e) {
		//void
		//alert( e);
	}


}