//----------------------------------------------------------------------------------------
//                      API Explorer/Navigator : accès aux couches
//                  testé sous Netscape 4.7/6.0, MSIE 5.0/5.5, Opera 5.11
//
// function creeCouche(wind, id, l, HTML)     --> Ne fonctionne ni sous Netscape 6 ni sous Opera. OK sous Explorer
// function getObject(obj)
// function getStyleObject(obj)
// function setZIndex(obj, zOrder)
// function shiftTo(obj, x, y)
// function shiftBy(obj, deltaX, deltaY)
// function setX(obj, x)
// function setY(obj, y)
// function setBGColor(obj, color)             --> réagit bizarrement sous Netscape 4.7
// function show(obj)
// function hide(obj)
// function openCouche (obj)                   --> Cette série (open, write, writeln et close) ne fonctionne
// function writeCouche (obj, data)            --> pas sous Opera
// function writelnCouche (obj, data)
// function closeCouche (obj)
// function getX(obj)
// function getY(obj)
// function getWidth(obj)
// function getHeight(obj)
//----------------------------------------------------------------------------------------

var layersVersion = 2.1;

var agt=navigator.userAgent.toLowerCase();
var isOpera = (agt.indexOf('opera') != -1);
var isNav   = (navigator.appName == 'Netscape') && !isOpera;
var isIE    = (agt.indexOf('msie') != -1) && !isOpera;
var isNav6  = (agt.indexOf('gecko') != -1);
var isNav4  = (isNav && !isNav6);
var isW3    = (document.getElementById) ? true : false;
var styleObj = (isW3 || isIE) ? '.style' : '';
var range    = (isIE) ? 'all.' : '';
var unite    = (isW3 && !isOpera) ? 'px' : 0;

// Crée une couche dans la fenêtre 'wind' contenant du code HTML.
// Entrée : la fenêtre mère, son ID (obligatoire pour IE), sa largeur (obligatoire pour Netscape),
// et le code HTML (facultatif);
// La couche est créée invisible.
// En sortie, un pointeur sur la couche.
function creeCouche(wind, id, l, HTML) {          // L'ID peut être n'importe quoi, on s'en fout.
  if (isNav4) {                                   // En particulier pour Netscape, il ne sert à rien.
    var lay = new Layer(l,wind);                  // On accède à la couche en utilisant le pointeur
    lay.visibility = 'hidden';                    // donné en sortie.
    lay.document.write(HTML);
    lay.document.close();
    return lay;
  }
  if (isIE) {
    var htmlCode = '<DIV ID='+id+' STYLE="position:absolute;';
    if (l) htmlCode += ' width:'+l+';';
    htmlCode += ' visibility:hidden">'+HTML+'</DIV>';
    wind.document.body.insertAdjacentHTML("BeforeEnd", htmlCode);
    return wind.document.all[id];
  }
}

// Convert object name string or object reference
// into a valid object reference
function getObject(obj) {
  if (typeof obj == "string") {
    if (isW3) return document.getElementById(obj);
    return eval("document." + range + obj);
  }
  return obj;
}
function getStyleObject(obj) {
  if (typeof obj == "string") {
    if (isW3) return document.getElementById(obj).style;
    return eval("document." + range + obj + styleObj);
  }
  return eval ("obj" + styleObj);
}

/* Dans les fonctions suivantes, le paramètre 'obj' désigne
     - soit une chaîne de caractères donnant le nom d'une couche top-level
     - soit une référence directe à une couche imbriquée dans une autre (document.couche0.document.couche1
	   pour Navigator ou document.all.couche1 pour MSIE)
*/
// Fixer l'ordonnée Z de la couche
function setZIndex(obj, zOrder) {
  getStyleObject(obj).zIndex = zOrder;
}

//--------------------------- Positionner une couche ----------------------------
function shiftTo(obj, x, y) {
  var theObj = getStyleObject(obj);
  if (isNav4) {theObj.moveTo(x,y); return}
  if (isIE) {
    theObj.pixelLeft = x;
    theObj.pixelTop = y;
    return;
  }
  if (isW3) {
    theObj.left = x + unite;
    theObj.top  = y + unite;
  }
}

function shiftBy(obj, deltaX, deltaY) {
  var theObj = getObject(obj);
  if (isNav4) {theObj.moveBy(deltaX, deltaY); return}
  if (isIE) {
    theObj = theObj.style;
   	theObj.pixelLeft += deltaX;
    theObj.pixelTop += deltaY;
    return;
  }
  if (isW3) {
    var theObjS = theObj.style;
    theObjS.left = (parseInt(theObjS.left) + deltaX) + unite;
    theObjS.top  = (parseInt(theObjS.top) + deltaY) + unite;
  }
}

function setX(obj, x) {
  var theObj = getStyleObject(obj)
  if (isNav4) { theObj.left = x; return }
  if (isIE)   { theObj.pixelLeft = x; return }
  if (isW3)   { theObj.left = x + unite; return }
}

function setY(obj, y) {
  var theObj = getStyleObject(obj)
  if (isNav4) { theObj.top = y; return }
  if (isIE)   { theObj.pixelTop = y; return }
  if (isW3)   { theObj.top = y + unite; return }
}

//-------------------------- Changer la couleur d'une couche -----------------------
function setBGColor(obj, color) {
  var theObj = getStyleObject(obj);
  if (isNav4) { theObj.bgColor = color; return }
  if (isOpera) { theObj.background = color; return }
  theObj.backgroundColor = color;
}

//--------------------- Rendre une couche visible ou invisible ------------------
function show(obj) {
  getStyleObject(obj).visibility = "visible";
}

function hide(obj) {
  getStyleObject(obj).visibility = "hidden";
}

//------------------ Ecrire des données HTML dans une couche ------------------
function openCouche (obj) {
  if (isIE || isNav6) getObject(obj).innerHTML = '';
}

function writeCouche (obj, data) {
  var theObj = getObject(obj);
  if (isNav4) {theObj.document.write (data); return}
  if (isIE || isNav6) theObj.innerHTML += data;
}

function writelnCouche (obj, data) {
  var theObj = getObject(obj);
  if (isNav4) {theObj.document.writeln (data); return}
  if (isIE || isNav6) theObj.innerHTML += data + '\n';
}

function closeCouche (obj) {
  if (isNav4) getObject(obj).document.close();
}

//------------------ Obtenir des infos sur une couche ------------------
function getX(obj) {                             // Ne pas oublier de déclarer "left:10px" dans le code HTML
  if (isNav4)  return getObject(obj).left;
  if (isIE)    return getObject(obj).offsetLeft;
  if (isOpera) return getStyleObject(obj).pixelLeft;
  if (isW3)    return parseInt(getStyleObject(obj).left);
}

function getY(obj) {                             // Ne pas oublier de déclarer "top:10px" dans le code HTML
  if (isNav4) return getObject(obj).top;
  if (isIE)   return getObject(obj).offsetTop;
  if (isOpera) return getStyleObject(obj).pixelTop;
  if (isW3)   return parseInt(getStyleObject(obj).top);
}

function getWidth(obj) {
  var theObj = getObject(obj)
  if (isNav4)  return theObj.clip.width;
  if (isIE)    return theObj.clientWidth;
  if (isNav6)  return theObj.offsetWidth;
  if (isOpera) return theObj.style.pixelWidth;
}

function getHeight(obj) {
  var theObj = getObject(obj)
  if (isNav4)  return theObj.clip.height;
  if (isIE)    return theObj.clientHeight;
  if (isNav6)  return theObj.offsetHeight;
  if (isOpera) return theObj.style.pixelHeight;
}

