//cookie virkni
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);
}
//styling ie for abbr
 function styleAbbr() {
  var oldBodyText, newBodyText, reg
  if (isIE) {
    oldBodyText = document.body.innerHTML;
    reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
    newBodyText = oldBodyText.replace(reg, '<abbr $1><span class=\"abbr\" $1>$2</span></abbr>');
    document.body.innerHTML = newBodyText;
  }
}
isIE = (document.all) ? true:false;
//focus on inputs
sfFocus = function() {
	var sfEls = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfFocus);

function onLoadTasks() {
	styleAbbr();
}
Event.observe(window, 'load', onLoadTasks, false);

//fontsizer.js
//create cookie for fontsize
var cookieNameTextSize = "KompasFontSize";

var textSizes = "small;medium;big;huge".split(";");

function setTextSizeCookie(size) {
	eraseCookie(cookieNameTextSize);
	createCookie(cookieNameTextSize, size, 365);
}

function doTextSize(textSizeName, textSizeValue) {
	var bodyElement = document.getElementsByTagName('body')[0];
	bodyElement.style.fontSize = textSizeValue;
	setTextSizeCookie(textSizeName);
	markSelectedTextSize(textSizeName);
}


//font-size monster
function hugeText() {
	doTextSize("huge", '4em');
}

function bigText() {
	doTextSize("big", '120%');
}

function mediumText() {
	doTextSize("medium", '100%');
}

function smallText() {
	doTextSize("small", '75%');
}

function markSelectedTextSize(textSize) {
	for(var i=0; i < textSizes.length; i++) {
		var link = document.getElementById( textSizes[i] + 'Link');
		if (link != null) {
			if (link.className != null) {
				link.className = link.className.replace("selectedTextSize", "");
			}
		}
	}
	var link = document.getElementById( textSize + 'Link');
	if (link != null) {
		if (link.className != null) {
			link.className = " selectedTextSize";
		} else {
			link.className += " selectedTextSize";
		}
	}
}

function textResize() {
	var textSize = readCookie(cookieNameTextSize);
	if (textSize != null) {
		eval(textSize + "Text()");
	}
}

Event.observe(window, 'load', textResize, false);
