   function getCookieInfo(dataName)
   {
      var cookieLen = dataName.length;
      var cookieData = document.cookie;
      var allcookieLen = cookieData.length;
      var i = 0;
      var cookieEnd;

      while (i < allcookieLen)
      {
         var j = i + cookieLen;
         if (cookieData.substring(i, j) == dataName)
         {
            cookieEnd = cookieData.indexOf(";", j);
            if (cookieEnd == -1)
            {
               cookieEnd = cookieData.length;
            }
            return unescape(cookieData.substring(j + 1, cookieEnd))
         }
         i++;
      }
      return "Echec : cookie non cree ?";
   }

   function ajoute(pm, name)
   {
      nb = document[pm][name].value;
      nb++;
      if (nb > 999)
      {
         nb = 999;
      }
      document[pm][name].value = nb;
   }

   function enleve(pm, name)
   {
      nb = document[pm][name].value;
      nb--;
      if (nb < 1)
      {
         nb = 1;
      }
      document[pm][name].value = nb;
   }

   function ajouter_caddie(produit, numprod, quantite, taille)
   {
      var verif = /^[0-9]+$/;
      if ((verif.exec(quantite) == null) || (quantite == 0))
      {
         alert("La quantité spécifiée est incorrecte !");
      }
      else
      {
         if (taille >= 0)
         {
            if (taille == 0)
            {
               message = 'Ajouter ' + quantite + ' fois le produit ' + produit + ' dans votre panier ?';
            }
            else
            {
               message = 'Ajouter ' + quantite + ' fois le produit ' + produit + ' de taille ' + document.getElementById('taille' + numprod).options[document.getElementById('taille' + numprod).options.selectedIndex].text + ' dans votre panier ?';
            }
            if (confirm(message))
            {
               nbart = getCookieInfo("nbarticles");
               if ((nbart > 0) && (nbart < 18))
               {
                  trouve = false;
                  for (i = 1; ((i <= nbart) && (!(trouve))); i++)
                  {
                     art = getCookieInfo("panier" + i + "");
                     q = art.substring(0, art.indexOf(':'));
                     n = q.length;
                     q = parseInt(q);
                     t = art.substring(n+1, art.indexOf(':', n + 1));
                     m = t.length;
                     t = parseInt(t);
                     m+= n;
                     m = m + 2;
                     p = art.substring((m), art.length);
                     m = p.length;
                     p = parseInt(p);
                     if ((numprod == p) && (taille == t))
                     {
                        trouve=true;
                        q+= parseInt(quantite);
                        if (q > 999)
                        {
                           q = 999;
                        }
                        document.cookie = "panier" + i + "=" + q + ":" + t + ":" + p + "";
                     }
                     document.location.href = 'caddie.php';
                  }
                  if (!(trouve))
                  {
                     nbart++;
                     document.cookie = "nbarticles=" + nbart + "";
                     document.cookie = "panier" + nbart + "=" + quantite + ":" + taille + ":" + numprod + "";
                     document.location.href = 'caddie.php';
                  }
               }
               else
               {
                  if (nbart == 18)
                  {
                     alert("Panier plein !");
                     document.location.href = 'caddie.php';
                  }
                  else
                  {
                     nbart = 1;
                     document.cookie = "nbarticles=" + nbart + "";
                     document.cookie = "panier" + nbart + "=" + quantite + ":" + taille + ":" + numprod + "";
                     document.location.href = 'caddie.php';
                  }
               }
            }
         }
         else
         {
            alert("Veuillez sélectionner une taille pour votre produit !");
         }
      }
   }
