
function Cookie(name) {
   this.name = name;
   this.value = null;
   this.expires = null;
   this.domaine = null;
   this.path = null;
   this.secure = null;
   this.remove = function() {
      var date = new Date();
      date.setFullYear(date.getFullYear() - 1);
      this.setValue(null);
      this.setExpires(date);
   };
   this.setExpires = function(date) {
      this.expires = date;
      this.save();
   };
   this.setDomaine = function(domaine) {
      this.domaine = domaine;
      this.save();
   };
   this.setPath = function(path) {
      this.path = path;
      this.save();
   };
   this.setSecure = function(isSecure) {
      this.secure = isSecure;
      this.save();
   };
   this.setValue = function(value, index) {
      if(index) {
         var values = getValue();
         values[index] = value;
         this.value = values;
      }
      else {
         this.value = value;
      }
      this.save();
   };
   this.getValue = function(index) {
      //on récupère la liste des paires de valeurs
      var cookies = document.cookie.split("; ");
      for(var i = 0; i < cookies.length; i++) {
         var theCookie = cookies[i].split("=");
         if(theCookie[0] == this.getName()) {
            if(index) {
               var values = theCookie[1].split(",");
               return values[index];
            }
            else {
               return theCookie[1];
            }
         }
      }
      return null;
   };
   this.setName = function(name) {
      var oldValue = this.getAttribute();
      this.remove();
      this.name = name;
      this.setAttribute(oldValue);
   };
   this.getName = function() {
      return this.name;
   };
   this.save = function() {
      document.cookie = this.name + "=" + this.value +(this.expires ? "; expires=" + this.expires.toGMTString() : "") +(this.path ? "; path=" + this.path : "") +(this.domain ? "; domain=" + this.domain : "") +(this.secure ? "; secure" : "");
   };
}
Cookie.getList = function() {
   var cookies = document.cookie.split("; ");
   var cookiesArray = new Array();
   for(var i = 0; i < cookies.length; i++) {
      var theCookie = cookies[i].split("=");
      var cookieObj = new Cookie(theCookie[0]);
      cookiesArray.push(cookieObj);
   }
   return cookiesArray;
};
Cookie.getByName = function(name) {
   var cookies = Cookie.getList();
   for(var i = 0; i < cookies.length; i++) {
      if(cookies[i].getName() == name) {
         return cookies[i];
      }
   }
   return null;
};
