/* ------------------------------------------------------------------------
	@application: Atelier logiciel
	@titre      : Affichage d'un tooltip sous un champ de formulaire
	@auteur     : JTA
	@seealso	: util.html
	@(#)@date	: 12/03/05
 	@(#) $Id$
 	@dependances : commun/util.js
 ------------------------------------------------------------------<note>
Affichage d'un tooltip sous un champ de formulaire.
<tex>
<i>1/ Création du composant</i>
var tt = new toolTip();
tt.timeOut = 1000; // 1 seconde de timeout
<i>2/ utilisation dans un onFocus d'un champ text</i>
onFocus="tt.on(this,'le texte du tooltip');"
</tex>
</note>----------------------------------------------------------------- */

if (!_objects) {var _objects = [];};

/**%
*	Ce composant permet d'afficher un tooltip juste au dessous d'un objet de formulaire
*/
function toolTip(){

	this._id = _objects.length;
	_objects[this._id] = this;

	/**
	*	Timeout (millisecondes) pour l'affichage du tooltip. Si non renseigné : tooltip permanent
	*/
	this.timeOut;
	this._timeoutID;
	this._div = document.getElementById("ttip");

	/**
	*	Affichage du tooltip 'message' sous l'objet obj
	*	@param obj l'objet (de formulaire) à commenter (champ text...)
	*	@param message le message à afficher
	*/
	this.on = function(obj,message,leftpos,postop){
		if(typeof(obj)!="object") return;

		if(this._timeoutID) clearTimeout(this._timeoutID);
		if(this._div == null) {
			var newDiv = document.createElement('div');
			document.getElementsByTagName('body').item(0).appendChild(newDiv);
			newDiv.id = "ttip"
			ref = newDiv.style;
			ref.position = 'absolute';
			ref.display = 'none';
			ref.border= "1px solid black";
			ref.backgroundColor = "#FFFFE7";
			//ref.padding = "2px 2px 2px 2px";
			ref.padding = "4px";
			ref.cursor = "default";
			ref.fontFamily = "arial,helvetica";
			ref.fontSize = "11px"; 
			this._div = document.getElementById("ttip");
		}
		this._div.innerHTML     = message;
		var p             		= getAbsolutePos(obj,true);
		this._div.style.left    = p.x + leftpos; // décalage à droite du tooltip
		this._div.style.top     = parseInt(p.y) + parseInt(obj.offsetHeight) + 1 + postop;
		this._div.style.width   = 100;
		this._div.style.display = 'block';
		if(!isNaN(this.timeOut)) {
			this._timeoutID = setTimeout("_objects["+this._id+"].off()", this.timeOut);
		}
	}

	/**
	*	Efface un éventuel commentaire
	*/
	this.off = function(){
		if(this._div == null) return;
		this._div.style.display = 'none';
	}
} //toolTip

