function ToolTip()
{
this.x_offset_tooltip = 5;
this.y_offset_tooltip = 0;
this.tooltipObj = false;
this.tooltipObj_shadow = false;
this.tooltipObj_iframe = false;
this.shadowSize = 4;
this.tooltipMaxWidth = 200;
this.tooltipMinWidth = 100;
this.tooltip_MSIE = false;
if(navigator.userAgent.indexOf('MSIE')>=0)this.tooltip_MSIE=true;
}

ToolTip.prototype.Show = function(message,element,width)
{
	if(!this.tooltipObj)
	{
		this.tooltipObj = document.createElement('DIV');
		this.tooltipObj.style.position = 'absolute';
		this.tooltipObj.id = 'tooltipObj';		
		this.tooltipObj_shadow = document.createElement('DIV');
		this.tooltipObj_shadow.id = 'tooltipShadow';
		document.body.appendChild(this.tooltipObj);
		document.body.appendChild(this.tooltipObj_shadow);	

		
		var leftDiv = document.createElement('DIV');
		leftDiv.className='tooltip_arrow';
		leftDiv.id = 'tooltip_arrow';
		this.tooltipObj.appendChild(leftDiv);
		
		var contentDiv = document.createElement('DIV'); 
		contentDiv.className = 'tooltip_content';
		this.tooltipObj.appendChild(contentDiv);
		contentDiv.id = 'tooltip_content';
		
		if(this.tooltip_MSIE){
			this.tooltipObj_iframe = document.createElement('<IFRAME frameborder="0">');
			this.tooltipObj_iframe.style.position = 'absolute';
			this.tooltipObj_iframe.border='0';
			this.tooltipObj_iframe.frameborder=0;
			this.tooltipObj_iframe.style.backgroundColor='#FFF';
			this.tooltipObj_iframe.src = 'about:blank';
			contentDiv.appendChild(this.tooltipObj_iframe);
			this.tooltipObj_iframe.style.left = '0px';
			this.tooltipObj_iframe.style.top = '0px';
		}			
	}
	// Find position of tooltip
	this.tooltipObj.style.display='block';
	this.tooltipObj_shadow.style.display='block';
	document.getElementById('tooltip_content').innerHTML = message;
	
	if(this.tooltipObj.offsetWidth>this.tooltipMaxWidth){	/* Exceeding max width of tooltip ? */
			this.tooltipObj.style.width = this.tooltipMaxWidth + 'px';
		}
		
		var tooltipWidth = this.tooltipObj.offsetWidth;		
		if(tooltipWidth<this.tooltipMinWidth)tooltipWidth = this.tooltipMinWidth;
		
		if(width)
		{
			tooltipWidth = width;
		}
		
		
		this.tooltipObj.style.width = tooltipWidth + 'px';
		this.tooltipObj_shadow.style.width = this.tooltipObj.offsetWidth + 'px';
		this.tooltipObj_shadow.style.height = this.tooltipObj.offsetHeight + 'px';	
	
	
	if(this.tooltip_MSIE){
		this.tooltipObj_iframe.style.width = this.tooltipObj.clientWidth + 'px';
		this.tooltipObj_iframe.style.height = this.tooltipObj.clientHeight + 'px';
	}

	this.Position(element);
}

ToolTip.prototype.Position = function(element)
{	
	var positions = this.GetPosition(element);
	//var positions = Position.page(element);
	//var positions = getTopLeft(element);
	var leftPos = (positions.x + element.offsetWidth);
	var topPos = positions.y;
//	var leftPos = (this.GetLeftPos(element) + element.offsetWidth);
//	var topPos = this.GetTopPos(element);
	
	var tooltipWidth = document.getElementById('tooltip_content').offsetWidth +  document.getElementById('tooltip_arrow').offsetWidth; 
	this.tooltipObj.style.left = (leftPos) + 'px';
	this.tooltipObj.style.top = topPos + 'px';	
	
	this.tooltipObj_shadow.style.left =  (leftPos + 20) + this.shadowSize + 'px';
	this.tooltipObj_shadow.style.top = topPos + this.shadowSize + 'px';	
}

function getTopLeft(o){  
   if(o==null){return [0,0];} 
   var top=o.offsetTop,left=o.offsetLeft; 
   o=o.offsetParent; 
   while(o){ 
            if(document.all){ 
         if(o.offsetParent){ 
            if(o.scrollTop)top-=o.scrollTop; 
            if(o.scrollLeft)left-=o.scrollLeft; 
         } 
      }else{ 
 
         if(o.scrollTop)top-=o.scrollTop; 
         if(o.scrollLeft)left-=o.scrollLeft; 
         // Mozilla bug 
         if((o.tagName=='DIV')||(o.tagName=='TABLE'&&navigator.vendor=='Netscape')) 
            top+=getAttrPixValue(o,'border-top-width')|0,left+=getAttrPixValue(o,'border-left-width')|0; 
      } 
      top+=o.offsetTop; 
      left+=o.offsetLeft; 
      o=o.offsetParent; 
   } 
   if(navigator.userAgent.indexOf('Mac')!=-1 && typeof(document.body.leftMargin)!='undefined'){ 
      left+=document.body.leftMargin,top+=document.body.topMargin;   // working? 
   } 
   return [top,left]; 
} 
function getAttrPixValue(e,a){ 
   var px=0; 
    if(window.getComputedStyle){ 
        var css,sty=window.getComputedStyle(e,''); 
      if(sty&&sty.getPropertyCSSValue){ 
         css=sty.getPropertyCSSValue(a); 
         if((css)&&css.primitiveType<=18){try{px=css.getFloatValue(5)|0;}catch(e){};} 
      } 
    } 
    return px; 
} 


ToolTip.prototype.GetPosition = function(element)
{
var left = 0;
var top = 0;
	
if (element != null)
{
    // Try because sometimes errors on offsetParent after DOM changes.
    try
    {
        while (element.offsetParent)
        {
            // While we haven't got the top element in the DOM hierarchy
            // Add the offsetLeft
            left += element.offsetLeft;
            // If my parent scrolls, then subtract the left scroll position
            if (element.offsetParent.scrollLeft) {left -= element.offsetParent.scrollLeft; }
	
            // Add the offsetTop
            top += element.offsetTop;
            // If my parent scrolls, then subtract the top scroll position
            if (element.offsetParent.scrollTop) { top -= element.offsetParent.scrollTop; }
	
            // Grab
            element = element.offsetParent;
        }
    }
    catch (e)
    {
        // Do nothing
    }
   	
    // Add the top element left offset and the windows left scroll and subtract the body's client left position.
    left += element.offsetLeft + document.body.scrollLeft - (document.body.clientLeft?document.body.clientLeft:0);
	
    // Add the top element topoffset and the windows topscroll and subtract the body's client top position.
    top += element.offsetTop + document.body.scrollTop - (document.body.clientTop?document.body.clientTop:0);
   // alert(top+":"+left);
}
return {x:left, y:top};
}


ToolTip.prototype.Hide = function()
{
	this.tooltipObj.style.display='none';
	this.tooltipObj_shadow.style.display='none';
}



ToolTip.prototype.GetTopPos = function(element)
{		
  var returnValue = element.offsetTop;
  while((element = element.offsetParent) != null){
  	if(element.tagName!='HTML')
  	{returnValue += element.offsetTop;
  	if(element.tagName!='BODY')
  		returnValue -= element.scrollTop;
  		
  	}
  }
  return returnValue;
}

ToolTip.prototype.GetLeftPos = function(element)
{
  var returnValue = element.offsetLeft;
  while((element = element.offsetParent) != null){
  	if(element.tagName!='HTML')returnValue += element.offsetLeft;
  }
  return returnValue;
}

var toolTip = new ToolTip();