function initPage () 
{
	var cookieName = "fontSize";
	var fMin = document.getElementById("font-min");
	var fMax = document.getElementById("font-max");
	var fSize = 64;

	var fontSize = readCookie(cookieName);
	if (fontSize == null) fontSize = "64%";
	
	var body = document.getElementsByTagName("body")[0];
	body.style.fontSize = fontSize;

	fMin.onclick = function (){
		fSize = body.style.fontSize.replace("%","");
		fSize = parseInt(fSize) - 17;
		if (fSize <= 64) fSize = 64;  
		body.style.fontSize = fSize+"%";
		createCookie(cookieName, body.style.fontSize, 360);
		return false;
	}
	fMax.onclick = function (){
		fSize = body.style.fontSize.replace("%","");
		fSize = parseInt(fSize) + 17;
		if (fSize >= 88) fSize = 88; 
		body.style.fontSize = fSize+"%";
		createCookie(cookieName, body.style.fontSize, 360);
		return false;
	}

	fixBottom();
}

function fixBottom()
{
	var bValue = 300;
	var tValue = 445;
	
	if (typeof trialIcon_bValue != "undefined") bValue = trialIcon_bValue;
	if (typeof trialIcon_tValue != "undefined") tValue = trialIcon_tValue;

	var _bottom_div = _$('trial-ico');
	if(_bottom_div)
	{
		var w = getWindowSize();
		_bottom_div.style.top = Math.min(_$('content').offsetHeight + bValue ,Math.max(tValue, w.height + w.scrollY - 89)) + "px";
	}
}

if (window.addEventListener)
{
	window.addEventListener("load", initPage, false);
	window.addEventListener("resize", fixBottom, false);
	window.addEventListener("scroll", fixBottom, false);
}
else if (window.attachEvent)
{
	window.attachEvent("onload", initPage);
	window.attachEvent("onresize", fixBottom);
	window.attachEvent("onscroll", fixBottom);
}

function _$(id)
{
	return document.getElementById(id);
}

function getWindowSize()
{
	var _return = {'width':0,'height':0,'scrollX':0,'scrollY':0};

	if(!window.opera)
	{
		_return['height'] = document.documentElement.clientHeight;
		_return['width'] = document.documentElement.clientWidth;
	}
	else if(window.opera && window.innerHeight)
	{
		_return['height'] = window.innerHeight;				
		_return['width'] = window.innerWidth;				
	}
	
	_return['scrollX'] = document.documentElement.scrollLeft;
	_return['scrollY'] = document.documentElement.scrollTop;
	
	return _return;
}

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 var 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 eraseCookie(name) {
	createCookie(name,"",-1);
}

