var total
function addslashes(ch) 
{
ch = ch.replace(/\\/g,"\\\\")
ch = ch.replace(/\'/g,"\\'")
ch = ch.replace(/\"/g,"\\\"")
return ch
}
function menu(sectionchoisi)
{
   /*for (i=1;i<=total;i++)
   {
      document.getElementById("choix"+i).className="menu";
   }
   document.getElementById("choix" + choix).className="menuchoisi";*/
   section = sectionchoisi;
   //top.chargermenugauche();   
   //window.open("principal.php?section=" + section, "bas");
}
function menu2(section,soussection)
{
   /*for (i=1;i<=total;i++)
   {
      document.getElementById("choix2"+i).className="menu";
   }   
   document.getElementById("choix2" + choix).className="menuchoisi";*/
   window.open("contenu.php?soussection="+soussection+"&section=" + section, "frameGlobale");
}
function menu3(choix)
{
   /*for (i=1;i<=total;i++)
   {
      document.getElementById("choix3"+i).className="menu";
   }   
   document.getElementById("choix3" + choix).className="menuchoisi";*/
   if (choix==1)
   {
      window.open("section.php", "frameGlobale");
   }
   if (choix==2)
   {
      window.open("ssection.php", "frameGlobale");
   }
   if (choix==3)
   {
      window.open("contenu.php", "frameGlobale");
   }
   if (choix==4)
   {
      window.open("listefichiers.php", "frameGlobale");
   }
   if (choix==5)
   {
      window.open("histo.php", "frameGlobale");
   }
   if (choix==6)
   {
      window.open("deconnect.php", "_self");
   }
   if (choix==7)
   {
      window.open("../index.php", "_self");
   }
}


function loadmenu()
{
   var xhr=null;
    if (window.XMLHttpRequest) {
      xhr = new XMLHttpRequest();
   }
   //ie
   else if (window.ActiveXObject) {
      try {
         xhr = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
         xhr = new ActiveXObject("Microsoft.XMLHTTP");
      }
   } 
   //non supporté
   else {
      alert("Fonction non supportée par le navigateur");
      xhr = false;
   }
   if (xhr != false)
   {
      //on définit l'appel de la fonction au retour serveur
      xhr.onreadystatechange = function() { sortirmenu(xhr); };
      //on appelle le fichier reponse.txt
      xhr.open("GET", "getmenusmenu.php", true);
      xhr.send(null);
   }
}
function sortirmenu(xhr)
{
   var texte = ""
   var texthtml
   var section = ""
   var soussection = ""
   if (xhr.readyState==4) 
   {
      if(xhr.status == 200)
      {
         //var docXML = xhr.responseXML;
         if (window.XMLHttpRequest) {
         	docXML = xhr.responseXML;
         } else if (window.ActiveXObject) {
         	docXML = new ActiveXObject("Microsoft.XMLDOM");
         	docXML.loadXML(xhr.responseText);
         }
         var items = docXML.getElementsByTagName("nom")
         var items2 = docXML.getElementsByTagName("total")
         var items3 = docXML.getElementsByTagName("soussectiondef")
         var items4 = docXML.getElementsByTagName("contenu")
         var nombre = 1
         //var lf = window.frames["menuhaut"].document;
         var lf = document.getElementById("menu");  
         var sectionlue
         var soussectionlue
         texthtml = "";

         total = items2.item(0).firstChild.data;
         for (i=0;i<items.length;i++)
         {
            soussectiondef = items3.item(i).firstChild.data;
            sectionlue = items.item(i).firstChild.data;
            if (i==0)
            {
               section = sectionlue;
               soussection = soussectiondef;
            }
            //texthtml +=  '<td width = "130" class="menu" id='+"choix"+nombre+'><a href="javascript:menu('+nombre+','+total+',\''+sectionlue+'\');">'+sectionlue+'</a></td>' + "\n";
            texthtml += '<dt onclick="javascript:montre(\'\','+total+'); montre(\'smenu'+nombre+'\');"><a href="#" onclick="javascript:menu2(\''+addslashes(sectionlue)+'\',\'Defaut\');">'+sectionlue+'</a></dt>' + "\n";
            if (items4.item(i).childNodes.length > 1)
            {
               texthtml += '<dd id="smenu'+nombre+'"><ul>';
               for (var iNode = 1; iNode < items4.item(i).childNodes.length; iNode++) {
                  var node = items4.item(i).childNodes.item(iNode);
                  if (items4.item(i).childNodes.item(iNode).nodeName == "snom") {                 
                     try
                     {
                        var ssectionlue = node.firstChild.data;
                        texthtml += '<li><a href="#" onclick="javascript:menu2(\''+addslashes(sectionlue)+'\',\''+addslashes(ssectionlue)+'\');">'+ssectionlue+'</a></li>' + "\n";
      					}
                     catch(e)
                     {
                       alert(e);
                     }    
                  }							
               }
               texthtml += '</ul></dd>';  
            } 
            nombre = nombre + 1; 
              
         }
         /*lf.open();
         lf.write(texthtml);
         lf.close();*/
         lf.innerHTML = texthtml;
         montre('smenu1');
         menu2(section,soussection);
         if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
         }
         //ie
         else if (window.ActiveXObject) {
            try {
               xhr = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
               xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
         } 
         //window.frames["iframe_detail"].location.href = 'about:blank';      
         //document.getElementById("message").className="tumevoispas";
         //indexStatus.innerHTML = "TEST";
      }
      else
         dump("Erreur pendant le chargement de la page.\n");
   }
}
/*
function sousmenu(sectionlue)
{
   var xhr=null;
    if (window.XMLHttpRequest) { 
      xhr = new XMLHttpRequest();
   }
   //ie
   else if (window.ActiveXObject) {
      try {
         xhr = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
         xhr = new ActiveXObject("Microsoft.XMLHTTP");
      }
   } 
   //non supporté
   else {
      alert("Fonction non supportée par le navigateur");
      xhr = false;
   }

   //on définit l'appel de la fonction au retour serveur
   xhr.onreadystatechange = function() { sortirsousmenu(xhr); };
   //on appelle le fichier reponse.txt
   xhr.open("GET", "getmenu.php?section="+sectionlue, true);
   xhr.send(null);
}
function sortirsousmenu(xhr)
{
   var texte = ""
   if (xhr.readyState==4) 
   {
      if(xhr.status == 200)
      {
         var docXML = xhr.responseXML;
         var items = docXML.getElementsByTagName("nom")
         var items2 = docXML.getElementsByTagName("total")
         var nombre = 1
         var tableau = window.frames["gauche"].document.getElementById('tableau')
         var ssectionlue
         var texthtml = ""
         
         
         var total = items2.item(0).firstChild.data
         for (i=0;i<items.length;i++)
         {
            ssectionlue = items.item(i).firstChild.data;
            if (soussection != ssectionlue)            
               texthtml += '<tr align="center"><td width = "190" class="menu" id='+"choix2"+nombre+'><a href="#" onclick="javascript:menu2('+nombre+','+total+',\''+addslashes(section)+'\',\''+addslashes(ssectionlue)+'\');">'+ssectionlue+'</a></td></tr>';
            else            
               texthtml += '<tr align="center"><td width = "190" class="menuchoisi" id='+"choix2"+nombre+'><a href="#" onclick="javascript:menu2('+nombre+','+total+',\''+addslashes(section)+'\',\''+addslashes(ssectionlue)+'\');">'+ssectionlue+'</a></td></tr>';
            nombre = nombre + 1;
         }
         texthtml += '</TABLE>';
         tableau.innerHTML = texthtml;
         
         if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
         }
         //ie
         else if (window.ActiveXObject) {
            try {
               xhr = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
               xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
         } 
         window.open("contenu.php?soussection="+soussection+"&section=" + section, "droite");
         //window.frames["iframe_detail"].location.href = 'about:blank';      
         //document.getElementById("message").className="tumevoispas";
         //indexStatus.innerHTML = "TEST";
      }
      else
         dump("Erreur pendant le chargement de la page.\n");
   }
}
*/