<!--

if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.clientX+document.body.scrollLeft;
        yMousePos = window.event.clientY+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}


function createNode(position,id)
{
	var createUrl = "/modules/structure/edit.php?action=insertNode&siblingId=" +
					id +
					"&position=" +
					position
	content.location.href = createUrl;
}

function moveNode(dst,id)
{
	if (dst == "location") {
		content.location.href = "/modules/structure/move.php?id=" + id;
	} else if (dst != "") {
		window.location = "/modules/structure/edit.php?action=moveNode&dst=" + dst + "&id=" +id;
	}
}	

function goDeleteTree(id)
{
	if (confirm('Weet u het zeker?')) {
		window.location = '/modules/structure/edit.php?action=delete&id='+id
	}
}


// functies 
var contextPopupFrame = false;
var keepContextPopup = false;
var contextPopupTimer = false;
function createContextmenu(id,items) 
{
	var oldH = document.body.clientHeight.toString();
	if (items.length == 0) return false;
	if (document.getElementById && document.createElement)
	{
		// er kan maar 1 popup scherm zijn
		if(contextPopupFrame) { removeContextmenu(); }
		// maak popupschermpje
		
		// sla huidige schermhoogte op
		contextPopupFrame = document.createElement('DIV');
		contextPopupFrame.className = "contextPopupFrame";
		cw = document.body.clientWidth;
		ch = document.body.clientHeight;
		
		if (xMousePos+300 > xMousePosMax) // te ver naar rechts
		{
			contextPopupFrame.style.left = xMousePosMax -300; //(cw/2)-100;
		} else {
			contextPopupFrame.style.left = xMousePos; //(cw/2)-100;
		}
		if (yMousePos+100 > yMousePosMax)
		{
			contextPopupFrame.style.top = yMousePosMax-100; //(ch/2)-100;
		} else {
			contextPopupFrame.style.top = yMousePos; //(ch/2)-100;
		}
		contextPopupFrame.style.zIndex = 100010;
		
		// voeg er items aan toe
		contextPopupItem = new Array();
		//alert(items.toString());
		for (var item=0;item<items.length;item++)
		{
			if (items[item] == "space") {
				contextPopupItem[item] = document.createElement('DIV');
				tbl = "<table width=100% cellpadding=0 cellspacing=0 border=0 class=contextPopupTable><tr>"
				+ "<td class=contextPopupIcon></td>"
				+ "<td class=contextPopupSpace></td>"
				+ "</tr></table>\n";
				contextPopupItem[item].innerHTML = tbl;
			} else if (items[item] == "menutitle") {
				icon  = contextitem[items[item]][0];
				if (id.length==3)
				{
					txt   = stringReplace(contextitem[items[item]][1],id[2]);
				} else {
					txt   = contextitem[items[item]][1];
				}
				lnk   = stringFormat(contextitem[items[item]][2],id[0],id[1]);
				
				tbl = "<table width=100% cellpadding=0 cellspacing=0 border=0 class=contextPopupTable>"
				+"<tr>"
				+ "<td colspan=2 class=contextPopupText align=center>"+ txt + "</td>"
				+ "</tr></table>\n";
				// voeg toe aan popup
				contextPopupItem[item] = document.createElement('DIV');
				contextPopupItem[item].innerHTML = tbl;
				contextPopupItem[item].className = "contextPopupItemMenutext";
				contextPopupItem[item].onmouseup = function() {
					removeContextmenu();
					return false;
				}
			} else {
				// verzamel de gegevens
				//alert(id.join("#"));

				icon  = contextitem[items[item]][0];
				if (id.length==3)
				{
					txt   = stringReplace(contextitem[items[item]][1],id[2]);
				} else {
					txt   = contextitem[items[item]][1];
				}
				lnk   = stringFormat(contextitem[items[item]][2],id[0],id[1]);
				
				//alert(txt);

				tbl = "<table width=100% cellpadding=0 cellspacing=0 border=0 class=contextPopupTable>"
				+"<tr onclick="+lnk+">"
				+ "<td class=contextPopupIcon><img src=" + icon + " border=0></td>"
				+ "<td class=contextPopupText>"+ txt + "</td>"
				+ "</tr></table>\n";
				// voeg toe aan popup
				contextPopupItem[item] = document.createElement('DIV');
				contextPopupItem[item].innerHTML = tbl;
				contextPopupItem[item].className = "contextPopupItemNormal";
				contextPopupItem[item].onmouseover = function() {
					this.className = "contextPopupItemOver";
				}
				contextPopupItem[item].onmouseout = function() {
					this.className = "contextPopupItemNormal";
				}
				contextPopupItem[item].onmouseup = function() {
					//removeContextmenu();
					return false;
				}
			}
			contextPopupFrame.appendChild(contextPopupItem[item]);
		}
		// presenteer popupschermpje
		document.body.appendChild(contextPopupFrame);
		// laat het schermpje ook weer verlopen na een bepaalde tijd
		initTimer();
		// als het popupje gebruikt word verwijder deze dan niet.
		contextPopupFrame.onmouseover = function() {
			keepContextPopup = true;
		}
		// kijk anders opnieuw of ie weg gehaald moet worden
		contextPopupFrame.onmouseout = function() {
			keepContextPopup = false;
			initTimer();
		}
		// geen selectie mogelijk
		contextPopupFrame.onselectstart = function() {
			//window.focus();
			return false;
		}
	} 
	else 
	{
		// nog maken voor oude browsers?
		alert('Your browser doesn\'t support the Level 1 DOM');
	}
	return false;
}

function removeContextmenu()
{
	document.body.removeChild(contextPopupFrame);
	contextPopupFrame = false;
	clearTimeout(contextPopupTimer);
	//window.focus();
}

function timeOutVisibleContextmenu()
{
	if (!keepContextPopup) removeContextmenu();
}

function initTimer()
{
	clearTimeout(contextPopupTimer);
	contextPopupTimer = setInterval("timeOutVisibleContextmenu()", 3000);
	//contextPopupTimer = setInterval("timeOutVisibleContextmenu()", 1200);
}

/*
if (browser.ns4) {
  window.document.captureEvents(Event.MOUSEMOVE);
}

document.onmousemove = function(evt) 
{
	if (browser.ns4) {
		window.mouseX = evt.pageX;
		window.mouseY = evt.pageY;
	} else if (browser.ie) {
		window.mouseX = window.event.x;
		window.mouseY = window.event.y;
	} else if (browser.dom) {
		window.mouseX = evt.pageX;
		window.mouseY = evt.pageY;
	}
}
*/

function stringReplace(str)
{
	var i = 0;
	for (var x=1; x<arguments.length; x++ )
	{
		str = str.replace("{"+x+"}",arguments[x].toLowerCase());
	}
	return str;
}
function stringFormat(strInput)
{
	var idx = 0;
	for (var i=1; i<arguments.length; i++) {
		while ((idx = strInput.indexOf('{' + (i - 1) + '}', idx)) != -1) {
			strInput = strInput.substring(0, idx) + arguments[i] + strInput.substr(idx + 3);
		}
	}
	return strInput;
}
-->