var menuItem = null;
var menuID = 0;
var menuhref = null;
var cmDiv = null;
var cmWidth = 100;
var cmHeight = 200;
if ( window.createPopup )
	{
	var cmWindow = window.createPopup();
	var cmDoc = cmWindow.document;
	}
function displayMenu(e)
	{
	if ( cmWindow.isOpen )
		return false;

	menuItem = event.srcElement;
	menuID = menuItem.getAttribute("menuid");
	menuhref = menuItem.getAttribute("href");
	
	if ( cmDiv == null )
		{
		cmDiv = document.getElementById("contextMenuDiv");
		cmDiv.style.display = "block";
		cmWidth = cmDiv.offsetWidth;
		cmHeight = cmDiv.offsetHeight;
		cmDiv.style.display = "none";
		}

	cmDoc.open();
	cmDoc.write('<html><head><link href="jscripts/tiny_mce/plugins/contextmenu/css/contextmenu.css" rel="stylesheet" type="text/css" /></head><body unselectable="yes" class="contextMenuIEPopup" style="background-color:honeydew; border:1px indent black;"></body></html>');
	cmDoc.close();
	cmWindow.document.body.innerHTML = '<div class="contextMenu">' + cmDiv.innerHTML + "</div>";
//	cmWindow.show(event.screenX,event.screenY, cmWidth, cmHeight);
	cmWindow.show(event.screenX+1,event.screenY+1,107,122);
	return false;
	}

function doCallback(url)
    {
	var pageUrl = url;
	var xmlRequest;
	if (window.XMLHttpRequest)
		xmlRequest = new XMLHttpRequest
	else
		xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	xmlRequest.open("POST", pageUrl, false);
	xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlRequest.send(null);
	return xmlRequest;
    }

function moveDown()
	{
	cmWindow.hide();
	document.getElementById("nav").outerHTML = doCallback("menu.asp?menualter=down&menuid=" + menuID).responseText;
	sfHover();
	}

function moveUp()
	{
	cmWindow.hide()
	document.getElementById("nav").outerHTML = doCallback("menu.asp?menualter=up&menuid=" + menuID).responseText;
	sfHover();
	}

function addItem()
	{
	cmWindow.hide();
	var pg = "/AmbulanceWeb/menuDialog.asp?mode=add&menuid=" + menuID;
	window.showModalDialog(pg, "", "dialogHeight:220px;dialogWidth:450px;resizable;status:off;");
	document.getElementById("nav").outerHTML = doCallback("menu.asp").responseText;
	sfHover();
	}

function addSubItem()
	{
	cmWindow.hide();
	alert("Add Sub Item To " + menuID);
	}

function delItem()
	{
	cmWindow.hide();
	var pg = "/AmbulanceWeb/menuDialog.asp?mode=delete&menuid=" + menuID + "&menuhref=" + menuhref;
	window.showModalDialog(pg, "", "dialogHeight:220px;dialogWidth:470px;resizable;status:off;");
	document.getElementById("nav").outerHTML = doCallback("menu.asp").responseText;
	sfHover();
	}
	
function confItem()
	{
	cmWindow.hide();
	var pg = "/AmbulanceWeb/menuDialog.asp?mode=confItem&menuid=" + menuID;
	window.showModalDialog(pg, "", "dialogHeight:420px;dialogWidth:470px;resizable;status:off;");
	document.getElementById("nav").outerHTML = doCallback("menu.asp").responseText;
	sfHover();
	}

function sfOver()
	{
	if ( !cmWindow.isOpen )
		this.className += " sfhover";
	}

function sfOut()
	{
	if ( cmWindow.isOpen )
		setTimeout("sfAllOut()", 1000)
	else
		this.className = this.className.replace(/ sfhover/g, "");
	}
	
function sfAllOut()
	{
	if ( cmWindow.isOpen )
		setTimeout("sfAllOut()", 1000)
	else
		{
		var sfEls = document.getElementById("nav").getElementsByTagName("li");
		var l = sfEls.length;		while ( l-- )			sfEls[l].className = sfEls[l].className.replace(/ sfhover/g, "");
		}
	}

function sfHover()
	{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	var l = sfEls.length;	while ( l-- )
		{
		sfEls[l].onmouseover = sfOver;
		sfEls[l].onmouseout = sfOut;
		}
	}
if (window.attachEvent) window.attachEvent("onload", sfHover);

