function customMenu(optionColl,name,handlerFunc,minWidth,xPos,yPos,subColl,aResults,sMouseOverFunc,asMouseOverData)
{
	this.closeGlobal=0;
	this.closeCanvasLabel="customMenuCanvas";
	this.optionNames=optionColl||new Array("Exit");
	this.optionColours=0;
	this.menuHeight="auto";
	this.menuWidth="auto";
	this.openMenu=menuOpen;
	this.closeMenu=menuClose;
	this.minWidth=minWidth||0;
	this.optionCount=0;
	this.name=name||"defaultMenu";
	this.handler=handlerFunc||"handlerFunc";
	this.mouseOver=sMouseOverFunc||"";
	this.xPos=xPos;
	this.yPos=yPos;
	this.openSubmenu=0;
	this.results=aResults;
	this.subColl=subColl;
	this.mouseOverData=asMouseOverData||0;
	this.escapedTitles=false;
	this.hoverover=false
	spaceCheck=new RegExp("( )","gi");
	for (a in this.optionNames)
	{
		this.optionCount++;
		this.optionNames[a]=this.optionNames[a].replace(spaceCheck,"&nbsp;");
	}
	gMenus[gMenuLimit]=this;
	gMenuLimit++;
}

function menuOpen(parentObj,tempXPos,tempYPos,subMenu,e)
{

	canvasNode=document.getElementById(this.closeCanvasLabel);
	menuNode=document.getElementById(this.name);
	if (canvasNode && canvasNode!=undefined && !subMenu)
	{
		canvasNode.parentNode.removeChild(canvasNode);
	}
	if (menuNode && menuNode!=undefined)
	{
		menuNode.parentNode.removeChild(menuNode);
	}
	if (!subMenu)
	{
		newCanvas=document.createElement("IMG");
		closeCanvas=document.body.appendChild(newCanvas);
		closeCanvas.src="lib/transparent1x1.gif";
		closeCanvas.style.position="absolute";
		closeCanvas.style.left="0px";
		closeCanvas.style.top="0px";
		closeCanvas.style.height=document.body.clientHeight;
		closeCanvas.style.width=document.body.clientWidth;
		closeCanvas.style.zIndex=1005;
		closeCanvas.onclick=this.closeMenu;
		closeCanvas.setAttribute("id",this.closeCanvasLabel);
		closeCanvas.setAttribute("handlingFunc",this.handler);
		closeCanvas.setAttribute("rootMenu",this.name);
	}
	newBack=document.createElement("DIV");
	menuBack=parentObj.appendChild(newBack);
	menuBack.className="menuArea";
	menuBack.style.position="absolute";
	menuBack.style.overflow="visible";
	menuBack.style.left=tempXPos||(this.xPos||event.offsetX);
	menuBack.style.top=tempYPos||(this.yPos||event.offsetY);
	menuBack.style.marginLeft=0;
	menuBack.style.textIndent=0;
	menuBack.style.zIndex=1010;
	menuBack.style.width="600px";
	menuBack.setAttribute("id",this.name);
	menuBack.setAttribute("name",this.name);
	var maxWidth=0,maxHeight=0,b=0,vertPos=0,optionString="";
	for (a=0;a<this.optionCount;a++)
	{
		optionString=optionString + "<DIV id='" + this.name + "menuopt" + a + "'"
		if (this.optionNames[a]!="*divider*")
		{
			var result;
			if (this.results)
			{
				result="'" + this.results[a] + "'";
			}
			else
			{
				result=a;
			}
			/*if (this.subColl=0)
			{
				iSubColl=0;
			}
			else
			{
				iSubColl=this.subColl[a];
			}*/
			iSubColl=this.subColl[a];
			optionString+="CLASS=\"menuOption\" onClick=\"menuClose('" + this.name + "','" + this.name + "',false,false,"+result+",'"+this.closeCanvasLabel+"')\" onmouseover=\"optionSelect('" + this.name + "menuopt" + a + "'," + iSubColl + "," + this.name + ",'" + this.mouseOver + "','"+this.mouseOverData[a]+"',event,"+this.closeGlobal+")\"";
			if (typeof menuBack.onmouseleave!='undefined')
			{
				optionString+=" onmouseleave=\"optionDeselect('" + this.name + "menuopt" + a + "', event)\"";
			}
			if (this.optionColours && this.optionColours[a])
			{
				optionString+=" STYLE=\"BACKGROUND-COLOR:"+this.optionColours[a]+";cursor:pointer;word-wrap:normal\"";
			}
			if (this.hoverover)
			{
				optionString+=" onmouseout=\"StartClose('" + this.name + "',"+this.closeGlobal+")\"";
			}
			if (this.mouseOverData!=0)
			{
				optionString=optionString + " deselectopt1=\"" + this.mouseOver + "\" deselectopt2=\"" + this.mouseOverData[a] + "\" "
			}
			else
			{
				optionString=optionString + " deselectopt1=\"\" deselectopt2=\"\" "
			}
		}
		optionString=optionString + "></DIV>";
	}
	menuBack.innerHTML=optionString;
	for (a=0;a<this.optionCount;a++)
	{
		menuOption=document.getElementById(this.name + "menuopt" + a);		
		menuOption.style.position="absolute";
		menuOption.style.left=0;
		menuOption.setAttribute("id",this.name + "menuopt"+a);
		menuOption.setAttribute("parentMenu",this.name)
		if (this.optionNames[a]=="*divider*")
		{
			menuOption.className="dividerOption";
			vertPos+=Number(menuOption.offsetHeight);
			newDivider=document.createElement("IMG");
			optionDivider=menuOption.appendChild(newDivider);
			optionDivider.src="images/menuLine.gif";
			optionDivider.style.position="absolute";
			optionDivider.style.left=2;
			optionDivider.style.top=4;
			optionDivider.style.height=2;
			b++;
			optionDivider.setAttribute("id",this.name + "optdivi"+b);			
		}
		else
		{	
			//menuOption.onmouseleave="optionDeselect(event)";
			newText=document.createElement("SPAN");
			optionText=menuOption.appendChild(newText);
			optionText.style.width='';
			optionText.className="menuText";		
			//menuOption.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=60)"
			//optionText.style.filter="";
			optionText.setAttribute("id",this.name+"opttext"+a);
			optionText.innerHTML="<SPAN>"+(this.escapedTitles?unescape(this.optionNames[a]):this.optionNames[a])+"</SPAN><SPAN STYLE=\"position:absolute\">"+(this.subColl[a]?">":" ")+"</SPAN>";
			if (optionText.clientWidth>maxWidth)
			{
				maxWidth=optionText.clientWidth;
			}
		}
	}
	menuBack.style.width=maxWidth+10;
	for (a=0;a<this.optionCount;a++)
	{

		eOpt=document.getElementById(this.name + "menuopt" + a);
		eOptText=eOpt.childNodes[0];
		eOpt.style.top=vertPos;
		eOpt.style.width=maxWidth+40;
		eOptText.childNodes[0].style.width=maxWidth;
		eOptText.childNodes[1].style.left=maxWidth+10;
		if (Number(eOptText.offsetHeight)+3>Number(eOpt.offsetHeight))
		{
			eOpt.style.height=(eOptText.offsetHeight+3)+"px";
		}
		vertPos+=eOpt.offsetHeight;

	}
	menuBack.style.height=vertPos;
	for (a=1;a<=b;a++)
	{
		document.getElementById(this.name + "optdivi" + a).style.width=maxWidth+36;
	}
	minLeft=closeCanvas.offsetWidth-menuBack.offsetWidth;
	if (menuBack.offsetLeft>minLeft)
	{
		menuBack.style.left=minLeft;
	}
	minTop=closeCanvas.offsetHeight-menuBack.offsetHeight;
	if (menuBack.offsetTop>minTop)
	{
		menuBack.style.top=minTop;
	}
	menuBack.setAttribute("handlingFunc",this.handler);	
}

function menuClose(closingObjStr,divObjStr,noFullClose,noCommand,commandVal,sCloseCanvas)
{
	var divObj=null;
	if (!sCloseCanvas)
	{
	    sCloseCanvas=this.closeCanvasLabel
    }
	if (!document.getElementById(sCloseCanvas))
	{
		return (false);
	}
	if (closingObjStr)
	{
		menuObj=eval(closingObjStr);
	}
	if (divObjStr)
	{
		divObj=eval("document.getElementById('"+divObjStr+"')");
	}
	//if (this.id=="customMenuCanvas")
	if (this.getAttribute && this.getAttribute('rootMenu') && this.getAttribute('rootMenu')!="")
	{
		menuHandlerInput=-1;
		divObj=eval("document.getElementById('" + this.getAttribute('rootMenu') + "')");
		menuObj=eval(this.getAttribute("rootMenu"));
	}
	else if (!commandVal)
	{
		menuHandlerInput=-1;
	}
	else
	{
		menuHandlerInput=commandVal;
	}
	if (divObj)
	{
		funcName=divObj.getAttribute("handlingFunc");
		menuId=divObj.getAttribute("name");
	}
	if (!noFullClose)
	{
		canvasDiv=document.getElementById(sCloseCanvas);
		menuObj=eval(canvasDiv.getAttribute("rootMenu"));
		document.getElementById(canvasDiv.getAttribute("rootMenu")).parentNode.removeChild(document.getElementById(canvasDiv.getAttribute("rootMenu")));
		canvasDiv.parentNode.removeChild(canvasDiv);		
	}
	else
	{
		divObj.parentNode.removeChild(divObj);
	}
	subMenuReset(menuObj);
	if (!noCommand && divObjStr)
	{
		eval(funcName + "(menuHandlerInput,menuId,2);");
	}	

}

function subMenuReset(menuObj)
{
	if (menuObj.openSubmenu)
	{
		subMenuReset(eval(menuObj.openSubmenu));
	}
	menuObj.openSubmenu=0;
}

function optionSelect(id,submenu,menu,sMouseOverFunc,iResult,event,iCloseGlobal)
{
	gCloseMenu[iCloseGlobal]=false;
	if (event)
	{
		event.cancelBubble=true;
	}
	currentOpt=document.getElementById(id);
	currentOpt.className="selectedOption";
	//Dirty hack to unselect last option for browsers that don't support onmouseleave
	
	if (typeof(currentOpt.onmouseleave)=="undefined")
	{
		var aeOptions=currentOpt.parentNode.childNodes,iOptionsLength=aeOptions.length,iCounter=0
		for (iCounter=0;iCounter<iOptionsLength;iCounter++)
		{
			if (aeOptions[iCounter]!=currentOpt)
			{
				aeOptions[iCounter].className="menuOption";
			}
		}

	}
	// end of hackage
	if (menu.openSubmenu)
	{
		menu.closeMenu(menu.openSubmenu,menu.openSubmenu,true,true);
		menu.openSubmenu=0;
	}
	if (submenu)
	{
		submenu.openMenu(currentOpt,currentOpt.offsetWidth,-1,true);
		menu.openSubmenu=submenu.name;
	}
	if (iResult!=0 && sMouseOverFunc!="")
	{
		eval(sMouseOverFunc + "('" + iResult + "',true)");
	}
}

function optionDeselect(id,event)
{
	if (event)
	{
		event.cancelBubble=true;
	}
	currentOpt=document.getElementById(id);
	currentOpt.className="menuOption";
	if ((currentOpt.getAttribute("deselectopt1")!="") && (currentOpt.getAttribute("deselectopt2")!=""))
	{
		eval(currentOpt.getAttribute("deselectopt1") + "('" + currentOpt.getAttribute("deselectopt2") + "',false)");
	}
}

function menuBar(barId,menuTitles,menuIds,daddy,iXOffset,iYOffset)
{
	this.menuTitles=menuTitles||new Array();
	this.menuIds=menuIds||new Array();
	this.barId=barId||"newBar";
	this.parent=daddy;
	this.count=0
	for (x in menuTitles)
	{
		this.count++;
	}
	newBar=document.createElement("DIV");
	menuBar=this.parent.appendChild(newBar);
	menuBar.className="menuBar";
	var innerStr=""
	for (a=0;a<this.count;a++)
	{
		innerStr=innerStr + "<DIV STYLE='z-index:100' ID='" + this.menuTitles[a] + "' onClick='" + this.menuIds[a] + ".openMenu(this"
		if (iXOffset && iYOffset)
		{
			innerStr+=","+iXOffset+","+iYOffset;
		}
		innerStr+=")'></DIV>"
	}
	menuBar.innerHTML=innerStr;
	xAlign=0;
	for (y=0;y<this.count;y++)
	{
		y?xAlign+=15:xAlign+=5;
		menuEle=document.getElementById(this.menuTitles[y]);
		menuEle.style.position="absolute";
		menuEle.style.left=xAlign;
		menuEle.style.top=3;
		menuEle.innerText=this.menuTitles[y];
		xAlign+=menuEle.offsetWidth;
	}
}

function editLabel(parentObj,handler,xPos,yPos,parName,initVal)
{
	if (document.getElementById("customMenuCanvas")!=undefined)
	{
		document.getElementById("customMenuCanvas").removeNode(true);
		document.getElementById("customMenuBack").removeNode(true);
	}
	newCanvas=document.createElement("DIV");
	closeCanvas=document.body.appendChild(newCanvas);
	closeCanvas.style.position="absolute";
	closeCanvas.style.left="0px"
	closeCanvas.style.top="0px"
	closeCanvas.style.height="100%";
	closeCanvas.style.width="100%";
	closeCanvas.setAttribute("id",this.closeCanvasLabel)
	closeCanvas.setAttribute("handlingFunc",handler);
	newBox=document.createElement("DIV");
	menuBox=parentObj.appendChild(newBox);
	menuBox.style.position="relative";
	menuBox.style.overflow="visible";
	menuBox.style.left=xPos; //xPos||event.offsetX;
	menuBox.style.top=0; //yPos||event.offsetY;
	menuBox.setAttribute("id","customMenuBack");
	menuBox.setAttribute("name",parName);
	menuBox.setAttribute("handlingFunc",handler);
	newBox=document.createElement("FORM");
	menuForm=menuBox.appendChild(newBox);
	menuForm.style.position="absolute";
	menuForm.style.overflow="visible";
	menuForm.setAttribute("id","renameForm");
	menuForm.setAttribute("handlingFunc",handler);
	newText=document.createElement("INPUT");
	labelText=menuForm.appendChild(newText);
	labelText.type="TEXT";
	labelText.style.position="absolute";
	labelText.style.overflow="visible";
	labelText.style.zIndex=1;
	labelText.className="renameBox";
	labelText.value=initVal||"New Profile";
	labelText.onclick=function () {return false;}
	labelText.tabIndex=1;
	labelText.setAttribute("handlingFunc",handler);
	labelText.setAttribute("id","labelText");
	labelText.focus();
	labelText.select();
	menuForm.onsubmit=function () {labelText.blur;return false;}
	labelText.onblur=endEdit;
	labelText.onkeydown=returnCheck;
}

function endEdit(textVal)
{
	menuHandlerInput=this.value||textVal;
	funcName=document.getElementById("customMenuBack").getAttribute("handlingFunc");
	menuId=document.getElementById("customMenuBack").getAttribute("name");
	document.getElementById("customMenuCanvas").removeNode(true);
	document.getElementById("customMenuBack").removeNode(true);
	eval(funcName + "(menuHandlerInput,menuId);")
}

function returnCheck()
{
	if (window.event.keyCode==13)
	{
		endEdit(this.value);
	}
}

function GetBodyTop(eElement)
{
	iTop=0;
	while (eElement!=document.body)
	{
		iTop+=eElement.offsetTop;
		eElement=eElement.parentElement;
	}
	return (iTop);
}

function GetBodyLeft(eElement)
{
	iLeft=0;
	while (eElement!=document.body)
	{
		iLeft+=eElement.offsetLeft;
		eElement=eElement.parentElement;
	}
	return (iLeft);	
}

function StartClose(sMenuObj,iCloser)
{
	gCloseMenu[iCloser]=sMenuObj;
	window.setTimeout("EndClose("+iCloser+")",500);
}

function EndClose(iCloser)
{
	if (gCloseMenu)
	{
		eval(gCloseMenu[iCloser]+".closeMenu()");
		gCloseMenu[iCloser]=false;
	}
}


var gMenus=new Array(),gMenuLimit=0,gCloseMenu=new Array();//
