// Objet de détection de la version du navigateur
function lib_bwcheck(){
  this.ver    = navigator.appVersion;
  this.agent  = navigator.userAgent;
  this.dom    = document.getElementById?1:0;
  this.ie5    = (this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
  this.ie6    = (this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
  this.ie4    = (document.all && !this.dom)?1:0;
  this.ie     = this.ie4||this.ie5||this.ie6;
  this.opera5 = this.agent.indexOf("Opera 5")>-1;
  this.ns6    = (this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4    = (this.agent.indexOf('Mozilla/')>-1 && !this.dom)?1:0;
  this.bw     = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom);
  this.mac    = this.agent.indexOf("Mac")>-1;
  this.win    = this.agent.indexOf("Win")>-1;
  return this
}
var bw = new lib_bwcheck();

// *** Layers ***
// Recherche d'un layer
function getNav4Layer(layerId, parent) {
  var objLayer;
  var parentObj = (parent)? parent:document;
  for(var i=0 ; i<parentObj.layers.length && !objLayer ; i++) {
    if (parentObj.layers[i].id == layerId) {
      objLayer = parentObj.layers[i];
    } else{
      objLayer = getNav4Layer(layerId, parentObj.layers[i]);
    }
  }
  return objLayer;
}
function CSSObject(obj) {
  if (bw.ie5 || bw.ie6 || bw.ns6) {
    this.name = obj;
    this.elem = document.getElementById(obj);
    this.css  = this.elem.style;
  } else if (bw.ns4) {
    this.name = obj;
    this.elem = getNav4Layer(obj, 0);
    this.css  = this.elem;
  } else if (bw.ie4) {
    this.name = obj;
    this.elem = document.all[obj];
    this.css  = this.elem.style;
  }
}
// Déplacement relatif des layers
function moveByNav(x,y) {
  this.css.left = parseInt(this.css.left) + x;
  this.css.top  = parseInt(this.css.top) + y;
}
function moveByIE(x,y) {
  this.css.pixelLeft += x;
  this.css.pixelTop  += y;
}
if (bw.ns4 || bw.ns6) CSSObject.prototype.moveBy = moveByNav;
else if (bw.ie)       CSSObject.prototype.moveBy = moveByIE;
// Déplacement absolu des layers
function moveToNav(x,y) {
  this.css.left = x;
  this.css.top  = y;
}
function moveToIE(x,y) {
  this.css.pixelLeft = x;
  this.css.pixelTop  = y;
}
if (bw.ns4 || bw.ns6) CSSObject.prototype.moveTo = moveToNav;
else if (bw.ie)       CSSObject.prototype.moveTo = moveToIE;
// Dimmensions et position des layers
function clipByNav(t,r,b,l) {
  this.css.clip.top = t;
  this.css.clip.right = r;
  this.css.clip.bottom = b;
  this.css.clip.left = l;
}
function clipByIE(t,r,b,l) {
  this.css.clip = "rect(" + t + "px "+ r + "px " + b + "px " + l + "px)";
}
function getLeftNav() {
  return parseInt(this.css.left);
}
function getLeftIE() {
  return this.css.pixelLeft;
}
function getTopNav() {
  return parseInt(this.css.top);
}
function getTopIE() {
  return this.css.pixelTop;
}
function getRightNav() {
  return this.css.left + getWidthNav();
}
function getRightIE() {
  return this.css.pixelLeft + getWidthIE();
}
function getBottomNav() {
  return this.css.top + getHeightNav();
}
function getBottomIE() {
  return this.css.pixelTop + getHeightIE();
}
function getWidthNav() {
  if (this.elem.document.width)
    return this.elem.document.width;
  else
    return this.css.clip.right - this.css.clip.left;
}
function getWidthIE() {
  if (this.css.pixelWidth)
    return(this.css.pixelWidth);
  else
    return(this.elem.clientWidth);
}
function getHeightNav() {
  if (this.elem.document.height)
    return this.elem.document.height;
  else
    return this.css.clip.bottom - this.css.clip.top;
}
function getHeightIE() {
  if (false && this.css.pixelHeight)
    return this.css.pixelHeight;
  else
    return this.elem.clientHeight;
}
function setTopNav(y) {
  this.css.top = y;
}
function setTopIE(y) {
  this.css.pixelTop = y;
}
function setLeftNav(x) {
  this.css.left = x;
}
function setLeftIE(x) {
  this.css.pixelLeft = x;
}
if (bw.ns4 || bw.ns6) {
  CSSObject.prototype.clipBy    = clipByNav;
  CSSObject.prototype.getLeft   = getLeftNav;
  CSSObject.prototype.getRight  = getRightNav;
  CSSObject.prototype.getTop    = getTopNav;
  CSSObject.prototype.getBottom = getBottomNav;
  CSSObject.prototype.getWidth  = getWidthNav;
  CSSObject.prototype.getHeight = getHeightNav;
  CSSObject.prototype.setTop    = setTopNav;
  CSSObject.prototype.setLeft   = setLeftNav;
} else if (bw.ie) {
  CSSObject.prototype.clipBy    = clipByIE;
  CSSObject.prototype.getLeft   = getLeftIE;
  CSSObject.prototype.getRight  = getRightIE;
  CSSObject.prototype.getTop    = getTopIE;
  CSSObject.prototype.getBottom = getBottomIE;
  CSSObject.prototype.getWidth  = getWidthIE;
  CSSObject.prototype.getHeight = getHeightIE;
  CSSObject.prototype.setTop    = setTopIE;
  CSSObject.prototype.setLeft   = setLeftIE;
}
// Couleurs
function setColor(color) {
  this.css.color = color;
}
function setBgColorNav(color) {
  this.css.bgColor = color;
}
function setBgColorIE(color) {
  this.css.backgroundColor = color;
}
if (bw.dom || bw.ie4) {
  CSSObject.prototype.setBgColor = setBgColorIE;
} else {
  CSSObject.prototype.setBgColor = setBgColorNav;
}
CSSObject.prototype.setColor = setColor;
// Ecriture dans les layers
function HTMLWriteNav4(html) {
  this.css.document.open();
  this.css.document.write(html);
  this.css.document.close();
}
function HTMLWriteIE5(html) {
  this.elem.innerHTML = html;
}
if (bw.ns4)                                                CSSObject.prototype.write = HTMLWriteNav4;
else if (bw.ie6 || bw.ie5 || (bw.ie4 && bw.win) || bw.ns6) CSSObject.prototype.write = HTMLWriteIE5;
// Visibilité des layers
function showNav() {
  this.css.visibility = "show";
}
function showIE() {
  this.css.visibility = "visible";
}
function hideNav() {
  this.css.visibility = "hide";
}
function hideIE() {
  this.css.visibility = "hidden";
}
if (bw.ns4 || bw.ns6) {
  CSSObject.prototype.show = showNav;
  CSSObject.prototype.hide = hideNav;
} else if (bw.ie) {
  CSSObject.prototype.show = showIE;
  CSSObject.prototype.hide = hideIE;
}
// *** Fin layers ***

// *** Images ***
// Recherche d'une image
function getImageByName(imgName) {
  if (bw.ie || bw.ns6) {
    return document.images[imgName];
  } else if (bw.ns4) {
    return getImgObjNav4(imgName);
  }
}
function getImgObjNav4(imgName,parent) {
  var objImage;
  var parentObj = (parent)? parent:document;
  objImage = parentObj.images[imgName];
  if (!objImage) {
    for (var i=0 ; i < parentObj.layers.length && !objImage ; i++) {
      objImage = getImgObjNav4(imgName,parentObj.layers[i].document);
    }
  }
  return objImage;
}
// *** Fin Images ***

// *** Formulaires ***
// Recherche d'un formulaire
function getFormByName(formName) {
  if (bw.ie || bw.ns6) {
    return document.forms[formName];
  } else if (bw.ns4) {
    return getFormObjNav4(formName);
  }
}
function getFormObjNav4(formName,parent) {
  var objForm;
  var parentObj = (parent)? parent:document;
  objForm = parentObj.forms[formName];
  if (!objForm) {
    for (var i=0 ; i < parentObj.layers.length && !objForm ; i++) {
      objForm = getFormObjNav4(formName,parentObj.layers[i].document);
    }
  }
  return objForm;
}
// *** Fin formulaires ***

// *** Tableaux ***
function getRows(theTable) {
  var theRows = null;

  if (typeof(document.getElementsByTagName) != 'undefined') {
    theRows = theTable.getElementsByTagName('tr');
  }
  else if (typeof(theRow.cells) != 'undefined') {
    theRows = theTable.cells;
  }
  
  return theRows;
}
function getCells(theRow) {
  var theCells = null;

  if (typeof(document.getElementsByTagName) != 'undefined') {
    theCells = theRow.getElementsByTagName('td');
  }
  else if (typeof(theRow.cells) != 'undefined') {
    theCells = theRow.cells;
  }
  
  return theCells;
}
// *** Fin tableaux ***

// *** Eléments généraux ***
function getBgColor(theElem) {
  return theElem.style.backgroundColor;
}
function setBgColor(theElem,theColor) {
  theElem.style.backgroundColor = theColor;
}
// *** Fin éléments généraux *** 

// *** Document ***
function getScrollTop() {
  if (bw.ie) {
    return document.body.scrollTop;
  } else {
    return window.pageYOffset;
  }
}

function getScrollLeft() {
  if (bw.ie) {
    return document.body.scrollLeft;
  } else {
    return window.pageXOffset;
  }
}
// *** Fin document ***
