﻿var fontSizeCookieName = "fontSize";

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=/";
}

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 ChangeFontSize(size)
{
    SetFontSize(size);
    createCookie(fontSizeCookieName, size, 365);
}

function LoadFontSize()
{
    var size = readCookie(fontSizeCookieName);
    if (size != null)
    {
        SetFontSize(size);
    }
}

function SetFontSize(size)
{
    if (size == 1)
    {
        $("body").removeClass("BiggestFont");
        $("body").addClass("BiggerFont");
        var dir = $("#FontImage_0").attr("src");
        dir = dir.substring(0, dir.lastIndexOf("/"));
        $("#FontImage_0").attr("src", dir + "/SmallFontIcon.gif");
        $("#FontImage_1").attr("src", dir + "/MediumFontIconSel.gif");
        $("#FontImage_2").attr("src", dir + "/LargeFontIcon.gif");
    }
    else if (size == 2)
    {
        $("body").removeClass("BiggerFont");
        $("body").addClass("BiggestFont");
        var dir = $("#FontImage_0").attr("src");
        dir = dir.substring(0, dir.lastIndexOf("/"));
        $("#FontImage_0").attr("src", dir + "/SmallFontIcon.gif");
        $("#FontImage_1").attr("src", dir + "/MediumFontIcon.gif");
        $("#FontImage_2").attr("src", dir + "/LargeFontIconSel.gif");
    }
    else // size == 0
    {
        $("body").removeClass("BiggerFont");
        $("body").removeClass("BiggestFont");
        var dir = $("#FontImage_0").attr("src");
        dir = dir.substring(0, dir.lastIndexOf("/"));
        $("#FontImage_0").attr("src", dir + "/SmallFontIconSel.gif");
        $("#FontImage_1").attr("src", dir + "/MediumFontIcon.gif");
        $("#FontImage_2").attr("src", dir + "/LargeFontIcon.gif");
    }
}