/* Tab area script */
function tabber(tabname) {
	var elms = document.getElementsByTagName("*");
	for(i=0;elms.length>i;i++) {
		if( elms[i].className.indexOf('tabsheader')>-1 ) {
			try {
				elms[i].className='tabsheader';
				document.getElementById('Tab'+tabname).className = 'tabsheaderover' ;
			} catch(e) {
				alert('Error block 1:\n'+e.message);
				return false;
			}
		}
	}
	  
	var tabelms = document.getElementsByTagName("*");
	for (i=0;tabelms.length>i;i++) {
		if(tabelms[i].className.indexOf('showhidetab')>-1) {
			try {
				tabelms[i].style.display = 'none' ;
				document.getElementById('showhidetab'+tabname).style.display = 'block' ;
			} catch(e) {
				alert('Error block 2:\n'+e.message);
				return false;
			}
		}
	}
}
/* Add to favorites script - cross browser */
function bookmark(parTitle,parUrl){
	/* Title and url */
    var title = parTitle;
    var url = parUrl;
	if(title=='' || url==''){
		/* Error: No url or title has been specified */
		//alert('Error!')
	} else {
		/* Mozilla */
		if (window.sidebar) window.sidebar.addPanel(title, url,"");
	
		/* Opera */
		else if(window.opera && window.print){
			var mbm = document.createElement('a');
			mbm.setAttribute('rel','sidebar');
			mbm.setAttribute('href',url);
			mbm.setAttribute('title',title);
			mbm.click();
		}
	
		/* IE */
		else if(document.all) window.external.AddFavorite(url, title);
	}
}
/* Cookies
----------------------------------------------------------- */
var expDays = 14;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;	
	var i = 0;
while (i < clen) {
	var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
/* Toogle font sizes
----------------------------------------------------------- */
function toogleDown(){
	/* Get fontsize */
	var myFontSize = GetCookie('myFontSize');
	
	/* If no cookie has been registred the set the fontsize 1px down */
	if (myFontSize==null){
	
		/* Remember font size */
		SetCookie('myFontSize','77',exp);
	
	}else{
		/* Make fontsize to integer */
		var newFontSize = parseInt(myFontSize);
		/* Make the fontsize 1px larger */
		newFontSize = newFontSize - 5;
		
		/* Remember new font size */
		if(newFontSize<=1){
			//alert('It is not possible to set the font less than 1 pixels');
		}else{
			SetCookie('myFontSize',''+newFontSize+'',exp);
		}
		
		/* Execute new fontsize */
		document.body.style.fontSize = newFontSize+'%';
	}
	
	// Keep the sections intact
	keepIntact();
}
function toogleUp(){
	/* Get fontsize */
	var myFontSize = GetCookie('myFontSize');
	
	/* If no cookie has been registred the set the fontsize 1px up */
	if (myFontSize==null){
	
		/* Remember font size */
		SetCookie('myFontSize','87',exp);
	
	}else{
		/* Make fontsize to integer */
		var newFontSize = parseInt(myFontSize);
		/* Make the fontsize 1px larger */
		newFontSize = newFontSize + 5;
		
		/* Remember new font size */
		SetCookie('myFontSize',''+newFontSize+'',exp);
		
		/* Execute new fontsize */
		document.body.style.fontSize = newFontSize+'%';
	}
	
	// Keep the sections intact
	keepIntact();
}
function toogleOnload(){
	/* Get fontsize */
	var myFontSize = GetCookie('myFontSize');
	
	/* If no cookie has been registred then dont do anything */
	if (myFontSize==null){
	
		// Keep the sections intact - use only if a cookie has been set
		keepIntact();
	
	}else{
		/* Make fontsize to integer */
		var curFontSize = parseInt(myFontSize);
		
		/* Execute current fontsize */
		document.body.style.fontSize = curFontSize+'%';
		// Keep the sections intact - use only if a cookie has been set
		keepIntact();
	}
	
}
function keepIntact(){
	/* Keep these sections intact */
	if(document.getElementById('service')){
		document.getElementById('service').style.fontSize = '11px';
		document.getElementById('service').style.lineHeight = '16px';
	}
	
	if(document.getElementById('top')){
		document.getElementById('top').style.fontSize = '11px';
		document.getElementById('top').style.lineHeight = '16px';
	}
	
	if(document.getElementById('mainmenu')){
		document.getElementById('mainmenu').style.fontSize = '11px';
		document.getElementById('mainmenu').style.lineHeight = '16px';
	}
	
	if(document.getElementById('tabs')){
		document.getElementById('tabs').style.fontSize = '11px';
		document.getElementById('tabs').style.lineHeight = '16px';
	}
	
	if(document.getElementById('aktivitetform')){
		document.getElementById('aktivitetform').style.fontSize = '11px';
		document.getElementById('aktivitetform').style.lineHeight = '16px';
	}
}
/* Toogle font sizes onload / page change aso. */
window.onload = function(){
	/* Call the toogleOnload function */
	toogleOnload();
}
