var offsetxpoint=-60; //Customize x offset of tooltip
var offsetypoint=20; //Customize y offset of tooltip
var ie=document.all;
var ns6=document.getElementById && !document.all
var tipobj=null;
var isFlowing=false;

function ieTrueBody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function showToolTip(thetext,evt){	
	isFlowing=true;			
	tipobj=document.all? document.all['tipOutter'] : document.getElementById? document.getElementById('tipOutter') : "";
	tipobjinner=document.all? document.all['tipDiv'] : document.getElementById? document.getElementById('tipDiv') : "";
	tipobj.style.position="absolute";
	if (ns6||ie){
		tipobjinner.innerHTML=thetext;
		tipobj.style.zIndex=1000;
		positionTip(evt);
		tipobj.style.visibility="visible";
		tipobj.style.display = "";
	}
	return false;
}

function showState(stateId,thetext){		
	var stateobj=document.all? document.all[stateId] : document.getElementById? document.getElementById(stateId) : "";
	if (ns6||ie){		
		stateobj.innerHTML=thetext;
		stateobj.style.visibility="visible";
	}
	return false;
}

function hiddenState(stateId){
	if (ns6||ie){
		var stateobj=document.all? document.all[stateId] : document.getElementById? document.getElementById(stateId) : "";
		stateobj.style.visibility="hidden";		
		stateobj.style.backgroundColor='';
		stateobj.style.width='';
		stateobj=null;
		
		stateobj.style.display = "none";
	}
}

function positionTip(evt){
	if(tipobj==null||!isFlowing)
	return;
	var curX=(ns6)?evt.pageX : event.clientX+ieTrueBody().scrollLeft;
	var curY=(ns6)?evt.pageY : event.clientY+ieTrueBody().scrollTop;
	//Find out how close the mouse is to the corner of the window
	var rightedge=ie&&!window.opera? ieTrueBody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-evt.clientX-offsetxpoint-20;
	var bottomedge=ie&&!window.opera? ieTrueBody().clientHeight-event.clientY-offsetypoint : window.innerHeight-evt.clientY-offsetypoint-20;
	var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<tipobj.offsetWidth){
		//move the horizontal position of the menu to the left by it's width
		tipobj.style.left=ie? (ieTrueBody().scrollLeft+event.clientX-tipobj.offsetWidth)+"px" : (window.pageXOffset+evt.clientX-tipobj.offsetWidth)+"px";
	}else if (curX<leftedge){
		tipobj.style.left="5px";
	}else{
	//position the horizontal position of the menu where the mouse is positioned
	
		tipobj.style.left=ie? (ieTrueBody().scrollLeft+evt.clientX)+"px" : (window.pageXOffset+evt.clientX)+"px";
	
	
	}
	//same concept with the vertical position
	if (bottomedge<tipobj.offsetHeight){
		tipobj.style.top=ie? (ieTrueBody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint)+"px" : (window.pageYOffset+evt.clientY-tipobj.offsetHeight-offsetypoint)+"px";
	}else{
		tipobj.style.top=(curY+offsetypoint)+"px";
	}
}

function hideToolTip(){	
	if (ns6||ie){
		tipobj=document.all? document.all['tipOutter'] : document.getElementById? document.getElementById('tipOutter') : "";
		tipobj.style.visibility="hidden";		
		tipobj.style.zIndex=10;
		tipobj=null;
	}
}

