function ToolTip()
{
    this.div=document.createElement("div");
    this.div.className="tooltip_container";
    this.div.toolTipCtrl=this;
		
    this.show=function(tip,x,y)
    {
        this.div.innerHTML=tip;
        this.div.style.display='block'; 
        this.div.style.left=x+"px";
        this.div.style.top=y+"px";
    }

    this.hide=function() {this.div.style.display='none';}
    
    this.bindElement=function(element,tip,offsetx,offsety)
    {
        var posx=0;
        var posy=0;
                  
        if (offsetx) posx=offsetx;
        if (offsety) posy=offsety;
             
        element.toolTipCtrl=this;
        element.tip=tip;
        element.tipOffset=Array(posx,posy);
        element.onmouseover=function() 
        {   
            var pos=getElemPos(this);
            
            pos[0]+=/*this.offsetWidth+*/this.tipOffset[0];
            pos[1]+=this.tipOffset[1];
            
            this.toolTipCtrl.show(this.tip,pos[0],pos[1]);
        }
        
        //element.onmouseout=function()   {this.toolTipCtrl.hide();}
        element.onfocus=element.onmouseover;
    }
    
		
		this.div.onmouseout=function(e)   
		{
		var pos=getMouseXY(e);
		var elemPos=getElemPos(this);
		
		//this.innerHTML="<div>"+pos[0]+" "+pos[1]+"<br/>"+elemPos[0]+" "+elemPos[1]+" "+this.offsetWidth+" "+this.offsetHeight+"</div>";
		if (pos[0]<=elemPos[0] || pos[0]>=elemPos[0]+this.offsetWidth || pos[1]<=elemPos[1] || pos[1]>=elemPos[1]+this.offsetHeight)
				this.toolTipCtrl.hide();
		} //Rem out if have problem with flicker on div
		
    document.body.appendChild(this.div);
    return this;
}

function getElemPos(elem)
{
    var x=0;
    var y=0;
    
    if (elem.offsetLeft) x+=elem.offsetLeft;
    if (elem.offsetTop) y+=elem.offsetTop;
    
    if (elem.offsetParent)
    {
        var pos=getElemPos(elem.offsetParent);
        
        x+=pos[0];
        y+=pos[1];
    }
    
    return Array(x,y);
}

function getMouseXY(e) 
{
  if (document.all) 
	{ // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } 
	else 
	{  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }
	  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return Array(tempX,tempY);
}
