/********************************************************/
/* Tooltips												*/
/********************************************************/

var offsetfromcursorX = 2;
var offsetfromcursorY = 30;

document.write('<div id="tt"><br /></div>');

var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
if (ie||ns6) {
	var tipobj=document.all? document.all["tt"] : document.getElementById? document.getElementById("tt") : "";
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function tooltip(thetext, thewidth, thecolor) {
	if (ns6||ie) {
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
		tipobj.innerHTML=thetext;
		enabletip=true;
		return false;
	}
}

function positiontip(e) {
	if (enabletip) {
		var nondefaultpos=false;
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20;
		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX;
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;
		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;

		if (rightedge<tipobj.offsetWidth) {
			tipobj.style.left=curX+15-tipobj.offsetWidth+"px";
			nondefaultpos=true;
		}
		else if (curX<leftedge)
			tipobj.style.left="5px";
		else{
			tipobj.style.left=curX+offsetfromcursorX+"px";
		}

		if (bottomedge<tipobj.offsetHeight) {
			tipobj.style.top=curY+20-tipobj.offsetHeight-offsetfromcursorY+"px";
			nondefaultpos=true;
		}
		else{
			tipobj.style.top=curY+offsetfromcursorY+"px";
		}
		tipobj.style.visibility="visible";
	}
}

function hidetooltip(){
	if (ns6||ie){
		enabletip=false;
		tipobj.style.visibility="hidden";
		tipobj.style.left="-1000px";
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
	}
}

document.onmousemove=positiontip;

/********************************************************/
/* DashBoard dialog overlay								*/
/********************************************************/

function DashboardDialog()	{
	document.getElementById('DashboardDialog').style.display='block';
}

/* DashBoard overlay */

function makeHttpRequest(url, callback_function, extra_function_properties, return_xml) {
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Helaas ondersteunt uw browser deze functie niet.');
		return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					eval(callback_function + '(http_request.responseXML)');
				} else {
					extra_function_properties = ', \'' + extra_function_properties + '\'';
					eval(callback_function + '(http_request.responseText' + extra_function_properties + ')');
				}
			} else {
				return;
			}
		} else {
			return;
		}
	}
	http_request.open('GET', url, true);
	http_request.send(null);
}

function DashBoard(url, boxdiv) {
	if (boxdiv == true) {
		var DashBoardBlankContent = '<div id="DashBoardEmptyContent"></div>';
	} else {
		var DashBoardBlankContent = '<div id="DashBoardContent"></div>';
	}
	// Create the DashBoard DIV
	var tipNameSpaceURI = 'http://www.w3.org/1999/xhtml';
	if (!tipContainerID) {
		var tipContainerID = 'DashBoard';
	}
	var tipContainer = document.getElementById(tipContainerID);
	if(!tipContainer) {
		tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, 'div') : document.createElement('div');
		tipContainer.setAttribute('id', tipContainerID);
		document.getElementsByTagName('body').item(0).appendChild(tipContainer);
		tipContainer.innerHTML = DashBoardBlankContent;
	}
	if (!document.getElementById) return;

	if (boxdiv == true) {
		makeHttpRequest(url, 'PrintAJAX', 'DashBoardEmptyContent');
	} else {
		makeHttpRequest(url, 'PrintAJAX', 'DashBoardContent');
	}
	tipContainer.style.display = 'block';
}

function CloseDashBoard() {
	if(document.getElementById('DashBoard')) {
		document.getElementById('DashBoard').style.display = 'none';
		document.getElementById('DashBoard').innerHTML = DashBoardBlankContent;
	}
}

document.onkeydown = function(e) {
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	if(keycode == 27) { // close
		CloseDashBoard();
	}
};

function PrintAJAX(text, box) {
	document.getElementById(box).innerHTML = text;
}
