
Cookie = function(name, expiration, path, domain, secure) {
    this._name = name;
    this._expiration = (expiration) ? new Date(expiration) : null;
    this._path = (path) ? path : null;
    this._domain = (domain) ? domain : null;
    this._secure = (secure) ? secure : false;
}

// Value and pair separators
Cookie.VALSEP = ":";
Cookie.PAIRSEP = "|";

Cookie.prototype.save = function() {
    var nameValuePairs = new Array();
    for (var prop in this) {
        if (prop.charAt(0) != "_" && typeof this[prop] != "function") {
            nameValuePairs.push(prop + Cookie.VALSEP + escape(this[prop]));
        }
    }

    var cookie = this._name + "=" + nameValuePairs.join(Cookie.PAIRSEP);
    if (this._expiration) {
        cookie += "; expires=" + this._expiration.toGMTString();
    }
    if (this._path) {
        cookie += "; path=" + this._path;
    }
    if (this._domain) {
        cookie += "; domain=" + this._domain;
    }
    if (this._secure) {
        cookie += "; secure";
    }

    // Write the cookie
    document.cookie = cookie;
}

Cookie.prototype.load = function() {
    var allCookies = document.cookie;
    if (allCookies != "" && allCookies.indexOf(this._name) != -1) {
        var startPos = allCookies.indexOf(this._name) + (this._name.length + 1);
        var endPos = (allCookies.indexOf(";", startPos) != -1) ? allCookies.indexOf(";", startPos) : allCookies.length;
        var cookie = allCookies.substring(startPos, endPos);

        var nameValuePairs = cookie.split(Cookie.PAIRSEP);
        for (var i = 0; i < nameValuePairs.length; i++) {
            nameValuePairs[i] = nameValuePairs[i].split(Cookie.VALSEP);
            this[nameValuePairs[i][0]] = unescape(nameValuePairs[i][1]);
        }

        return true;
    }
    else {
        return false;
    }
}

Cookie.prototype.remove = function() {
    var expiration = new Date("1/1/1970");
    var cookie = this._name + "=; expires=" + expiration.toGMTString();
    if (this._path) {
        cookie += "; path=" + this._path;
    }
    if (this._domain) {
        cookie += "; domain=" + this._domain;
    }
    document.cookie = cookie;
}


// BEGIN FONT SELECTOR FUNCTIONS

function setFont(fontsize) {
    var font_i, font_a, font_main;
    for (font_i=0; (font_a = document.getElementsByTagName("link")[font_i]); font_i++) {   
        if(font_a.getAttribute("rel").indexOf("style") > -1 && font_a.getAttribute("title")) {
            font_a.disabled = true;
            if (font_a.getAttribute("title") == fontsize) {
                font_a.disabled = false;
            }
        }  
    }
    var fontCookie = new Cookie('fontsize', '01/01/2015', '/');
    fontCookie.valueName = fontsize;
    fontCookie.save();
    //fontsetting = fontCookie.valueName;
    //document.getElementById('small').className = 'small';
    //document.getElementById('medium').className = 'medium'; 
    //document.getElementById('large').className = 'large'; 
    //document.getElementById('xlarge').className = 'xlarge';                     
    //document.getElementById(fontsize).className = 'fontsize_'+fontsetting+'_active';
}

var fontCookie = new Cookie('fontsize');
if(fontCookie.load() == false){
	fontsetting = 'medium';
} 
else
	fontsetting = fontCookie.valueName;
setFont(fontsetting);
// END FONT SELECTOR FUNCTIONS
