var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;

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

function tip(target) { $('dhtmltooltip').innerHTML=$(target).innerHTML; 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-12 : winwidth-e.clientX-12;
		var bottomedge=ie&&!window.opera? winheight-event.clientY-10 : winheight-e.clientY-10;
		var leftedge=(12<0)? 12*(-1) : -1000;
		if (rightedge<$('dhtmltooltip').offsetWidth){
			$('dhtmltooltip').style.left=curX-$('dhtmltooltip').offsetWidth+"px";
			nondefaultpos=true;
		}
		else if (curX<leftedge)
		$('dhtmltooltip').style.left="5px";
		else{
			//position the horizontal position of the menu where the mouse is positioned
			$('dhtmltooltip').style.left=curX+2+"px";
			$('dhtmlpointer').style.left=curX+12+"px";
		}

		//same concept with the vertical position
		if (bottomedge<$('dhtmltooltip').offsetHeight){
			$('dhtmltooltip').style.top=curY-$('dhtmltooltip').offsetHeight-10+"px";
			nondefaultpos=true;
		}
		else{
			$('dhtmltooltip').style.top=curY+24+"px";
			$('dhtmlpointer').style.top=curY+10+"px";
		}
		$('dhtmltooltip').style.visibility="visible";
		if (!nondefaultpos)
		$('dhtmlpointer').style.visibility="visible";
		else {
			$('dhtmlpointer').style.visibility="hidden";
		}
	}
}

function untip(){
	if (ns6||ie){
		enabletip=false;
		$('dhtmltooltip').style.visibility="hidden";
		$('dhtmlpointer').style.visibility="hidden";
		$('dhtmltooltip').style.left="-1000px";
	}
}

document.onmousemove=positiontip; 