var bgcolor="";
var bgGroup='black';
var fgGroup='gray';
var bgItem='black';
var fgItem='gray';
var bgItemSelected='gray';
var fgItemSelected='black';//'#160072';

var font="FONT-WEIGHT:bolder; FONT-SIZE:8pt; FONT-FAMILY:arial;";
var menudom;
function createMenu(xmlurl,div) {
	u=xmlurl;
	for(i=0;i<document.styleSheets[0].rules.length;i++) {
		var rule=document.styleSheets[0].rules[i];
		if(rule.selectorText==".menubar") {
			bgItem=bgGroup=rule.style.backgroundColor;
			fgItem=fgGroup=rule.style.color;
			font="FONT-WEIGHT:"+rule.style.fontWeight+"; FONT-SIZE:"+rule.style.fontSize+"; FONT-FAMILY:"+rule.style.fontFamily+";";
		}
		if(rule.selectorText==".menubaron") {
			bgItemSelected=rule.style.backgroundColor;
			fgItemSelected=rule.style.color;
		}
	}
	menudom=new ActiveXObject("Microsoft.XMLDOM");
	menudom.async=false;
	ok=menudom.load(xmlurl);
	if(!ok) {
		path=document.location.href;
		path=path.substring(0,path.lastIndexOf("/"));
		xmlurl=path+"/"+xmlurl;
		ok=menudom.load(xmlurl);
	}
	if(!ok) {
		document.all(div).innerHTML="<BR>Error creating menu<BR>URL passed in: "+u+"<BR>Derived URL: "+xmlurl;
		return;
	}
	if(!ok) menudom=document.all("menuxml").XMLDocument;
	if(document.styleSheets.length>0) {
		for(i=0;i<document.styleSheets[0].rules.length;i++) {
			style=document.styleSheets[0].rules[i];
			if(style.selectorText=="BODY") 
				bgcolor=style.style.backgroundColor;
		}
	}
	if(bgcolor=="") bgcolor=document.body.style.backgroundColor;
	if(bgcolor=="") bgcolor=document.body.bgColor;
	if(bgcolor=="") bgcolor="white";
	html="<table width='90%' cellspacing=8 cellpadding=3 border=0 align=center>";
	html2=""; i=0;
	var group=menudom.firstChild.firstChild;
	while(group) {
		if(group.nodeType!=8) {
			var id="p"+i;
			label=group.getAttribute("label");
			href=group.getAttribute("href");
			
			if(href) {
				html+="<tr><td id=HD"+i+" width=200 align=left onMouseOver='selectItem(\"HD"+i+"\",true); showgroup(\""+id+"\");' onMouseOut='selectItem(\"HD"+i+"\",false); mouseOut(\""+id+"\");'";
				target=group.getAttribute("target");
				if(target)
					html+=" onclick='window.open(\""+href+"\");'";
				else
					html+=" onclick='navigate(\""+href+"\");'";
				html+=" style='"+font+" CURSOR:hand; COLOR:"+fgGroup+"; BACKGROUND-COLOR:"+bgGroup+";'>"+label+"</td></tr>";
			} else {
				html+="<td width=133 align=center onMouseOver='showgroup(\""+id+"\");' onMouseOut='mouseOut(\""+id+"\");'";
				html+=" style='"+font+" CURSOR:default; COLOR:"+fgGroup+"; BACKGROUND-COLOR:"+bgGroup+";'>"+label+"</td></tr>";
			}
			var item=group.firstChild;
			html2+="<div id='DIV"+id+"'";
			html2+=" style='position:absolute; left:0; top:0; width:0; height:0; z-index:100; visibility:hidden;'>";
			html3="<table cellspacing=0 cellpadding=3 style='border:0px solid bordercolor:white";
			if(bgcolor>"") html3+=" "+bgcolor;
			html3+=";'";
			html3+=" onmouseover='document.all(\"DIV"+id+"\").style.visibility=\"visible\";'";
			html3+=" onmouseout='hidegroup(\""+id+"\");'";
			html3+=">";

			while(item) {
				label=item.getAttribute("label");
				indent=item.getAttribute("indent");
				if(indent) 
					label="&nbsp;&nbsp;<img src=ra.gif>&nbsp;&nbsp;"+label+"&nbsp;&nbsp;";
				else
					label="&nbsp;&nbsp;"+label+"&nbsp;&nbsp;";
				url=item.getAttribute("href");
				target=item.getAttribute("target");
				mailto=url.substring(0,6)=="mailto";
				brk=item.getAttribute("break");
				html3+="<tr><td id=TD"+i+" style='"+font+" CURSOR:hand; COLOR:"+fgItem+"; BACKGROUND-COLOR:"+bgItem+";";
				if(brk) 
					html3+=" BORDER-TOP:"+bgcolor+" 1px solid;'";
				html3+="'";
				html3+=" onmouseover='selectItem(\"TD"+i+"\",true);'";
				html3+=" onmouseout='selectItem(\"TD"+i+"\",false);'";
				if(target) {
					html3+=" onclick='window.open(\""+url+"\");'";
					html3+=">"+label+"</td></tr>";
				} else {
					html3+=" onclick='navigate(\""+url+"\");'";
					html3+=">"+label+"</td></tr>";
				}
				item=item.nextSibling;
				i++;
			}
			i++;
			html3+="</table>";
			html2+=html3+"</div>";
		}
		group=group.nextSibling;
	}
	html+="</td></table>";	
	if(document.all(div))
		document.all(div).innerHTML=html+html2;
}
function selectItem(iid,selected) {
	if(selected) {
		document.all(iid).style.backgroundColor=bgItemSelected;
		document.all(iid).style.color=fgItemSelected;
	} else {
		document.all(iid).style.backgroundColor=bgItem;
		document.all(iid).style.color=fgItem;
	}
}
function showgroup(id) {
	document.all("DIV"+id).style.visibility="visible";
	if(event.toElement.tagName=="IMG") {
		//document.all("DIV"+id).style.left=event.x-event.offsetX+80-event.toElement.offsetLeft+document.body.scrollLeft;
		//document.all("DIV"+id).style.top=event.y-event.offsetY+event.toElement.offsetHeight-3+event.toElement.offsetTop+document.body.scrollTop;	
		document.all("DIV"+id).style.left=event.x-event.offsetX+80-event.toElement.offsetLeft+document.body.scrollLeft;
		document.all("DIV"+id).style.top=event.y-event.offsetY+event.toElement.offsetHeight-3+event.toElement.offsetTop+document.body.scrollTop;
	} else {
		//document.all("DIV"+id).style.left=event.x-event.offsetX+80+event.toElement.offsetWidth-2+document.body.scrollLeft;
		//document.all("DIV"+id).style.top=event.y-event.offsetY+document.body.scrollTop;
		document.all("DIV"+id).style.left=event.x-event.offsetX+80+document.body.scrollLeft;
		document.all("DIV"+id).style.top=event.y-event.offsetY+event.toElement.offsetHeight-10+document.body.scrollTop;
	}
}
function mouseOut(id) {
	hidegroup(id);
}
function hidegroup(id) {
	document.all("DIV"+id).style.visibility="hidden";
}
