﻿function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // kill the timer
    if (_timer) {
        clearInterval(_timer);
        _timer = null;
    }

    // create the "page loaded" message
    //var text = document.createTextNode("Page loaded!");
    //var message = document.getElementById("message");
    //message.appendChild(text);

    mydefaultsize();

};

/* for Mozilla */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on@*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") {
        init(); // call the onload handler
    }
};
/*@end@*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
window.onload = init;


function changemysize(myvalue)
// this function is called by the user clicking on a text size choice
{
    // find the div to apply the text resizing to
    var div = document.getElementById("mymain");
    // apply the text size change
    div.className = myvalue;
    // store the text size choice into a cookie
    document.cookie = "mysize=" + myvalue;
}

function getmycookie(myname)
// this function is called by the function mydefaultsize()
// this function merely looks for any previously set cookie and then returns its value
{
    // if any cookies have been stored then
    if (document.cookie.length > 0) {
        // where does our cookie begin its existence within the array of cookies  
        mystart = document.cookie.indexOf(myname + "=");
        // if we found our cookie name within the array then
        if (mystart != -1) {
            // lets move to the end of the name thus the beginning of the value
            // the '+1' grabs the '=' symbol also
            mystart = mystart + myname.length + 1;
            // because our document is only storing a single cookie, the end of the cookie is found easily
            myend = document.cookie.length;
            // return the value of the cookie which exists after the cookie name and before the end of the cookie
            return document.cookie.substring(mystart, myend);
        }
    }
    // if we didn't find a cookie then return nothing  
    return "";
}

function mydefaultsize() {
    // this function is called by the body onload event
    // this function is used by all sub pages visited by the user after the main page
    var div = document.getElementById("mymain");

    // call the function getmycookie() and pass it the name of the cookie we are searching for
    // if we found the cookie then
    if (getmycookie("mysize").length > 0) {
        // apply the text size change
        div.className = getmycookie("mysize") //  getmycookie("mysize");
    }
}
