/* Routines */
function go(c){
           if(!c.data.replace(/\s/g,''))
           c.parentNode.removeChild(c);
           }



function clean(d){
        var bal=d.getElementsByTagName('*');

        for(i=0;i<bal.length;i++){
          a=bal[i].previousSibling;
          if(a && a.nodeType==3)
            go(a);
          b=bal[i].nextSibling;
          if(b && b.nodeType==3)
            go(b);
        }
        return d;
      } 


function writediv(texte,queldiv)
  {
    document.getElementById(queldiv).innerHTML = texte;
  }
var xhr = null;
   
function getXhr(){
        if(window.XMLHttpRequest)
           xhr = new XMLHttpRequest();
        else if(window.ActiveXObject){
           try {
                      xhr = new ActiveXObject("Msxml2.XMLHTTP");
                  } catch (e) {
                      xhr = new ActiveXObject("Microsoft.XMLHTTP");
                  }
        }
        else {
           alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...vous n'aurez donc pas accès aux mises à jour, installez un navigateur plus récent (Mozilla Firefox, Internet Explorer 5 [...])");
           xhr = false;
        } 
      }
/* Fin des routines */
/* Fonctions liées aux maj */
function afficherLogiciel(solution, id_client, indice)
  {
    writediv("","logiciels");
    writediv("","telecharger");
    if(document.getElementById(solution).style.display=="block")
    {
    writediv("", solution);
    document.getElementById('rep'+indice).src = "images/folder_closed.gif";
    document.getElementById(solution).style.display="";
    }
    else if(document.getElementById(solution).style.display=="")
    {
    getXhr();
    xhr.onreadystatechange = function()
	{
	  if(xhr.readyState == 4 && xhr.status == 200)
	  {
		var reponse = clean(xhr.responseXML.documentElement);
		var nb_logiciels = reponse.getElementsByTagName("nb_logiciels")[0].firstChild.nodeValue;
		if(nb_logiciels == 0)
						{
						writediv("", "telecharger");
						writediv("Aucun logiciel ne vous est disponible pour ce pôle de logiciel", "logiciels");
						}
		else
			{
			logiciel='<div id="contenu">';		
			for (i=0; i<nb_logiciels; i++)
				{
				var id_logiciel=reponse.getElementsByTagName("id_logiciel")[i].firstChild.nodeValue;
				var libelle_logiciel=reponse.getElementsByTagName("libelle_logiciel")[i].firstChild.nodeValue;
				logiciel = logiciel+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong><a href='javascript:afficherMaj("+id_logiciel+", "+'"'+id_client+'"'+");' class='noir'>- "+libelle_logiciel+"</a></strong><br>";
				}
			 logiciel=logiciel+'</div>';
			 document.getElementById('rep'+indice).src = "images/folder_opened.gif";
			 writediv(logiciel,solution);			 
			 document.getElementById(solution).style.display="block";
			 }
	  }
	}
    xhr.open("POST","scripts/afficher_logiciels.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send("solution="+solution+"&id_client="+id_client);
    }
  }

function afficherMaj(id_logiciel, id_client)
  {
    writediv("","telecharger");
    getXhr();
    xhr.onreadystatechange = function()
    {
      if(xhr.readyState == 4 && xhr.status == 200)
      {
        var reponse = clean(xhr.responseXML.documentElement);
        var nb_maj = reponse.getElementsByTagName("nb_maj")[0].firstChild.nodeValue;
        if(nb_maj==0)
            {
            texte = "Aucune mise à jour ne vous est disponible pour ce logiciel";
            writediv(texte, "logiciels");
            }
        else
            {
        maj='<div id="majs"><table width="100%"><tr><td colspan="2">&nbsp;<strong>Liste des mises à jour disponibles pour ce logiciel</strong></td></tr>';

        for (i=0; i<=nb_maj-1; i++)
        {
          var id_version=reponse.getElementsByTagName("id_version")[i].firstChild.nodeValue;
          var id_maj=reponse.getElementsByTagName("id_maj")[i].firstChild.nodeValue;
          var libelle_maj=reponse.getElementsByTagName("libelle_maj")[i].firstChild.nodeValue;
          var libelle_version=reponse.getElementsByTagName("libelle_version")[i].firstChild.nodeValue;
          var date_sortie=reponse.getElementsByTagName("date_sortie")[i].firstChild.nodeValue;
          var libelle_logiciel=reponse.getElementsByTagName("libelle_logiciel")[i].firstChild.nodeValue;
          var id_logiciel=reponse.getElementsByTagName("date_sortie")[i].firstChild.nodeValue;
          var reste=i%2;
          if(lastVersion!=libelle_version)
              {
              if(i!=0)
                  {
                  maj +="<tr><td colspan='2' align='center'><hr align='center' width='260' size='1' color='#DDDDDD' NOSHADE/><td></tr>";
                  }
              if(reste==1)
                  {
                  maj +="<tr bgcolor='#e4e4e4' width='100%'><td width='40%'><strong><a href='javascript:afficherDownload("+id_maj+","+'"'+id_client+'"'+");' class='noir'>"+libelle_logiciel+" "+libelle_version+"."+libelle_maj+"</a></strong></td><td><font size='1'>&nbsp;&nbsp;&nbsp;&nbsp;Disponible depuis le : "+date_sortie+"</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='1' color='red'><strong>dernière version !</strong></font></td></tr>";
                  }
              else
                  {
                  maj +="<tr bgcolor='#ebebeb' width='100%'><td width='40%'><strong><a href='javascript:afficherDownload("+id_maj+","+'"'+id_client+'"'+");' class='noir'>"+libelle_logiciel+" "+libelle_version+"."+libelle_maj+"</a></strong></td><td><font size='1'>&nbsp;&nbsp;&nbsp;&nbsp;Disponible depuis le : "+date_sortie+"</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='1' color='red'><strong>dernière version !</strong></font></td></tr>";
                  }
              }
          else
              {
              if(reste==1)
                  {
                  maj +="<tr bgcolor='#e4e4e4' width='100%'><td width='40%'><strong><a href='javascript:afficherDownload("+id_maj+","+'"'+id_client+'"'+");' class='noir'>"+libelle_logiciel+" "+libelle_version+"."+libelle_maj+"</a></strong></td><td><font size='1'>&nbsp;&nbsp;&nbsp;&nbsp;Disponible depuis le : "+date_sortie+"</font></td></tr>";
                  }
              else
                  {
                  maj +="<tr bgcolor='#ebebeb' width='100%'><td width='40%'><strong><a href='javascript:afficherDownload("+id_maj+","+'"'+id_client+'"'+");' class='noir'>"+libelle_logiciel+" "+libelle_version+"."+libelle_maj+"</a></strong></td><td><font size='1'>&nbsp;&nbsp;&nbsp;&nbsp;Disponible depuis le : "+date_sortie+"</font></td></tr>";
                  }
              }
          var lastVersion = libelle_version;
        }
        maj=maj+'</div></table>';
        writediv(maj,"logiciels");
      }
    }
    }
    xhr.open("POST","scripts/afficher_maj.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send("logiciel="+id_logiciel+"&id_client="+id_client);
  }

function afficherDownload(id_maj, id_client)
  {
    getXhr();
    xhr.onreadystatechange = function()
    {
      if(xhr.readyState == 4 && xhr.status == 200)
      {
        var reponse = clean(xhr.responseXML.documentElement);
        var nb_downloads = reponse.getElementsByTagName("nb_downloads")[0].firstChild.nodeValue;
        if(nb_downloads==0)
            {
            texte = "Aucune mise à jour ne vous est disponible pour ce logiciel";
            writediv(texte, "logiciels");
            }
        download='<div id="downloads">';
        for (i=0; i<=nb_downloads-1; i++)
        {

          var fichier=reponse.getElementsByTagName("fichier")[i].firstChild.nodeValue;
          var id_version=reponse.getElementsByTagName("id_version")[i].firstChild.nodeValue;
          var id_maj=reponse.getElementsByTagName("id_maj")[i].firstChild.nodeValue;
          var libelle_maj=reponse.getElementsByTagName("libelle_maj")[i].firstChild.nodeValue;
          var libelle_version=reponse.getElementsByTagName("libelle_version")[i].firstChild.nodeValue;
          var date_sortie=reponse.getElementsByTagName("date_sortie")[i].firstChild.nodeValue;
          var libelle_logiciel=reponse.getElementsByTagName("libelle_logiciel")[i].firstChild.nodeValue;
          destination = "espace_client/mises_a_jour/"+libelle_logiciel+"/"+fichier;
          download = download+"<br><span class='grand_noir'>Logiciel : "+libelle_logiciel+" "+libelle_version+"."+libelle_maj+"</span>";
          download = download+"<br><a href='force_download.php?f="+fichier+"&liblog="+libelle_logiciel+"&id_m="+id_maj+"&id_c="+id_client+"' onmouseout='return showStatus();' onmouseover='return showStatus();'><img src='images/telecharger.gif' onmouseout='return showStatus();' onmouseover='return showStatus();' BORDER=0></a>";
        }
        download=download+'</div>';
        writediv(download,"telecharger");
      }
    }
    xhr.open("POST","scripts/afficher_download.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send("maj="+id_maj+"&id_client="+id_client);
  }
/* Fin des fonctions liées aux maj */
/* Fonctions liées à la FAQ */
function afficherReponseFaq(id_faq)
  {
  if(document.getElementById(id_faq).style.display=="block")
    {
    writediv("", id_faq);
    document.getElementById("img"+id_faq).src = "images/plus.gif";
    document.getElementById(id_faq).style.display="";
    }
    else if(document.getElementById(id_faq).style.display=="")
    {
    getXhr();
    xhr.onreadystatechange = function()
    {
      if(xhr.readyState == 4 && xhr.status == 200)
      {
        var reponse = clean(xhr.responseXML.documentElement);
        var nb_reponses = reponse.getElementsByTagName("nb_reponses")[0].firstChild.nodeValue;

        reponsefaq='<div id="reponse">';
        for (i=0; i<=nb_reponses-1; i++)
        {
          var id_faq=reponse.getElementsByTagName("id_faq")[i].firstChild.nodeValue;
          var reponsefaq=reponse.getElementsByTagName("reponse")[i].firstChild.nodeValue;
          
          reponsefaq="<span class='noir'>"+reponsefaq+".</span>";
        }
        reponsefaq=reponsefaq+'</div>';
        writediv(reponsefaq,id_faq);
        document.getElementById("img"+id_faq).src = "images/moinsf.gif";
        document.getElementById(id_faq).style.display="block";
      }
    }
    xhr.open("POST","scripts/afficher_reponsefaq.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send("id_faq="+id_faq);
    }
  }
function rechercherFaq(requete)
  {
    getXhr();
    xhr.onreadystatechange = function()
    {
      if(xhr.readyState == 4 && xhr.status == 200)
      {
        var reponse = clean(xhr.responseXML.documentElement);
        var nb_reponses = reponse.getElementsByTagName("nb_reponses")[0].firstChild.nodeValue;
        if(requete!="")
            {
            reponsefaq = "<strong><span class='moyen_noir' STYLE='padding-left: 25px;'><img src='images/puce_jaune.gif'>Recherche: <font color='#CC0033'>"+requete+"</font></span></strong><span class='text_contact'><a href='javascript:afficherAideEnLigne();' class='text5'>Retour au sommaire de l'aide en ligne</a></span><hr/>";
            reponsefaq += "<div style='padding-left: 25px;'><table border='0' width='100%'>";
            }
        else
            {
            reponsefaq = "<strong><span class='moyen_noir' STYLE='padding-left: 25px;'><img src='images/puce_jaune.gif'>Recherche: <font color='#CC0033'>Recherche vide (tout)</font></span></strong><span class='text_contact'><a href='javascript:afficherAideEnLigne();' class='text5'>Retour au sommaire de l'aide en ligne</a></span><hr/>";
            reponsefaq += "<div style='padding-left: 25px;'><table border='0' width='100%'>";
            }
        for (i=0; i<=nb_reponses-1; i++)
        {
          var id_faq=reponse.getElementsByTagName("id_faq")[i].firstChild.nodeValue;
          var reponseRecherche=reponse.getElementsByTagName("reponse")[i].firstChild.nodeValue;
          var themeRecherche=reponse.getElementsByTagName("theme")[i].firstChild.nodeValue;
          var questionRecherche=reponse.getElementsByTagName("question")[i].firstChild.nodeValue;

          reponsefaq=reponsefaq+"<tr><td><a href='javascript:afficherReponseFaq("+id_faq+");' class='moyen_noir'><img src='images/plus.gif' id='img"+id_faq+"' BORDER=0>"+questionRecherche+"</a>&nbsp; <span class='text_contact'>("+themeRecherche+")</span></td></tr>";
          reponsefaq=reponsefaq+"<tr><td><div id='"+id_faq+"'></div></td></tr>";
        }
        reponsefaq = reponsefaq+"</table>";
        writediv(reponsefaq,"recherche");
      }
    }
    xhr.open("POST","scripts/afficher_rechercheFaq.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send("requete="+requete);
  }
function afficherQuestionTheme(id_theme, val, nom_log)
  {
    getXhr();
    xhr.onreadystatechange = function()
    {
      if(xhr.readyState == 4 && xhr.status == 200)
      {
        var reponse = clean(xhr.responseXML.documentElement);
        var nb_reponses = reponse.getElementsByTagName("nb_reponses")[0].firstChild.nodeValue;
        var nom_theme = reponse.getElementsByTagName("nom_theme")[0].firstChild.nodeValue;
        var questionTheme = "";
        if(val == 0)
               {
               questionTheme = "<strong><span class='moyen_noir' STYLE='padding-left: 25px;'><img src='images/puce_jaune.gif'>Aide sur l'Espace Client : <font color='#CC0033'>"+nom_theme+"</font></span></strong><span class='text_contact'><a href='javascript:afficherAideEnLigne();' class='text5'>Retour au sommaire de l'aide en ligne</a></span><hr/>";
               questionTheme += "<div style='padding-left: 25px;'><table border='0' width='100%'>";
               }
        else
            {
            questionTheme = "<strong><span class='moyen_noir' STYLE='padding-left: 25px;'><img src='images/puce_jaune.gif'>Aide sur les logiciels : <font color='#CC0033'>"+nom_log+"</font>/<font color='#CC0033'>"+nom_theme+"</font></span></strong><span class='text_contact'><a href='javascript:afficherThemeLogiciel("+val+",\""+nom_log+"\");' class='text5'>Retour aux thèmes du logiciel</a></span><hr/>";
            questionTheme += "<div style='padding-left: 25px;'><table border='0' width='100%'>";
            }
        if(nb_reponses<=0)
            {
            questionTheme = questionTheme + "<tr><td class='noir'>Il n'y a aucune aide pour ce thème</td></tr></table>";
            writediv(questionTheme,"recherche");
            }
        for (i=0; i<=nb_reponses-1; i++)
        {
          var id_faq=reponse.getElementsByTagName("id_faq")[i].firstChild.nodeValue;
          var reponseRecherche=reponse.getElementsByTagName("reponse")[i].firstChild.nodeValue;
          var questionRecherche=reponse.getElementsByTagName("question")[i].firstChild.nodeValue;

          questionTheme=questionTheme+"<tr><td><a href='javascript:afficherReponseFaq("+id_faq+");' class='moyen_noir'><img src='images/plus.gif' id='img"+id_faq+"' BORDER=0>"+questionRecherche+"</a></td></tr>";
          questionTheme=questionTheme+"<tr><td><div id='"+id_faq+"'></div></td></tr>";
        }
        questionTheme = questionTheme+"</table>";
        writediv(questionTheme,"recherche");
      }
    }
    xhr.open("POST","scripts/afficher_questionTheme.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send("id_theme="+id_theme);
  }

function afficherThemeLogiciel(id_theme, nom_logiciel)
  {
    getXhr();
    var theme_principal = id_theme;
    xhr.onreadystatechange = function()
    {
      if(xhr.readyState == 4 && xhr.status == 200)
      {
        var reponse = clean(xhr.responseXML.documentElement);
        var nb_reponses = reponse.getElementsByTagName("nb_reponses")[0].firstChild.nodeValue;
        var themes = "<strong><span class='moyen_noir' STYLE='padding-left: 25px;'><img src='images/puce_jaune.gif'>Aide sur les logiciels : <font color='#CC0033'>"+nom_logiciel+"</font></span></strong><span class='text_contact'><a href='javascript:afficherAideEnLigne();' class='text5'>Retour au sommaire de l'aide en ligne</a></span><hr/>";
            themes = themes + "<div style='padding-left: 25px;'><table border='0' width='100%'>";
        var reste=0;
        if(nb_reponses<=0)
            {
            themes = themes + "<tr><td class='noir'>Il n'y a aucune aide pour ce thème</td></tr></table>";
            writediv(themes,"recherche");
            }
        for (i=0; i<=nb_reponses-1; i++)
        {
          var id_theme=reponse.getElementsByTagName("id_theme")[i].firstChild.nodeValue;
          var nom_theme=reponse.getElementsByTagName("nom_theme")[i].firstChild.nodeValue;
          reste = i%4;
          switch (reste)
                 {
                 case 0:
                      themes += "<tr><td><a href='javascript:afficherQuestionTheme("+id_theme+","+theme_principal+",\""+nom_logiciel+"\");' class='rouge2'>"+nom_theme+"</a></td>";
                 break;
                 case 1:
                      themes +=  "<td><a href='javascript:afficherQuestionTheme("+id_theme+","+theme_principal+",\""+nom_logiciel+"\");' class='rouge2'>"+nom_theme+"</a></td>";
                 break;
                 case 2:
                      themes += "<td><a href='javascript:afficherQuestionTheme("+id_theme+","+theme_principal+",\""+nom_logiciel+"\");' class='rouge2'>"+nom_theme+"</a></td>";
                 break;
                 case 3:
                      themes += "<td><a href='javascript:afficherQuestionTheme("+id_theme+","+theme_principal+",\""+nom_logiciel+"\");' class='rouge2'>"+nom_theme+"</a></td></tr>";
                 break;
                 default:
                      themes += "<tr><td>Aucun thème disponible pour le logiciel"+logiciel+"</td></tr>";
                 break;
                 }
        }
        themes = themes+"</table></div>";
        writediv(themes,"recherche");
      }
    }
    xhr.open("POST","scripts/afficher_themeLogiciel.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.send("id_theme="+id_theme);
  }

function afficherAideEnLigne() {
    getXhr();
    xhr.onreadystatechange = function()
    {
      if(xhr.readyState == 4 && xhr.status == 200)
      {
        var reponse = xhr.responseText;
        writediv(reponse,"recherche");
      }
    }
    xhr.open("POST","scripts/afficher_sommaireAideEnligne.php",true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    var truc = "";
    xhr.send("truc="+truc);
}
/* Fin des fonctions liées à la FAQ */





