var defaultFontSize = 80;
var currentFontSize = defaultFontSize;

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);
}

function b3restorePrefs(id)
{
	var closebutton = (document.getElementById) ? document.getElementById(id) : document.all(id);
	var para = closebutton.parentNode.childNodes[2];
	if (readCookie(id) == 0)
	{
		para.style.display = "none";
		closebutton.innerHTML = "+";
	}
}

function b3ToggleTheBox(id){
	if (document.getElementById || document.all)
	{
		var closebutton = (document.getElementById) ? document.getElementById(id) : document.all(id);
		var para = closebutton.parentNode.childNodes[2];
		if (para.style.display != "none")
		{
			para.style.display = "none";
			closebutton.innerHTML = "+";
			createCookie(id, 0, 7);
		}
		else
		{
			para.style.display = "block";
			closebutton.innerHTML = "\u2212";
			createCookie(id, 1, 7);
		}
	}
}

function b3changeFontSize(sizeDifference){
	
	var cookieFontSize = readCookie("fontSize");
	if(cookieFontSize>59){
		currentFontSize = cookieFontSize; 
	}
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);

	if(currentFontSize < 60){
		currentFontSize = 60;
	}

	createCookie("fontSize", currentFontSize, 7);
	if (!readCookie("fontSize"))
		alert("Cookies, which are required to remember user settings across pages, cannot be stored on your browser. Thus, any text size setting changed cannot be stored. To change text size setting and to allow the setting to be stored, please enable cookies or switch to a cookie-enabled browser.");

	b3setFontSize(currentFontSize);
};

function b3setFontSize(fontSize){
	document.body.style.fontSize = fontSize + '%';	
}

function b3restoreFontSize()
{
	var cookie = readCookie("fontSize");
	var currentFontSize = (cookie) ? cookie : defaultFontSize;
	b3setFontSize(currentFontSize);
}

function b3resetFontSize()
{
	b3setFontSize(defaultFontSize);
	createCookie('fontSize', defaultFontSize, 7);
	if (!readCookie("fontSize"))
		alert("Cookies, which are required to remember user settings across pages, cannot be stored on your browser. Thus, any text size setting changed cannot be stored. To change text size setting and to allow the setting to be stored, please enable cookies or switch to a cookie-enabled browser.");	
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
