//LM 20110808 added path to the cookie
var Cookies = new (function () {
    //Will store the cookies
    var _store = new Array();

    //Remove the enclosing spaces 
    var trim = function (str) { return str.replace(/^\s+|\s+$/g, ""); }

    //Access to the cookie's value
    this.read = function (name) {
        if (_store[name])
            return _store[name];
        return false;
    };

    //Add or replace cookie
    this.set = function (name, value, expiration) {
        var expdate = new Date();
        expdate.setTime(expdate.getTime() + (365 * 24 * 60 * 60 * 1000));
        expdate = (expiration != null) ? expiration : expdate;
        document.cookie = name + "=" + value + "; expires=" + expdate.toGMTString() + ";path=/;";
        _store[name] = value;
    };

    //Remove cookie
    this.erase = function (name) {
        this.set(name, "", 0);
    };

    //Populate the Store
    this.cook = function () {
        var flour = document.cookie;
        for (i = 0; true; i++) {
            e = flour.indexOf("=");
            if (e < 1) break;
            c = flour.indexOf(";");
            if (c < 0) {
                _store[trim(flour.substring(0, e))] = trim(flour.substring(e + 1));
                break;
            }
            else {
                _store[trim(flour.substring(0, e))] = trim(flour.substring(e + 1, c));
                flour = flour.substring(c + 1);
            }
        }
    };

    //Initialisation
    this.cook();
    return this;
})();
