
/*************************************************************************

Name:	help.js
Desc:	adds help rollovers for form items

*************************************************************************/

function HelpJS() {
}

//set target help div
HelpJS.prototype.target = function(target) {
	var parent = this;
	this.ent_help = target;
	
	EventListener.add(	target, 
						'mouseover', 
						function() {
							parent.showMessage();
						}
					);
	
	EventListener.add(	target, 
						'mouseout', 
						function() {
							parent.hideHelp();
						}
					);
}

//add an item to use help with
HelpJS.prototype.add = function(target) {
	var parent = this;
	
	target.old_focus =		target.focus;
	target.old_mouseover =	target.mouseover;
	target.old_mouseout =	target.mouseout;
	target.old_blur =		target.blur;
	target.title2 =			target.title;
	target.title =			'';
	
	EventListener.add(	target, 
						'mouseover', 
						function() {
							parent.showMessage(this);
							if (this.old_mouseover != null) {this.old_mouseover();}
						}
					);
					
	EventListener.add(	target, 
						'mouseout', 
						function() {
							parent.hideHelp(this);
							if (this.old_mouseout != null) {this.old_mouseout();}
						}
					);
}



//clear hide/show interval
HelpJS.prototype.clearHelp = function(target) {
	clearInterval(this.interval);
}

//hides the help box after a delay
HelpJS.prototype.hideHelp = function(target) {
	var parent = this;
	this.clearHelp();
	this.interval = setInterval(function() {parent.hideApply()}, 500);
}

//does the actual hiding
HelpJS.prototype.hideApply = function() {
	this.clearHelp();
	this.ent_help.style.visibility = 'hidden';
}

//show the help dialog with the correct content (instant)
HelpJS.prototype.showMessage = function(target) {

	var top;
	if (target != null) {
		this.current = target;
	} else {
		target = this.current;
	}
	
	switch (target.type) {
		case 'checkbox':
			top = target.offsetTop + target.offsetParent.offsetTop
			break;
		default:
			top = target.offsetTop;
			break;
	}
	this.clearHelp();
	
	if (target.title2 != '') {
		this.ent_help.innerHTML = target.title2;
		this.ent_help.style.visibility = 'visible';
		this.ent_help.style.top = top + 'px';
	} else {
		this.hideHelp();
	}
}

