﻿function Cookie(name) {
    this.name = name;
    this.value = loadCookieData(name);
    this.expires = new Date().getTime();
    this.domain = null;
    this.path = null;
    }
Cookie.prototype.setExpires = function(timestamp) {
    this.expires = timestamp;
    }
Cookie.prototype.setPath = function(path) {
    this.path = path;
    }
Cookie.prototype.setDomain = function(domain) {
    this.domain = domain;
    }
Cookie.prototype.getValue = function() {
    return this.value;
    }
Cookie.prototype.getParamString = function() {
    return this.paramString;
    }
Cookie.prototype.setValue = function(value) {
    this.value = value;
    }
Cookie.prototype.remove = function() {
    this.expires = new Date().getTime();
    this.data = new CookieData();
    this.send();
    }
Cookie.prototype.send = function() {
    document.cookie = this.name + "=" + escape(this.value) + "; expires=" + new Date(this.expires).toGMTString() + (this.path ? "; path=" + this.path : "") + (this.domain ? "; domain=" + this.domain : "");
    }
function loadCookieData(cookieName) {
    var a = document.cookie.split("; ");
    for (var i = 0; i < a.length; i++) {
        var kv = a[i].split('=');
        if (kv[0] == cookieName) {
            return unescape(kv[1]);
        }
    }
    return null;
}
var eonStyle = new Cookie("eonStyle");
var ergFontClass = "sizesmall";
function SetFontSize(){
    ergFontClass = eonStyle.getValue();
    var ergFontSize;
    switch (ergFontClass) {
        case "sizesmall":
            ergFontClass = "sizesmall";
            ergFontSize = '1em';
            break;
        case "sizemedium":
            ergFontClass = "sizemedium";
            ergFontSize = '1.125em';
            break;
        case "sizelarge":
            ergFontClass = "sizelarge";
            ergFontSize = '1.25em';
            break;
        default:
            if (ergFontClass == null) {
                ergFontClass = "sizesmall";
                ergFontSize = '1em';
            } else if (ergFontClass.indexOf("sizemedium") >= 0) {
                ergFontClass = "sizemedium";
                ergFontSize = '1.125em';
            } else if (ergFontClass.indexOf("sizelarge") >= 0) {
                ergFontClass = "sizelarge";
                ergFontSize = '1.25em';
            } else {
                ergFontClass = "sizesmall";
            }
            writeCookie();
            break;
        }
    SetActiveLink(ergFontClass);
    document.body.style.fontSize = ergFontSize;
    //document.body.className = ergFontClass;
    }
function writeCookie() {
    var lifetime = 1000 * 60 * 60 * 24 * 365;
    var now = new Date();
    eonStyle.setExpires(new Date(now.getTime() + lifetime).toGMTString());
    eonStyle.setPath("/");
    eonStyle.setValue(ergFontClass);
    eonStyle.send();
    }
function SwitchFontSize(fontSize, fontClass) {
    return SetFontClass(fontClass);
    }    
    
function SetFontClass(fontClass){
    var ergFontSize;
    switch (fontClass) {
        case "sizesmall":
            ergFontClass = "sizesmall";
            ergFontSize = '1em';
            break;
        case "sizemedium":
            ergFontClass = "sizemedium";
            ergFontSize = '1.125em';
            break;
        case "sizelarge":
            ergFontClass = "sizelarge";
            ergFontSize = '1.25em';
            break;
        default:
            return false;
    }
    writeCookie();
    if (ergFontClass == loadCookieData("eonStyle")) {
        document.body.style.fontSize = ergFontSize;
        document.body.className = ergFontClass;
        SetActiveLink(ergFontClass);
        return false;
    } else {
        return true;
    }
}
function SetActiveLink(ergFontClass) {
    if (document.getElementById("FontSizeSmall") != null) document.getElementById("FontSizeSmall").style.color = "#840201";
    if (document.getElementById("FontSizeMedium") != null) document.getElementById("FontSizeMedium").style.color = "#840201";
    if (document.getElementById("FontSizeLarge") != null) document.getElementById("FontSizeLarge").style.color = "#840201";
    switch (ergFontClass) {
        case "sizesmall":
            if (document.getElementById("FontSizeSmall") != null) document.getElementById("FontSizeSmall").style.color = "#ffffff";
            break;
        case "sizemedium":
            if (document.getElementById("FontSizeMedium") != null) document.getElementById("FontSizeMedium").style.color = "#ffffff";
            break;
        case "sizelarge":
            if (document.getElementById("FontSizeLarge") != null) document.getElementById("FontSizeLarge").style.color = "#ffffff";
            break;
        default:
            break;
    }
}