/* setting global variables on page, first checking to see if tooltip.js was loaded previously */
if (!RICOLAToolTip_Defined) {
	var RICOLAToolTip_Defined = 1;

	var RICOLAToolTip_IDNum=0;
	var RICOLAToolTip_ie4 = (document.all) ? true : false;
	var RICOLAToolTip_ns4 = (document.layers) ? true : false;
	var RICOLAToolTip_ns6 = (document.getElementById && !document.all) ? true : false;
	var RICOLAToolTip_HideDropdowns=false;
	var RICOLAToolTip_SelectBoxAry=new Array();
	var RICOLAToolTip_ToolTipStr = new String("");
}

function RICOLAToolTip_hidelayer(lay) {
	if (RICOLAToolTip_ie4) {document.all[lay].style.display = "none";}
	if (RICOLAToolTip_ns4) {document.layers[lay].visibility = "hide";}
	if (RICOLAToolTip_ns6) {document.getElementById([lay]).style.display = "none";}
}

function RICOLAToolTip_showlayer(lay) {
	if (RICOLAToolTip_ie4) {document.all[lay].style.display = "inline";}
	if (RICOLAToolTip_ns4) {document.layers[lay].visibility = "show";}
	if (RICOLAToolTip_ns6) {document.getElementById([lay]).style.display = "inline"; }
}

function RICOLAToolTip_vis_hidelayer(lay) {
	if (RICOLAToolTip_ie4) {document.all[lay].style.visibility = "hidden";}
	if (RICOLAToolTip_ns4) {document.layers[lay].visibility = "hide";}
	if (RICOLAToolTip_ns6) {document.getElementById([lay]).style.visibility = "hidden";}
}

function RICOLAToolTip_vis_showlayer(lay) {
	if (RICOLAToolTip_ie4) {document.all[lay].style.visibility = "visible";}
	if (RICOLAToolTip_ns4) {document.layers[lay].visibility = "show";}
	if (RICOLAToolTip_ns6) {document.getElementById([lay]).style.visibility = "visible"; }
}

function RICOLAToolTip_HideSelectBoxes() {
	return true;
/*		Depricated Code - function that would hide all dropdowns on the page - Start */
/*
	RICOLAToolTip_HideDropdowns=true;
*/
/*		Depricated Code - function that would hide all dropdowns on the page - End */
}

function RICOLAToolTip_HDropDownFunc(inFlag) {
	return true;
	/*		Depricated Code - function that would hide all dropdowns on the page - Start */

	/*
	var SelectBoxAry=document.getElementsByTagName("SELECT");
	if (inFlag && !RICOLAToolTip_ns4) {		// Make Hidden
		for (var i=0; i < SelectBoxAry.length; i++) {
			if (SelectBoxAry[i].style.visibility == "visible") {
				RICOLAToolTip_SelectBoxAry[RICOLAToolTip_SelectBoxAry.length]=SelectBoxAry[i];
				SelectBoxAry[i].style.visibility="hidden";
			}
		}
	} else {			// Show Dropdowns
		for (var i=0; i < RICOLAToolTip_SelectBoxAry.length; i++) {
			if (RICOLAToolTip_SelectBoxAry[i].style.visibility == "hidden") {
				RICOLAToolTip_SelectBoxAry[i].style.visibility="visible";
			}
		}
	}
	*/
	/*		Depricated Code - function that would hide all dropdowns on the page - End */

}

function RICOLAToolTip_TTLayerShow(inNum,inEvent) {

	var tempX = 0;
	var tempY = 0;
	if (RICOLAToolTip_ie4) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else if (RICOLAToolTip_ns6) {
		tempX = inEvent.clientX;
		tempY = inEvent.clientY;
	}

	if (tempX < 0){ tempX = 0; }
	if (tempY < 0){ tempY = 0; }
	var inItem=eval("document.getElementById(['RICOLAToolTip_InfoLayer" + inNum + "'])");  // inItem is the Tooltip div Object now

	RICOLAToolTip_vis_hidelayer("RICOLAToolTip_InfoLayer" + inNum);
	RICOLAToolTip_showlayer("RICOLAToolTip_InfoLayer" + inNum);

	// Determine, per browser, where the tooltip should be located and direction (ex. top-left, lower-right, etc.) 
	if (RICOLAToolTip_ie4) {
		if ((tempX - document.body.scrollLeft) > (document.body.clientWidth / 2)) {
			tempX=tempX - eval("document.all['RICOLAToolTip_InfoLayer" + inNum + "'].clientWidth");
		}
		if ((tempY - document.body.scrollTop) > (document.body.clientHeight / 2)) {
			tempY=tempY - eval("document.all['RICOLAToolTip_InfoLayer" + inNum + "'].clientHeight");
		}
	} else if (RICOLAToolTip_ns6) {
		RICOLAToolTip_showlayer("RICOLAToolTip_InfoLayer" + inNum);
		if (tempX > (document.body.clientWidth / 2)) {
			var layWidth=eval("document.getElementById(['RICOLAToolTip_InfoLayer" + inNum + "']).offsetWidth");
			tempX=tempX + document.body.scrollLeft - layWidth;
		} else {
			tempX=tempX + document.body.scrollLeft;
		}
		if (tempY > (document.body.clientHeight / 2)) {
			var layHeight=eval("document.getElementById(['RICOLAToolTip_InfoLayer" + inNum + "']).offsetHeight");
			tempY=tempY + document.body.scrollTop - layHeight;
		} else {
			tempY=tempY + document.body.scrollTop;
		}
	}



	RICOLAToolTip_vis_showlayer("RICOLAToolTip_InfoLayer" + inNum);   // In order to get percise calculation, we have to show the layer, make it invisible, get dimensions and set position, then make it visible.
	inItem.style.left=tempX + 'px';
	inItem.style.top=tempY + 'px';

	/* resize and reposition background iframe - Start */
	document.getElementById("RICOLAToolTip_backgroundIframe" + inNum).style.display = "block";
	document.getElementById("RICOLAToolTip_backgroundIframe" + inNum).style.width = document.getElementById("RICOLAToolTip_InfoLayer" + inNum).offsetWidth;
	document.getElementById("RICOLAToolTip_backgroundIframe" + inNum).style.height = document.getElementById("RICOLAToolTip_InfoLayer" + inNum).offsetHeight;
	document.getElementById("RICOLAToolTip_backgroundIframe" + inNum).style.top = document.getElementById("RICOLAToolTip_InfoLayer" + inNum).offsetTop;
	document.getElementById("RICOLAToolTip_backgroundIframe" + inNum).style.left = document.getElementById("RICOLAToolTip_InfoLayer" + inNum).offsetLeft;
	/* resize and reposition background iframe - End */
	RICOLAToolTip_hidelayer("RICOLAToolTip_InfoLayer" + inNum);

/*		Depricated Code - function that would hide all dropdowns on the page - Start */
/*
	if (RICOLAToolTip_HideDropdowns) {
		RICOLAToolTip_HDropDownFunc(true);
	}
*/
/*		Depricated Code - function that would hide all dropdowns on the page - End */

	RICOLAToolTip_showlayer("RICOLAToolTip_InfoLayer" + inNum);
}

function RICOLAToolTip_TTLayerHide(inNum) {
	RICOLAToolTip_hidelayer("RICOLAToolTip_InfoLayer" + inNum);
/*		Depricated Code - function that would hide all dropdowns on the page - Start */
/*
	if (RICOLAToolTip_HideDropdowns) {
		RICOLAToolTip_HDropDownFunc(false);
	}
*/
/*		Depricated Code - function that would hide all dropdowns on the page - End */
	document.getElementById("RICOLAToolTip_backgroundIframe" + inNum).style.display = "none";
}

function RICOLAToolTip(inDescription) {
	var classStr = " CLASS=\"tooltip\"";
	if (arguments.length < 1) {
		alert("RICOLA ToolTip Error #3713: \n\nYou did not pass in the tooltip text to ToolTip() function. \n\nPlease review the documentation at http://home.www.uprr.com/emp/it/hf/ricola/tooltip/ for more information.");
		return false;
	}
	// Done Error Checking
	var currID=RICOLAToolTip_IDNum++;
	var useText = false;

	/* Loop through all of the arguments to see if additional parameters are passed in */
	for (var i=1; i < arguments.length; i++) {
		if (arguments[i].search(/^\s*text\s*\:/i) != -1) {
			useText = true;
			var useText_Text = arguments[i].replace(/\s*$/, "").replace(/^\s*text\s*\:\s*(.*)$/i, "$1")
		} else if (arguments[i].toString().search(/^\s*No\s*Style\s*/i) != -1) {
			classStr = "";
		}
	}

	if (useText) {	// If the tooltip is a text tooltip (i.e. text with the dotted underline)
		var currText ="<SPAN ID=\"RICOLAToolTip_TTLayer" + currID + "\" onMouseOver=\"RICOLAToolTip_TTLayerShow('" + currID + "',event);\" onMouseOut=\"RICOLAToolTip_TTLayerHide('" + currID + "');\" " + classStr + ">" + useText_Text + "</SPAN>";
	} else {		// else if the tooltip is a question mark tooltip
		var currText="<IMG SRC=\"/graphics/apps/tooltip/desc.gif\" WIDTH=\"9\" HEIGHT=\"10\" BORDER=\"0\" onMouseOver=\"RICOLAToolTip_TTLayerShow('" + currID + "',event);\" onMouseOut=\"RICOLAToolTip_TTLayerHide('" + currID + "');\">";
	}
	document.write(currText);
	RICOLAToolTip_checkOnLoad();
	RICOLAToolTip_ToolTipStr += "<DIV ID=\"RICOLAToolTip_InfoLayer" + currID + "\" CLASS=\"RICOLAToolTipInfoLayerClass\">" + inDescription + "</DIV><iframe id=\"RICOLAToolTip_backgroundIframe" + currID + "\" name=\"RICOLAToolTip_backgroundIframe" + currID + "\" class=\"RICOLAToolTip_BackgroundIframe\" src=\"javascript:false;\" frameBorder=\"0\" scrolling=\"no\"></iframe>";
	

}


function RICOLAToolTip_AddDiv() { // Actually appends the tooltip div tags to the end of the document model object of the body tag.  This way all of the tooltip div tags will, for sure, not be inside of other div tags
	var parentAry = document.getElementsByTagName("Body");
	if (parentAry.length > 0) {		// Has a body tag;
		var parent = parentAry[0];
		var divAdd = document.createElement("div");
		divAdd.innerHTML = RICOLAToolTip_ToolTipStr;
		parent.appendChild(divAdd);

	}
}


function RICOLAToolTip_checkOnLoad() {	// Sets the onload function to append the RICOLAToolTip_AddDiv() function after the page is done loading
	if (RICOLAToolTip_Defined == 1) {
		RICOLAToolTip_Defined++;
		var RICOLAToolTip_oldOnload = window.onload;

		if (RICOLAToolTip_oldOnload) {
			window.onload = function () { RICOLAToolTip_oldOnload(); RICOLAToolTip_AddDiv(); }
		} else {
			window.onload = function () { RICOLAToolTip_AddDiv(); }
		}
	}
}