
var prefs = {

    data: {},

    name: 'techtwo_cart',    
    
    load: function (name) {
        
        this.name = name || 'techtwo_cart';
        
        var the_cookie = document.cookie.split(';');
        
        var cookie;
        
        for (i=0; i<the_cookie.length; i++) {
            var cookie_parts = the_cookie[i].split('=');
              
            if (cookie_parts[0] == ' ' + this.name) {
                cookie = cookie_parts[1];
            }
        }
        
        if (cookie) {
            try {
                this.data = JSON.parse(unescape(cookie));
            } catch (e) {
                this.data = {};
            }
        }
        
        return this.data;
    },

    save: function (expires, path) {
        
        var d = expires || new Date(2020, 02, 02);
        var p = path || '/';
        
        document.cookie = this.name+'='+escape(JSON.stringify(this.data))
                          + ';path=' + p
                          + ';expires=' + d.toUTCString();
    }

}


