/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e2) {
      xmlHttp = false;
    }
  }
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

var mouseX;
var mouseY;

function getCoord( event ) {
   mouseX = event.pageX;
   mouseY = event.pageY;
}

if( document.all ) { 
 } else if( document.getElementById ) {
  document.captureEvents( Event.MOUSEMOVE );
  document.onmousemove = getCoord;
}

function updateCMenu() {
  if (xmlHttp.readyState == 4) {
      var response = xmlHttp.responseText;
      document.getElementById("ContextMenu").innerHTML = response;
    }
}

function CloseCMenu(){
	document.getElementById("ContextMenu").style.display='none';
//	window.open('/admin','_self');
}



function OpenCMenu(objct) {
  if(objct.id.length < 1) return;
  if( document.all ) {
	var XXX = event.clientX;
	var YYY = event.clientY;
  }
  else if ( document.getElementById ) {
	var XXX = mouseX;
	var YYY = mouseY;
  }
  
  var ContextMenu = document.getElementById("ContextMenu");
  ContextMenu.style.top = YYY+'px';
  ContextMenu.style.left = XXX+'px';
  ContextMenu.innerHTML = '&nbsp;Loading...';
  ContextMenu.style.display = '';
  // Build the URL to connect to
  var url = "st_ContextMenu.php?action=show&id="+ objct.id;

  // Open a connection to the server
  xmlHttp.open("GET", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = updateCMenu;

  // Send the request
  xmlHttp.send(null);

}



function expand(a,dinamicPrefix) {
	var id = a.id;
	var ul = document.getElementById(dinamicPrefix+'ul_'+id);
	if (ul.innerHTML == '') {
		ul.style.display = 'inline-block';
		ul.innerHTML = '<div>Loading...</div>';
		return load(id,dinamicPrefix);
	} else {
		var image = document.getElementById(dinamicPrefix+'im_'+id);
		if (ul.style.display == 'none') {
			if (window.ActiveXObject){
				ul.style.display = 'inline-block';
			}
			else{
				ul.style.display = '';
				}
			image.src = 'images/minus.gif';
		} else {
			ul.style.display = 'none';
			image.src = 'images/plus.gif';
		}
		return false;
	}
}

function load(id,dinamicPrefix) {
	var iframe = document.getElementById(dinamicPrefix+'if_'+id);
	var image = document.getElementById(dinamicPrefix+'im_'+id);
	iframe.src = 'st_ContextMenu.php?action=exp&id='+id+'&dinamicPrefix='+dinamicPrefix;
	image.src = 'images/minus.gif';
	return false;
}

function showLoaded(id, content, dinamicPrefix) {
	var ul = document.getElementById(dinamicPrefix+'ul_'+id);
	ul.innerHTML = content;
	ul.style.display = 'inline-block';
}