var imgOpened    = new Image(9,9);
var imgClosed    = new Image(9,9);


var isDOM        = (typeof(document.getElementsByTagName) != 'undefined') ? 1 : 0;
var isIE4        = ((typeof(document.all) != 'undefined') && (parseInt(navigator.appVersion) >= 4)) ? 1 : 0;
var isNS4        = (typeof(document.layers) != 'undefined') ? 1 : 0;
var capable      = (isDOM || isIE4 || isNS4) ? 1 : 0;
var compteur     = 2;

function closeOneDiv(el,divPath)
{
  if (!capable)
    return;
  if (isDOM) {
    var whichEl = document.getElementById(el);
    var whichIm = document.getElementById(el + 'IMG');
    if (!lockDiv(el,divPath)) {
        whichEl.style.display  = 'none';
        if (whichIm != null) whichIm.src = imgClosed.src;
    } else {
        whichEl.style.display  = 'block';
        if (whichIm != null) whichIm.src = imgOpened.src; 
    }
  } // end of the DOM case
  else if (isIE4) {
    var whichEl = document.all(el);
    var whichIm = document.images.item(el + 'IMG');
    if (!lockDiv(el,divPath)) {
        whichEl.style.display  = 'none';
        if (whichIm != null) whichIm.src = imgClosed.src;
    } else {
        whichEl.style.display  = 'block';
        if (whichIm != null) whichIm.src = imgOpened.src; 
    }   
  } // end of the IE4 case
  else if (isNS4) {
    var whichEl = document.layers[el];
    if (!lockDiv(el,divPath)) {
        whichEl.visibility  = 'hide';
    } else { 
        whichEl.visibility  = 'show';
    }   
  } // end of the NS4 case
} // end of the 'expandBase()' function

function expandDiv(el)
{
  if (!capable)
    return;
  initDiv(el);
    
  if (isDOM) {
    var whichEl = document.getElementById(el);
    var whichIm = document.getElementById(el + 'IMG');
    if ( whichEl.style.display == 'block') {
        whichEl.style.display  = 'none';
        if (whichIm != null) whichIm.src = imgClosed.src;
    }else {  
        whichEl.style.display  = 'block';
        if (whichIm != null) whichIm.src = imgOpened.src; 
    }   
  } // end of the DOM case
  else if (isIE4) {
    var whichEl = document.all(el);
    var whichIm = document.images.item(el + 'IMG');
    if ( whichEl.style.display == 'block') {
        whichEl.style.display  = 'none';
        if (whichIm != null) whichIm.src = imgClosed.src;
    } else {
        whichEl.style.display  = 'block';
        if (whichIm != null) whichIm.src = imgOpened.src; 
    }   
  } // end of the IE4 case
  else if (isNS4) {
    var whichEl = document.layers[el];
     if ( whichEl.visibility == 'show')
         whichEl.visibility  = 'hide';
    else
        whichEl.visibility  = 'show';
  } // end of the NS4 case
} // end of the 'expandBase()' function


function initDiv(divPath)
{
  if (!capable)
    return;

  if (isDOM) {
    var tempColl    = document.getElementsByTagName('DIV');
    var tempCollCnt = tempColl.length;
    for (var i = 0; i < tempCollCnt; i++) {
      if (tempColl[i].className == 'layout') {
        if (!lockDiv(tempColl[i].id,divPath)) {
            tempColl[i].style.display = 'none';
            var whichIm = document.getElementById(tempColl[i].id + 'IMG');
            if (whichIm != null)    whichIm.src = imgClosed.src;
        }
      }
    }
  } // end of the DOM case
  else if (isIE4) {
    tempColl        = document.all.tags('DIV');
    var tempCollCnt = tempColl.length;
    for (var i = 0; i < tempCollCnt; i++) {
      if (tempColl[i].className == 'layout') {
        if (!lockDiv(tempColl[i].id,divPath)) {
            tempColl[i].style.display = 'none';
            var whichIm = document.images.item(tempColl[i].id  + 'IMG');
            if (whichIm != null)    whichIm.src = imgClosed.src;
    }
      }
    }
  } // end of the IE4 case
  else if (isNS4) {
    var layersCnt   = document.layers.length;
    for (var i=0; i<layersCnt; i++) {
      var whichEl = document.layers[i];
      if (whichEl.id.indexOf('layout') != -1){
        if (!lockDiv(whichEl.id,divPath))
            whichEl.visibility        = 'hide';
      } else
        whichEl.visibility        = 'show';
    }
    //nsArrangeList();
  } // end of the NS4 case
}
  
function lockDiv (div,divPath) {
    //alert(divPath+"    div: "+div+"     result : "+divPath.indexOf(div));
    if (divPath.indexOf(div)!= -1)
        return true;
    else 
        return false;   
}
