var moze, cookie, expl;
if(document.getElementById) moze=true;
if(navigator.appName.indexOf("Explorer")>-1) expl=true;

/**
 * Increases the font size on the page by 10 percent.
 */
function increasefontsize()
{
    if(expl) e=event; else e=Event;
    if(e.keyCode==3 || e.keyCode==13 || !e.keyCode)
    {
        val=getbodysize();
        val+=10;
        if(val>100) val=100;
        setbodysize(val+"%");
        return false;
    }
}

/**
 * Decreases the font size on the page by 10 percent.
 */
function decreasefontsize()
{
    if(expl)
        e=event;
    else
        e=Event;

    if(e.keyCode==3 || e.keyCode==13 || !e.keyCode)
    {
        val=getbodysize();
        val-=10;
        if(val<60)
            val=60;
        setbodysize(val+"%");
        return false;
    }
}

/**
 * Changes the font size to that specified, or 70% if the specified amount is invalid.
 */
function setbodysize(value)
{
    obj=document.getElementsByTagName("body");
    obj = obj[0];

    if(isNumeric(value.substring(0,value.length-1)))
        val = value;
    else
    {
        val = obj.style.fontSize;
        if("" == val || null == val)
            val = "70%";
        else
            val += "%";

    }

    obj.style.fontSize=val;
    if(moze)
        createCookie("fontsize", val, 365);
}

function setActiveStyleSheet(title)
{
    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
    {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
        {
            a.disabled = true;
            if(a.getAttribute("title") == title)
                a.disabled = false;
        }
    }
    if(moze)
        createCookie("style", title, 365);
}

function getActiveStyleSheet()
{
    var i, a;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
    {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled)
            return a.getAttribute("title");
    }
    return null;
}


function getPreferredStyleSheet()
{
    var i, a;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
    {
        if(a.getAttribute("rel").indexOf("style") != -1 &&
           a.getAttribute("rel").indexOf("alt") == -1 &&
           a.getAttribute("title"))
            return a.getAttribute("title");
    }
    return null;
}

/**
 * Gets the current body size.
 */
function getbodysize()
{
    obj=document.getElementsByTagName("body");
    bodyobj = obj[0];
    fnt=bodyobj.style.fontSize;
    val=parseInt(fnt.substring(0,fnt.length-1));
    return val;
}

/**
 * Creates a cookie with the given name and value which expires in the set
 * number of days.
 */
function createCookie(name,value,days)
{
    if(days)
    {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

/**
 * Reads the specified cookie and returns its value.
 */
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;
}

/**
 * Adds the styling of the page when the user returns to the site.

window.onload = function(e)
{
    //Use the user's preferred stylesheet
    var cookie = readCookie("style");
    var strStyleSheet = cookie;
    if(!(null == strStyleSheet || 0 == strStyleSheet.length || "" == strStyleSheet))
    {
        setActiveStyleSheet(strStyleSheet);
    }

    //Use the user's preferred font size
    cookie = readCookie("fontsize");
    val=cookie ? cookie : "70%";
    setbodysize(val);
}*/

/**
 * Records the styling of the page for when the user returns.

window.onunload = function(e)
{
    var title = getActiveStyleSheet();
    createCookie("style", title, 365);
    var iSize = getbodysize()+"%";
    createCookie("fontsize", iSize, 365);
}*/

function printFrame()
{
    document.write('<iframe id="slideframe" src="'+unescape(objSession)+'" title="PathXL Virtual Slide Viewer" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>');
}

var iDivHeight = -1;
var iDivWidth = -1;
/*
function resizeDiv()
{
    var iNewWidth = document.documentElement.clientWidth;
    var iNewHeight = document.documentElement.clientHeight - 45;
    if(iDivHeight == -1 || iNewWidth != iDivWidth || iNewHeight != iDivHeight)
    {
        var objFrame = document.getElementById("slideframe");
        if(null != objFrame)
        {
            objFrame.style.width = iNewWidth+"px";
            objFrame.style.height = iNewHeight+"px";
            iDivHeight = iNewHeight;
            iDivWidth = iNewWidth;
        }
    }
}
*/