function XMLtoHTML(chaine) //Permet d'interpréter le HTML
{
    chaine=chaine.replace(/&amp;/g,"&");
    chaine=chaine.replace(/&lt;/g,"<");
    chaine=chaine.replace(/&gt;/g,">");
    return chaine;
}
function compteVuAjaxProduit(id_produit)
{
     var xmlhttp = getHTTPObject();

    xmlhttp.open('GET', 'xml_produit_vu.php?id_produit='+id_produit, true);
    xmlhttp.onreadystatechange = function()
    {

        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
            {
             // On ne fait rien
            }
        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);
//
}

function afficheAutrePageRubrique(rubrique,debut,marque,famille_attribut,attribut,mode_affichage,mobilite_reduite)
{

     var xmlhttp = getHTTPObject();

     // On ferme les fiches produits ouvertes
      for(i=1;i<=12;i++)  //Cas ou affichage par 12
       {
          if(document.getElementById('divProduit'+i)!=null)
          {
             document.getElementById('divProduit'+i).style.display="none";
             document.getElementById('divProduit'+i).style.visibility="hidden";
          }
       }

       if(document.getElementById('divProduit')!=null) //Différenciation chargement Ajax et Affichage/Masquage Div
       {
           //Sur que la fiche préchargé de base n'est pas visible
           document.getElementById('divProduit').style.display="none";
           document.getElementById('divProduit').style.visibility="hidden";
       }

    xmlhttp.open('GET', 'xml_recharge_rubrique.php?rubrique='+rubrique+"&debut="+debut+"&marque="+marque+"&famille_attribut="+famille_attribut+"&attribut_choisi="+attribut+"&mode_affichage="+mode_affichage+"&mobilite_reduite="+mobilite_reduite, true);
    /* The callback function */
    xmlhttp.onreadystatechange = function()
    {

        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
                afficheAutrePageRubriqueNow(xmlhttp.responseXML,rubrique,debut,marque,famille_attribut,attribut,mode_affichage,mobilite_reduite);

        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  //  alert("rubrique="+rubrique+"&debut="+debut+"&marque="+marque+"&famille_attribut="+famille_attribut+"&attribut_choisi="+attribut+"&mode_affichage="+mode_affichage);
    xmlhttp.send(null);
//

//   alert("xml_recharge_rubrique.php?rubrique="+rubrique+"&debut="+debut+"&marque="+marque+"&famille_attribut="+famille_attribut+"&attribut_choisi="+attribut+"&mode_affichage="+mode_affichage);
}
function afficheAutrePageRubriqueNow(responseXML,rubrique,debut,marque,famille_attribut,attribut,mode_affichage,mobilite_reduite)
{
    var j=0;
    var i;
    var url_retour="";
    //Commencement idem puisque que fin qui change

    url_retour='R-'+rubrique+'-';
    if(marque)
       url_retour+=marque+'-';
    else if(attribut)
       url_retour+=famille_attribut+'-'+attribut+'-';
    url_retour+='Rubrique';


    //On check les différents choix de pages et on modifie quand c'est cliqué
    for(i=0;document.getElementById('choixDebut'+(i*mode_affichage))!=null;i++)
    {
        if((i*mode_affichage)==debut)
        {
            document.getElementById('choixDebut'+(i*mode_affichage)).className='divNumPageSelect';
            document.getElementById('choixDebut'+(i*mode_affichage)).innerHTML=(i+1);

        }
        else
        {
            document.getElementById('choixDebut'+(i*mode_affichage)).className='divNumPage';
            //On ne prend pas en compte le nom de la rubrique importe peu puisqu'Ajax



            if(i==0)
               document.getElementById('choixDebut'+(i*mode_affichage)).innerHTML='<a href="'+url_retour+'.html" onClick="afficheAutrePageRubrique(\''+rubrique+'\',\''+(i*mode_affichage)+'\',\''+marque+'\',\''+famille_attribut+'\',\''+attribut+'\',\''+mode_affichage+'\',\''+mobilite_reduite+'\');return false;"  class="linkStd">'+(i+1)+'</a>';
            else
                document.getElementById('choixDebut'+(i*mode_affichage)).innerHTML='<a href="'+url_retour+','+(i*mode_affichage)+'.html" onClick="afficheAutrePageRubrique(\''+rubrique+'\',\''+(i*mode_affichage)+'\',\''+marque+'\',\''+famille_attribut+'\',\''+attribut+'\',\''+mode_affichage+'\',\''+mobilite_reduite+'\');return false;"  class="linkStd">'+(i+1)+'</a>';
        }

    }



    for(i=0;responseXML.getElementsByTagName('produit')[i]!=null;i++)
    {
        // Modifier tout les attributs de chaque fiche produit indépendante
        j=i*1+1;


        //Changements des évènements onClick
        if(mode_affichage==40)
        {
            if(responseXML.getElementsByTagName('image')[i].firstChild!=null)
            {
               document.getElementById('apercuProduit'+j).innerHTML='<a href="'+responseXML.getElementsByTagName('url')[i].firstChild.data+'" id="lienProduit'+i+'" onClick="affiche_produit(0,'+responseXML.getElementsByTagName('id')[i].firstChild.data+');return false;" onMouseOver="overlib(\'<img src='+responseXML.getElementsByTagName('imagezoom')[i].firstChild.data+'>\')" onMouseOut="nd()"><img src="'+responseXML.getElementsByTagName('image')[i].firstChild.data+'" border="0" /></a>';
            }
        }
        else
        {
            if(responseXML.getElementsByTagName('marque')[i].getAttribute('nom')!=null)
               document.getElementById('nomMarque'+j).innerHTML=responseXML.getElementsByTagName('marque')[i].getAttribute('nom');
//            alert(document.getElementById('logoMarque'+j));
            if(responseXML.getElementsByTagName('marque')[i].getAttribute('logo')!=null)
               document.getElementById('logoMarque'+j).setAttribute('src',responseXML.getElementsByTagName('marque')[i].getAttribute('logo'));
//            alert('lienFiche'+j+'_1');

             if(responseXML.getElementsByTagName('mobilitereduite')[i].firstChild!=null
               && responseXML.getElementsByTagName('mobilitereduite')[i].firstChild.data=='oui')
             {
                  mobilite_reduite='<div class="mobilite_reduite"><img src="/images/logo-mobilite-reduite.gif"></div>';
             }
             else
                 mobilite_reduite='';



            if(mode_affichage==6)
               document.getElementById('lienFiche'+j+'_1').innerHTML='<a href="#" onClick="affiche_produit(0,'+responseXML.getElementsByTagName('id')[i].firstChild.data+');return false;"><img id="imageProduit'+i+'" src="'+responseXML.getElementsByTagName('image')[i].firstChild.data+'" alt="" width="205" height="205" border="0" /></a>'+mobilite_reduite;
            else
               document.getElementById('lienFiche'+j+'_1').innerHTML='<a href="#" onClick="affiche_produit(0,'+responseXML.getElementsByTagName('id')[i].firstChild.data+');return false;"><img id="imageProduit'+i+'" src="'+responseXML.getElementsByTagName('image')[i].firstChild.data+'" alt="" width="155" height="155" border="0" /></a>'+mobilite_reduite;
                document.getElementById('lienFiche'+j+'_2').innerHTML='<a href="#" onClick="affiche_produit(0,'+responseXML.getElementsByTagName('id')[i].firstChild.data+');return false;">Fiche produit</a>';

            if(responseXML.getElementsByTagName('sous_titre')[i].firstChild)
                document.getElementById('lienFiche'+j+'_1').innerHTML+='<p id="sousTitreProduit'+i+'">'+XMLtoHTML(responseXML.getElementsByTagName('sous_titre')[i].firstChild.data)+'</p>';
            else
                document.getElementById('lienFiche'+j+'_1').innerHTML+='<p id="sousTitreProduit'+i+'"></p>';
                //Changement des données
                //Avec création du lien
                document.getElementById('titreProduit'+j).innerHTML='<a href="#" id="lienProduit'+i+'" onClick="affiche_produit(0,'+responseXML.getElementsByTagName('id')[i].firstChild.data+');return false;">'+XMLtoHTML(responseXML.getElementsByTagName('titre')[i].firstChild.data)+'</a>';
               //<a href="<?=$page_produit?>"  <?if(!$mode_edit) echo "onClick=\"affiche_produit($i,'$i');return false;\"";?>><?=$titre_produit?></a>
               //        document.getElementById('sousTitreProduit'+j).innerHTML=;
            if(responseXML.getElementsByTagName('prix_indicatif')[i].firstChild && responseXML.getElementsByTagName('prix_indicatif')[i].firstChild.data>0)
                document.getElementById('prixIndicatif'+j).innerHTML=responseXML.getElementsByTagName('prix_indicatif')[i].firstChild.data+"&euro;";
            else
                document.getElementById('prixIndicatif'+j).innerHTML="";


        }
        document.getElementById('apercuProduit'+j).style.display="block";
        document.getElementById('apercuProduit'+j).style.visibility="visible";

    }
    i++;

    //On cache les divs si en fin de listing
    while(document.getElementById('apercuProduit'+i)!=null)
    {

          document.getElementById('apercuProduit'+i).style.display="none";
          document.getElementById('apercuProduit'+i).style.visibility="hidden";
          i++;
    }

    document.getElementById('lienProduit0').focus();



}
function afficheAjaxProduit(id_produit)
{

     var xmlhttp = getHTTPObject();

    xmlhttp.open('GET', 'xml_recharge_produit.php?id_produit='+id_produit, true);
    //alert('appel 2');
    /* The callback function */
    xmlhttp.onreadystatechange = function()
    {

        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
                afficheAjaxProduitNow(xmlhttp.responseXML,id_produit);

        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);

}
function afficheAjaxProduitNow(responseXML,id_produit)
{
     if(responseXML.getElementsByTagName('image')[0].firstChild!=null)
        document.getElementById('logoMarque').src=responseXML.getElementsByTagName('image')[0].firstChild.data;
     else
        document.getElementById('logoMarque').src="/images/rien5.gif";



      //alert(responseXML.getElementsByTagName('titre')[0].firstChild.data);
      if(responseXML.getElementsByTagName('titre')[0].firstChild!=null)
         document.getElementById('titreProduit').innerHTML=responseXML.getElementsByTagName('titre')[0].firstChild.data;
      else
         document.getElementById('titreProduit').innerHTML="";
      //Modifie le résumé
      if(responseXML.getElementsByTagName('resume')[0].firstChild!=null)
         document.getElementById('resumeProduit').innerHTML=responseXML.getElementsByTagName('resume')[0].firstChild.data;
      else
         document.getElementById('resumeProduit').innerHTML="";
      //Modifie le prix
      if(responseXML.getElementsByTagName('prix')[0].firstChild!=null && responseXML.getElementsByTagName('prix')[0].firstChild.data>0)
         document.getElementById('prixProduit').innerHTML=XMLtoHTML(responseXML.getElementsByTagName('prix')[0].firstChild.data)+"&nbsp;&euro;";
      else
         document.getElementById('prixProduit').innerHTML="";

      document.getElementById('titreFicheProd').innerHTML=responseXML.getElementsByTagName('titre')[0].firstChild.data;
      //Modifie le texte de description
//      alert(responseXML.getElementsByTagName('description')[0].firstChild.data);
      if(responseXML.getElementsByTagName('description')[0].firstChild!=null)
         document.getElementById('descriptifProduit').innerHTML=XMLtoHTML(responseXML.getElementsByTagName('description')[0].firstChild.data);
      else
         document.getElementById('descriptifProduit').innerHTML="";
      //Modifie le visuel du produit
      if(responseXML.getElementsByTagName('photo')[0].firstChild!=null)
         document.getElementById('imageProduit').src=responseXML.getElementsByTagName('photo')[0].firstChild.data;
      else
         document.getElementById('imageProduit').src="images/rien5.gif";

      if(responseXML.getElementsByTagName('mobilitereduite')[0].firstChild!=null &&
      responseXML.getElementsByTagName('mobilitereduite')[0].firstChild.data=='oui'
      && document.getElementById('divImageMobRdivProduit')!=null)
         document.getElementById('divImageMobRdivProduit').innerHTML="<img src='/images/logo-mobilite-reduite.gif'>";
      else if( document.getElementById('divImageMobRdivProduit')!=null)
         document.getElementById('divImageMobRdivProduit').innerHTML="";

      if(document.getElementById('ajoutPanier')) // Apercu hors ma sélection
         document.getElementById('ajoutPanier').innerHTML='<a href="ajouter_produit.php?id='+responseXML.getElementsByTagName('id')[0].firstChild.data+'" onClick="window.open(\'ajouter_produit.php?id='+responseXML.getElementsByTagName('id')[0].firstChild.data+'\',\'_blank\',\'toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, left=0, top=0\');return false;" target="_blank"><img src="images/btAjouterAMaSelection.gif" width="150" height="16" border="0" /></a>';
      if(responseXML.getElementsByTagName('modecollectivite')[0]!=null && responseXML.getElementsByTagName('modecollectivite')[0].firstChild!=null
      && responseXML.getElementsByTagName('modecollectivite')[0].firstChild.data==1)
      {
          if(responseXML.getElementsByTagName('collection')[0].firstChild!=null)
          {
             document.getElementById('dsLaMemeCollection').innerHTML=XMLtoHTML(responseXML.getElementsByTagName('collection')[0].firstChild.data);
             document.getElementById('imgDsMmCollection').setAttribute('src','/images/t_dans_la_meme_collection-vert.gif');
          }
          else
          {
              document.getElementById('dsLaMemeCollection').innerHTML="";
              document.getElementById('imgDsMmCollection').setAttribute('src','/images/bg_dans_la_meme_collection-vert.gif');
          }
      }
      else
      {
         if(responseXML.getElementsByTagName('collection')[0].firstChild!=null)
          {
             document.getElementById('dsLaMemeCollection').innerHTML=XMLtoHTML(responseXML.getElementsByTagName('collection')[0].firstChild.data);
             document.getElementById('imgDsMmCollection').setAttribute('src','/images/t_dans_la_meme_collection.gif');
          }
          else
          {
              document.getElementById('dsLaMemeCollection').innerHTML="";
              document.getElementById('imgDsMmCollection').setAttribute('src','/images/bg_dans_la_meme_collection.gif');
          }
      }

      document.getElementById('imprimerMailAddr').innerHTML=XMLtoHTML(responseXML.getElementsByTagName('liensimprimerenvoi')[0].firstChild.data);


      //Modifie les liens vers les popups
     /* document.getElementById('imageProduitZoom1').setAttribute('href',"#");
      document.getElementById('imageProduitZoom2').setAttribute('href',"#");
       */
      document.getElementById('imageProduitZoom1').setAttribute('target',"_self");
      document.getElementById('imageProduitZoom2').setAttribute('target',"_self");

      document.getElementById('imageProduitZoom1').setAttribute('href',"javascript:PopupImage('"+responseXML.getElementsByTagName('photoZoom')[0].firstChild.data+"');");
      document.getElementById('imageProduitZoom2').setAttribute('href',"javascript:PopupImage('"+responseXML.getElementsByTagName('photoZoom')[0].firstChild.data+"');");


}
function getNbreArticlesSelection()
{
     var xmlhttp = getHTTPObject();
    xmlhttp.open('GET', 'xml_recharge_selection.php', true);
   // alert('appel 2');
    /* The callback function */
    xmlhttp.onreadystatechange = function()
   {
        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
                getNbreArticlesSelectionNow(xmlhttp.responseXML);
        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);

}
function getNbreArticlesSelectionNow(responseXML)
{
         document.getElementById('maSelectionInfos').innerHTML=XMLtoHTML(responseXML.getElementsByTagName('nbre')[0].firstChild.data);

}
function afficheClassAttributs(indice,rubrique,produit)
{
      var xmlhttp = getHTTPObject();

    xmlhttp.open('GET', 'xml_recharge_attributs.php?rubrique='+rubrique+"&produit="+produit, true);
   // alert('appel 2');
    /* The callback function */
    xmlhttp.onreadystatechange = function()
   {
        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
                afficheClassAttributsNow(xmlhttp.responseXML,indice,rubrique);
        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);
}
function afficheClassAttributsNow(responseXML,indice,rubrique)
{
//     alert(rubrique);
     var chaine="";
     if(document.getElementById('class_attributs_'+indice)==null)
     {
        //Création de la div
         document.getElementById('class_attributs').innerHTML+="<div id='class_attributs_"+indice+"'></div>";
     }
     var cible=document.getElementById('class_attributs_'+indice);
     var famille=null;
     var selected="";

     chaine="<fieldset><legend>Classes d'attributs : "+responseXML.getElementsByTagName('rubrique')[0].getAttribute('titre')+"</legend>";

     for(i=0;responseXML.getElementsByTagName('famille_attributs')[i]!=null;i++)
     {
         famille=responseXML.getElementsByTagName('famille_attributs')[i];
         chaine+="Choix par "+famille.getAttribute('titre')+" : ";

         for(j=0;responseXML.getElementsByTagName('attribut'+i)[j]!=null;j++)
         {
             attribut=responseXML.getElementsByTagName('attribut'+i)[j];

             if(attribut.getAttribute('selected')=="1")
                selected=" checked='checked' ";
             else
                selected="";

             chaine+=" <input type='checkbox' name='attribut_"+famille.getAttribute('id')+"_"+attribut.getAttribute('id')+"' value='1' "+selected+">&nbsp;"+attribut.firstChild.data;
         }
         chaine+="<br />";
     }
     chaine+="</fieldset>";
     cible.innerHTML=chaine;
}
function rechargeMarques()
{
        var xmlhttp = getHTTPObject();

    xmlhttp.open('GET', 'xml_recharge_marques.php', true);
   // alert('appel 2');
    /* The callback function */
    xmlhttp.onreadystatechange = function()
   {
        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
                rechargeMarquesNow(xmlhttp.responseXML);
        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);
}
function rechargeMarquesNow(responseXML)
{
    var select=document.getElementById('marque');
    var o=null;
    select.options.length=0;
    o=new Option("Aucune marque",0);
    select.options[select.options.length]=o;

    for(i=0;responseXML.getElementsByTagName('marque')[i]!=null;i++)
    {
        o=new Option(responseXML.getElementsByTagName('marque')[i].getAttribute('titre'),responseXML.getElementsByTagName('marque')[i].getAttribute('id'));
        select.options[select.options.length]=o;
    }
}
function rechargeProduitsVoir(id,id_rubrique,id_prod)
{
        var xmlhttp = getHTTPObject();

    xmlhttp.open('GET', '/xml_recharge_produits.php?rubrique='+id_rubrique, true);
   // alert('appel 2');
    /* The callback function */
    xmlhttp.onreadystatechange = function()
   {
        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
            {
                //alert(id_prod);
                if(id_prod==null)
                {
                    for(j=1;document.getElementById('select_produit_'+id+'_'+j)!=null;j++)
                    {
                     //alert(j);
                            rechargeProduitsVoirNow(xmlhttp.responseXML,id,id_rubrique,j);
                    }
                    //alert(document.getElementById('select_produit_'+id+'_'+j)+" "+j);
                }
                else
                {
                    //alert(id_prod);
                    rechargeProduitsVoirNow(xmlhttp.responseXML,id,id_rubrique,id_prod);
                }
            }
        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);
}
 function rechargeProduitsVoirNow(responseXML,indice_rub,id_rubrique,id_prod)
{
    //alert(indice_rub+" "+id_prod);
    var select=document.getElementById("select_produit_"+indice_rub+"_"+id_prod);
    var o=null;
    select.options.length=0;
    o=new Option("Produits affichés au hasard",0);
    select.options[select.options.length]=o;

    for(i=0;responseXML.getElementsByTagName('produit')[i]!=null;i++)
    {
        o=new Option(responseXML.getElementsByTagName('produit')[i].getAttribute('titre'),responseXML.getElementsByTagName('produit')[i].getAttribute('id'));
        select.options[select.options.length]=o;
    }
}
function rechargeCollections()
{
        var xmlhttp = getHTTPObject();

    xmlhttp.open('GET', 'xml_recharge_collections.php', true);
   // alert('appel 2');
    /* The callback function */
    xmlhttp.onreadystatechange = function()
   {
        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
                rechargeCollectionsNow(xmlhttp.responseXML);
        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);
}
function rechargeCollectionsNow(responseXML)
{
    var select=document.getElementById('collection');
    var o=null;
    select.options.length=0;
    o=new Option("Aucune collection",0);
    select.options[select.options.length]=o;

    for(i=0;responseXML.getElementsByTagName('collection')[i]!=null;i++)
    {
        o=new Option(responseXML.getElementsByTagName('collection')[i].getAttribute('titre'),responseXML.getElementsByTagName('collection')[i].getAttribute('id'));
        select.options[select.options.length]=o;
    }
}
function aff_magasin(insee)
{

        var xmlhttp = getHTTPObject();
    //alert(insee);
    xmlhttp.open('GET', 'xml_charge_magasin_insee.php?insee='+insee, true);
   // alert('appel 2');
    /* The callback function */
    xmlhttp.onreadystatechange = function()
   {
        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
                aff_magasin_now(xmlhttp.responseXML);
        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);

}
function aff_magasin_now(responseXML)
{
      //alert("retour");
      var contenu_html="";
//      alert(responseXML.getElementsByTagName('magasinproche')[0].firstChild);


      //alert(contenu_html);
      if(responseXML.getElementsByTagName('autresmagasins')[0].firstChild!=null)//Il y a d'autres magasins
      {
          contenu_html+="<br/>Les dépôts aux alentours : <br/>";

          //COmmence à 1 à cause du magasin proche
//          alert(responseXML.getElementsByTagName('magasin')[1]);
          for(i=0;responseXML.getElementsByTagName('magasin')[i]!=null;i++)
          {

                  if(i%2)
                     contenu_html+="<div class='fondGF'>";
                  else
                     contenu_html+="<div class='fondGC'>";
                  contenu_html+="<a href='#' onclick='rechargeMagasin("+responseXML.getElementsByTagName('id')[i].firstChild.data+");return false;'><b>"+responseXML.getElementsByTagName('depot')[i].firstChild.data+"</b> - "+responseXML.getElementsByTagName('ville')[i].firstChild.data+"</a>"
                  contenu_html+="</div>";

          }
      }
      if(i==1)//C à d une seule réponse on affiche direct le résultat
      {
          rechargeMagasin(responseXML.getElementsByTagName('id')[0].firstChild.data);

      }

      //alert(contenu_html);
      document.getElementById('moduleRecherche').innerHTML=contenu_html;

}




function rechercheAjaxMagasins()
{
    
    var cp=document.getElementById('cp').value;
    var xmlhttp = getHTTPObject();

    xmlhttp.open('GET', 'xml_recherche_magasins.php?cp='+cp, true);

    /* The callback function */
    xmlhttp.onreadystatechange = function()
   {
        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
               
               // alert(xmlhttp.response);
               rechercheAjaxMagasinsNow(xmlhttp.responseXML,cp);
        }
    }

/*     Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);
}


function rechercheAjaxMagasinsNow(responseXML,cp)
{
      //alert("retour");
      var contenu_html="";
      var init=1;
//      alert(responseXML.getElementsByTagName('magasinproche')[0].firstChild);
      if(cp.length>=3 && responseXML.getElementsByTagName('magasinproche')!=null && responseXML.getElementsByTagName('magasinproche')[0].firstChild!=null )//Il y a un magasin proche
      {
          contenu_html+="<br/><b>Le dépôt le plus proche de chez vous est :</b><br/>";

          contenu_html+="<div class='fondGC'>";
          contenu_html+="<a href='#' onclick=\"rechargeMagasin("+responseXML.getElementsByTagName('id')[0].firstChild.data+");return false;\"><b>"+responseXML.getElementsByTagName('depot')[0].firstChild.data+"</b> - "+responseXML.getElementsByTagName('ville')[0].firstChild.data+"</a>"
          contenu_html+="</div>";
      }
      else if(cp.length<3)
      {
          contenu_html+="<br/><b>Les dépôts dans votre département sont :</b><br/>";
      }
      else
      {
          contenu_html+="<br/><font color='red'><b>Aucun dépôt près de chez vous.</b></font><br/>";

      }

      //alert(contenu_html);
      if(responseXML.getElementsByTagName('autresmagasins')[0].firstChild!=null)//Il y a d'autres magasins
      {
          if(cp.length>=3)
             contenu_html+="<br/>Autres dépôts aux alentours de chez vous : <br/>";
          else
             init=0;

          //COmmence à 1 à cause du magasin proche
//          alert(responseXML.getElementsByTagName('magasin')[1]);
          for(i=init;responseXML.getElementsByTagName('magasin')[i]!=null;i++)
          {

                  if(i%2)
                     contenu_html+="<div class='fondGF'>";
                  else
                     contenu_html+="<div class='fondGC'>";
                  contenu_html+="<a href='#' onclick=\"rechargeMagasin("+responseXML.getElementsByTagName('id')[i].firstChild.data+");;return false;\"><b>"+responseXML.getElementsByTagName('depot')[i].firstChild.data+"</b> - "+responseXML.getElementsByTagName('ville')[i].firstChild.data+"</a>"
                  contenu_html+="</div>";

          }
      }

      //alert(contenu_html);
      document.getElementById('moduleRecherche').innerHTML=contenu_html;

}

function rechargeMagasin(id_magasin)
{

    var xmlhttp = getHTTPObject();
    xmlhttp.open('GET', 'xml_recharge_magasin.php?id='+id_magasin, true);
    
   // alert('appel 2');
    // The callback function
    xmlhttp.onreadystatechange = function()
   {
        if (xmlhttp.readyState == 4)
        {
            if (xmlhttp.status == 200)
                rechargeMagasinNow(xmlhttp.responseXML);
        }
    }

//     Send the POST request
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(null);


}
function rechargeMagasinNow(responseXML)
{
  var contenu_html="";
  contenu_html+="<font class='titrePlan'>"+responseXML.getElementsByTagName('nom')[0].firstChild.data+"</font>";

  document.getElementById('titreCoordonne').innerHTML=contenu_html;

  contenu_html=responseXML.getElementsByTagName('adresse')[0].firstChild.data+"<br />";
  contenu_html+=responseXML.getElementsByTagName('cp')[0].firstChild.data+" "+responseXML.getElementsByTagName('ville')[0].firstChild.data+"<br />";
  contenu_html+=XMLtoHTML(responseXML.getElementsByTagName('telephone_fax')[0].firstChild.data)+"<br />";
  if(responseXML.getElementsByTagName('email')[0].firstChild!=null  &&
     responseXML.getElementsByTagName('email')[0].firstChild.data.length>1)
      contenu_html+="<b>Email :</b> <a href='mailto:"+responseXML.getElementsByTagName('email')[0].firstChild.data+"'>"+responseXML.getElementsByTagName('email')[0].firstChild.data+"</a><br />";
  if(responseXML.getElementsByTagName('siteinternet')[0].firstChild!=null &&
     responseXML.getElementsByTagName('siteinternet')[0].firstChild.data.length>1)
     {
      contenu_html+="<b>Site Internet :</b> <a href='"+responseXML.getElementsByTagName('siteinternet')[0].firstChild.data+"' target='_blank'>"+responseXML.getElementsByTagName('siteinternet')[0].firstChild.data+"</a>";

     }
  document.getElementById('adresseMag').innerHTML=contenu_html;
  if(responseXML.getElementsByTagName('horaires')[0].firstChild!=null)
    contenu_html=XMLtoHTML(responseXML.getElementsByTagName('horaires')[0].firstChild.data);
  else
    contenu_html="";

  document.getElementById('horaireMag').innerHTML=contenu_html;

  if(responseXML.getElementsByTagName('plan')[0].firstChild!=null)
    document.getElementById('planImg').setAttribute('src',"images/zoom/"+responseXML.getElementsByTagName('plan')[0].firstChild.data);
  else
    document.getElementById('planImg').setAttribute('src',"images/rien5.gif");
  if(responseXML.getElementsByTagName('photo')[0].firstChild!=null)
    document.getElementById('photoMag').setAttribute('src',"images/zoom/"+responseXML.getElementsByTagName('photo')[0].firstChild.data);
  else
    document.getElementById('photoMag').setAttribute('src',"images/rien5.gif");

  document.getElementById('lienImprimer').setAttribute('href',"aff_mini_magasin.php?id_magasin="+responseXML.getElementsByTagName('id')[0].firstChild.data);

  document.getElementById('cadreCoordonnee').style.visibility="visible";
  document.getElementById('cadreCoordonnee').style.display="block";
  document.getElementById('lienImprimer').focus()


}