var hostRemove = "/aaas"; // remove this string from the scriptstring every pageload.

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function toggleMenuActive(intCell) {
	// reset current active root-meny cell
	if ( document.getElementById ) {
		var ointCell = document.currentCell;
		if ( ointCell != null ) {
			var oObjC = MM_findObj("m"+ointCell);
			var oSep1 = MM_findObj("sep"+ointCell);
			var oSep2 = MM_findObj("sep"+(ointCell+1));

			oObjC.style.backgroundColor = '#307EC0';
			if ( ointCell<2  ) {
				oSep1.src = '/images/topmenu_left_off.gif';
			} else {
				oSep1.src = '/images/topmenu_sep1.gif';
			}
			if ( ointCell==7 ) {
				oSep2.src = '/images/topmenu_right_off.gif';
			} else {
				oSep2.src = '/images/topmenu_sep1.gif';
			}
		}

		// set new cell as active
		var oObjC = MM_findObj("m"+intCell);
		var oSep1 = MM_findObj("sep"+intCell);
		var oSep2 = MM_findObj("sep"+(intCell+1));
		oObjC.style.backgroundColor = '#0A599B';

		if ( intCell<2  ) {
			oSep1.src = '/images/topmenu_left_on.gif';
		} else {
			oSep1.src = '/images/topmenu_sep2.gif';
		}
		if ( intCell==7 ) {
			oSep2.src = '/images/topmenu_right_on.gif';
		} else {
			oSep2.src = '/images/topmenu_sep3.gif';
		}

		document.currentCell = intCell;
	}
}
document.currentCell = 1;

function togglePageMenu(intPid, bolClose) {
	var imgObj = MM_findObj("img"+intPid);
	var spanObj = MM_findObj("p"+intPid);

	var ointPid = document.intPid ;

	// --- hide current load subpage menu --- //
	if ( ointPid != null ) {
		if ( ointPid != intPid ) {
			togglePageMenu(ointPid, true);
		}
	}

	// --- toggle arrow image right next to the menu item itself --- //
	if ( imgObj != null ) {
		if ( imgObj.src.substring(imgObj.src.lastIndexOf('/')+1, imgObj.src.length) == "pixel.gif" && !bolClose) {
			imgObj.src = "/images/submenu_arrow_down.gif";
		} else {
			imgObj.src = "/images/pixel.gif";
		}
	}
	// --- toggle display for the level 4 menu-items --- //
	if ( spanObj != null ) {
		if ( (spanObj.style.display == "" || spanObj.style.display == "none") && !bolClose) {
			spanObj.style.display = "block";
		} else {
			spanObj.style.display = "none";
		}
	}

	document.intPid = intPid;
}

window.onload = function() {
	initFoldout();

	var hostString = document.location.pathname; // get current path for current loaded page
	hostString = hostString.replace(hostRemove, ""); // strip any unwanted folders if specified

	var levelIndex = 1;
	var folderPointer = 1;
	while ( hostString.indexOf('/', folderPointer)>-1 ) { // loop while there are more sub-folders present
		eval("var level"+levelIndex+"id = leve"+levelIndex+"Menus[hostString.substring(1, hostString.indexOf('/', folderPointer))];"); // set variable-name depeding on level to corresponding path
		folderPointer = hostString.indexOf('/', folderPointer)+1; // move "pointer" to following folder
		levelIndex++;
	}

	if ( !(typeof(level1id) == "undefined") ) {
		toggleMenuActive(parseInt(level1id)); // mark root-menu as active
		MM_showHideLayers('sub'+level1id,'','show'); // display submenu for current root-menu
	}
	if ( !(typeof(level2id) == "undefined") ) {
		if ( !(browser == 'Netscape' && version >= 4.0) )
			MM_findObj("s"+level1id+"c"+level2id).style.backgroundColor = '#3B8ACC'; // mark current submenu-item as active
	}
	if ( !(typeof(level3id) == "undefined") ) {
		menu(level3id); // show current subpage-menu (to the left) if any...
	}
}