﻿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 nettoyerListe(id, text){
  $(id).innerHTML = '';
  uneOption = document.createElement('option');
  uneOption.text = text;
  uneOption.value = '';
  $(id).appendChild(uneOption);
}

function goTri(critere){
  $('tri').value = critere;
  $('formulaire').submit();
}

function show(id){
  $(id).style.visibility = 'visible';
  $(id).style.display = 'block';
}

function hide(id){
  $(id).style.visibility = 'hidden';
  $(id).style.display = 'none';
}

function constructionListe(id, nbElements, noeudRacine, init){
  for ( var i = 0 ; i < nbElements ; i++ )
  {
    noeudEnCours = noeudRacine.childNodes[i];
  
    if(noeudEnCours.firstChild.nodeValue != ""){
      uneOption = document.createElement('option');
      leTexte = document.createTextNode(noeudEnCours.firstChild.nodeValue);
      uneOption.appendChild(leTexte);
      uneOption.setAttribute('value', noeudEnCours.getAttribute('value') );
      
      if(init == noeudEnCours.getAttribute('value')){
        uneOption.setAttribute('selected','selected');
      }
      $(id).appendChild(uneOption);
    }
  }
}

function goChangementProfil(profilid){
  if(confirm('Etes-vous sûr de vouloir changer de profil ?')){
    document.location.href = 'traitement_changement_profil.php?id='+profilid;
  }
}

function goPop(page, nom){
  width="1000";
  height=screen.height;
  window.open(page,nom,'scrollbars,resizable,status=yes,toolbar=no,directories=no,width='+width+',height='+height);
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf("&" + strParamName.toLowerCase() + "=") > -1 || aQueryString[iParam].indexOf("?" + strParamName.toLowerCase() + "=") > -1){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function goAnnuaire(id, titre, tri, ordre, articleid, specialite, profil){
  url = '?';
  if(id == ''){
    paramId = getURLParam('id');
    if(paramId != ''){
      url += 'id='+paramId;
    }
  }
  else{
    url += 'id='+id;
  }
  
  if(titre == ''){
    paramTitre = getURLParam('titre');
    if(paramTitre!= ''){
      if(url != '?'){
        url += '&';
      }
      url += 'titre='+paramTitre;
    }
  }
  else{
    if(url != '?'){
      url += '&';
    }
    url += 'titre='+titre;
  }
  
  if(tri == ''){
    paramTri = getURLParam('tri');
    if(paramTri!= ''){
      if(url != '?'){
        url += '&';
      }
      url += 'tri='+paramTri;
    }
  }
  else{
    if(url != '?'){
      url += '&';
    }
    url += 'tri='+tri;
  }
  
  if(ordre == ''){
    paramOrdre = getURLParam('ordre');
    if(paramOrdre!= ''){
      if(url != '?'){
        url += '&';
      }
      url += 'ordre='+paramOrdre;
    }
  }
  else{
    if(url != '?'){
      url += '&';
    }
    url += 'ordre='+ordre;
  }
  
  if(articleid == ''){
    paramArticleid = getURLParam('articleid');
    if(paramArticleid!= ''){
      if(url != '?'){
        url += '&';
      }
      url += 'articleid='+paramArticleid;
    }
  }
  else{
    if(url != '?'){
      url += '&';
    }
    url += 'articleid='+articleid;
  }
  
  if(specialite == ''){
    paramSpecialiete = getURLParam('specialite');
    if(paramSpecialiete!= ''){
      if(url != '?'){
        url += '&';
      }
      url += 'specialite='+paramSpecialiete;
    }
  }
  else{
    if(url != '?'){
      url += '&';
    }
    url += 'specialite='+specialite;
  }
  
  if(profil == ''){
    paramTitre = getURLParam('profil');
    if(paramTitre!= ''){
      if(url != '?'){
        url += '&';
      }
      url += 'profil='+paramTitre;
    }
  }
  else{
    if(url != '?'){
      url += '&';
    }
    url += 'profil='+profil;
  }
  
  
  
  
  morceauxUrl = document.location.pathname.split("/");
    
  
  document.location.href = morceauxUrl[morceauxUrl.length - 1] + url;
}

function saveMail(id){
  document.getElementById('id').value = id;
  document.getElementById('objet').value = document.getElementById('objet_'+id).value;
  document.getElementById('corps').value = document.getElementById('corps_'+id).value;
  
  document.getElementById('formulaire').submit();
}

function visibiliteRubrique(){
  if(document.getElementById('statutRevision').value == 1406){
    document.getElementById('choixRubrique').style.visibility = 'visible';
    document.getElementById('choixRubrique').style.display = 'block';
  }
  else{
    document.getElementById('choixRubrique').style.visibility = 'hidden';
    document.getElementById('choixRubrique').style.display = 'none';
  }
}
