var toolTipDiv = false;

var iFrameDiv = false;

var timerShow = false;

var timerHide = false;

var posX, posY, _id;



function showTooltip(e, id)

{	

    // get coordinate of mouse

    e = e || window.event;    

    scrollTop    = document.body.scrollTop  || document.documentElement.scrollTop;

    scrollLeft   = document.body.scrollLeft || document.documentElement.scrollLeft;            

	posX = (e.pageX) ? e.pageX : (e.clientX + scrollLeft);

	posY = (e.pageY) ? e.pageY : (e.clientY + scrollTop);

	

	if(timerShow)

	{

		clearTimeout(timerShow);

	}

	

	// put in global variable for callback

	_id = id;



	timerShow = setTimeout("showToolTipCallback(_id)", 250);



}



function showToolTipCallback(id)

{

    var toolTip;

    

    timerShow = false;

    

    // create a div on the body scope if it doesn't yet exist

    if(!toolTipDiv)

    {

    	toolTipDiv = document.createElement('div');

    	toolTipDiv.className = "toolTipBox";    	

    	document.body.appendChild(toolTipDiv); 

    	toolTipDiv.style.position = "absolute";    	

    }



	// reset previously set style so adjust height values does not accumulate

	toolTipDiv.style.height  =  null;

        

    // get reference to actual tooltip element

    toolTip = document.getElementById(id);

 

    // copy tooltip element contents to new div on body scope

    toolTipDiv.innerHTML = toolTip.innerHTML;

    toolTipDiv.style.display = 'block';

    toolTipDiv.style.visibility = 'visible';

    

    // position it according to mouse coordinates

    	

    obj_width  = toolTipDiv.offsetWidth;

    obj_height = toolTipDiv.offsetHeight;	

    

    posX -= 0;

    posY -= obj_height;

    

    // adjust height so it does not cover icons

    toolTipDiv.style.height = (obj_height - 25) + "px";

    

    //iFrameDiv.style.width = obj_width + "px";

	toolTipDiv.style.left = posX + "px";

	toolTipDiv.style.top  = posY + "px";	



}



/** Closes tooltip */



function hideTooltip(id)

{

	if(toolTipDiv)

	{

   		toolTipDiv.style.display = "none";

   	}

   	

}



/* hides tooltip onclick anywhere outside the tooltip */



function hideTooltip2(e)

{

	var e = e || window.event;

	var clickedElem = e.target || e.srcElement;

	var isOnTooltip = false;

	

	// iterates through to see if the clicked element is a descendant of toolTipBox

	for(i=0; i < 5; ++i)

	{

		if(clickedElem.className == 'toolTipBox') 

		{

			isOnTooltip = true;

		}

		else if(clickedElem.parentNode)

		{

			clickedElem = clickedElem.parentNode;

		}

	}

	

	if(toolTipDiv && !isOnTooltip)

	{

		toolTipDiv.style.display = "none";

	}

}



function addBodyOnclickHide()

{

	var oldonclick = document.body.onclick;

	

	if (typeof document.body.onclick !='function')

	{

		document.body.onclick = hideTooltip2;

	} 

	else 

	{

		document.body.onclick = function()

		{

			oldonclick();

			hideTooltip2();

		}

	}

}