var timeoutForMenuDelay="";
function StopDelay()
{
	//alert(timeoutForMenuDelay);
	if(timeoutForMenuDelay)
	window.clearTimeout(timeoutForMenuDelay);
}
function DelayOnShowMenu()
{
	timeoutForMenuDelay=window.setTimeout("ShowMenu()", 100)
}
function ShowMenu()
{
	with (document)
	{
		getElementById("M").className="menu";
		getElementById("iMainFrame").style.height=document.getElementById("M").offsetHeight;
		getElementById("iMainFrame").style.display="block";
	}
	StopDelay();
}
/* clickItemLink */
function CIL(obj,strDirectoryPath,strSQLString,strObjectType,strListId)
{
	var WEBPAGE="90";
	var WARE_RECALL="110";
	var NON_WARE_RECALL="115";
	var MAN_UPDATE="120";
	var REPORT="80";
	var EMAIL="130";
	var EXTERNAL_LINK="100";
	var strPath=strDirectoryPath+strSQLString;
	switch(strObjectType)
	{
		case WEBPAGE:case WARE_RECALL: case NON_WARE_RECALL: case MAN_UPDATE:
			var hdOpenWindow=document.createElement("input");
			with (hdOpenWindow){
				name="hdOpenWindow";
				type="hidden";
				value="DOCUMENTS";}
			document.forms[0].appendChild(hdOpenWindow);
			
			var hdDirectoryPath=document.createElement("input");
			with (hdDirectoryPath){
				name="hdDirectoryPath";
				type="hidden";
				value=strDirectoryPath;}
			document.forms[0].appendChild(hdDirectoryPath);
			
			var hdSQLString=document.createElement("input");
			with (hdSQLString){
				name="hdSQLString";
				type="hidden";
				value=escape(strSQLString);}
			document.forms[0].appendChild(hdSQLString);
			
			var hdListId=document.createElement("input");
			with (hdListId){
				type="hidden";
				name="hdListId";
				value=strListId;}
			document.forms[0].appendChild(hdListId);
			
			with (document.forms[0]){
				method='post';
				target='_top';
				submit();}		
		break;
		case EMAIL:
			var hdOpenWindow=document.createElement("input");
			with (hdOpenWindow){
				name="hdOpenWindow";
				type="hidden";
				value="EMAIL";}
			document.forms[0].appendChild(hdOpenWindow);
			
			var hdDirectoryPath=document.createElement("input");
			with (hdDirectoryPath){
				name="hdDirectoryPath";
				type="hidden";
				value=strDirectoryPath;}
			document.forms[0].appendChild(hdDirectoryPath);
			
			var hdSQLString=document.createElement("input");
			with (hdSQLString){
				name="hdSQLString";
				type="hidden";
				value=escape(strSQLString);}
			document.forms[0].appendChild(hdSQLString);
			
			var hdListId=document.createElement("input");
			with (hdListId){
				type="hidden";
				name="hdListId";
				value=strListId;}
			document.forms[0].appendChild(hdListId);
			
			with (document.forms[0]){
				method='post';
				target='_top';
				submit();}			
		break;
		case EXTERNAL_LINK:
			var hdOpenWindow=document.createElement("input");
			with (hdOpenWindow){
				name="hdOpenWindow";
				type="hidden";
				value="EXTERNAL";}
			document.forms[0].appendChild(hdOpenWindow);
			
			var hdDirectoryPath=document.createElement("input");
			with (hdDirectoryPath){
				name="hdDirectoryPath";
				type="hidden";
				value=strDirectoryPath;}
			document.forms[0].appendChild(hdDirectoryPath);
			
			var hdSQLString=document.createElement("input");
			with (hdSQLString){
				name="hdSQLString";
				type="hidden";
				value=escape(strSQLString);}
			document.forms[0].appendChild(hdSQLString);
			
			var hdListId=document.createElement("input");
			with (hdListId){
				type="hidden";
				name="hdListId";
				value=strListId;}
			document.forms[0].appendChild(hdListId);
			
			with (document.forms[0]){
				method='post';
				target='_top';
				submit();}	
		break;
		case REPORT:
			var hdOpenWindow=document.createElement("input");
			with (hdOpenWindow){
				name="hdOpenWindow";
				type="hidden";
				value="REPORT";}
			document.forms[0].appendChild(hdOpenWindow);
			
			var hdDirectoryPath=document.createElement("input");
			with (hdDirectoryPath){
				name="hdDirectoryPath";
				type="hidden";
				value=strDirectoryPath;}
			document.forms[0].appendChild(hdDirectoryPath);
			
			var hdSQLString=document.createElement("input");
			with (hdSQLString){
				name="hdSQLString";
				type="hidden";
				value=escape(strSQLString);}
			document.forms[0].appendChild(hdSQLString);
			
			var hdListId=document.createElement("input");
			with (hdListId){
				type="hidden";
				name="hdListId";
				value=strListId;}
			document.forms[0].appendChild(hdListId);
			
			with (document.forms[0]){
				method='post';
				target='_top';
				submit();}	
		break;
		default:
				if(strPath.search(/\x3F/)==-1){
					location.href=strPath+"?LoggedListId="+strListId;
				}
				else{
					location.href=strPath+"&LoggedListId="+strListId;
				}
		break;
	}
}
function startIt(menu,thisItem,level) {
	if (menuOn == true) {
		window.event.cancelBubble = true;
		hideAllDivs();
		return;
	} else {
		select = document.all.tags("select");
		selectCount = select.length;
		if (selectCount > 0) {
			for (i=0;i<selectCount;i++) {
				select.item(i).style.visibility = "hidden";
			}
		}
		applets = document.all.tags("applet");
		appletCount = applets.length;
		if (appletCount > 0) {
			for (i=0;i<appletCount;i++) {
				applets.item(i).style.visibility = "hidden";
			}
		}
		menuOn = true;			
		started = true;
		clickX = event.clientX;
		clickY = event.clientY;
		if (clickStart) window.event.cancelBubble = true;		
		SC(menu,thisItem,level);
	}	
}
/* statechange */
function SC(menu,thisItem,level) {
	window.event.cancelBubble = true;
	if (currentSpanElement != thisItem.id && started != true) {
		if (currentSpanElement == "") currentSpanElement = thisItem.id;

		eItemOld = eval("document.all('" + currentSpanElement + "')");
		eItemNew = eval("document.all('" + thisItem.id + "')");
		eParent = eItemNew.parentElement;
		eParent.style.background = offCellColor;
		
			
		eItemOld.style.background = offCellColor;
		eItemOld.style.color = offTextColor;
		eItemOld.style.border=offBorderStyle;

		eItemNew.style.background = onCellColor;
		eItemNew.style.color = onTextColor;
		eItemNew.style.border=onBorderStyle;


		currentSpanElement = thisItem.id;
	}

	if (menu != "") {

		eiFrameMenu = eval("document.all('iFrame" + menu + "')");			

		eMenu = eval("document.all('" + menu + "')");			
		eItem = eval("document.all('" + thisItem.id + "')");
		hideDiv(level);

		menuArray[menuArray.length] = menu;
		var positionX = eItem.parentElement.offsetLeft + eItem.offsetLeft + offsetMenuX;
		var positionY = eItem.parentElement.offsetTop + eItem.offsetTop + offsetMenuY;
		eMenu.style.display='block';

		if (started == true && withStart == true) {
			positionX =	clickX + startDistanceX	+ document.body.scrollLeft
			positionY =	clickY + startDistanceY	+ document.body.scrollTop
		}
		if ((positionX + eMenu.offsetWidth) >= document.body.clientWidth) {
			positionX -= (eMenu.offsetWidth * 1.3);
			positionY += 15;
		}
		if ((positionX + eMenu.offsetWidth) <= eMenu.offsetWidth) {
			positionX += (eMenu.offsetWidth * 1.3);
		}
		if ((positionY + eMenu.offsetHeight) >= document.body.clientHeight) {
			if (started != true) positionY = document.body.clientHeight - eMenu.offsetHeight;
		}	
		with (eiFrameMenu.style){
			left = positionX;
			top = positionY;}
		with (eMenu.style){
			left = positionX;
			top = positionY;}
		with (eiFrameMenu.style){
			height=eMenu.offsetHeight;
			display='block';}
	}
	started = false;
}
function hideDiv(currentLevel) {
		
		for (var i=currentLevel;i<menuArray.length;i++) {
			var arrayString = new String(menuArray[i]);
			if (arrayString == "undefined") continue;
			eval("document.all('" + menuArray[i] + "').style.display='none'");
			eval("document.all('iFrame" + menuArray[i] + "').style.display='none'");
		}
			menuArray.length = currentLevel;
}
function hideAllDivs() {
	if (typeof(window.menuOn)!='undefined') {
		if (menuOn == true) {
			document.getElementById("M").className="menuItems";
			document.getElementById("iMainFrame").style.display="none";
			for (var i=0;i<menuArray.length;i++) {
				var arrayString = new String(menuArray[i]);
				if (arrayString == "undefined") continue;
				with (document){
					all(menuArray[i]).style.display = "none";
					all(menuArray[i]).style.left = 0;
					all(menuArray[i]).style.top = 0;
					all("iFrame"+menuArray[i]).style.display = "none";
					all("iFrame"+menuArray[i]).style.left = 0;
					all("iFrame"+menuArray[i]).style.top = 0;}
			}
			if (currentSpanElement != "") {
				eItem = eval("document.all('" + currentSpanElement + "')");
				with (eItem.style){
					borderStyle='none';
					background = offCellColor;
					color = offTextColor;}
				menuArray = new Array();	
				currentSpanElement = "";		
			}
			if (selectCount > 0) {
				for (i=0;i<selectCount;i++) {
					select.item(i).style.visibility = "visible";
				}
				selectCount = 0;
				select = "";
			}
			if (appletCount > 0) {
				for (i=0;i<appletCount;i++) {
					applets.item(i).style.visibility = "visible";
				}
				appletCount = 0;
				applets = "";
			}
		}
		if (withStart == true) {
			menuOn = false;	
		}
		else {
			menuOn = true;
		}
	}
}
document.onclick = hideAllDivs;