window.onload = function() {
    var size = readCookie('fontsize');
    if (size) {
        setFontsize(size);
    }
    if (document.getElementById('button-decrease-font'))	{ document.getElementById('button-decrease-font').onclick	= function(){ decreaseFont(); }; }
    if (document.getElementById('button-normal-font'))		{ document.getElementById('button-normal-font').onclick		= function(){ setnormalFont(); }; }
    if (document.getElementById('button-increase-font'))	{ document.getElementById('button-increase-font').onclick	= function(){ increaseFont(); }; }
    
    if (document.getElementById('button-decrease-font-up'))	{ document.getElementById('button-decrease-font-up').onclick	= function(){ decreaseFont(); }; }
    if (document.getElementById('button-normal-font-up'))		{ document.getElementById('button-normal-font-up').onclick		= function(){ setnormalFont(); }; }
    if (document.getElementById('button-increase-font-up'))	{ document.getElementById('button-increase-font-up').onclick	= function(){ increaseFont(); }; }
};

// Font-resizer 
// all values in em
var kbFontSizeDefault = 1.0;
var kbFontSizeMin = 0.8;
var kbFontSizeMax = 1.2;
var kbFontSizeIntervall = 0.2;

function getFontsize () {
	//return document.getElementsByTagName('body')[0].style.fontSize;
	return document.getElementById('content').style.fontSize;
}

function setFontsize (size) {
	//document.getElementsByTagName('body')[0].style.fontSize = size;
	document.getElementById('content').style.fontSize = size;
	document.getElementById('main_content').style.fontSize = size;
	elementRef = document.getElementById('main_content');
	for (var i = 0; i < elementRef.children.length; i++) {
	  //alert(elementRef.children[i].className);
          if (elementRef.children[i].tagName == "FORM") {
          // operate on a form element
          }
	}
    var date = new Date();
    date.setTime(date.getTime()+30*24*60*60*1000);
    document.cookie = 'fontsize='+size+'; expires'+date.toGMTString()+'; path=/';	
	void(0);
}

// main
function getCurrentFontSize () {
	var currentSizeTmp = getFontsize();
    
	if (currentSizeTmp == '') {
		currentSizeTmp = kbFontSizeDefault+'em';
		setFontsize(currentSizeTmp);
	}
	currentSizeTmp = currentSizeTmp.replace(/em/g, '');
	return Number(currentSizeTmp);
}

function decreaseFont () {
	var currentSize = getCurrentFontSize();
	if (currentSize > kbFontSizeMin) {
		currentSize = currentSize - kbFontSizeIntervall;
		setFontsize(currentSize+'em');
	}
	void(0);
}

function setnormalFont () {
	setFontsize(kbFontSizeDefault+'em');
	void(0);
}

function increaseFont () {
	var currentSize = getCurrentFontSize();
	if (currentSize < kbFontSizeMax) {
		currentSize = currentSize + kbFontSizeIntervall;
		setFontsize(currentSize+'em');
	}
	void(0);
} 

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;
}

