function loadXMLDoc(url) {
  if (window.XMLHttpRequest) {
     req = new XMLHttpRequest();
     req.onreadystatechange = processReqChange;
     req.open("GET", url, true);
     req.send(null);
  } else if (window.ActiveXObject) {
     isIE = true;
     req = new ActiveXObject("Microsoft.XMLHTTP");
     if (req) {
         req.onreadystatechange = processReqChange;
         req.open("GET", url, true);
         req.send();
     }
  }
}

function afficheCommentaires(evt) {
  evt = (evt) ? evt : ((window.event) ? window.event : null);
  if (evt) {
    try {
      url='commentaires.php?ean='+ean+'&type='+typeArticle;
      loadXMLDocCommentaires(url);
    } catch(e) {
      var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
      alert("Unable to get XML data:\n" + msg);
      return;
    }
  }
}

function afficheDetails(evt) {
  evt = (evt) ? evt : ((window.event) ? window.event : null);
  if (evt) {
    try {
      url='detail.php?ean='+ean+'&type='+typeArticle;
      loadXMLDoc(url);
    } catch(e) {
      var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
      alert("Unable to get XML data:\n" + msg);
      return;
    }
  }
}
function afficheDetailsFamille(evt) {
  evt = (evt) ? evt : ((window.event) ? window.event : null);
  if (evt) {
    try {
      url='detail_famille.php?ean='+ean;
      loadXMLDocFamille(url);
    } catch(e) {
      var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
      alert("Unable to get XML data:\n" + msg);
      return;
    }
  }
}

function loadXMLDocFamille(url) {
  if (window.XMLHttpRequest) {
     req = new XMLHttpRequest();
     req.onreadystatechange = processReqChangeFamille;
     req.open("GET", url, true);
     req.send(null);
  } else if (window.ActiveXObject) {
     isIE = true;
     req = new ActiveXObject("Microsoft.XMLHTTP");
     if (req) {
         req.onreadystatechange = processReqChangeFamille;
         req.open("GET", url, true);
         req.send();
     }
  }
}

function loadXMLDocCommentaires(url) {
  if (window.XMLHttpRequest) {
     req = new XMLHttpRequest();
     req.onreadystatechange = processReqChangeCommentaires;
     req.open("GET", url, true);
     req.send(null);
  } else if (window.ActiveXObject) {
     isIE = true;
     req = new ActiveXObject("Microsoft.XMLHTTP");
     if (req) {
         req.onreadystatechange = processReqChangeCommentaires;
         req.open("GET", url, true);
         req.send();
     }
  }
}
function masqueDetails() {
  tmp='details_'+ean;
  div = document.getElementById(tmp);
  div.innerHTML = "";
  tmp='commande_detail_'+ean;
  div = document.getElementById(tmp);
  div.innerHTML = '';
  texte="<a href=\"#\" onClick=\"javascript:ean='"+ean+"';typeArticle='"+typeArticle+"';afficheDetails(event);return false;\" title=\"Voir la fiche complète\" alt=\"Voir la fiche complète\"><img src=\"/img/b_afficher_detail_"+typeArticle+".png\" border=\"0\"></a>";
  div.innerHTML =texte;
}

function masqueCommentaires() {
  tmp='comm_'+ean;
  div = document.getElementById(tmp);
  div.innerHTML = "";
  tmp='commande_comm_'+ean;
  div = document.getElementById(tmp);
  div.innerHTML = '';
  texte="<a href=\"#\" onClick=\"ean='"+ean+"';typeArticle='"+typeArticle+"';afficheCommentaires(event);return false;\" title=\"Afficher les commentaires\" alt=\"Afficher les commentaires\" class=\"produitlientexte\">Afficher les commentaires</a>";
  div.innerHTML =texte;
}


function processReqChange() {
  if (req.readyState == 4) {
    if (req.status == 200) {
  //    if (typeArticle=='1') {
  //      tmp='description_'+ean;
  //    } else {
        tmp='details_'+ean;
  //    }
      div = document.getElementById(tmp);
      div.innerHTML = "";

      div.innerHTML = req.responseText;
      tmp='commande_detail_'+ean;
      div = document.getElementById(tmp);
      div.innerHTML = "";
      texte="<a href=\"#\" onClick=\"javascript:ean='"+ean+"';typeArticle='"+typeArticle+"';masqueDetails();return false;\" title=\"Masquer la fiche\" alt=\"Masquer la fiche\"><img src=\"/img/b_masquer_detail_"+typeArticle+".png\" border=\"0\"></a>";
      div.innerHTML =texte;
    } else {
      alert("There was a problem retrieving the XML data:\n" + req.statusText);
    }
  }
}
function processReqChangeCommentaires() {
  if (req.readyState == 4) {
    if (req.status == 200) {
      tmp='comm_'+ean;
      div = document.getElementById(tmp);
      div.innerHTML = "";
      div.innerHTML = req.responseText;
      tmp='commande_comm_'+ean;
      div = document.getElementById(tmp);
      div.innerHTML = "";
      texte="<a href=\"#\" onClick=\"javascript:ean='"+ean+"';typeArticle='"+typeArticle+"';masqueCommentaires();return false;\" class=\"produitlientexte\" title=\"Masquer les commentaires\">Masquer les commentaires</a>";
      div.innerHTML =texte;
    } else {
      alert("There was a problem retrieving the XML data:\n" + req.statusText);
    }
  }
}

function processReqChangeFamille() {
  if (req.readyState == 4) {
    if (req.status == 200) {
      tmp='famille_'+familleId;

      div = document.getElementById(tmp);
      div.innerHTML = "";
      div.innerHTML = req.responseText;
//      tmp='commande_detail_'+ean;
//      div = document.getElementById(tmp);
//      div.innerHTML = "";
//      texte="<a href=\"#\" onClick=\"javascript:ean='"+ean+"';typeArticle='"+typeArticle+"';masqueDetails()\" title=\"Masquer la fiche\" alt=\"Masquer la fiche\"><img src=\"/img/ar.up.gif\" border=\"0\"></a>&nbsp;&nbsp;";
//      div.innerHTML =texte;
    } else {
      alert("There was a problem retrieving the XML data:\n" + req.statusText);
    }
  }
}

