﻿//	TO USE:
//		<tag onmouseout="popUp(event,'divID');" onmouseover="popUp(event,'divID');" />
//		<div class="tip" id="divID" style="visibility: hidden;">...</div>

//	TIPS AND NOTES:

//	This builds the style classes used by the tooltips
document.write ('<style type="text/css">');
document.write ('	.tip {');
//document.write ('		filter:alpha(opacity=70); -moz-opacity:0.70; opacity: 0.70;');
document.write ('		font:11px Arial,Helvetica,sans-serif;');
document.write ('		border:solid 1px #000000;');
document.write ('		padding:6px;');
document.write ('		width:270px;');
document.write ('		position:absolute;');
document.write ('		z-index:300;');
document.write ('		color:#333333;');
document.write ('		margin-left: 15px;');
document.write ('		background-color:#fbffc5;');
document.write ('		layer-background-color:#fbffc5;');
document.write ('		text-align: left;');
document.write ('		width: 150px;');
document.write ('	}');
document.write ('</style>');

//	Define the variables that are used on a global level
var DH = 0;
var an = 0;
var al = 0;
var ai = 0;
var ttpMargin = 10;
var ttpHeightAdjust = 20;
var delay = 0; // milliseconds
var curObj = "";

////////////////////////////////////////////////////////////////////////////////////////////////////
// BROWSER HANDLING CODE
////////////////////////////////////////////////////////////////////////////////////////////////////
if (document.getElementById)
{
	ai = 1;
	DH = 1;
}
else
{
	if (document.all)
	{
		al = 1;
		DH = 1;
	}
	else
	{
		browserVersion = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4))
		{
			an = 1;
			DH = 1;
		}
	}
}

function fd(oi, wS)
{
	if (ai) return wS ? _getElementById(oi).style:_getElementById(oi);
	if (al) return wS ? document.all[oi].style: document.all[oi];
	if (an) return document.layers[oi];
}

function pw()
{
	return window.innerWidth != null? window.innerWidth: document.body.clientWidth != null? document.body.clientWidth:null;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
// MOUSE METHODS
////////////////////////////////////////////////////////////////////////////////////////////////////
function ttpMousePos(evnt) 
{
	if (window.event != null)
	{
		ttpCurX = window.event.x;
		ttpCurY = window.event.y;
	}
	else
	{
		ttpCurX = evnt.pageX+20;
		ttpCurY = evnt.pageY;
	}
  }
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
// REPOSITIONING METHODS
////////////////////////////////////////////////////////////////////////////////////////////////////
function ttp_PageWidth() 
{
    return window.innerWidth != null ? 
        window.innerWidth : document.documentElement && document.documentElement.clientWidth ?
            document.documentElement.clientWidth : document.body != null ? 
                document.body.clientWidth : null;
} 

function ttp_PageHeight() 
{
    return window.innerHeight != null ? 
        window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  
            document.documentElement.clientHeight : document.body != null ? 
                document.body.clientHeight : null;
} 

function ttp_PosLeft() 
{
    return typeof window.pageXOffset != 'undefined' ? 
        window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? 
            document.documentElement.scrollLeft : document.body.scrollLeft ? 
                document.body.scrollLeft : 0;
} 

function ttp_PosTop() 
{
    return typeof window.pageYOffset != 'undefined' ?  
        window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
            document.documentElement.scrollTop : document.body.scrollTop ? 
                document.body.scrollTop : 0;
} 

function ttp_PosRight() 
{
    return ttp_PosLeft() + ttp_PageWidth();
} 

function ttp_PosBottom() 
{
	return ttp_PosTop() + ttp_PageHeight();
}
  function ttp_FindPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function ttp_FindPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
// MAIN POPUP METHOD
////////////////////////////////////////////////////////////////////////////////////////////////////

//	This function applies any above specified adjustments to the
//	tooltip, see the ttpHeightAdjust, ttpMargin etc
function popReposition(obj)
{
	var width = obj.clientWidth;
	var height = obj.clientHeight;
	var leftMargin = 0;
	var topMargin = 0;
	
	//alert("ttpCurX: " + ttp_FindPosX(obj) + "\nwidth: " + width + "\nttp_PosRight:" + ttp_PosRight());
	
	ttpPositionAdjustment(obj,0,0);
}

//	This function accepts on the fly top and left adjustment values
//	so that specific instances can be repositioned as needed
function popRepositionCustom(evt,obj,leftAdjust,topAdjust)
{
	var width = obj.clientWidth;
	var height = obj.clientHeight;
	var leftMargin = 0;
	var topMargin = 0;
	
	//alert("ttpCurX: " + ttp_FindPosX(obj) + "\nwidth: " + width + "\nttp_PosRight:" + ttp_PosRight());
	//alert(topAdjust);
	
	if ((ttp_FindPosX(obj)+width+leftAdjust) > ttp_PosRight())
	{
		leftMargin = (ttp_PosRight() - (ttp_FindPosX(obj)+width+ttpMargin));
	}
	
	ttpPositionAdjustment(obj,leftAdjust,topAdjust);
}

function ttpPositionAdjustment(obj,leftAdjust,topAdjust)
{
	var width = obj.clientWidth;
	var height = obj.clientHeight;
	var leftMargin = 0;
	var topMargin = 0;
	
	if ((ttp_FindPosX(obj)+width) > ttp_PosRight())
	{
		leftMargin = (ttp_PosRight() - (ttp_FindPosX(obj)+width+ttpMargin));
	}
	
	//alert("top: " + (ttp_FindPosY(obj)+height) + "\ncontent height: " + ttp_PosBottom());
	
	if ((ttp_FindPosY(obj)+height) > ttp_PosBottom())
	{
	
	//alert("top: " + ttp_FindPosY(obj) + "\nheight: " + height);
	
		if (ttp_FindPosY(obj) > height)
		{
			//alert("dont adjust the height");
			topMargin = (0-(height+ttpHeightAdjust));
		}
		else
		{
			//alert("adjust the height");
			showElement(obj);
		}
	}
	
	obj.style.marginTop = (topMargin + topAdjust) + "px";
	obj.style.marginLeft = (leftMargin + leftAdjust) + "px";
}

//	This function parses the event and object, calling
//	the necessary function to either show or hide the tooltip
function popUp(evt,oi)
{
	ttpMousePos(evt);
	
	if (DH)
	{
		var wp = pw();
		ds = fd(oi,1);
		dm = fd(oi,0);
		st = ds.display;
		
		curObj = oi;
		
		hidePopups();
		
		if ((st != "none" || st == "show") && evt.type == "mouseout")
		{
			//hidePopup(oi);
			dm.style.marginTop = "";
			dm.style.marginLeft = "";
			hideElement(dm);
		}
		else
		{
			//setTimeout ( "popUpEvent('" + oi +"')", delay );
			showElement(dm);
			popReposition(dm);
		}
	}
	
	return;
}

//	This function displays the tooltip
function popUpEvent(oi)
{

	if (DH)
	{
		var wp = pw();
		ds = fd(oi,1);
		dm = fd(oi,0);
		st = ds.display;
		
		if (curObj == oi)
		{
			dm.style.display = "";
			//popReposition(evt,dm);
			popReposition(dm);
		}
	}
}

//	This function hides the tooltip
function hidePopup(oi)
{
	if (DH)
	{
		var wp = pw();
		ds = fd(oi,1);
		dm = fd(oi,0);
		st = ds.display;
		
		dm.style.marginTop = "";
		dm.style.marginLeft = "";
		//dm.style.display = "none";
		
		hideElement(dm);
		
		curObj = "";
	}
}

//	This function hides all of the tooltips via their 
//	css class. This helps to eliminate 'hanging' tooltips
function hidePopups()
{
	var arr = getElementsByClassName(document,"div","tip");
	
	if (arr == null) return;
	
	for (var i=0; i < arr.length; i++)
	{
		//arr[i].style.display = "none";
		hideElement(arr[i]);
	}
	
	return;
}