/******************************************************************************/
/*             MODULE   Gescalque                                             */
/******************************************************************************/
/* DATE DE CREATION    : 20/11/01	                                          */
/*                                                                            */
/* AUTEUR              : Matthieu FERON                                       */
/*                                                                            */
/* DESCRIPTION         : creation de calques dynamiques                       */
/*                                                                            */
/* INCLUDES            : aucun                                                */
/*                                                                            */
/* FONCTIONS : MFE_calque( nom, visibilite, top, left,                        */
/*                                       [width, height, bgcolor, source] )   */
/*                nom : identifiant du calque                                 */
/*                visi : "visible" ou "hidden"                                */
/*                top et left : position en pixel dans la zone client         */
/*                 les paramètres suivants sont facultatifs mais doivent être */
/*                 utilises dans l'ordre. (Ils peuvent être remplace par null)*/
/*                width,height : dimensions souhaitees                        */
/*                bgcolor : couleur du fond du calque                         */
/*                source : source HTML a inserer dans le calque               */
/*                                                                            */
/*              proprietes : lecture seule                                    */
/*                layer : objet calque specifique au navigateur (DIV ou LAYER)*/
/*                top,left,right,bottom : coordonnees                         */
/*                width,height : dimensions                                   */
/*				  source : contenu HTML du calque                             */
/*                id : identifiant                                            */
/*                visibility : visibilite                                     */
/*                                                                            */
/*              methodes :                                                    */
/*                bgcolor( code couleur ) : change la couleur de fond         */
/*                setHTML( source ) : charge le source HTML (par remplacement)*/
/*                show() : affiche le calque                                  */
/*                hide() : cache le calque                                    */
/*                setCoords( top, left ): repositionne le calque              */
/*                kill() : detruit le calque                                  */
/*                                                                            */
/******************************************************************************/
/* MODIFIE LE   00/00/00  PAR  x                                              */
/* DESCRIPTION DE LA MODIFICATION : x                                         */
/*                                  x                                         */
/******************************************************************************/

// Id, Visibility, Top, Left, Width, Height, bgcolor

function Is() {
  var agent = navigator.userAgent.toLowerCase();
  this.ie4 = (agent.indexOf("msie 4") != -1);
  this.ie5 = (agent.indexOf("msie 5") != -1);
  this.mac   = (agent.indexOf("mac")!=-1);
}

function MFE_calque()
{
  var i=0;
  var MFE_calque_zIndex=-1;
  var MFE_calque_Id        ;
  var MFE_calque_Visibility;
  var MFE_calque_Top       ;
  var MFE_calque_Left       ;
  var MFE_calque_Width     ;
  var MFE_calque_Height   ;
  var MFE_calque_BgColor   ;

  MFE_calque_zIndex = 200
  MFE_calque_Id         = "MFE_calque"+MFE_calque_zIndex;
  MFE_calque_Visibility = "visible";
  MFE_calque_Top        = 0;
  MFE_calque_Left       = 0;
  MFE_calque_Width      = null;
  MFE_calque_Height     = null;
  MFE_calque_BgColor    = null;

  for ( i=0 ; i<MFE_calque.arguments.length ; i++ )
  {
	if (( MFE_calque.arguments[i] != -1 ) &&
		( MFE_calque.arguments[i] != null ) &&
		( MFE_calque.arguments[i] != "null" ))
    {
		switch ( i )
		{
			case 0:
				MFE_calque_Id = MFE_calque.arguments[i];
				break;
			case 1:
				MFE_calque_Visibility = MFE_calque.arguments[i];
				break;
			case 2:
				MFE_calque_Top = MFE_calque.arguments[i];
				break;
			case 3:
				MFE_calque_Left = MFE_calque.arguments[i];
				break;
			case 4:
				MFE_calque_Width = MFE_calque.arguments[i];
				break;
			case 5:
				MFE_calque_Height = MFE_calque.arguments[i];
				break;
			case 6:
				MFE_calque_BgColor = MFE_calque.arguments[i];
				break;
		}
	}
  }
  this.nav = new Is();
  if ( document.all )
    {
	    this.layer = document.createElement("DIV");
		if ( !this.nav.ie4 )
		{
    		document.body.appendChild( this.layer );
            this.layer.id = MFE_calque_Id;
        	this.layer.style.position = "absolute";
		}
		this.layer.style.pixelTop = MFE_calque_Top;
    	this.layer.style.pixelLeft = MFE_calque_Left;
        this.layer.style.zIndex = MFE_calque_zIndex;
		if ( MFE_calque_Width )
			this.layer.style.pixelWidth = MFE_calque_Width;
		this.width = this.layer.style.pixelWidth;
		if ( MFE_calque_Height )
			this.layer.style.pixelHeight = MFE_calque_Height;
		this.height = this.layer.style.pixelHeight;
    	this.layer.style.visibility = MFE_calque_Visibility;
		if ( MFE_calque_BgColor )
			this.layer.style.backgroundColor = MFE_calque_BgColor;
	}
  else if ( document.layers )
    {
		this.layer = new Layer( 1 );
        this.layer.name = MFE_calque_Id;
    	this.layer.position = "absolute";
	    this.layer.top = MFE_calque_Top;
    	this.layer.left = MFE_calque_Left;
        this.layer.zIndex = MFE_calque_zIndex;
		if ( MFE_calque_Width != null )
			this.layer.width = MFE_calque_Width;
		this.width = this.layer.width;
		if ( MFE_calque_Height != null )
			this.layer.height = MFE_calque_Height;
		this.height = this.layer.height;
    	this.layer.visibility = MFE_calque_Visibility;
		if ( MFE_calque_BgColor )
			this.layer.bgColor = MFE_calque_BgColor;
	}
  this.top = MFE_calque_Top;
  this.left= MFE_calque_Left;
  this.right = this.left + this.width;
  this.bottom = this.top+this.height;
  this.layer.MFE_calque_Ptr = this;
  this.source = "";
  this.bgcolor = MFE_calque_SetBgColor;
  this.setHTML = MFE_calque_AddHTML;
  this.show = MFE_calque_Show;
  this.hide = MFE_calque_Hide;
  this.setCoords = MFE_calque_Set_Coords;
  this.kill = MFE_calque_delete;
  this.id = new String(MFE_calque_Id);
  this.visibility = MFE_calque_Visibility;

  return this;
}

function MFE_calque_Set_Coords( top, left )
{
  if ( document.all )
    {
      this.layer.style.pixelTop = top;
	  this.top = top;
	  this.bottom = this.top + this.height;
	  this.layer.style.pixelLeft = left;
	  this.left = left;
	  this.right = this.left + this.width;
	}
  else
    {
      this.layer.top = top;
	  this.top = top;
	  this.bottom = this.top + this.height;
	  this.layer.left = left;
	  this.left = left;
	  this.right = this.left + this.width;
    }
}

function MFE_calque_SetBgColor( sColor )
{
  if ( document.all )
    this.layer.style.backgroundColor = sColor;
  else
    this.layer.bgColor = sColor;
}

function MFE_calque_AddHTML( sSource )
{
  var iChild;

  if ( sSource != null )
    {
	  this.source = sSource;
	  if ( document.all )
	    {
          this.layer.innerHTML = this.source;
		  if ( this.nav.ie5 )
		    this.layer.style.pixelHeight = this.layer.clientHeight ;
		  else
		    this.layer.style.pixelHeight = this.layer.scrollHeight ;
		  this.height = this.layer.style.pixelHeight;
		  if ( this.nav.ie5 )
		    this.layer.style.pixelWidth = this.layer.clientWidth ;
		  else
		    this.layer.style.pixelWidth = this.layer.scrollWidth ;
		  this.width = this.layer.style.pixelWidth;
		  this.bottom = this.top+this.height;
		  this.right = this.left+this.width;
		}
	  if ( document.layers )
	    {
		  //alert( this.layer.document.height + "," + this.layer.document.width );

		  this.layer.document.open();
		  this.layer.document.write( this.source );
		  this.layer.document.close();

		  //alert( this.layer.document.height + "," + this.layer.document.width );
		  this.layer.height = this.layer.document.height ;
		  this.height = this.layer.height;
		  this.layer.width = this.layer.document.width ;
		  this.width = this.layer.width;
		  this.bottom = this.top+this.height;
		  this.right = this.left+this.width;
		}
	}
}

function MFE_calque_Show()
{
  if ( document.all )
    {
	  this.layer.style.visibility = "visible";
	}
  if ( document.layers )
    {
	  this.layer.visibility = "visible";
	}
  this.visibility = "visible";
}

function MFE_calque_Hide()
{
  if ( document.all )
    {
	  this.layer.style.visibility = "hidden";
	}
  if ( document.layers )
    {
	  this.layer.visibility = "hidden";
	}
  this.visibility = "hidden";
}

function MFE_calque_delete()
{
  this.hide();
  this.id="";
  delete this.layer;
  delete this.nav;
}
