 

      //TODO : mettre un controle sur la crois de fermeture des popups modales : voir le source de hidePopupWin pour ça

      //TODO : enlever initPopup de la lib JS, car ça ne sert a rien d'initialiser la popup modale si l'on en n'a pas besoin
      // donc mettre l'initialisation dans cette jsp


      var cartWindow = null;

      // Envoi a la servlet ajax des parametres, le lancement se fait par un listener sur le bouton, donc on simule
      // un clic sur le bouton pour lancer la requete
      function sendCartRequest(type, mediaId) {
        document.getElementById("cartType").value = type;
        document.getElementById("cartMediaId").value = mediaId;
        if (document.getElementById("cartWindowSelect"))
          document.getElementById("cartSelectId").value = document.getElementById("cartWindowSelect").value;
        document.getElementById("cartHandlerButton").click();
      }

      function sendCartUsageRequest(type, mediaId, selectedElt) {
        //alert("dans sendCartUsageRequest 1");
        document.getElementById("cartType").value = type;
        document.getElementById("cartMediaId").value = mediaId;
        document.getElementById("cartSelectId").value = selectedElt;
        document.getElementById("cartHandlerButton").click();
      }

      function sendCalculPriceRequest(select_usage, select_printing, select_format, select_spread, select_period) {
        document.getElementById("cartType").value = "calculPrice";
        document.getElementById("select_usage").value = select_usage;
        document.getElementById("select_printing").value = select_printing;
        document.getElementById("select_format").value = select_format;
        document.getElementById("select_spread").value = select_spread;
        document.getElementById("select_period").value = select_period;
        document.getElementById("cartHandlerButton").click();
      }

      function sendCancelCartRequest(mediaId) {
        sendCartRequest("cancel", mediaId);
      }

      // Recuperation du 1er fils du noeud donné, de la classe donnée
      function getChildByClassName(tag, className) {
          if (tag.className == className) {
              return tag;
          }
          else if (tag.hasChildNodes()) {
              for (var i = 0; i < tag.childNodes.length; i++) {
                  var child = getChildByClassName(tag.childNodes[i], className);
                  if (child != null)
                      return child;
              }
          }
          return null;

      }

      // Fonction lancee par la servlet, afin d'afficher une nouvelle fenetre
      function changeCartWindow(type, mediaId, previousSummary, selectContent ) {
        // On injecte dans l'innerHTML de la popup l'innerHTML statique correspondant a la fenetre a afficher
        getCartWindow().innerHTML = document.getElementById("cartWindow_" + type).innerHTML;

        /*** Creation du Summary ***/
       /* if (previousSummary != "") {
          var tab = convertIntoArray(previousSummary);

          var content = "<ul>";
          for (var i=0;i<tab.length;i++) {
            content += "<li><b>" + tab[i][0]+ '</b> : ' +tab[i][1] + "</li>";
          }
          content += "</ul>";

          var summaryDiv = getChildByClassName(getCartWindow(), "summaryContainer");

          // Injection du sumarry dans le bon div
          if (summaryDiv) {
            summaryDiv.innerHTML = content;
          }
        }*/

        /*** Creation du select ***/
       // var selectTag = getChildByClassName(getCartWindow(), "selectContainer");
         var selectTag = getChildByClassName(document.getElementById("cartWindow_"+type), "selectContainer");

        // Injection d'une nouvelle balise select dans le selectContainer (on ne peut pas injecter directement des
        // options dans le select sous IE7).

        //alert("dans changeCartWindow, cartWindowSelect_usage = " + document.getElementById("cartWindowSelect_usage") + ", cartWindowSelect_usage.value = " + document.getElementById("cartWindowSelect_usage").value);

        idSelect = "cartWindowSelect_" + type;
        if (selectTag) {
          if ((document.getElementById("cartWindowSelect_usage") == null) || (document.getElementById("cartWindowSelect_usage").value == "NULL")){
            selectTag.innerHTML = "<select disabled='true' onchange='calculPrice()' class='selectChoice' id='" + idSelect + "' name='" + idSelect + "'>" + selectContent + "</select>";
          }else{
            selectTag.innerHTML = "<select onchange='calculPrice()' class='selectChoice' id='" + idSelect + "' name='" + idSelect + "'>" + selectContent + "</select>";
          }
        }
        //showPopWin(null);

        // Assignation de l'action associee au bouton valider de la fenetre
       /* var validateTag = getChildByClassName(getCartWindow(), "validateButton");
        if (validateTag) {
          validateTag.onclick = function() {
            sendCartRequest(type, mediaId);
            hidePopWin(null);
          }
        }

        // Assignation de l'action associee au bouton cancel de la fenetre
        var cancelTag = getChildByClassName(getCartWindow(), "cancelButton");
        if (cancelTag) {
          cancelTag.onclick = function() {
            sendCancelCartRequest(mediaId);
            hidePopWin(null);
          }
        }*/
      }

      function convertIntoArray(summary) {
        var parts = summary.split(";");
        var size = parts.length-1;
        var tab = new Array(size);
        for (var i=0;i<tab.length;i++) {
          var temp = parts[i].substring(1,parts[i].length-1);
          var res = temp.split(",");
          tab[i] = new Array(2);
          if (res != null) {
            tab[i][0] = res[0];
            tab[i][1] = res[1];
          }
        }
        return tab;
      }



      function getCartWindow() {
        return document.getElementById("cartWindow");
/*        if (cartWindow == null) {
          var parentTag = document.getElementById("pageContent");
          if (!parentTag)
            parentTag = document.getElementsByTagName("body")[0];
          cartWindow = document.createElement('div');
          parentTag.appendChild(cartWindow);
          cartWindow.id = "cartWindow";
          cartWindow.style.display = "block";
        }
        return cartWindow;*/
      }

  /*function addToFolder(obj) {
    document.getElementById('action').name='<pegahtml:button name="addToFolder" nameOnly="true" actionName="addToFolder"/>';
    document.getElementById('selectedIndex').value=obj;
    document.getElementById('media').submit();
    return true;
  }    */


   function deleteMedia() {
    document.getElementById('action').name='<pegahtml:button name="deleteFromFolder" nameOnly="true" actionName="deleteFromFolder" />';
    document.getElementById('media').submit();
    return true;
  }

  function copyMedia() {
    document.getElementById('action').name='<pegahtml:button name="copyFromFolder" nameOnly="true" actionName="copyFromFolder" />';
    document.getElementById('media').submit();
    return true;
  }

  function pasteMedia() {
    document.getElementById('action').name='<pegahtml:button name="pasteToFolder" nameOnly="true" actionName="pasteToFolder" />';
    document.getElementById('media').submit();
    return true;
  }
