﻿function checkFontSize() {
    // Do this onload
//    debugger
    //		var receivedCookieData = getCookie("fontsize");		
    var cookie2 = readCookie("fontsizecookie");
    if (cookie2 != null) {

        if (cookie2 == "small") {
            smallFont();
        }
        if (cookie2 == "med") {
            medFont();
        }
        if (cookie2 == "large") {
            largeFont();
        }
    }
    else {
        medFont();
    }
}

// Get cookie function - Return the value of the cookie
function getCookie(name) {
    var dc = document.cookie;

    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function smallFont() {
    ///debugger

    // Change the current font size and write the value back to cookie
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number

        if (ieversion >= 5 && ieversion < 8) {
            document.body.style.fontSize = '9.6px';
            //document.cookie = "fontsize=small" + "; expires=" + expires.toUTCString();
            createCookie("fontsizecookie", "small", 1);
        }
        else {
            document.body.style.fontSize = '0.6em';
          //  document.cookie = "fontsize=small" + "; expires=" + expires.toUTCString();
            createCookie("fontsizecookie", "small", 1);
        }
    }
    else {
        document.body.style.fontSize = '0.6em';
        //document.cookie = "fontsize=small" + "; expires=" + expires.toUTCString();
        createCookie("fontsizecookie", "small", 1);
    }

}

function medFont() {
    // Change the current font size and write the value back to cookie
    // Change the current font size and write the value back to cookie
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number

        if (ieversion >= 5 && ieversion < 8) {
            document.body.style.fontSize = '12.8px';
            //document.cookie = "fontsize=med" + "; expires=" + expires.toUTCString();
            createCookie("fontsizecookie", "med", 1);
        }
        else {
            document.body.style.fontSize = ' + "; expires="+expires.toUTCString();0.8em';
            //document.cookie = "fontsize=med";
            createCookie("fontsizecookie", "med", 1);
        }
    }
    else {
        document.body.style.fontSize = '0.8em';
        //document.cookie = "fontsize=med" + "; expires=" + expires.toUTCString();
        createCookie("fontsizecookie", "med", 1);
    }
}

function largeFont() {
    // Change the current font size and write the value back to cookie
    // Change the current font size and write the value back to cookie
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number

        if (ieversion >= 5 && ieversion < 8) {
            // Change the current font size and write the value back to cookie
            document.body.style.fontSize = '16px';
            //  document.cookie = "fontsize=large" + "; expires="+expires.toUTCString();
            createCookie("fontsizecookie", "large", 1);
        }
        else {
            // Change the current font size and write the value back to cookie
            document.body.style.fontSize = '1.0em';
            //document.cookie = "fontsize=large" + "; expires="+expires.toUTCString();
            createCookie("fontsizecookie", "large", 1);
        }
    }
    else {
        // Change the current font size and write the value back to cookie
        document.body.style.fontSize = '1.0em';
        //        document.cookie = "fontsize=large" + "; expires=" + expires.toUTCString() + "; ";
        createCookie("fontsizecookie", "large", 1);
    }

}

function createCookie(name, value, days) {
//        debugger
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        //var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
//    document.cookie = name + "=" + value + expires + "; path=/";
    document.cookie = name + "=" + value + "; path=/";

}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}


