
function GetWindowWidth()
{

	var width = 0;

	if ( window.innerWidth )
	{
		width = window.innerWidth;
	}
	else if ( document.documentElement && document.documentElement.clientWidth )
	{
		width = document.documentElement.clientWidth;
	}
	else if ( document.body && document.body.clientWidth )
	{
		width = document.body.clientWidth;
	}

	return width;

}

function GetWindowHeight()
{

	var height = 0;

	if ( window.innerHeight )
	{
		height = window.innerHeight;
	}
	else if ( document.documentElement && document.documentElement.clientHeight )
	{
		height = document.documentElement.clientHeight;
	}
  	else if ( document.body && document.body.clientHeight )
  	{
		height = document.body.clientHeight;
	}

	return height;

}

function GetWindowScrollX()
{
	var scrollX = 0;

  	if ( typeof window.pageXOffset == "number" )
	{
		scrollX = window.pageXOffset;
	}
  	else if ( document.documentElement && document.documentElement.scrollLeft )
  	{
		scrollX = document.documentElement.scrollLeft;
	}
  	else if ( document.body && document.body.scrollLeft )
  	{
		scrollX = document.body.scrollLeft;
	}
  	else if ( window.scrollX )
	{
		scrollX = window.scrollX;
	}

	return scrollX;

}

function GetWindowScrollY()
{
	var scrollY = 0;

	if ( typeof window.pageYOffset == "number" )
	{
		scrollY = window.pageYOffset;
	}
	else if ( document.documentElement && document.documentElement.scrollTop )
	{
		scrollY = document.documentElement.scrollTop;
	}
  	else if ( document.body && document.body.scrollTop )
  	{
  		scrollY = document.body.scrollTop;
  	}
  	else if ( window.scrollY )
	{
		scrollY = window.scrollY;
	}

	return scrollY;

}

	function Tooltip_SetPos( e, LayerName, offX, offY )
	{

		var Element = document.getElementById( LayerName );

      if ( Element && Element.style )
		{

			var x = e.pageX ? e.pageX : e.clientX + GetWindowScrollX();
         var y = e.pageY ? e.pageY : e.clientY + GetWindowScrollY();

         if ( x + Element.offsetWidth + offX > GetWindowWidth() + GetWindowScrollX() )
			{
         	x = x - Element.offsetWidth - offX;
            if ( x < 0 ) x = 0;
         }
			else x = x + offX;

         if ( y + Element.offsetHeight + offY > GetWindowHeight() + GetWindowScrollY() )
			{
         	y = y - Element.offsetHeight - offY;
            if ( y < GetWindowScrollY() ) y = GetWindowHeight() + GetWindowScrollY() - Element.offsetHeight;
         }
			else y = y + offY;

         Element.style.left = x + "px";
			Element.style.top = y + "px";

      }

      return;

	}

	function Tooltip_MouseOver( e, LayerName, offX, offY )
	{

		var Element = document.getElementById( LayerName );

		if ( Element && Element.style )
		{

			Tooltip_SetPos( e, LayerName, offX, offY );

			Element.style.display = 'inline';
			Element.style.visibility = 'visible';

		}

		return;

	}

	function Tooltip_MouseMove( e, LayerName, offX, offY )
	{

		Tooltip_SetPos( e, LayerName, offX, offY );

		return;

	}

	function Tooltip_MouseOut( LayerName )
	{

		//setTimeout( "Tooltip_Hide("+LayerName+")", 100 );
		Tooltip_Hide( LayerName );

	}

	function Tooltip_Hide( LayerName )
	{

		var Element = document.getElementById( LayerName );

		if ( Element && Element.style )
		{

			Element.style.display = 'none';
			Element.style.visibility = 'hidden';

		}

		return;

	}