/**
 *
 * Cookie manipulator.
 *
 * Author: 2v adapting sam eubank's cookies.js
 *
 */

var Cookies = {

  /**
   * Set a cookie.
   */
  set: function(name, value, days, domain, path) {
    if (days) {
      var date = new Date();
      date.setTime(days * 86400000 + date.getTime());
      var expires = '; expires=' + date.toGMTString();
    }
    else var expires = '';
    document.cookie = name + '=' + escape(value) + expires + (domain ? ";domain=" + domain : "") + ';path=' + (path ? path : '/');
  },

  /**
   * Get a cookie.
   */
  get: function(name) {
    var nameEquals = name + '=';
    var cookieArray = document.cookie.split(';');
    for (var i = 0; i < cookieArray.length; i++) {
      var cookie = cookieArray[i].replace(/^[ ]+/, '');
      if (cookie.indexOf(nameEquals) == 0) return unescape(cookie.substring(nameEquals.length, cookie.length));
    }
    return null;
  },

  /**
   * Remove a cookie if it has a value, and return the value that was removed.
   */
  remove: function(name, path) {
    var value = this.get(name);
    if (value) {
        this.set(name, '', -1, 0, path);
    }
    return value;
  }

};