<!-- Begin
// Menu generation system v1.4 2-May-2010 (added menu having URL as well using "menu;url")
// Prior is v1.3 9-Jan-2002
//
var isIE4 = (document.all? true : false);
var isNS4 = (document.layers? true : false);
var isDOM = ((document.getElementById && !isIE4 && !isNS4)? true : false);
//
var mmTimer = null;
var mmDelay = 400;
var mmOver = false;
var mmCurpage = "";
var mmRestore = "";
var mmAx = 0;
var mmAy = 0, mmAyM = 0;

function getRef(id) {
  if (isNS4) return document.layers[id];
  if (isIE4) return document.all[id];
  if (isDOM) return document.getElementById(id);
  // return nothing if not recognized browser
}
function getSty(id) {
  return (isNS4 ? getRef(id) : getRef(id).style);
}

//
// 	Menu system
//
var myMenu = new Array(200);
var mmDomMenu = new Array(400);
var myDomLast = -1;
var myLast = 0;
var mmLastLayer = null;
var mmLastLevel;
var mmLastSubIdx = -1;

function displayMenu()
{
	var i;

	if (!myLast)
	{
		document.writeln("<B>No menu!</B><BR><BR>Try to<BR>reload or<BR>refresh<BR>this page");
		return;
	}
	document.writeln('<TABLE BORDER=0><TR><TD WIDTH="85%">');
	document.writeln(buildMenu(0));
//	i = buildMenu(0); document.writeln(i); alert(i);
	if(isNS4)
		document.writeln('</TD><TD VALIGN=top ALIGN=left><A NAME="msubX"> &nbsp;</A></TD></TR></TABLE>');
	else
		document.writeln('</TD><TD><DIV ID="msubX"> &nbsp;</DIV></TD></TR></TABLE>');
}

function buildMenu(start)
{
	var lvl = myMenu[start].level;
	var i = start - 1;
	var clspre = (start? "mmsub" : "mm");
	var menuStr = '<TABLE CELLSPACING="0" CELLPADDING="1" ALIGN="left" BORDER="0">';
	var si, tstr;
	var si2 = "this.style.backgroundColor='"+(start? mmBGsubover : mmBGover)+"'";
	var si3 = "this.style.backgroundColor='"+(start? mmBGsub : mmBG)+"'";
	var si4 = (isDOM? "MMSelEvent(event," : "MMselect(");
	var si5;
	var suffix2;
	var menuLast = i;
	// first find last item in this level menu
	while(++menuLast < myLast)
	{
		if(myMenu[menuLast].level > lvl) continue;
		if(myMenu[menuLast].level < lvl)
		{
			--menuLast;	// lat item in menu
			break;
		}
	}
	if(menuLast == myLast)
		--menuLast;
	// now go for it
	while(++i <= menuLast)
	{
		si = "mref"+i;
		if(myMenu[i].level > 1)
		{
			MMerror(start,"Nested menus beyond one not allowed yet");
			return null;
		}
		if(myMenu[i].level > lvl) continue;
		if(myMenu[i].level < lvl) break;
		suffix2 = '';
		if(i == menuLast) suffix2 = 'last';
		menuStr += '<TR><TD NOWRAP ';
		
		if(myMenu[i].url == null || myMenu[i].url == "label" || myMenu[i].url == "")
	  		menuStr += ' ALIGN=center CLASS="'+clspre+'ti"> '+myMenu[i].name;	// label
		else if(myMenu[i].name == mmCurpage)
	  		menuStr += ' CLASS="mmcur"> &nbsp;'+myMenu[i].name+' &nbsp;';	// current page
		else if (myMenu[i].url.substring(0,4) == "menu")
		{
			tstr = '>';
			if(isDOM)
				tstr += '<DIV ID="'+si+'">';
			tstr += ' &nbsp;<A HREF="';
			if(mmRolloverSubmenu)
			{
				if(myMenu[i].url.substring(0,5) == "menu;")
					tstr += myMenu[i].url.substring(5)+'" class="mma"';
				else
					tstr += '#" class="mma" onClick="'+si4+i+',false)"';
				tstr += ' onMouseOver="'+si4+i+',false)"';
			}
			else
				tstr += '#" class="mma" onClick="'+si4+i+',false)"';
			tstr += ' onMouseOut="MMselect('+i+',true)"';
			tstr += '>'+myMenu[i].name+' &raquo; </A>';	// was &raquo; &rArr works in Mozilla; &#8658;
			if(isNS4)
			{
				tstr += '<A NAME="'+si+'"><!-- --></A>';
				menuStr += ' CLASS="'+clspre+'cas"' + tstr;
			}
			else
			{
				if(isDOM)
					tstr += '</DIV>';
//					tstr += '<DIV ALIGN="right" ID="'+si+'"> </DIV>';
//					tstr += '<DIV ALIGN="right" ID="'+si+'">&nbsp;</DIV>';
				menuStr += ' CLASS="'+clspre+'cas" onMouseOver="'+si2+'" onMouseOut="'+si3+'"' + tstr;
			}
		}
		else if(isNS4)	// add dot in front with &#149;
		{
			if(myMenu[i].level)	// submenu
				si5 = '" ';
			else
				si5 = '" onMouseOver="MMshow2(null,false);"';
			menuStr += ' NAME="'+si+'" CLASS="'+clspre+'it'+suffix2+'"> &nbsp;<A class="mma" HREF="'+myMenu[i].url+si5+'>'+myMenu[i].name+'</A>&nbsp;';
		}
		else
		{
			if(myMenu[i].level)	// submenu
				si5 = '';
			else
				si5 = 'MMshow2(null,false);';
			menuStr += ' NAME="'+si+'" CLASS="'+clspre+'it'+suffix2+'" onMouseOver="'+si5+si2+'" onMouseOut="'+si3+'"> &nbsp;<A class="mma" HREF="'+myMenu[i].url+'">'+myMenu[i].name+'</A>&nbsp;';
		}
		menuStr += ' </TD></TR>';
	}
	menuStr += '</TABLE>';
	mmLastLevel = i;	// where we should be next
	return menuStr;
}

function MMitem(name, urlormenu, level)
{
	this.name = name;
	this.url = urlormenu;
	this.level = level;
	return this;
}

function MMadd (name, url, level)
{
	if (myLast > 199)
    {
		alert("Out of menu space");
		return;
	}
	if(url.substring(0,4) != "menu" && url != "label" && url.substring(0,5) != "http:")
		url = mmRestore + url;
	if(url.substring(0,5) == "menu;" && url.substring(5,10) != "http:")
		url = "menu;" + mmRestore + url.substring(5);
	var item = new MMitem(name,url,level);
	myMenu[myLast] = item;
	++myLast;
}

function MMerror(val,msg)
{
	var msg2 = (msg == null? "" : msg);
	alert("There is an error for menu item "+val+". "+msg2);
}

function MMsubmenu (idx)
{
	var stLvl = myMenu[idx].level;	// start level
	var refIdx = idx - 1;	// parent index
	var iname = "msub" + refIdx;
	var mStr = 'onMouseOut="MMshow(\''+iname+'\',true);" onMouseOver="mmOver=true;"';

	if(!idx)
	{
		MMerror(idx,"Submenu without prior menu");
		return 999;
	}
	if(isNS4)
		mStr = '<LAYER ID="' + iname + '" VISIBILITY="hide" '+mStr+'>';
	else
		mStr = '<DIV ID="' + iname + '" STYLE="position:absolute;visibility:hidden" '+mStr+'><TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0">'; // padding was 1
	mStr += buildMenu(idx);
	mStr += (isNS4? "</LAYER>" : "</DIV>");
	if(isDOM && !isIE4)
	{
		mmDomMenu[++myDomLast] = mStr;
		mmDomMenu[++myDomLast] = iname;
	}
	else
		MMstr += mStr;
	return mmLastLevel;
}

function MMshow2(id,val)
{
	if(mmLastLayer != null)
	{
		if(isNS4) mmLastLayer.visibility = "hide";
		else mmLastLayer.style.visibility = 'hidden';
		clearTimeout(mmTimer);
		mmTimer = null;
	}
	mmLastLayer = (val? id : null);
	if(val)
	{
		if(isNS4) id.visibility = "show";
		else id.style.visibility = 'visible';
		mmOver = false;
//	if(val)
		mmTimer = setTimeout("MMcheck()",2*mmDelay);
	}
}

function MMcheck()
{
	if(mmLastLayer != null)
	{
		if(mmOver)
		{
			if(mmTimer != null)
				clearTimeout(mmTimer);
			mmTimer = setTimeout("MMcheck()",mmDelay);
		}
		else
			MMshow2(mmLastLayer,false);
	}
}

function MMshow(nameid,val)
{
	var id = getRef(nameid);
	if(!id)
	  alert("Bad reference " + nameid);
	else
		MMshow2(id,val);
}

function MMaloc (name)		// location of anchor for menu to show
{
	var i, iref;

	if(isIE4 || isDOM)
	{
//		alert("MMaloc of "+name);
		i = getRef(name);
		if(i == null)
		{
			alert("Could not MMaloc "+name);
			return false;
		}
		mmAx = i.offsetLeft + i.offsetWidth;	// double bump right
		mmAy = 0;
//		alert(i+" start "+mmAx+","+mmAy);
		while(i != null)
		{
//			alert(i+" at "+i.offsetLeft+","+i.offsetTop);
			mmAx += i.offsetLeft;
			mmAy += i.offsetTop;
			i = i.parentElement;
		}
//		alert("Total is "+mmAx+","+mmAy);
		return true;
	}
	// must be NS4
	for(i = -1; ++i < document.anchors.length;)
	{
		if(document.anchors[i].name == name)
			break;
	}
	if(i == document.anchors.length)
	{
		alert("No such anchor: "+name+" in "+document.anchors.length+" anchors");
		mmAx = mmAy = 0;
		return false;
	}
	mmAx = document.anchors[i].x;
	mmAy = document.anchors[i].y;
	return true;
}

function MMselect(subIdx,timeOut)
{
	var msel = "msub" + subIdx;
	var mref = getRef(msel);
	var mref2 = getRef("msubX");

	if(isIE4 && eval(event))
	{
		MMaloc("msubX");
//		alert("Mouse at "+event.x+","+event.y);
//		alert("msubX at "+mmAx+","+mmAy);
		if(!mmLastLayer || subIdx != mmLastSubIdx)
		{
			mmLastSubIdx = subIdx;
			mmAyM = event.y;
		}
		mmAx = mmAx - mref2.offsetLeft-mref2.offsetWidth - 2*(bWidth + iPad);
//		mmAy = event.y - bWidth - iPad + document.body.scrollTop;
		mmAy = mmAyM - bWidth - iPad + document.body.scrollTop;
//		alert("Select IE "+msel+" moved to "+mmAx+","+mmAy);
		mref.style.pixelLeft = mmAx;
		mref.style.pixelTop = mmAy;
	}
	else if(isDOM)
	{
		var m2 = "mref" + subIdx;

		MMaloc(m2);
//		var j = getRef(m2);
//		alert("Finding "+m2+" at "+mmAx+","+mmAy+" at "+j.screenX+","+j.screenY);
//		alert("mref2.offsetWidth="+mref2.offsetWidth);
		mmAx = mmAx + mref2.offsetWidth +  2*(bWidth + iPad);
		mmAy = mmAyM - bWidth - iPad;
//		alert("Select DOM "+msel+" moved to "+mmAx+","+mmAy);
		mref.style.left = mmAx;
		mref.style.top = mmAy;
	}
	else if(MMaloc("mref"+subIdx))
	{
		var mmAy0 = mmAy;	// save this position
//		alert("Select NS "+msel+" moved to "+mmAx+","+mmAy);
		MMaloc("msubX");
		mref.moveToAbsolute(mmAx,mmAy0);
	}
	MMshow(msel,true);
	mmOver = !timeOut;
	return;
}

function MMSelEvent(event,subIdx,val)
{
	if(!mmLastLayer || subIdx != mmLastSubIdx)
	{
		mmLastSubIdx = subIdx;
		mmAyM = event.clientY;
	}
	MMselect(subIdx,val);
}

// load menu with current page name
// restoreHome is path back to home ("" if in home dir, "../" if in subdir,...)
function loadMenu(curPage,restoreHome)
{
	var i = (curPage == "HOME")? 3 : 0;
	mmRestore = (restoreHome == null? "" : restoreHome);
	myLast = 0;
	MMstr = "";
	menuLoc = window;
	mmCurpage = curPage;
	for(;i < MMarray.length; i += 3)	// first add everything
		MMadd(MMarray[i+1],MMarray[i+2],MMarray[i]);
	for(i = -1; ++i < myLast;)	// now create submenus
	{
		if(myMenu[i].level > 1)
		{
			MMerror(i,"Skipped menu levels");
			return;
		}
		else if(myMenu[i].level == 1)
		{
			if(myMenu[i-1].url.substring(0,4) != "menu")
			{
				MMerror(i,"Submenu not preceded by 'menu'");
				return;
			}
			i = MMsubmenu(i);
		}
	}
}

// write the menu to the system
function writeMenu()
{
	if(isNS4 || isIE4)
		document.write(MMstr);
	else if(isDOM)
	{
		var newDiv;
		var idx0 = -1;

		while(idx0 < myDomLast)
		{
			newDiv = document.createElement('div');
			document.getElementsByTagName('body').item(0).appendChild(newDiv);
			newDiv.innerHTML = mmDomMenu[++idx0];
			++idx0;
		}
	}
	// if nothing applies, just fall through
}

// globals
bWidth = 2;			// border width
iPad = 3;			// item padding

// Navigation ARRAY is constructed as follows:
// format is Name,URL or "menu" or "menu;URL" or "label",level (start from 0)
// all items at level 0 are on MAIN MENU on page
// all items at level N are grouped with subsequent level N that
//     are at the same level and have only encountered other menu
//     items which are at level N or higher
// MMarray = new Array (....)
// Need to follow this by "loadMenu("menu_page")"
// if menu_page matches menu label, then that label is unselectable
// if menu_page == "HOME", then the first label line is REMOVED

// END -->
