//-------------------------------------------------------------
//  Nom Document : GFBULLE.JS
//  Auteur       : G.Ferraz
//  Objet        : Info Bulle...
//  Creation     : 01.12.2003
//--29.05.2006-------------------------------------------------
// Compatibilite IE6 et DOCTYPE
//--21.06.2006-------------------------------------------------
// Prise en compte des <SELECT>
//--15.09.2006-------------------------------------------------
// Amelioration et modif suite a commentaires
//--10.11.2006-------------------------------------------------
// Correction Bug sous FF si document <DIV style="float...">
//--15.10.2007-------------------------------------------------
// Prise en compte document dans IFRAME
//  -----------------------------------------------------------
var DOM = (document.getElementById ? true : false);
var IE  = (document.all && !DOM ? true : false);
var EXPLORER = ( navigator.appName == 'Microsoft Internet Explorer');
var OPERA    = ( window.opera ? true : false);
var Mouse_X;          // Position X en Cours de la Mouse
var Mouse_Y;          // Position Y en Cours de la Mouse
var Decal_X  = -10;   // Decalage X entre Pointeur Mouse et Bulle
var Decal_Y  = -10;   // Decalage Y entre Pointeur Mouse et Bulle
var bBULLE   = false; // Flag Affichage de la Bulle
//-- Flag pour presence Select sous IE
var bSELECT  = ( navigator.appName =='Microsoft Internet Explorer') && !OPERA;
//-- Pour Test mode Cadre
var ZObjet = new RECT();   // Zone pour MouseMove
var ZBulle = new RECT();
var bCADRE = false;        // Flag Affichage du Cadre
var bINIT  = false;
var Fenetre = new RECT();
//--15.10.2007------------------------------
var O_Frame = null;
//-- Fonction pour lecture dimension cadre
var Get_DimFenetre = Fct_DimFenetre;  // affectation fonction par defaut
//=========================
// Definition pour le Cadre
//=========================
function RECT(){
  this.Left   =0;
  this.Top    =0;
  this.Right  =0;
  this.Bottom =0;
  this.InitRECT = RECT_Set;
  this.PtInRECT = RECT_PtIn;
}
//-------------------------------------------
function RECT_Set( left_, top_, larg_, haut_){
  with( this){
    Left   = ( left_ ? left_ : -1);
    Top    = ( top_  ? top_  : -1);
    Right  = Left + ( larg_ ? (larg_ -1): 0);
    Bottom = Top  + ( haut_ ? (haut_ -1): 0);
  }
}
//-------------------------
function RECT_PtIn( x_, y_){
  with( this){
    return(( x_ > Left) && ( x_ < Right) && ( y_ > Top ) && ( y_ < Bottom));
    if( x_ < Left || x_ > Right)  return( false);
    if( y_ < Top  || y_ > Bottom) return( false);
    return( true);
  }
}
//---------------------
function GetObjet(div_){
  if( DOM) return document.getElementById(div_);
  if( IE)  return document.all[div_];
  return( null);
}
//-----------------------------
function ObjWrite( div_, html_){
  var Obj = GetObjet( div_);
  if( Obj)
    Obj.innerHTML = html_;
}
//--15.10.2007------------------------
// Recup position absolute de l'objet
//------------------------------------
function Obj_GetPosition(obj_){
  var PosX = 0;
  var PosY = 0;
  if( typeof(obj_)=='object')
    var Obj  = obj_;
  else
    var Obj  = document.getElementById( obj_);
  //-- Si l'objet existe
  if( Obj){
    //-- Recup. Position Objet
    PosX = Obj.offsetLeft;
    PosY = Obj.offsetTop;
    //-- Si propriete existe
    if( Obj.offsetParent){
      //-- Tant qu'un parent existe
      while( (Obj = Obj.offsetParent)){
        if( Obj.offsetParent){ // on ne prend pas le BODY
          //-- Ajout position Parent
          PosX += Obj.offsetLeft;
          PosY += Obj.offsetTop;
        }
      }
    }
  }
  //-- Retour des positions
  return({ left :PosX, top :PosY});
}
//--15.10.2007---------------------------------------
// Test si document contenu dans une FRAME ou IFRAME
//---------------------------------------------------
function Doc_In_Frame(){
  if( parent.document){
    if( parent.document.location != document.location)
      return( true);
    else
      return( false);
  }
}
//--15.10.2007---------------
// Recup position des scroll
//---------------------------
function Doc_GetScroll( doc_){
  if( !doc_) doc_= document;
  var De = doc_.documentElement;
  var Db = doc_.body;
  //-- Recup Scroll Top
  var Top = Db.scrollTop;
  if( De.scrollTop > Top)
    Top = De.scrollTop;
  //-- Recup Scroll Left
  var Left = Db.scrollLeft;
  if( De.scrollLeft > Left)
    Left = De.scrollLeft;
	return({ left: Left, top: Top});
}
//--15.10.2007-------------------------------
// Recup des dimension clientHeight et Width
//-------------------------------------------
function Doc_GetClientDimension( doc_){
  if( !doc_) doc_= document;
  var De = doc_.documentElement;
  var Db = doc_.body;
  var Larg = Db.clientWidth;
  var Haut = Db.clientHeight;
  if( De && De.clientWidth)
    Larg = De.clientWidth;
  if( De && De.clientHeight)
    Haut = De.clientHeight;
	return({ width: Larg, height: Haut});
}
//-- 15.10.2007 ---------------------------------
// Recup dimension des fenetres pour les iframes
//-----------------------------------------------
function Fct_DimFenetreIframe (){
  var Dim_1 = new Object;
  var Scroll_1 = new Object;
  //-- Document actif
  var Dim_0 = Doc_GetClientDimension(document);
  var Scroll_0 = Doc_GetScroll( document);
  //-- Position de l'iframe
  var Pos_Iframe = Obj_GetPosition( O_Frame);
  //-- Taille de l'iframe
  Dim_1.width   = O_Frame.offsetWidth;
  Dim_1.height  = O_Frame.offsetHeight;
  //-- Garde le plus petit
  Dim_0.width  = Dim_1.width  > Dim_0.width  ? Dim_0.width  : Dim_1.width;
  Dim_0.height = Dim_1.height > Dim_0.height ? Dim_0.height : Dim_1.height;
  //-- Affectation dans Fenetre
  with( Fenetre){
    Left   = Scroll_0.left;
    Top    = Scroll_0.top;
    Right  = Dim_0.width  +Left;
    Bottom = Dim_0.height +Top;
  }
  //-- Info document parent
  var Dim_1 = Doc_GetClientDimension( parent.document);
  var Scroll_1 = Doc_GetScroll( parent.document);
  //-- Calcul partie masquee
  var DeltaX = (Dim_1.width  +Scroll_1.left) -(O_Frame.offsetWidth  +Pos_Iframe.left);
  var DeltaY = (Dim_1.height +Scroll_1.top)  -(O_Frame.offsetHeight +Pos_Iframe.top);
  //-- Reajuste la fenetre
  if( DeltaX < 0)
    Fenetre.Right  += DeltaX;
  if( DeltaY < 0)
      Fenetre.Bottom  += DeltaY;
}
//-- 10.11.2006 ----------------------------
// correction bug sur <DIV style="float...">
//------------------------------------------
function Fct_DimFenetre(){
  var L_Doc;
  var H_Doc;
  var DocRef;
  with( Fenetre){
    if( window.innerWidth){
      with( window){
        Left   = pageXOffset;
        Top    = pageYOffset;
        Right  = innerWidth;
        Bottom = innerHeight;
        //-- Modif du 10.11.2006
        L_Doc = document.body.clientWidth;
        H_Doc = document.body.clientHeight;
        //-- fin modif.
        if( Right  > L_Doc) Right  = L_Doc;
        if( Bottom > H_Doc) Bottom = H_Doc;
      }
    }
    else{ // Cas Explorer a part
      if( document.documentElement && document.documentElement.clientWidth)
        DocRef = document.documentElement;
      else
        DocRef = document.body;

      with( DocRef){
        Left   = scrollLeft;
        Top    = scrollTop;
        Right  = clientWidth;
        Bottom = clientHeight;
      }
    }
    //-- limite Maxi Fenetre Affichage
    Right  += Left;
    Bottom += Top;
  }
}
//--15.10.2007------------------------
function ObjShowAll( div_, x_, y_, z_){
  var B_Obj = GetObjet( div_);
  var F_Obj = GetObjet( 'F' +div_);
  var MaxX, MaxY;
  var Haut, Larg;
  var SavY = y_;

  if( B_Obj){
    //-- Recup. dimension du DIV
    Larg = B_Obj.offsetWidth;
    Haut = B_Obj.offsetHeight;
    with( Fenetre){
      //-- Reajuste dimension fenetre
      MaxX = Right  - Larg;
      MaxY = Bottom - Haut;
      //-- Application Bornage
      if( x_ > MaxX) x_ = MaxX;
      if( x_ < Left) x_ = Left;
      if( y_ > MaxY) y_ = MaxY;
      if( y_ < Top)  y_ = Top;
    }
    //-- si en bas On reajuste
    //-- pour que la bulle ne prenne pas le focus
    if( y_== MaxY){
      var DeltaY = MaxY -SavY;
      y_ = MaxY - DeltaY -Haut -2*Decal_Y;
    }
    //-- On place la Bulle
    if( bSELECT){//-- Ajout pour SELECT sous IE
      with(F_Obj.style){
        left       = x_ +"px";
        top        = y_ +"px";
        zIndex     = z_-1;
        visibility = "visible";
      }
    }
    with(B_Obj.style){
      left       = x_ +"px";
      top        = y_ +"px";
      zIndex     = z_;
      visibility = "visible";
    }
    //-- Affectation Zone du Rectangle
    ZBulle.InitRECT( x_, y_, Larg, Haut);
  }
}
//-- 15.09.2006 -------------------------------
// Ajout Fonction Add_Event
//---------------------------------------------
function Add_Event( obj_, event_, func_, mode_){
  if( obj_.addEventListener)
    obj_.addEventListener( event_, func_, mode_? mode_:false);
  else
    obj_.attachEvent( 'on'+event_, func_);
}
//-- 15.09.2006 ------------------------
// Utilisation de Add_Event
//--------------------------------------
function Init_Bulle(){
  //-- Pour les SELECT on supprime l'evenement herite
  var Obj = document.body.getElementsByTagName('SELECT');
  if( Obj && Obj.length){
    for(var i=0; i < Obj.length; i++){
      if( Obj[i].size == 1){
        for(var k=0; k < Obj[i].options.length; k++){
          Add_Event( Obj[i].options[k], 'mousemove', BulleHide);
        }
      }
      Add_Event( Obj[i], 'mousedown', BulleHide);
      Add_Event( Obj[i], 'scroll', BulleHide);
    }
  }
  else 
    bSELECT = false; // Pas de SELECT dans le document
  bINIT =true;

  //--15.10.2007---------------
  if( Doc_In_Frame()){
    var T_Frame = parent.document.getElementsByTagName('IFRAME');
    var szUrl   = document.location.href;  // recup URL
    //-- Recherche du parent
    szUrl = szUrl.toLowerCase();           // mise en minuscule URL
    for( var i=0; i < T_Frame.length; i++){
      if( T_Frame[i].src.toLowerCase().indexOf( szUrl > -1)) // c'est la maman
        O_Frame = T_Frame[i];
    }
    Get_DimFenetre = Fct_DimFenetreIframe; // Affectation fonction
  }
}
////////////////////////////
// mode Cadre Independant //
////////////////////////////
//------------------------
function CadreWrite( txt_){
  var Html;
  var B_Obj = GetObjet( 'Bulle');
  var F_Obj = GetObjet( 'FBulle');
  if( !bINIT) Init_Bulle();
  if( B_Obj){
    //-- Recup dimension d'affichage
    Get_DimFenetre();
    Decal_X = -10;  // Decalage dans de la Bulle
    Decal_Y = -10;
    Html  = "<TABLE BORDER='1' BORDERCOLOR='#808080' CELLSPACING=0 CELLPADDING=2 BGCOLOR='#C0C0C0'>";
    Html += "<TR><TD class='Bulle' NOWRAP>";
    Html += txt_;
    Html += "<\/TD><\/TR><\/TABLE>";
    B_Obj.innerHTML = Html;

    if( bSELECT){ //-- Ajout pour SELECT sous IE
      with(F_Obj.style){
        height = B_Obj.offsetHeight;
        width  = B_Obj.offsetWidth;
        left   = B_Obj.offsetLeft;
        top    = B_Obj.offsetTop;
      }
    }
    //-- On affiche le resultat
    ObjShowAll('Bulle', Mouse_X +Decal_X, Mouse_Y +Decal_Y, 1000);
    bCADRE= true;
    return( true);
  }
  return(false);
}
////////////////////////////
// mode Bulle Independant //
////////////////////////////
//-- 15.09.2006 ------------------------
// Ajout parametre x_ et y_
//--------------------------------------
function BulleWrite( txt_,txt2_, x_, y_){
  var B_Obj = GetObjet( 'Bulle');
  var F_Obj = GetObjet( 'FBulle');
  var Html;
  if( !bINIT) Init_Bulle();
  if( B_Obj){
    //-- Recup dimension d'affichage
    Get_DimFenetre();
    // Decalage hors de la Bulle
    Decal_X =( x_ ? x_: 5);//    Decal_X = 5 par defaut
    Decal_Y =( y_ ? y_: 5);//    Decal_Y = 5 par defaut
    //-- Ecriture de la Bulle 
	Html  = "<div class=\"Bulle\">";
	Html += "<table cellpadding=1 cellspacing=0 border=0 width=200><tr><td bgcolor=Gray><table border=0 width=100% cellpadding=8 cellspacing=0><tr><td bgcolor=#EEEEFF><font face=verdana size=1 color=blue><b>" + txt_ + "</b></font></td></tr><tr><td bgcolor=white><font face=verdana size=1 color=black>" + txt2_ + "<\/font><\/td><\/tr><\/table><\/td><\/tr><\/table>";
    //Html += txt_;
    Html += "<\/div>";
	
    B_Obj.innerHTML = Html;
    //-- Ajout pour SELECT sous IE
    if( bSELECT){
      with(F_Obj.style){
        height = B_Obj.offsetHeight;
        width  = B_Obj.offsetWidth;
        left   = B_Obj.offsetLeft;
        top    = B_Obj.offsetTop;
      }
    }
    //-----------------------------------------//
    // IMPORTANT on n'affiche pas la Bulle     //
    // l'evenement MouseOver va avec MouseMove //
    //-----------------------------------------//
    // ObjShowAll('Bulle', Mouse_X +Decal_X, Mouse_Y +Decal_Y, 1000);
    bBULLE= true;
    return( true);
  }
 return(false);
}
//------------------
function BulleHide(){
  var B_Obj = GetObjet( 'Bulle');
  var F_Obj = GetObjet( 'FBulle');
  if( bSELECT){ //-- Ajout pour SELECT sous IE
    F_Obj.style.height = 0 +"px";
  }
  with(B_Obj){
    innerHTML        = "&nbsp;"
    style.left       = -1000 +"px";
    style.top        = -1000 +"px";
    style.zIndex     = 0;
    style.visibility = "hidden";
  }
  //-- Pose les Flags
  bCADRE = false;
  bBULLE = false;
  return(true);
}
//--------------------
function WhereMouse(e){
  var DocRef;
  var Obj  = null;
  var bRECT= true;
  //-- On traque les hybrides
  if( e && e.target){
    Mouse_X = e.pageX;
    Mouse_Y = e.pageY;
    Obj     = e.target;
    //-- Specifique FireFox
    if( Obj.boxObject){
      with( Obj){
        //-- La Zone de prise en compte
        ZObjet.InitRECT( boxObject.x, boxObject.y, boxObject.width, boxObject.height);
      }
      //-- Barre de defilement et autre sous FireFox
      Obj = e.originalTarget;
      if( Obj)
        if( Obj.prefix =="xul"){
          BulleHide();
          return( true);
        }
      //-- Test pour SELECT sous FireFox
      bRECT = ZObjet.PtInRECT( Mouse_X, Mouse_Y);
    }
  }//-- Endif
  else{
    if( document.documentElement && document.documentElement.clientWidth)
      DocRef = document.documentElement;
    else
      DocRef = document.body;

    Mouse_X = event.clientX +DocRef.scrollLeft;
    Mouse_Y = event.clientY +DocRef.scrollTop;
  }

  if( bBULLE)
    if( bRECT)
      ObjShowAll('Bulle', Mouse_X +Decal_X, Mouse_Y +Decal_Y, 1000);

  if( bCADRE)// on ne move pas on test juste si dans Rect
    if( !ZBulle.PtInRECT( Mouse_X, Mouse_Y))
      BulleHide();

  return( true);
}
//== INITIALISATION ==================================
//-- 15.09.2006 ------------------------
// Ajout Fonction Add_Event
// Permet de faire autre chose...
//--------------------------------------
Add_Event(  document, 'mousemove', WhereMouse);

//-- Creation STYLE Bulle et DIV----------------------
var Html;
  //-- On met du style pour la bulle
  Html  = '<style type="text/css">';
  Html += '.Bulle{cursor:default;color:#000000;font-size:10px;font-family:Verdana;z-index:1000;}';
  Html += '<\/style>';
  document.write( Html);
  //-- Creation du DIV Bulle
  Html ='<div id="Bulle" style="position:absolute; left:auto; top:auto; width:auto; height:auto; z-index:1000; visibility:hidden"><\/div>';
  if( bSELECT) //-- Ajout pour SELECT sous IE
    Html +='<iframe id="FBulle" style="position:absolute;visibility:hidden;border:0px;" frameborder="0" scrolling="no">&nbsp;<\/iframe>';
  document.write( Html);
//-- EOF ------------------------------------------------------


