/**************************************************
HelpBox popup

Instructions:
Include following two lines within your BODY tags before any 

	<div id="helpLayer" style="position:absolute; visibility:hide; z-index: 1;"></div>
	<script src=/ics/inc/helpLabel.js></script>

Sample of how to render a help label:

	Sample Form Input Here
	<script>helpLabelDraw('Enter the origin of the ticket');</script>
	
***************************************************/

//realtime mouse positions
var x = 0;
var y = 0;
var is_moz5 = ((navigator.userAgent.indexOf("Gecko")!=1) && (parseInt(navigator.appVersion)>=5));

//array of labels objs on page
var helpLabelList = new Array();

function mouseMove(e) {
	if (is_nav) {x=e.pageX; y=e.pageY;}
	if (is_ie) {x=event.x; y=event.y;}
	if (is_ie5up) {x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;}
}

if (is_ie)		var help = helpLayer.style;
if (is_nav4)	var help = document.helpLayer;
if (is_nav6up || is_moz5)	var help = document.getElementById("helpLayer").style;

document.onmousemove = mouseMove;
if (is_nav) document.captureEvents(Event.MOUSEMOVE);

//class/constructor
function HelpLabel(content) {
	this.content = unescape(content);
	this.stick = false; //true if help is clicked
	this.visible = false; 
	this.over = false; //mouse position over 
	this.draw = helpLabelDraw;
	this.show = helpLabelShow;
	this.hide = helpLabelHide;
	this.moveTo = helpLabelMoveTo;
	this.id = helpLabelList.length;
	helpLabelList[helpLabelList.length] = this;
	return this;
}

// render help graphic and link
function helpLabelDraw(content,portal)
{
	var temp = new HelpLabel(content);
	var out = "<a href=\"javascript:helpLabelList[" + temp.id + "].show(true);\" onmouseover=\"helpLabelList[" + temp.id + "].show();return false;\" onmouseout=\"helpLabelList[" + temp.id + "].hide();return false;\">";
	if (portal) out += "<img border='0' src='/images/help.gif' width='14' height='14'></a>";
		else  out += "<img border='0' src='/images/help.gif' width='14' height='14'></a>";
	document.write(out);
}

//show a label
function helpLabelShow(stick) {
	if (stick) this.stick = true; //don't hide label on mouse out
	this.over = true;
	
	if (!this.visible) this.moveTo(x+5,y+5);
	
	if ((!this.visible) || (this.stick))
	{
		//insert text into layer
		var closeLink = "";
		if (this.stick) closeLink = "<div align=right><a align=right href=javascript:helpLabelList[" + this.id + "].hide(true);><img src='/images/iCloseSmall.gif' border='0' width='10' height='10'></a></div>";
		var text = "<TABLE WIDTH=200 BORDER=0 CELLPADDING=5 CELLSPACING=1 BGCOLOR=#000000 style='border-collapse: separate;'><TR><TD BGCOLOR=#FFFFE1 STYLE=\"font-family:tahoma;font-size:11px;\">" + this.content + closeLink + "</td></TR></TABLE>";
		if (is_nav4) {
			text = "<TABLE WIDTH=200 BORDER=1 CELLPADDING=5 CELLSPACING=0 BGCOLOR=#FFFFE1 style='border-collapse: separate;'><TR><TD><font face=Tahoma,Arial size=2>" + this.content + "</font>" + closeLink + "</td></TR></TABLE>";
			help.document.write(text);
			help.document.close();
		}
		else if (is_ie) document.all["helpLayer"].innerHTML = text;
		else if (is_nav6up || is_moz5) document.getElementById("helpLayer").innerHTML = text;
		
		if (is_nav4) help.visibility = "show";
		else if ((is_ie) || (is_nav6up)) help.visibility = "visible";
		this.visible = true;
		
		for (var i = 0; i < helpLabelList.length; i++) {
			if (i != this.id) {
				helpLabelList[i].visible = false;
				helpLabelList[i].stick = false;
			}
		}
	}
}


//hide a label
function helpLabelHide(forceClose) {
	this.over = false;
	if ((!this.stick) || (forceClose)) {
		if (forceClose) hideLayer(this.id);
			else setTimeout("hideLayer(" + this.id + ")",500);
	}
}

//hide the layer
function hideLayer(id) {
	if ((helpLabelList[id].visible) && (!helpLabelList[id].over)) {
		if (is_nav4) help.visibility = "hide";
		else if ((is_ie) || (is_nav6up)) help.visibility = "hidden";
		else if (is_moz5) document.getElementById("helpLayer").innerHTML = "";
		helpLabelList[id].visible = false;
		helpLabelList[id].stick = false;
	}
}

//move the layer layer
function helpLabelMoveTo(xL,yL) {
	help.left = xL;
	help.top = yL;
}