function resetZoomCookie()
{
    setCookie("fontSizeCounter",0);
    var sURL = unescape(window.location.pathname);
    window.location.replace( sURL );
    //alert("resetZoomCookie: " + getCookie("fontSizeCounter"));
}

function zoomOnReload()
{
    var count = parseInt(getCookie("fontSizeCounter"));
    if(count)
    {
        var max = Math.abs(count);

        //alert("zoomOnReload: " + max);
        if(count > 0)
        {
            for(x = 0; x < max; x++)
            {
                zoomIn();
            }
        }
        else
        {
            for(x = 0; x < max; x++)
            {
                zoomOut();
            }
        }
    }    
}

function zoomInWithCookie()
{
    var countStr = getCookie("fontSizeCounter");
    //alert("zoomInWithCookie: " + countStr);

    if(countStr > 0 || countStr != 'NaN' )
    {
        var count    = parseInt(countStr);
        count = count + 1;
        //alert("setting updated counter: " + count);
        setCookie("fontSizeCounter","" + count);
    }
    else
    {
        count = 1;
        setCookie("fontSizeCounter","" + count);
    }
    //alert("zoomInWithCookie: " + getCookie("fontSizeCounter"));
    changeFontSize(+2);
}

function zoomOutWithCookie()
{    
    var countStr = getCookie("fontSizeCounter");
    //alert("zoomInWithCookie: " + count);

    if(countStr < 0 || countStr != 'NaN' )
    {
        var count = parseInt(countStr);
        count = count - 1;
        //alert("setting updated counter: " + count);
        setCookie("fontSizeCounter","" + count);
    }
    else
    {
        count = -1;
        setCookie("fontSizeCounter","" + count);
    }
    changeFontSize(-2);
}


function zoomIn()
{
    changeFontSize(+2);
}

function zoomOut()
{
    changeFontSize(-2);
}

function changeFontSize(amount)
{
    var rules = getRules();

    if (rules && rules.length)
    {
        for (var i = 0; i < rules.length; i++)
        {
            var currentSize = rules[i].style.fontSize;
            var newSize = calculateNewSize(currentSize, amount);
            
            if (newSize)
            {
                rules[i].style.fontSize = newSize;
            }
        }
    }
}

function getRules()
{
    if (document && document.styleSheets && document.styleSheets[0])
    {
        if (document.styleSheets[0].rules)
        {
            return document.styleSheets[0].rules;
        }
        else if (document.styleSheets[0].cssRules)
        {
            return document.styleSheets[0].cssRules;
        }
    }
}                

function calculateNewSize(currentSize, amount)
{
    var valid = "0123456789";
    var newSize = "";

    if (currentSize && currentSize.length > 0)
    {
        for (var i = 0; i < currentSize.length; i++)
        {
            if (valid.indexOf(currentSize.charAt(i)) != -1)
            {
                newSize += currentSize.charAt(i);
            }
        }
    }
    
    if (newSize.length > 0)
    {
        newSize = parseInt(newSize) + parseInt(amount);
        
        if (newSize >= 6)
        {
            return newSize + "px";
        }
    }
}
