﻿//include CookieUtilities
document.write("<script type='text/javascript' src='/_layouts/Momentum.Foresters.Webparts/CookieUtilities.js'></script>");

/* Global variable */
var MINFONT = 10;       // 10
var MAXFONT = 18;        // 18
var STEP = 2;
var CURRENTFONT = 9;   //10
var DEFAULT_SIZE = 9;   //12

var COOKIE = "DB_FONT_COOKIE";

function mf_increase() {
    var startSize = CURRENTFONT;
    fontIncrease();
    changeAll(CURRENTFONT - startSize)
}
function mf_decrease() {
    var startSize = CURRENTFONT;
    fontDecrease();
    changeAll(CURRENTFONT - startSize)
}
function mf_reset() {
    var startSize = CURRENTFONT;
    fontReset();
    changeAll(CURRENTFONT - startSize);
}


function changeAll(change) {
    ResizeByTag("p", change);
    ResizeByTag("span", change);
    ResizeByTag("div", change);
    ResizeByTag("li", change);
}

function ResizeByTag(tag, change) {
    var s = 0;
    var mainContent = document.getElementById("ctl00_MSO_ContentDiv");
    var el = mainContent.getElementsByTagName(tag);
    for (var i = 0; i < el.length; i++) {

        if (el[i].style.fontSize) {
            s = parseInt(el[i].style.fontSize.replace("pt", ""));
        } else {
            s = DEFAULT_SIZE;
        }
        s = parseInt(s) + parseInt(change);
        el[i].style.fontSize = s + "pt";

    }
}

function fontDecrease() {
    try {
        // Get Size from Cookie or Default
        var size = parseInt(DBGetCookie(COOKIE));
        if (size == null || isNaN(size)) { size = DEFAULT_SIZE; }

        // Adjust Size
        if (size > MINFONT) { size -= STEP; }

        // Set size
        DBSetCookie(COOKIE, size, expiry);
        CURRENTFONT = size;
    }
    catch (e) {
        alert(e.message);
    }
}
function fontIncrease() {
    try {
        // Get Size from Cookie or Default
        var size = parseInt(DBGetCookie(COOKIE));
        if (size == null || isNaN(size)) { size = DEFAULT_SIZE; }

        // Adjust Size
        if (size < MAXFONT) { size += STEP; }

        //set size
        DBSetCookie(COOKIE, size, expiry);
        CURRENTFONT = size;
    }
    catch (e) {
        alert(e.message);
    }
}
function fontReset() {
    try {
        size = DEFAULT_SIZE;
        //set size
        DBSetCookie(COOKIE, size, expiry);
        DeleteCookie(COOKIE, "/");
        CURRENTFONT = size;
    }
    catch (e) {
        alert(e.message);
    }
}

//once the DOM is loaded change the font
$(document).ready(function () {
    CURRENTFONT = DBGetCookie(COOKIE);
    if (CURRENTFONT) {
        changeAll(CURRENTFONT - DEFAULT_SIZE);
    } else {
        CURRENTFONT = DEFAULT_SIZE
        changeAll(0);
    }
});

//function loaded() {
//    $(document).ready(function () {
//        CURRENTFONT = DBGetCookie(COOKIE);
//        changeAll();
//    });

//}

//ExecuteOrDelayUntilScriptLoaded(loaded, "sp.js");
