var initial_font_size = 100;
var font_unity = '%';
var delta = 2;
var fsize = initial_font_size;

function init_FontSize (ifs, fu, del)
{
	if (!isNaN(ifs))
		initial_font_size = parseFloat(ifs);
	if ("pt,pc,in,mm,cm,px,em,ex,%".indexOf (fu) != -1)
		font_unity = fu;
	if (!isNaN(del))
		delta = parseFloat(del);
	if (isNaN(parseFloat(document.getElementsByTagName('body')[0].style.fontSize)) || parseFloat(document.getElementsByTagName('body')[0].style.fontSize) == 0)
		fsize = getFontSize ();
	else
		fsize = parseFloat(document.getElementsByTagName('body')[0].style.fontSize);
	if (fsize != initial_font_size)
		addFontSizeToLinks ();
	document.getElementsByTagName('body')[0].style.fontSize = fsize + font_unity;
}

function incFontSize ()
{
	if (fsize<13)
	{
		if (!isNaN(delta))
			setFontSize (Math.round((parseFloat(fsize) + parseFloat(delta)) * 100) / 100);
	}
}

function decFontSize ()
{
	if (fsize>10)
	{
		if (!isNaN(delta))
			setFontSize (Math.round((parseFloat(fsize) - parseFloat(delta)) * 100) / 100);
	}
}

function setFontSize (newsize)
{
	if (!isNaN(newsize))
	{
		fsize = Math.round((parseFloat(newsize)) * 100) / 100;
		document.getElementsByTagName('body')[0].style.fontSize = fsize + font_unity;
		addFontSizeToLinks ();
	}
}

function getFontSize ()
{
	var fs;

	if (document.location.search != "" && (document.location.search).match (/fsize=[0-9]+\.?[0-9]*/i))
		fs = ("" + (document.location.search).match (/fsize=[0-9]+\.?[0-9]*/i)).replace (/fsize=/i, '');
	else
		fs = initial_font_size;
	return fs;
}

function getDomainURL (URL)
{
	if (URL.match (/^((http:\/\/)?(www\.)?((([0-9a-z][0-9a-z-]+\.)+)([a-z]{2,3}))).*/))
		return URL.match (/^((http:\/\/)?(www\.)?((([0-9a-z][0-9a-z-]+\.)+)([a-z]{2,3}))).*/)[1];
	else
		return "";
}

function addFontSizeToLinks ()
{
	for (i = 0; i < document.links.length; i++)
	{
		if (!(document.links[i].href).match (/^mailto:/)
		    && !(document.links[i].href).match (/^(http:\/\/)?(www\.)?((([0-9a-z][0-9a-z-]+\.)+)([a-z]{2,3}))[\/]+$/)
		    && (document.links[i].href).indexOf (getDomainURL (self.location.href)) != -1
		    )
		{
			if ((document.links[i].href).match (/fsize=[0-9]+\.?[0-9]{0,2}/i))
				document.links[i].href = (document.links[i].href).replace (/fsize=[0-9]+\.?[0-9]{0,2}/i, ("fsize=" + fsize));
			else
				if ((document.links[i].href).indexOf ('?') != -1)
					document.links[i].href = document.links[i].href + "&fsize=" + fsize;
				else
					document.links[i].href = document.links[i].href + "?fsize=" + fsize;
		}
	}
}

