var intCount = 0;

//-Fonction d'ajout d'entrées principales-------------------------
function DynamicMenu_addParent(strName) {
  var strID = 'ID' + intCount++; 

  var strTemp = '<DIV ID="' + strID + '" CLASS="parent"';
      strTemp += ' onClick="expandCollapse(this);">';
      strTemp += '<IMG SRC="/img/menu-fleche1.gif" >';
      strTemp += '&nbsp;' + strName ;
      strTemp += '<DIV STYLE="display: block" CLASS="child"></DIV>';
      strTemp += '</DIV>';

      this.div.innerHTML += strTemp;
      this.currentChild = document.getElementById(strID);
}

//-Fonction d'ajout de liens dans le menu-------------------------
function DynamicMenu_addChild(strName,strURL) {
  var strTemp = '<A HREF="' + strURL + '"'
              + ' onClick="cancelBubble(arguments[0]);">' 
              + strName + '</A><BR>';

  if (document.all) {
    this.currentChild.children[1].innerHTML += strTemp;
  } else {
    this.currentChild.childNodes[2].innerHTML += strTemp;
  }
}

//-inhibe la cascade d'évènements au DIV conteneur----------------
function cancelBubble(netEvent) {
  if (document.all) {
    window.event.cancelBubble = true;
  } else {
    netEvent.cancelBubble = true;
  }
}

//-Contracte ou expanse le menu-----------------------------------
function expandCollapse(objElement) {
  if (document.all) {
    var imgIcon = objElement.children[0];
    objElement = objElement.children[1];
  } else {
    var imgIcon = objElement.childNodes[0];
    objElement = objElement.childNodes[2];
  }    

  if (objElement.style.display == "none") {  
    objElement.style.display = "block" ;
    imgIcon.src = "/img/menu-fleche1.gif" ;
  } else {
    objElement.style.display = "none" ;
    imgIcon.src = "/img/menu-fleche2.gif" ;
  }
}

//-Fonction de création de menu dynamique------------------------- 
function DynamicMenu() {
  var id = "Menu" + intCount++;
  document.write('<DIV Id="' + id + '"></DIV>');

  this.div = document.getElementById(id);
  this.currentChild = null;

  this.addParent = DynamicMenu_addParent;
  this.addChild = DynamicMenu_addChild;
}

function openWindow(page,nom,tx,ty,sc) {
  v=window.open(page,nom,"width="+tx+",height="+ty+",scrollbars="+sc+",directories=no,menubar=no,status=no,location=no,resizable=no,toolbar=no");
  v.document.close();
  v.focus();
}

function openLink(page,nom,tx,ty) {
  v=window.open(page,nom,"width="+tx+",height="+ty+",directories=no,menubar=no,status=no,location=yes,scrollbars=yes,resizable=yes,toolbar=yes");
  v.focus();
}
