//--------------------------- popup -----------------------------
//------------------------detection du navigateur---------------
var w3c = false;
var ie5 = false;
var ns6 = false;

if (navigator.userAgent.indexOf("Firefox") != -1){
		w3c = true;
}else if (navigator.userAgent.indexOf("MSIE") != -1){		
		ie5 = true;
		w3c = true;
}else if (navigator.userAgent.indexOf("Netscape") != -1){	
		ns6 = true;
}else{
		w3c = true;
}

currIDb=null; xoff=0; yoff=0;
currRS=null; rsxoff=0; rsyoff=0;
oldac=null; newac=null; zdx=1; mx=0; my=0;

//-------------------------- init des couleurs -------------------
//var bgcolor='#E6C76A'; //couleur arrière-plan popup
var bgcolor='#FFFFFF'; //couleur arrière-plan popup
var textcolor='#234646'; //couleur du texte interieur
var fontstyleset='bold 10pt verdana'; //font
var titlecolor='#777777'; //arriere-plan titre
var titletextcolor='white'; //texte titre
var bordercolor='#D6D3CE'; // couleur bordure large
var scrollcolor='#D6D3CE'; // couleur arriere-plan titre desactive
var shadowcolor='#234646'; // couleur ombre
// le style pour les bulles se trouvr dans le css .bulle
// ------------------------fin init couleurs----------------------

var idlist=new Array();
idlist.btns=new Array();
idlist.btns[0]=new Image(); idlist.btns[0].src="min.gif";
idlist.btns[1]=new Image(); idlist.btns[1].src="max.gif";
idlist.btns[2]=new Image(); idlist.btns[2].src="close.gif";
idlist.btns[3]=new Image(); idlist.btns[3].src="resize.gif";

function hidebox(id){
if(w3c){
document.getElementById(id+'_b').style.display='none';
document.getElementById(id+'_s').style.display='none';
}}

function ns6bugfix(){
self.resizeBy(0,1);
self.resizeBy(0,-1);
}

function trackmouse(evt){
if (document.all) {
posX=event.clientX+document.body.scrollLeft;
posY=event.clientY+document.body.scrollTop;
} else {
posX=evt.pageX;
posY=evt.pageY;
}
movepopup();
if (bouge) moveBulle();
if((currIDb!=null)||(currRS!=null))return false;
}

function movepopup(){
if((currIDb!=null)&&w3c){
var x=posX+xoff;
var y=posY+yoff;
currIDb.style.left=x+'px';
currIDs.style.left=x+8+'px';
currIDb.style.top=y+'px';
currIDs.style.top=y+8+'px';
}
if((currRS!=null)&&w3c){
var rx=posX+rsxoff;
var ry=posY+rsyoff;
var c=currRS;
c.style.left=Math.max(rx,((ie5)?88:92))+'px';
c.style.top=Math.max(ry,((ie5)?68:72))+'px';
c.IDS[0].style.width=Math.max(rx+((ie5)?13:8),100)+'px';
c.IDS[0].style.height=Math.max(ry+((ie5)?12:8),80)+'px';// hauteur box
c.IDS[1].style.width=Math.max(rx+((ie5)?4:3),((ns6)?95:92))+'px'; // largeur titre
c.IDS[5].style.left=parseInt(c.IDS[1].style.width)-18+'px'; // position close
c.IDS[3].style.width=Math.max(rx+12,((ie5)?100:104))+'px';
c.IDS[3].style.height=Math.max(ry+((ie5)?12:13),((ie5)?80:86))+'px'; // haut ombre
c.IDS[2].style.width=Math.max(rx-((ie5)?-5:5),((ie5)?92:87))+'px';
c.IDS[2].style.height=Math.max(ry-((ie5)?18:28),50)+'px'; //haut interieur, int mini
c.IDS[10]=parseInt(c.IDS[0].style.height);
}}

function startRS(evt){
var ex=(ie5)?event.clientX+document.body.scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+document.body.scrollTop:evt.pageY;
rsxoff=parseInt(this.style.left)-ex;
rsyoff=parseInt(this.style.top)-ey;
currRS=this;
if(ns6)this.IDS[2].style.overflow='hidden';
return false;
}

function stopdrag(){
currIDb=null;
if(ns6){ns6bugfix()};
}

function grab_id(evt){
var ex=(ie5)?event.clientX+document.body.scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+document.body.scrollTop:evt.pageY;
xoff=parseInt(this.IDS[0].style.left)-ex;
yoff=parseInt(this.IDS[0].style.top)-ey;
currIDb=this.IDS[0];
currIDs=this.IDS[3];
return false;
}

function subBox(x,y,w,h,bgc,id){
var v=document.createElement('div');
v.setAttribute('id',id); 
v.style.position='absolute';
v.style.left=x+'px';
v.style.top=y+'px';
v.style.width=w+'px';
v.style.height=h+'px';
v.style.backgroundColor=bgc;
v.style.visibility='visible';
v.style.padding='0px 0px 0px 0px';
return v;
}


// isdrag=deplacement, isresize=redimentionner, oldOK=popup normale sur vieux nav
function popUp(w,h,cid,text,title,isdrag,isresize,oldOK){

// centrer la popUp
if (document.getElementById) { // NS
    var depuishaut=window.pageYOffset;
    var x=(window.innerWidth-w)/2;
    var y=depuishaut+(window.innerHeight-h)/2;
}
if (document.all) {
    var depuishaut=document.body.scrollTop;
    var x=(document.body.offsetWidth-w)/2;
    var y=depuishaut+(document.body.offsetHeight-h)/2;
}

if (eval(document.getElementById(cid+'_b'))){
  var bx=eval(document.getElementById(cid+'_b').style);
  var sh=eval(document.getElementById(cid+'_s').style);
	
  bx.display='block';
  sh.display='block';
  if(oldac!=null)oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
  document.getElementById(cid+'_t').style.backgroundColor=titlecolor;
  sh.zIndex=++zdx;
  bx.zIndex=++zdx;
   
  return;
}

  if(w3c){
    var tw, th;
    w=Math.max(w,100);
    h=Math.max(h,80);
    var rdiv=new subBox(w-((ie5)?12:8),h-((ie5)?12:8),7,7,'',cid+'_rs');
      if(isresize){
        rdiv.style.cursor='nw-resize';
      }
    tw=(ie5)?w:w+4;
    th=(ie5)?h:h+4;
    var shadow=new subBox(x+8,y+8,tw,th,shadowcolor,cid+'_s');
      if(ie5){
      shadow.style.filter="alpha(opacity=30)"; // transparence de l'ombre
      } else {
      shadow.style.MozOpacity=.3;
      }
    shadow.style.zIndex=++zdx;
    var tw,th;
    var outerdiv=new subBox(x,y,w,h,bordercolor,cid+'_b');
    outerdiv.style.borderStyle="outset";
    outerdiv.style.borderWidth="2px";
    outerdiv.style.borderColor=bordercolor;
    outerdiv.style.zIndex=++zdx;
    tw=(ie5)?w-9:w-5;
    th=(ie5)?h+4:h-4;
    var titlebar=new subBox(2,2,tw,20,titlecolor,cid+'_t');
    titlebar.style.overflow="hidden";
    titlebar.style.cursor="default";
    titlebar.innerHTML='<span style="position:absolute; left:3px; top:1px; font:bold 10pt sans-serif; color:'+titletextcolor+'; height:18px; overflow:hidden; clip-height:16px;">'+title+'</span><span id="'+cid+'_btt" style="position:absolute; width:48px; height:16px; left:'+(tw-18)+'px; top:3px;"><img src="/images/close.gif" width="16" height="14" id="'+cid+'_cls"></span>';

    tw=(ie5)?w-8:w-8;
    th=(ie5)?h-30:h-30;
    var content=new subBox(2,24,tw,th,bgcolor,cid+'_c');
    content.style.borderColor=bordercolor;
    content.style.borderStyle="inset";
    content.style.borderWidth="2px";
    content.style.overflow="auto";
    content.style.padding="0px 0px 0px 0px";
    content.style.font=fontstyleset;
    content.style.color=textcolor;
    if (ie5) content.style.scrollbarBaseColor=scrollcolor;
    content.innerHTML=text;
    outerdiv.appendChild(titlebar);
    outerdiv.appendChild(content);
    outerdiv.appendChild(rdiv);
    document.body.appendChild(shadow);
    document.body.appendChild(outerdiv);
    var IDS=new Array();
    IDS[0]=document.getElementById(cid+'_b');
    IDS[1]=document.getElementById(cid+'_t');
    IDS[2]=document.getElementById(cid+'_c');
    IDS[3]=document.getElementById(cid+'_s');
    IDS[4]=document.getElementById(cid+'_rs');
    IDS[5]=document.getElementById(cid+'_btt');
    IDS[8]=document.getElementById(cid+'_cls');
    IDS[9]=cid;
    IDS[10]=h;
    this.IDb=IDS[0]; this.IDb.IDS=IDS;
    this.IDt=IDS[1]; this.IDt.IDS=IDS;
    this.IDc=IDS[2]; this.IDc.IDS=IDS;
    this.IDs=IDS[3]; this.IDs.IDS=IDS;
    this.IDrs=IDS[4]; this.IDrs.IDS=IDS;
    this.IDbtt=IDS[5]; this.IDbtt.IDS=IDS;
    this.IDcls=IDS[8]; this.IDcls.IDS=IDS;
    this.IDb.activecolor=titlecolor;
    this.IDb.inactivecolor=scrollcolor;
      if(oldac!=null)oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
    oldac=this.IDb;
    this.IDcls.onclick=new Function("hidebox('"+cid+"');");
      if(isresize){
        this.IDrs.onmousedown=startRS;
        this.IDrs.onmouseup=new Function("currRS=null");
      }
    this.IDb.onmousedown=function(){
       if(oldac!=null){
         oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
        }
    if(ns6)this.IDS[2].style.overflow='auto';
    oldac=this;
    this.IDS[1].style.backgroundColor=this.activecolor;
    this.IDS[3].style.zIndex=++zdx;
    this.style.zIndex=++zdx;
    }
    if(isdrag){
      this.IDt.onmousedown=grab_id;
      this.IDt.onmouseup=stopdrag;
    }
    }else{
       if(oldOK){
          var ctr=new Date();
          ctr=ctr.getTime();
          var win=window.open("" , "abc"+ctr , "status=no,menubar=no,width="+w+",height="+h+",resizable=1,scrollbars=1");
          var t='<html><head><title>'+title+'</title></head><body bgcolor="'+bgcolor+'"><font style="font:'+fontstyleset+'; color:'+textcolor+'">'+text+'</font></body></html>';
          win.document.write(t);
          win.document.close();
      }
   }
}


//if(ns6)setInterval('movepopup()',40);

if(w3c){
document.onmousemove=trackmouse;
document.onmouseup=new Function("currRS=null");
}

//---------------------------fin popup --------------------------
//---------------------------InfoBUlle ----------------------------
var posX=0;posY=0;
var xOffset=15;yOffset=5;
var NbPixel=1;
var posOmbreX=7;
var posOmbreY=7;
var init=false;
var bouge=false;

function Bulle(texte) {
if (!init) {
creDiv('bulle');
creDiv('ombre');
init=true;
}
var avant='<table><tr><td class="bulle">';
var apres='</td></tr></table>';
  
  var finalPosX=posX-xOffset;
  if (finalPosX<0) finalPosX=0;
  if (document.layers) {
    // affichage bulle
    var b=document.layers["bulle"];
    b.document.write(contenu);
    b.document.close();
    b.top=posY+yOffset;
    b.left=finalPosX;
    b.visibility="show";
    b.zIndex=zdx+2;
    // affichage ombre
    var o=document.layers["ombre"];
    o.document.write(contenu);
    o.style.MozOpacity=.3; // valeur transparence de l'ombre
    o.document.close();
    o.top=posY+yOffset+posOmbreY;
    o.left=finalPosX+posOmbreX;
    o.visibility="show";
    o.zIndex=zdx+1;
  }
  
   
  if (document.getElementById || document.all) {// NS ou IE
  //------- affichage bulle---------------
    var buble=document.getElementById('bulle');
    var o=document.getElementById('ombre');
    if (document.all) {
    var buble=document.all["bulle"];
    var o=document.all["ombre"];
    }
    buble.style.width='';
    buble.innerHTML=texte;
    var larg=buble.offsetWidth+20+'px'; // modifier offset si modif padding
    if(buble.offsetWidth > 250) { // si le texte est trop long, alors on fixe une largeur
         larg='250px';
    }
    buble.style.width=larg;
    buble.innerHTML=avant+texte+apres; 
    buble.style.top=posY+yOffset;
    buble.style.left=finalPosX;
    buble.style.visibility="visible";
    buble.style.zIndex=zdx+2;
    
   // ------------affichage ombre----------- 
    
    o.style.width=larg;
    o.style.height=buble.offsetHeight+'px'
    o.style.top=posY+yOffset+posOmbreY;
    o.style.left=finalPosX+posOmbreX;
    o.style.backgroundColor=shadowcolor;
    if (document.getElementById && document.all){
    	o.style.filter="alpha(opacity=30)"; // valeur transparence de l'ombre
    } else {
    	o.style.MozOpacity=.3;
    } 
    o.style.visibility="visible";
    o.style.zIndex=zdx+1;
   
  }
bouge=true;
}

function moveBulle(evt){
var x=posX+xOffset;
var y=posY+yOffset;
if (document.layers) {
  document.layers["bulle"].top=y+'px';
  document.layers["bulle"].left=x+'px';
  document.layers["ombre"].top=y+posOmbreY+'px';
  document.layers["ombre"].left=x+posOmbreX+'px';
}

if (document.getElementById('bulle')) {
  var IDdB=document.getElementById("bulle");
  var Shad=document.getElementById("ombre");
  IDdB.style.left=x+'px';
  IDdB.style.top=y+'px';
  Shad.style.left=x+posOmbreX+'px'
  Shad.style.top=y+posOmbreY+'px';
} 

if (document.all["bulle"]) {
   var IDdB=document.all["bulle"];
   var Shad=document.all["ombre"];
   IDdB.style.left=x+'px';
   IDdB.style.top=y+'px';
   Shad.style.left=x+posOmbreX+'px'
   Shad.style.top=y+posOmbreY+'px';
}

}

function creDiv(id){
if (document.layers) {
	window.captureEvents(Event.MOUSEMOVE);window.onMouseMove=trackmouse;
	document.write("<LAYER name='bulle' top=0 left=0 visibility='hide'></LAYER>");
	document.write("<LAYER name='ombre' top=0 left=0 visibility='hide'></LAYER>");
}
if (document.getElementById || document.all){
var v=document.createElement('div');
v.setAttribute('id',id); 
v.style.position='absolute';
v.style.left='0px';
v.style.top='0px';
v.style.visibility='hidden';
document.body.appendChild(v)
}
}

function HideBulle() {
  if (document.layers) {
    var b=document.layers["bulle"];
    b.visibility="hide";
    b.document.write("");
    b.document.close();
    var o=document.layers["ombre"];
    o.visibility="hide";
    o.document.write("");
    o.document.close();
  }
	
  if (document.getElementById || document.all) {
    var buble=document.getElementById('bulle');
    var o=document.getElementById('ombre');
  }
      if (document.all){
	var buble=document.all["bulle"];
	var o=document.all["ombre"];	
      }
    buble.style.visibility="hidden";
    o.style.visibility="hidden";
    buble.innerHTML="";
    o.innerHTML="";
    buble.style.width='';
    o.style.width='';
    bouge=false;
}
//-------------------------FIN InfoBulle---------------------------
