// Copyright 2005 WebLab Informatics Limited

var fontSize = 2;
var hex;

function MakeArray()
{
    this.length = 16;
    return this;
}

hex = new MakeArray();
hex[1] = ";psbn&";    
hex[2] = ".";    
hex[3] = ";ammag&";    
hex[4] = ";atled&";    
hex[5] = ";nolispe&";    
hex[6] = ";atez&";    
hex[7] = ";ate&";    
hex[8] = ";ateht&";    
hex[9] = ";atoi&";    
hex[10] = ";appak&";    
hex[11] = ";adbmal&";    
hex[12] = ";um&";    
hex[13] = ";un&";    
hex[14] = ";ix&";    
hex[15] = ";norcimo&";    
hex[16] = ";ip&";    

function sendEmail(encodedEmail)
{
	var email = "";
	for (i = 0; i < encodedEmail.length;)
	{
		var letter = "";
		letter = encodedEmail.charAt(i) + encodedEmail.charAt(i+1)
		email += String.fromCharCode(parseInt(letter,16));
		i += 2;
	}
	location.href = email;
}

function setFaceSize()
{
	var tmpFontSize;
	obj = document.getElementById("content-container");
	if (obj)
	{
		switch (parseInt(fontSize))
		{
			case 0: tmpFontSize = "xx-small"; break;
			case 1: tmpFontSize = "x-small"; break;
			case 2: tmpFontSize = "small"; break;
			case 3: tmpFontSize = "medium"; break;
			case 4: tmpFontSize = "large"; break;
			case 5: tmpFontSize = "x-large"; break;
			case 6: tmpFontSize = "xx-large"; break;
			default: tmpFontSize = "medium"; break;
		}
		obj.style.fontSize = tmpFontSize;
		var thisDate = new Date();
		thisDate.setMonth(thisDate.getMonth()+1);
		setCookie("fontSize", fontSize, thisDate, '/');
	}
} 

function setFontCookieSize()
{
	if (getCookie('fontSize')>-1)
	{
		fontSize = getCookie('fontSize');
		setFaceSize();
	}
}

function eventFaceLarger()
{
	fontSize = parseInt(fontSize)+1;
	if (fontSize > 6)
	{
		fontSize = 6;
	}
	setFaceSize()
}

function eventFaceSmaller()
{
	fontSize = parseInt(fontSize)-1;
	if (fontSize < 0) fontSize = 0;
	setFaceSize();
}

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

// function DecimaltoAnother(N, radix)
// 
// return representation of a number N
// in the system based on radix 
//
function DecimaltoAnother(N, radix)
{
    s = "";

    A = N;
    while (A >= radix)
    {
        B = A % radix;
        A = Math.floor(A / radix);
        s += hex[B+1];
    }
    
    s += hex[A+1];
    return Transpose(s);
}

// function Transpose(s)
//
// return a string written from right to left
//
function Transpose(s)
{
    N = s.length;

    t = "";

    for (i = 0; i < N; i++)
        t = t + s.substring(N-i-1, N-i);

    s = t;
    return s;
}
