var sWidthToolTipDefault = 350;
/*----------------------------------------------------------------------------\
|                               Help Tip 1.12                                 |
|-----------------------------------------------------------------------------|
| GPL - The GNU General Public License    http://www.gnu.org/licenses/gpl.txt |
| Permits anyone the right to use and modify the software without limitations |
| as long as proper  credits are given  and the original  and modified source |
| code are included. Requires  that the final product, software derivate from |
| the original  source or any  software  utilizing a GPL  component, such  as |
| this, is also licensed under the GPL license.                               |
|-----------------------------------------------------------------------------|
| 2002-09-27 |                                                                |
| 2001-11-25 | Added a resize to the tooltip if the document width is too     |
|            | small.                                                         |
| 2002-05-19 | IE50 did not recognise the JS keyword undefined so the test    |
|            | for scroll support was updated to be IE50 friendly.            |
| 2002-07-06 | Added flag to hide selects for IE                              |
| 2002-10-04 | (1.1) Restructured and made code more IE garbage collector     |
|            | friendly. This solved the most nasty memory leaks. Also added  |
|            | support for hiding the tooltip if ESC is pressed.              |
| 2002-10-18 | Fixed verrical position in case of scrolled document.          |
| 2002-12-02 | Mozilla bug workaround related to mousedown and move.          |
|-----------------------------------------------------------------------------|
| Dependencies: helptip.css (To set up the CSS of the helptooltip class)     |
|-----------------------------------------------------------------------------|
| Usage:                                                                      |
|                                                                             |
|   <script type="text/javascript" src="helptip.js">< /script>                |
|   <link type="text/css" rel="StyleSheet" href="helptip.css" />              |
|                                                                             |
|   <a class="helpLink" href="?" onclick="showHelp(event, 'String to show');  |
|      return false">Help</a>                                                 |
|-----------------------------------------------------------------------------|
| Created 2001-09-27 | All changes are in the log above. | Updated 2002-12-02 |
\----------------------------------------------------------------------------*/

function HideShowElement( elmID, overDiv, h )
{
	if ( document.all )
	{
		for( i = 0; i < document.getElementsByTagName( elmID ).length; i++ )
		{
		  obj = document.getElementsByTagName( elmID )[i];
		  if( !obj || !obj.offsetParent )
		  {
			continue;
		  }
		  objLeft   = obj.offsetLeft;
		  objTop    = obj.offsetTop;
		  objParent = obj.offsetParent;
		  while( objParent.tagName.toUpperCase() != 'BODY' )
		  {
			objLeft  += objParent.offsetLeft;
			objTop   += objParent.offsetTop;
			objParent = objParent.offsetParent;
		  }
		  objHeight = obj.offsetHeight;
		  objWidth = obj.offsetWidth;


		  if(( overDiv.offsetLeft-12 + overDiv.offsetWidth ) <= objLeft );
		  else if(( overDiv.offsetTop-0 + overDiv.offsetHeight ) <= objTop );//-15
		  else if( overDiv.offsetTop-15 >= ( objTop + objHeight ));
		  else if( overDiv.offsetLeft-12 >= ( objLeft + objWidth ));
		  else
		  {
			obj.style.visibility = h;
		  }
		}
	}
}
var sWidthToolTip = 250;
function showHelpTip(e, sHtml, bHideSelects, sWidth)
{
	if (arguments.length == 4)
		sWidthToolTip = sWidth;
	else sWidthToolTip = sWidthToolTipDefault;
	var el = e.target || e.srcElement;
	var typeElement = e.tagName
	while (el.tagName != typeElement)
		el = el.parentNode;
	if (el._helpTip) {
		helpTipHandler.hideHelpTip(el);
return;
	}
	
	
	helpTipHandler.hideSelects = Boolean(bHideSelects);
	// create element and insert last into the body
	helpTipHandler.createHelpTip(el, sHtml);
	// position tooltip
	helpTipHandler.positionToolTip(e);
	// add a listener to the blur event.
	// When blurred remove tooltip and restore anchor
	el.onblur = helpTipHandler.anchorBlur;
	el.onkeydown = helpTipHandler.anchorKeyDown;
}

var helpTipHandler = {
	hideSelects:	false,
	
	helpTip:		null,
	
	showSelects:	function (bVisible) {
		var selects = [];

var elmID = "SELECT";
var overDiv = this.helpTip;//"testHelpTip";
var h = bVisible;


	},
	
	create:	function () {
		var d = document.createElement("DIV");
		d.id = "boxHelpTip"
		d.className = "helptooltip";
		d.onmousedown = this.helpTipMouseDown;
		d.onmouseup = this.helpTipMouseUp;
		
		document.body.appendChild(d);		
		this.helpTip = d;
	},
	
	createHelpTip:	function (el, sHtml) {
		if (this.helpTip == null) {
			this.create();
		}

		var d = this.helpTip;
		d.innerHTML=sHtml;
		d._boundAnchor = el;
		el._helpTip = d;
		return d;
	},
	
	helpTipMouseDown:	function (e) {
		var d = this;
		var el = d._boundAnchor;
		if (!e) e = event;
		var t = e.target || e.srcElement;
		while (t.tagName != "A" && t != d)
			t = t.parentNode;
		if (t == d) return;
		
		el._onblur = el.onblur;
		el.onblur = null;
	},
	
	helpTipMouseUp:	function () {
		var d = this;
		var el = d._boundAnchor;
		el.onblur = el._onblur;
		el._onblur = null;
		el.focus();
	},	
	
	anchorBlur:	function (e) {
		var el = this;
		helpTipHandler.hideHelpTip(el);
	},
	
	anchorKeyDown:	function (e) {
		if (!e) e = window.event
		if (e.keyCode == 27) {	// ESC
			helpTipHandler.hideHelpTip(this);
		}
	},
	
	removeHelpTip:	function (d) {
		d._boundAnchor = null;
		d.style.filter = "none";
		d.innerHTML = "";
		d.onmousedown = null;
		d.onmouseup = null;
		d.parentNode.removeChild(d);
	},
	
	hideHelpTip:	function (el) {
		var d = el._helpTip;
		
		d.style.visibility = "hidden";

		el.onblur = null;
		el._onblur = null;
		el._helpTip = null;
		el.onkeydown = null;
		
		this.showSelects(true);
	},
	
	positionToolTip:	function (e) {
		this.showSelects(false);		
		var scroll = this.getScroll();
		var d = this.helpTip;
		if ( sWidthToolTip < 0 )
			d.style.width = ""
		else
			d.style.width = sWidthToolTip;
		ss =scroll.width - d.offsetWidth
		
		if (e.clientX > scroll.width - d.offsetWidth)
			d.style.left = scroll.width - d.offsetWidth + scroll.left-20 + "px";//less 20 for mozilla and netscape
		else
			d.style.left = e.clientX - 2 + scroll.left - d.offsetWidth + "px";// " - d.offsetWidth" 07/01/05
			
		if (parseInt(d.style.left) < 0 ) d.style.left = 5 + "px";
		if (e.clientY + d.offsetHeight + 18 < scroll.height)
			d.style.top = e.clientY + 18 + scroll.top + "px";
		else if (e.clientY - d.offsetHeight > 0)
			d.style.top = e.clientY + scroll.top - d.offsetHeight + "px";
		else
			d.style.top = scroll.top + 5 + "px";
			
		d.style.visibility = "visible";
	},
	getScroll:	function () {
		if (document.all && typeof document.body.scrollTop != "undefined") {	// IE model
			var ieBox = document.compatMode != "CSS1Compat";
			var cont = ieBox ? document.body : document.documentElement;
			return {
				left:	cont.scrollLeft,
				top:	cont.scrollTop,
				width:	cont.clientWidth,
				height:	cont.clientHeight
			};
		}
		else {
			return {
				left:	window.pageXOffset,
				top:	window.pageYOffset,
				width:	window.innerWidth,
				height:	window.innerHeight
			};
		}
		
	}

};