var http = new Array();
var liste_a_remplir;
var type_noeud;
var nullVar;
function createRequestObject()
{
  if(navigator.appName == "Microsoft Internet Explorer")
  {
    try{xhr = new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){
      try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
      catch (E) {xhr = false;}}
  }
  else
  {
    try{xhr = new XMLHttpRequest();}
    catch (e){
      xhr = false;
      alert("Ce site nécessite un navigateur plus récent pour fonctionner correctement. Merci de mettre à jour votre navigateur (http://www.mozilla-europe.org)");
    }
  }
  return xhr;
}
function sndReq(id_http, action, fonction)
{
  if(http[id_http] != nullVar)
    http[id_http].abort();
  http[id_http].open('get', 'public/rpc/xml.php?action='+action, true);
  http[id_http].onreadystatechange = function()
  {
    if(http[id_http].readyState == 4)
    {
      try
      {
        if (http[id_http].status == 200)
        {
          fonction.call();
          http[id_http] = nullVar;
        }
//         else
//           alert("<?=Affichage::traduction('Erreur : réponse XML du serveur incorrecte.')?>");

      }
      catch(e){}
    }
  };
  http[id_http].send(null);
}
function setOn(id) {
  http['request'] = createRequestObject();
  sndReq('request','setOn_'+id);
}
function setOff(id) {
  http['request'] = createRequestObject();
  sndReq('request','setOff_'+id);
}
function getManifsFromLieu(id) {
  vide_liste('manifestation', true);
  http['request'] = createRequestObject();
  var tri_date = findObj('tri_date').checked;
  var tri_alpha = findObj('tri_alpha').checked;
  if(tri_alpha)
    tri = 'PL.titre';
  if(tri_date)
    tri = 'M.date_debut';
  sndReq('request','getManifsFromLieu_'+id+'_'+tri,function(){remplit_liste_manifestation('manifestation')});
}
function remplit_liste_manifestation(lstCible)
// {
//   remplit_liste('request', 'manifestation', id_liste);
// }
// function remplit_liste() //id_http, nom_noeud, liste, nom_noeud, liste,...
{
 response = http['request'].responseXML.getElementsByTagName('manifestation');
 nb = response.length;
 vide_liste(lstCible, false);
 lstCible = findObj(lstCible);
 for(i=0; i < nb; i++) {
   element = response[i];
   if(element.nodeType == 1) {
     nb_prop = element.childNodes.length;
     id = nom = '';
     for(j=0; j < nb_prop; j++) {
       prop = element.childNodes.item(j);
       if(prop.nodeType == 1) {
         if(prop.tagName == 'id')
           id = get_tag_content(prop);
         else {
           if(prop.tagName == 'nom')
             nom = get_tag_content(prop);
           //else
             //alert('tagname inconnu');
         }
       }
     }
     new_option = createElement('option');
     text=createTextNode(nom);
     new_option.appendChild(text);
     new_option.value = id;
     new_option.title = nom;
    /*if(manifestation.getAttribute('selected') && sous_rubrique.getAttribute('selected')=='selected')
            new_option.selected = true;*/
     lstCible.appendChild(new_option);
    }
  }
}
// function vide_liste(id_liste, met_chargement)
// {
//   var select = findObj(id_liste);
//   if(select.length > 0)
//     while (select.length > 0)
//     {
//       try
//         {select.remove(0);}
//       catch(e)
//         {}
//     }
//   if(met_chargement)
//   {
//     new_option = createElement('option');
//     text=createTextNode('<?=Affichage::traduction('Chargement en cours...')?>');
//     new_option.appendChild(text);
//     new_option.value = '-1';
//     select.appendChild(new_option);
//   }
// }
