/******************************************************************************/
/*             MODULE   GesInfoBulle                                          */
/******************************************************************************/
/* DATE DE CREATION    : 20/11/01	                                          */
/*                                                                            */
/* AUTEUR              : Matthieu FERON                                       */
/*                                                                            */
/* DESCRIPTION         : Info Bulle apparaissant a cote du curseur            */
/*                                                                            */
/* INCLUDES            : necessite GesCalque.js                               */
/*                                                                            */
/* FONCTIONS : Info_Bulle( source ) cree l'info bulle et l'affiche            */
/*                source : source HTML                                        */
/*                utilisation : appel explicite sur onmouseover               */
/*                              onmouseout est gere implicitement             */
/*             Info_Bulle_Style ( ... ) modifie les styles de bulle           */
/*                utilisation : appel explicite avec ou sans arguments        */
/*                sans arguments : réinitialise les styles par défaut         */
/*                avec arguments : nom du style = "Bulle_Texte" ou            */
/*                                                "Bulle_Bordure"             */
/*                                 serie de couple propriete,valeur separe par*/
/*                                 des virgules                               */
/*                                 ex :                                       */
/*                                  "Bulle_Texte","color","black","fontSize",1*/
/*                                                                            */
/******************************************************************************/
/* MODIFIE LE   00/00/00  PAR  x                                              */
/* DESCRIPTION DE LA MODIFICATION : x                                         */
/*                                  x                                         */
/******************************************************************************/

var Info_Bulle_handle=null;     /*  handle du calque popup        */
var Info_Bulle_Verrou=false;    /* si une erreur de crea calque se produit ou si un calque est en cours, empecher les futures crea */
var Info_Bulle_Debug=false;     /* masque toutes les alertes definies dans le source */
var Info_Bulle_Init=false;      /* lors du premier appel a Info_Bulle on reinitialise les styles sauf si la fonction d'init a deja ete appelee */
var Info_Bulle_Creation=false;  /* indique si le verrou est posé par la création en cours */
var Info_Bulle_X=0;
var Info_Bulle_Y=0;
var Info_Bulle_Index=0;
var Info_Bulle_Objet=null;
/* source obligatoire de la bulle */
var Info_Bulle_Head="<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD CLASS=Bulle_Bordure>";
var Info_Bulle_Part1="<TABLE CELLPADDING=2 CELLSPACING=1 BORDER=0><TR><TD CLASS=Bulle_Texte>";
var Info_Bulle_Part2="</TD></TR></TABLE>";
var Info_Bulle_End="</TD></TR></TABLE>";

/* parametres par defaut */

var Info_Bulle_Texte_Def_backgroundColor = "#FFFFB3";
var Info_Bulle_Texte_Def_color = "#000000";
var Info_Bulle_Texte_Def_fontFamily = "Arial";
var Info_Bulle_Texte_Def_textAlign = "center"
var Info_Bulle_Bordure_Def_backgroundColor = "#000000";

var Info_Bulle_Texte_Def_IEfontSize = "11px";
var Info_Bulle_Texte_Def_NSfontSize = "12px";

var Info_Bulle_Def_IEcss="\
			TD.Bulle_Bordure {\
				BACKGROUND-COLOR : " + Info_Bulle_Bordure_Def_backgroundColor +
			"}\
			TD.Bulle_Texte {\
				BACKGROUND-COLOR : " + Info_Bulle_Texte_Def_backgroundColor + ";\
				FONT-FAMILY : " + Info_Bulle_Texte_Def_fontFamily + ";\
				FONT-SIZE : " + Info_Bulle_Texte_Def_IEfontSize + ";\
				COLOR : " + Info_Bulle_Texte_Def_color + ";\
				TEXT-ALIGN : " + Info_Bulle_Texte_Def_textAlign + ";\
			}";

function Info_Bulle_Style()
{
	var IB_Si;
	var IB_Sj;

	Info_Bulle_Init = true;
	if ( document.all )
	{
		IB_Sj=-1;
		for ( IB_Si=0 ; IB_Si<document.styleSheets.length ; IB_Si++ )
		{
			if ( document.styleSheets[IB_Si].title == "InfoBulleCSS" )
			{
				IB_Sj = IB_Si;
				break;
			}
		}
		if ( IB_Sj == -1 )
		{
			IEcss = document.createStyleSheet();
			IEcss.title = "InfoBulleCSS";
			IEcss.disabled=false;
			IEcss.cssText = Info_Bulle_Def_IEcss;
		}
		else
		{
			IEcss = document.styleSheets[IB_Sj];
		}
		if ( Info_Bulle_Style.arguments.length > 0 )
		{

			for ( IB_Si = 0 ; IB_Si<IEcss.rules.length ; IB_Si++ )
			{
				if ( IEcss.rules[IB_Si].selectorText == "TD." + Info_Bulle_Style.arguments[0] )
				{
					IErule = IEcss.rules[IB_Si];
				}
			}
			for ( IB_Si = 1 ; IB_Si<Info_Bulle_Style.arguments.length ; IB_Si+=2 )
			{
				eval( "IErule.style." + Info_Bulle_Style.arguments[IB_Si] + "='" + Info_Bulle_Style.arguments[IB_Si+1] + "';" );
			}
		}
		else
		{
			IEcss.cssText = Info_Bulle_Def_IEcss;
		}
	}
	else
	{
		document.classes.Bulle_Texte.TD.backgroundColor = Info_Bulle_Texte_Def_backgroundColor;
		document.classes.Bulle_Texte.TD.color = Info_Bulle_Texte_Def_color;
		document.classes.Bulle_Texte.TD.fontFamily = Info_Bulle_Texte_Def_fontFamily;
		document.classes.Bulle_Texte.TD.fontSize = Info_Bulle_Texte_Def_NSfontSize;
		document.classes.Bulle_Texte.TD.textAlign = Info_Bulle_Texte_Def_textAlign;
		document.classes.Bulle_Bordure.TD.backgroundColor = Info_Bulle_Bordure_Def_backgroundColor;
		if ( Info_Bulle_Style.arguments.length > 0 )
		{
			for ( IB_Si = 1 ; IB_Si<Info_Bulle_Style.arguments.length ; IB_Si+=2 )
			{
				eval( "document.classes." + Info_Bulle_Style.arguments[0] + ".TD." + Info_Bulle_Style.arguments[IB_Si] + "='" + Info_Bulle_Style.arguments[IB_Si+1] + "';" );
			}
		}
	}
}

function Info_Bulle_Destroy()
{
	Info_Bulle_handle.hide();
	Info_Bulle_Verrou = false;
}

function Info_Bulle_NSCoord( evnt )
{
	Info_Bulle_X = evnt.pageY+15;
	Info_Bulle_Y = evnt.pageX+5;
	Info_Bulle_Objet = evnt.target;
}

function Info_Bulle_Coords()
{
	Info_Bulle_X = window.document.body.scrollTop + window.event.clientY+10;
	Info_Bulle_Y = window.document.body.scrollLeft + window.event.clientX+10;
}

function Info_Bulle( source )
{
	var IB_source="";

	//explore( window.document.body );
	if ( Info_Bulle_Verrou == false )
	{
		if ( Info_Bulle_Init == false )
		{
			Info_Bulle_Style();
		}
		Info_Bulle_Verrou = true;
		Info_Bulle_Creation=true;
		if ( document.all )
		{
			Info_Bulle_Coords();
			Info_Bulle_Objet = window.event.fromElement;
		}
		Info_Bulle_handle = new MFE_calque( "popup"+Info_Bulle_Index , "hidden",  Info_Bulle_X, Info_Bulle_Y );
		if (( Info_Bulle_handle != null ) && ( Info_Bulle_Objet != null ))
		{
			Info_Bulle_Objet.onmouseout = Info_Bulle_Destroy;
			IB_source = Info_Bulle_Head;
			IB_source += Info_Bulle_Part1;
			IB_source += unescape(source).replace( / /gi, "&nbsp;");
			IB_source += Info_Bulle_Part2;
			IB_source += Info_Bulle_End;
			Info_Bulle_handle.setHTML( IB_source );
			if ( document.all )
			{
				if ( Info_Bulle_handle.bottom > (window.document.body.scrollTop+window.document.body.clientHeight-25) )
				{
					Info_Bulle_handle.setCoords( Info_Bulle_handle.top-Info_Bulle_handle.height , Info_Bulle_handle.left );
				}
				if ( Info_Bulle_handle.right > (window.document.body.scrollLeft+window.document.body.clientWidth-20) )
				{
					Info_Bulle_handle.setCoords( Info_Bulle_handle.top, Info_Bulle_handle.left-Info_Bulle_handle.width-30 );
				}
			}
			else
			{
				if ( Info_Bulle_handle.bottom > (window.pageYOffset+window.innerHeight-25) )
				{
					Info_Bulle_handle.setCoords( Info_Bulle_handle.top-Info_Bulle_handle.height , Info_Bulle_handle.left );
				}
				if ( Info_Bulle_handle.right > (window.pageXOffset+window.innerWidth-20) )
				{
					Info_Bulle_handle.setCoords( Info_Bulle_handle.top, Info_Bulle_handle.left-Info_Bulle_handle.width-30 );
				}
			}
			Info_Bulle_handle.show();
			Info_Bulle_Index++;
	   	}
		else
		{
   			Info_Bulle_Verrou = true;
			if ( Info_Bulle_Debug == true ) alert( "erreur en création de popup" );
		}
		Info_Bulle_Creation=false;
	}
	else
	{
		if ( Info_Bulle_Creation == false )
		{
			Info_Bulle_handle.hide();
 			Info_Bulle_Verrou = false;
		}
	}
}

if ( document.layers )
{
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=Info_Bulle_NSCoord;
}
