
//Begin Martin's Tooltip Code
is_safari = ((navigator.userAgent.indexOf("Safari")!=-1))?true:false;
isShowing = false;
var defaultWidth=300;

function showTip(toolTipContent,defaultWidthOverride)
{
  if (defaultWidthOverride){
  	
	document.getElementById("tooltipcontainer").style.width=defaultWidthOverride+"px";
	//alert("Override - " + document.getElementById("tooltipcontainer").style.width)
  }else{
  	document.getElementById("tooltipcontainer").style.width=defaultWidth+"px";
	//alert("Default - " + document.getElementById("tooltipcontainer").style.width)
  }
  isShowing = true;
	windowHeight = document.body.clientHeight;
	windowWidth = document.body.clientWidth;
  document.getElementById("toolBox").innerHTML = toolTipContent;
  document.getElementById("tooltipcontainer").style.display = "block";
	var ttipOvershoot = (!is_safari) ? document.getElementById("tooltipcontainer").offsetHeight + mouseY + 10 : document.getElementById("tooltipcontainer").offsetHeight + mouseY + 10 - window.pageYOffset;
	var ttipSideOvershoot = document.getElementById("tooltipcontainer").offsetWidth + mouseX + 10;
	if(ttipOvershoot > windowHeight)
	{
		document.getElementById("tooltipcontainer").style.top = (!is_safari) ? windowHeight - document.getElementById("toolBox").offsetHeight - 12 + document.documentElement.scrollTop + "px" : windowHeight - document.getElementById("toolBox").offsetHeight - 12 + window.pageYOffset + "px";
	}
	else
	{
		document.getElementById("tooltipcontainer").style.top = (!is_safari) ? mouseY+10+document.documentElement.scrollTop+"px" : mouseY+5+"px";
	}
	if(ttipSideOvershoot > windowWidth)
	{
		document.getElementById("tooltipcontainer").style.left = mouseX-20-document.getElementById("toolBox").offsetWidth+"px";
	}
	else
	{
		document.getElementById("tooltipcontainer").style.left = mouseX+10+"px";
	}
	
	//alert("Final Width - " + document.getElementById("tooltipcontainer").style.width)
	
}

function hideTip()
{
  document.getElementById("tooltipcontainer").style.display = "none";
  isShowing = false;
}

function tipPosition(callingEvent)
{
  if (!callingEvent) callingEvent = window.event;
  mouseX = callingEvent.clientX;
  mouseY = callingEvent.clientY-1;
	if (isShowing)
	{
//		document.getElementById("tooltipcontainer").style.left = mouseX+10+"px";
		var ttipSideOvershoot = document.getElementById("tooltipcontainer").offsetWidth + mouseX + 10;
		var ttipOvershoot = (!is_safari) ? document.getElementById("tooltipcontainer").offsetHeight + mouseY + 10 : document.getElementById("tooltipcontainer").offsetHeight + mouseY + 10 - window.pageYOffset;
		if(ttipOvershoot > windowHeight)
		{
			document.getElementById("tooltipcontainer").style.top = (!is_safari) ? windowHeight - document.getElementById("toolBox").offsetHeight - 12 + document.documentElement.scrollTop + "px" : windowHeight - document.getElementById("toolBox").offsetHeight - 12 + window.pageYOffset + "px";
		}
		else
		{
			document.getElementById("tooltipcontainer").style.top = (!is_safari) ? mouseY+10+document.documentElement.scrollTop+"px" : mouseY+5+"px";
		}
		if(ttipSideOvershoot > windowWidth)
		{
		document.getElementById("tooltipcontainer").style.left = mouseX-20-document.getElementById("toolBox").offsetWidth+"px";
//			document.getElementById("tooltipcontainer").style.right = "0px";
		}
		else
		{
			document.getElementById("tooltipcontainer").style.left = mouseX+10+"px";
		}
	}
}
document.onmousemove = tipPosition;

//End Martin's Tooltip Code


function sendRequest(file, queryString, div) {
	if(xmlHttp) {
		/* Request Daten in die Warteschlange setzen, falls der vorherige noch nicht abgeschlossen ist */
		if(xmlHttp.readyState == 1 || xmlHttp.readyState == 2 || xmlHttp.readyState == 3) {
			queueLength = queue.length;
			queue[queueLength] = new Array();
			queue[queueLength][0] = file;
			queue[queueLength][1] = queryString;
			queue[queueLength][2] = div;
			document.getElementById(div).innerHTML = 'In Warteschlange...';
		} else {
			if(queryString == "") {
				xmlHttp.open('GET', file, true);
			} else {
				xmlHttp.open('POST', file, true);
				xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHttp.send(queryString);
			}
			xmlHttp.onreadystatechange = function () {
				if(xmlHttp.readyState == 4) {
					if(xmlHttp.status == 200) {
						document.getElementById(div).innerHTML = xmlHttp.responseText;
					} else if(xmlHttp.status == 404) {
						document.getElementById(div).innerHTML = 'Item nicht gefunden!';
					}
					/* Warteschlange abarbeiten */
					queueLength = queue.length;
					if(queueLength != 0) {
						sendRequest(queue[0][0], queue[0][1], queue[0][2]);
						queue.shift(); //Erstes Element entfernen
					}
				}
			};
			if(queryString == "") {
				xmlHttp.send(null);
			}
		}
	}
}