

//core

var ie=document.all;
var ns6=document.getElementById&&!document.all;

function removeText(elem, val) {
	if (elem.value==val) elem.value='';
};

function mailto(str) {
	var email=str, chars='0123456789!#$%&\'*+-/=?^_`{|}~abcdefghijklmnopqrstuvwxyz.@';
	var enckey = getEncodeKeyV1(chars);
	var scid=getCookie('scid');
		
	document.write('<a href=\"mail'+'to'+':'+email+'\">'+email+'<\/a>');
};

function sbSetHilite(elemName,hilite) {
	var sb=document.getElementById(elemName);
	var bName = sb.className.replace(/(\s)/g,'.');
	if (hilite) 
		sb.style.backgroundImage='url(/_/images/gui/' + bName + '.hl.gif)';
	else
		sb.style.backgroundImage='url(/_/images/gui/'+bName+'.gif)';
};

function replaceText(elem, val) {
	if (elem.value=='') elem.value=val;
};
 

function getAbsPos(elt) {
	this.x=0;
	this.y=0;

	while (elt) {
		this.x += parseInt(elt.offsetLeft);
		this.y += parseInt(elt.offsetTop);
		elt = elt.offsetParent;
	};
	return this;
};

function archivedNoteClicked(elem) {
	elem.style.display='none';
	elem.parentNode.className='';
};

function setAbsPos(elt, x, y) {
  var pos = getAbsPos(elt.offsetParent);
  elt.style.left = x-pos.x;
  elt.style.top = y-pos.y;
};

function addArrayElement(elem) {
  this[this.length]=elem;
};

function linkedListElement(ref) {
	this.ref=ref;
	this.next=null;
	this.prev=null;
};

function removeLinkedListElement(elem) {
	if (elem.prev) elem.prev.next = elem.next;
	if (elem.next) elem.next.prev = elem.prev;
	elem = null;
};

function addLinkedListElement(ref) {
	var newElem = new linkedListElement(ref);
	if (!this.head) {
		this.tail = newElem;
		this.head = newElem;
	} else {
		newElem.prev = this.tail; 
		this.tail = newElem;
		newElem.prev.next = newElem;
	};
	this.count++;
	return newElem;
};

function addLinkedListElementObsoleteInterface(elem) {
	return this.parent.add(elem);
};

function execute() {
	// Execute list of functions or method on objects as defined by action parameter
	var elem = this.head;

	while (elem) {
		switch (typeof(elem.ref)) {
		case 'function': elem.ref(); break;
		case 'string': eval(elem.ref); break;
		default:
			switch (this.action) {
				case 1: elem.ref.init(); break;
				case 2: elem.ref.reposition(); break;
			};
		};
		elem = elem.next;
	};
};

function LinkedList(action) {
	this.action = action;
	this.head = null;
	this.tail = null;
	this.count = 0;

	this.run = execute;
	this.add = addLinkedListElement;
	this.remove = removeLinkedListElement;

	this.list = [];
	this.list.add = addLinkedListElementObsoleteInterface;
	this.list.parent = this;
};


document.init=new LinkedList(1);
document.reposition = new LinkedList(2)

function init() {document.init.run();};
function reposition() {document.reposition.run();};

window.onload=init;
window.onresize=reposition;

document.getAbsPos=getAbsPos;
document.setAbsPos=setAbsPos;

function openLayer(layerName) {
	currentLayer=getLayer(layerName)
	if (getVisibility(currentLayer)=='visible') {
		hideLayer(currentLayer);
		setzIndex(currentLayer,1);		
	}	else {
		if (layerName=='logoninfo') {
			hideLayer(getLayer('soeg'));
			setzIndex(getLayer('soeg'),1)
			}
		if (layerName=='soeg') {
			hideLayer(getLayer('logoninfo'));
			setzIndex(getLayer('logoninfo'),1)
			}
		
		setzIndex(currentLayer,100);
		showLayer(currentLayer);};
};

function changeLink(id,href,text) {
  var link = document.getElementById(id);
  if (link) {
    link.innerText = text;
    link.href = href;
  };
};

function setOrder(fld,order) {
  fld.value = order; fld.form.submit();
};

function setDisplay(elem,val,mode) {
	if (!mode) mode='block';
	if (typeof(elem)=='string') elem = document.getElementById(elem);
	if (elem) elem.style.display=((val)?mode:'none');
};

// Validation

function validateRegExp(field,reg) {
	if (!field) return false;
	var re = new RegExp(reg,'ig'), r = field.value.search(re); 
 	return (r<0);
};

function validateFieldRegExp(withAlerts,elem,fieldName,reg,alertTxt) {
  if (!validateRegExp(elem,reg)) return false; 
  else return makeAlert(withAlerts, elem, alertTxt);
};

function makeAlert(withAlerts,field,msg) {
	if (withAlerts) {
		if (field) if (field.type!='checkbox') field.focus();
		if (msg) alert(msg);
	};
	return true;
};

function validateCheckbox(withAlerts,checkbox,alertTxt) {
	var err=false;
	if (checkbox) {
		err=(!checkbox.checked);
		if (err) makeAlert(withAlerts,checkbox,alertTxt);
	};
	return err;
};



function validateFieldEmail(withAlerts,elem,fieldName,alertTxt) {
  if (!alertTxt) alertTxt ='Email-adressen er ikke korrekt udfyldt.';
  return (validateFieldRegExp(withAlerts,elem,fieldName,'^[a-zA-Z0-9]+([\\.\\-\\_][a-zA-Z0-9]+)*@([a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*\\.)+[a-zA-Z]{2,4}$',alertTxt));
};

function validateFieldOrgNumber(withAlerts,field,fieldName,alertTxtOnEmpty) {
	if (!field) return false;
	if (alertTxtOnEmpty) alertTxtOnEmpty = fieldName + ' skal indtastes... - ' + alertTxtOnEmpty;
  var err=validateFieldNonEmpty(withAlerts,field,fieldName,alertTxtOnEmpty);
  if (!err) err=validateFieldRegExp(withAlerts,field,fieldName,'^[ ]*([0-9]{10}|[0-9]{6}[\\- ][0-9]{4})[ ]*$','CVR-nummer er ikke korrekt udfyldt');
	if (!err) err=validateCheckSum(withAlerts,field,fieldName,'?');
  return err;
};

function validateFieldPersonNumber(withAlerts,field,fieldName,alertTxt) {
	if (!field) return false;
  if (!alertTxt) alertTxt='?';
  var err=validateFieldNonEmpty(withAlerts,field,fieldName);
  if (!err) err=validateFieldRegExp(withAlerts,field,fieldName,'^[ ]*([0-9]{10}|[0-9]{6}[\\- ][0-9]{4})[ ]*$',alertTxt);
	if (!err) err=validateCheckSum(withAlerts,field,fieldName,'?');
  return err;
};


function validateCheckSum(withAlerts,field,fieldName,alertTxt) {
	if (!field) return false;
	var err=0,sum=0,n=field.value.replace(/[ -]/g,'');
	for (var i=0;(i<n.length) && (!err);i++) {
		var c=n.charCodeAt(i)-48;
		err = ((c<0) || (c>9));
		if ((!err) && (i<n.length-1)) {
			var psum = ((i % 2)?c:c*2);
			sum += ((psum<10)?psum:psum % 10 + Math.floor(psum/10));
		};
	};
	if (!err) err = (((10-(sum % 10))%10) != (n.charCodeAt(n.length-1)-48));
	if (err) makeAlert(withAlerts,field,alertTxt);
	return err;
};

function validateFieldNonEmpty(withAlerts, elem, fieldName, alertTxt, extAlertTxt) {
	if (!alertTxt) alertTxt = fieldName + ' skal indtastes...';
	alertTxt=alertTxt+(extAlertTxt?extAlertTxt:'');
	
	return (validateFieldRegExp(withAlerts,elem,fieldName,'\\S',alertTxt));
};


function validateFieldEANCheckSum(withAlerts,field,required) {
	var i=0, ean='',c,sum=0;
	while (i<field.value.length) {
		c=field.value.substr(i,1);
		if (((c<'0') || (c>'9')) && (c!=' ')) return makeAlert(withAlerts,field,'EAN-nummer må kun indeholde tal');
		if (c!=' ') {
			ean=ean+c;
			if (i<12) {
				if (i % 2) 
			  		sum=sum+(c.charCodeAt(0)-48)*3;
					else
		  			sum=sum+c.charCodeAt(0)-48;
			};
		};
		i++; 
	};
	field.value=ean;
	if ((required) || (ean.length>0)) {
		if (ean.length!=13) return makeAlert(withAlerts,field,'EAN-nummer skal indeholde 13 cifre');
 		if ((ean.charCodeAt(12)-48) != (10 - sum % 10) % 10) return makeAlert(withAlerts,field,'EAN-nummer er ikke gyldigt');
 	};
	return false;
};

// EVENT HANDLING

function addEventHandler(element, handlerObject, eventType, propagation) {
	addEvent(element, eventType, catchEvent, propagation);
	element.handler = handlerObject;
	if (!element.propagation) element.propagation = new Object;
	element.propagation[eventType] = propagation;
};

function addEvent(el, eType, fn, uC) {
  if (el) {
	  if (el.addEventListener) {
		  el.addEventListener(eType, fn, uC);
		  return true;
	  } else if (el.attachEvent) {
		  return el.attachEvent('on' + eType, fn);
	  } else {
		  el['on' + eType] = fn;
	  };
	};
};

function stopProp(e) {
	if (window.event) window.event.cancelBubble = true;
	else if (e.stopPropagation) e.stopPropagation();
};

function stopDef(e) {
	if ((e) && (e.preventDefault)) e.preventDefault();
	else if ((window.event) && (window.event.returnValue))
	window.eventReturnValue = false;
};

function catchEvent(e) {
  var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	while ((targ) && (!targ.handler)) targ = targ.parentNode;
	if ((targ) && (targ.handler)) {
		if (!targ.propagation[e.type]) stopProp(e);
		if (targ.handler[e.type]) targ.handler[e.type]();
	};
};

// TABS 2.0

function tabList(initialTab) {
	this.tabs = new Array();
	this.active = null;
	this.initialTab=(initialTab?initialTab:0);
	
	document.init.add(this);
	
	this.init = function() {
		for (var i=0; i<this.tabs.length; i++) {
			var tab = this.tabs[i];
			var btn = document.getElementById(tab.tabId);
			tab.baseClass = btn.className;
			addEventHandler(btn, tab, 'click', false);
			if (tab.mode!='') tab.className = tab.baseClass + ' ' + tab.mode;
			if (tab.mode=='active') tab.click();
			if (tab.unclickable) btn.style.cursor = 'default';
		};
	};
	
	this.open = function(i) {
		return this.tabs[i].open();
	};

	this.add = function(tabId, paneId, initialMode, ontabclose, unclickable) {
		this.tabs[this.tabs.length] = new tab(this, tabId, paneId, initialMode, ontabclose, unclickable);
	};
};

function tab(parentlist, tabId, paneId, initialMode, ontabclose, unclickable) {
	this.tabId = tabId;
	this.paneId = paneId;
	this.parentlist = parentlist;
	this.mode = ((initialMode)?initialMode:'');
	this.ontabclose = ontabclose;
	this.i = parentlist.tabs.length;
	this.unclickable = unclickable;
	
	this.open = function() {
		var btn = document.getElementById(this.tabId);
		var pane = document.getElementById(this.paneId);
		if (this.parentlist.active) {
			if (this.parentlist.active.tabId!=this.tabId) if (!this.parentlist.active.close(this.i)) return false;
		};
		if (pane) pane.style.display='block';
		this.parentlist.active = this;
		btn.className=this.baseClass+' active';
		if (this.parentlist.onstatechange) this.parentlist.onstatechange(this.i,true);
		this.mode = 'active';
		return true;
	};

	this.click = function() {
		if ((this.mode=='ghosted') || (this.unclickable)) return;
		this.open();
	};
	
	this.close = function(fromTab) {
		if (this.ontabclose) if (!this.ontabclose(fromTab)) return false;

		var pane = document.getElementById(this.paneId);
		if (pane) pane.style.display='none';
		this.parentlist.active=null;
		document.getElementById(this.tabId).className=this.baseClass;
		if (this.parentlist.onstatechange) this.parentlist.onstatechange(this.i,false);
		this.mode = '';
		return true;
	};
};



// TABS

var tabX = 100, tabI = 0, tabY, tabC=-1, initialTab=0, tabArray=[];

function tabOld(index, url, onopentab) {
	this.index = index;
	this.url = url;
	this.onopentab = onopentab;
};

function makeTab(caption,active,helptxt,url,hidetab,onopentab) {
  var zIndex = 100-tabI,tHTML;
  if (!tabI) {
    document.write('<img src="/_/images/common/blank.gif" width="1" height="17" border="0"><br><table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td height="1" class="smTabBorder"><img src="/_/images/common/blank.gif" width="1" height="1" border="0" id="tabHook"></td></tr></table>');
    document.init.add(reposTabs);
    document.reposition.add(reposTabs);
  };

  if (active) initialTab=tabI;

	tabArray[tabI] = new tabOld(tabI, url, onopentab);

  if (!hidetab) {
		tHTML = '<div id="tab'+tabI+'" style="float:left"';
	  tHTML += ' onclick="openTab(' + tabI + ')"';
		if (helptxt) if (helptxt!='') tHTML += ' title="' + helptxt + '"';
		tHTML += ' class="smTab0">';

		document.write(tHTML);
		document.write('<span class="smTabCaption">'+caption+'</span>');
		document.write('</div>');
	};
  tabI++;
};



function openTab(t) {
  var pane,tabElement;

  if (t==tabC) return;
  if (!confirmDiscardChanges()) return;

	if (tabArray[t].url) {
		if (pane=document.getElementById('pane'+t)) if (pane.innerHTML=='')	{
		  document.location.href=tabArray[t].url;
		  return;
		};
	};
	if (pane=document.getElementById('pane'+tabC)) {
		pane.style.display='none';
		if (tabElement=document.getElementById('tab'+tabC)) {
			tabElement.className='smTab0';
			tabElement.style.zIndex--;
		};
	};
  if (pane=document.getElementById('pane'+t)) {
		pane.style.display='block';
		if (tabElement=document.getElementById('tab'+t)) {
			tabElement.className='smTab1';
			tabElement.style.zIndex = 100;
		};
  };
	tabC=t;
	if (tabArray[t].onopentab) tabArray[t].onopentab();
};

function reposTabs() {
  if (tabI>0) {
		var tabAnchor=document.getElementById('tabHook');
    var imgPos=getAbsPos(tabAnchor);
    tabX = imgPos.x + 10;
    tabY = imgPos.y - 17;

		for (var i=0; i<tabI; i++) {
			if (tabAnchor=document.getElementById('tab'+i)) {
				setAbsPos(tabAnchor,tabX,tabY+1);
				tabX = tabX + parseInt(tabAnchor.clientWidth) - 5;
			};
		};
		if (tabC>=0) openTab(tabC);
		else openTab(initialTab);
  };
};


// funktion til at lave custom popup vindue
function OpenPopup(innerHTML,ePos,callbackFunction) {
	var popup = document.popup;
	if (!popup) popup = document.popup = document.createElement('div');
	popup.click = callbackFunction;
	//popup.onmouseup = cancelBubble;
	popup.style.position = 'absolute';
	popup.style.backgroundColor = "lightyellow";
	popup.style.fontSize = '10px';
	popup.style.border = "ridge white 2px";
	popup.style.padding = "5px";
	popup.style.width=200;
	popup.innerHTML = innerHTML;
	popup.style.display='block';
	document.body.appendChild(popup);

	setAbsPos(popup,ePos.x,ePos.y);
	if (popup.style.display=='none') popup.style.display='block';
}


function confirmDiscardChanges() {
	if (typeof(dataChanged)!='undefined') {
	  if (dataChanged) {
	    if (confirm('\r\n\r\nVil du forsætte uden at opdatere?')) {
				dataChanged=0;				
	    } else {
	      return false;
	    };
	  };
	};
	return true;
};

// MEDIA

function pad0(str) {
  var res='00'+str;
  return res.substr(res.length-2);
};



// OTHER FUNCTIONS

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
};

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
};

function getQueryStringVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&"); 
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");    
    if (pair[0] == variable) return pair[1];    
  }; 
};


// CROSS BROWSER DOM TRAVERSAL

function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}


function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
};


function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
};

function childByIndex(parent,idx) {
	var sib = firstChildElement(parent);
	while ((sib) && (idx>0)) {
		idx--; sib = nextSiblingElement(sib);
	};
	return sib;
};

function firstChildElement(sib) {
  sib = sib.firstChild;
  while (sib) {
    if (!is_ignorable(sib)) return sib;
     sib = sib.nextSibling
  }
  return null;
};

function nextSiblingElement(sib) {
  while (sib=sib.nextSibling) if (!is_ignorable(sib)) return sib;
  return null;
};


// SCROLL BOX

function InitScrollbox(id,scrollbarWidth,zIndex) {
  var scrollbox = document.getElementById(id);
  
  scrollbox.init = initScroller;
  scrollbox.reposition = reposScroller;
  scrollbox.scrollbarWidth = scrollbarWidth;
  scrollbox.zIndex = zIndex;
  
  document.init.list.add(scrollbox);
  document.reposition.list.add(scrollbox);
  
  function reposScroller() {

    this.scrollAreaHeight = parseInt(this.parentNode.clientHeight);
    
    var spos = getAbsPos(this.parentNode);
    this.scrollbar.style.height = this.scrollAreaHeight+'px';
    var brw = parseInt(this.parentNode.style.borderRightWidth);
    if (!this.parentNode.style.borderRightWidth) brw=0;

    this.scrollbar.style.left = (spos.x+this.parentNode.offsetWidth-this.scrollbarWidth-brw)+'px';
    this.scrollbar.style.top = spos.y+'px';


    var tabHeight = Math.floor(this.scrollAreaHeight*this.scrollAreaHeight/this.offsetHeight);

    if (tabHeight<1) tabHeight=1;
    
    if (tabHeight<this.scrollAreaHeight) {
      this.sliderMaxY = this.scrollAreaHeight-tabHeight;
			this.slider.style.top = Math.floor(-parseInt(this.style.marginTop)/(this.offsetHeight-this.scrollAreaHeight)*this.sliderMaxY)+'px';
      this.slider.style.height = tabHeight+'px';
      this.scrollbar.style.display = 'block';
    } else {
      this.scrollbar.style.display = 'none';
    };

    
  };
  
  function initScroller() {

    this.scrollbar = document.createElement('div');
		this.scrollbar.className='scrollbar';
		this.scrollbar.style.width = this.scrollbarWidth+'px';
		
		document.body.appendChild(this.scrollbar);
		this.scrollbar.innerHTML = '<div class="slider" id="myslider"></div>';

		this.style.marginTop = '0px';
    this.slider = firstChildElement(this.scrollbar);
    this.slider.scrollbox = this;
    this.scrollbar.scrollbox = this;
    this.slider.onmousedown = mousedown;
    this.slider.onmouseup = mouseup;
    this.scrollbar.onmouseup = moveslider;
    this.slideto = slideto;
    this.slideToSection = slideToSection;
    this.showall = showall;
    this.slider.style.zIndex = this.zIndex + 1;
    this.scrollbar.style.zIndex = this.zIndex ;

		scrollbox.reposition();    
  };
  
  function mousedown(e) {
    if (ie) e = window.event;
    document.onmousemove = slide;
    document.onmouseup = mouseup;
    document.scrollbox = this.scrollbox;
    document.scrollbox.dragFromY = e.clientY;
    document.scrollbox.dragTabY = parseInt(this.offsetTop);
    return false;
  };

  function moveslider(e) {
    var clickY = e?clickY=e.pageY : event.clientY+document.body.scrollTop, pos = new getAbsPos(this);
    if (clickY-pos.y<=parseInt(this.scrollbox.slider.style.top)+parseInt(this.scrollbox.slider.style.height)/2) 
      this.scrollbox.slideto(parseInt(this.scrollbox.slider.style.top)-parseInt(this.scrollbox.slider.style.height));
    else
      this.scrollbox.slideto(parseInt(this.scrollbox.slider.style.top)+parseInt(this.scrollbox.slider.style.height));
    return false;
  };

  function slide(e) {
    if (document.scrollbox) {
      if (ie) e = event;
      document.scrollbox.slideto(document.scrollbox.dragTabY+e.clientY-document.scrollbox.dragFromY);
    };
    return false;
  };

	function slideToSection(n) {
		var elem = childByIndex(this,n);
 		this.parentNode.style.height = parseInt(elem.offsetHeight)+'px';
    this.style.marginTop = (elem.parentNode.offsetTop-elem.offsetTop)+'px';
		this.reposition();
	};
	
	function showall() {
		this.parentNode.style.height = parseInt(this.offsetHeight) + 'px';
		this.style.marginTop = '0px';
		this.reposition();
	};
	

  function slideto(y) {
    if (y<0) y=0;
    if (y>this.sliderMaxY) y=this.sliderMaxY;
    this.slider.style.top = y+'px';
    var newOffsetY = -Math.floor((y/this.sliderMaxY)*(this.offsetHeight-this.scrollAreaHeight));
    this.style.marginTop = newOffsetY+'px';
  };

  function mouseup(e) {
    if (ie) e = event;
    document.scrollbox = null;
    document.onmousemove = null;
    document.onmouseup = null;
    e.cancelBubble=true; 
    return false;
  };
};


//-----------------------------------------------------------------------------
// Til Forsiden.
//-----------------------------------------------------------------------------

function getHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  }else if( document.documentElement && (document.documentElement.clientHeight ) ) {
  //IE 6+ in 'standards compliant mode'
  myHeight = document.documentElement.clientHeight;
  } else if( document.body && (document.body.clientHeight ) ) {
  //IE 4 compatible
  myHeight = document.body.clientHeight;
  }
  return myHeight;  
};
    
function resizeFrontImage() {
  var imBG=document.getElementById('imBG');
  var backgr=document.getElementById('backgr');
  var Pw  = imBG.nativeWidth;
  var Ph  = imBG.nativeHeight;
  var Ww = parseInt(document.body.clientWidth);
  var Wh = parseInt(getHeight());

  if ((Pw/Ph)>=(Ww/Wh)) {
		Pw=Math.floor((Pw*Wh) / Ph); Ph = Wh;
		backgr.style.left = Math.floor((Ww - Pw) / 2.0) +'px';
		backgr.style.top = 0+'px';
  } else {
    Ph = Math.floor((Ph*Ww) / Pw); Pw = Ww;
    backgr.style.left = 0+'px';
    backgr.style.top = Math.floor((Wh - Ph) / 2.0) +'px';
	};
  imBG.width = Pw; imBG.height = Ph;
};

function initFrontImage() {
  var img=document.getElementById('imBG');

  img.nativeWidth = img.width;
  img.nativeHeight = img.height;

  resizeFrontImage();

  document.getElementById('backgr').style.visibility = 'visible';
  document.reposition.add(resizeFrontImage);
  //document.reposition.add(updateImageOverlay);
};

function collapseAll() {
	toggleDynObject(null);
};

  
function slider(dim, callback, easeFunction, speed, ticks, name) {
  this.speed = speed;
  this.dim = dim.slice(0);
  this.callback = callback;
  this.pos = new Array(dim.length);
  this.easeFunction = easeFunction;
  this.ticks = ticks;
  this.t = this.ticks;
  this.timer = 0;
  this.name = name;

  this.tick = function() {
		var prop = this.easeFunction(1.0-(--this.t)/this.ticks);
		for (var i=0;i<this.dim.length;i++) 
			this.pos[i] = this.dim[i][0]+(this.dim[i][1]-this.dim[i][0])*prop;
		if (!this.t) 
			for (var i=0;i++;i<this.dim.length) this.pos[i]=dim[i][1];
		else 
			this.timer = window.setTimeout('document[\''+this.name+'\'].tick()',this.speed);

		this.callback(this.pos,(!this.t));
  };
  
  this.reset = function () {
		if (this.timer) {window.clearTimeout(this.timer); this.timer=0}
  };
};

function resetSlider(name) {
  var old = document[name];
  if (old) old.reset();
};

function StartSlider(dim, callback, easeFunction, speed, ticks, name) {
	resetSlider(name);
  document[name] = new slider(dim, callback, easeFunction, speed, ticks, name);
  
  document[name].tick();
};

function ease_Linear(t)    {return t};
function ease_Pow(t)       {return Math.pow(t,2)};
function ease_Sinus(t)     {return (Math.sin(t*Math.PI-Math.PI/2.0)+1.0)/2.0};
function ease_SinusPow(t)  {return Math.pow((Math.sin(t*Math.PI-Math.PI/2.0)+1.0)/2.0,2)};
function easeOut_Circle(t) {return Math.sqrt(1.0-Math.pow(1.0-t,2))};

function getAbsPos(elt) {
  this.x=0;	
  this.y=0;

  while (elt) {
	  this.x += parseInt(elt.offsetLeft);
	  this.y += parseInt(elt.offsetTop);
	  elt = elt.offsetParent;
  };
  return this;
};

// Front menu

var menuContentOffset=7;

function initMenu() {
	
  for (var i=1;i<=4;i++) {
		var section = document.getElementById('section_' + i);	
		
		if (section) {
			var obj = new dynObj(setMenuPos);
			obj.menu = i;
			
			obj.content = document.getElementById('section_' + i + '_content');
			obj.spacer=document.getElementById('section_' + i + '_spacer');	       
			obj.section=section;	       
			obj.height = parseInt(obj.content.offsetHeight);
			obj.width = parseInt(obj.content.offsetWidth);
			obj.onchange = updateMenuArrow;
			
			obj.reposition = function () {
				var sectionPos = getAbsPos(this.section);
				this.content.style.left = sectionPos.x+'px';
			};
			
			obj.reposition();
			
			obj.click = toggleMenu;
			
			addEventHandler(obj.section, obj, 'click', false);
			addEvent(obj.content,'click',stopProp,true);

			dynObjects[i]=obj;
			
			document.reposition.add(obj);
		};
  };
  
  if (dynObjects.length==2) {
		dynObjects[1].arrowFlashCount=8;
		dynObjects[1].arrowState=true;
		flashArrow();
  };
  if (dynObjects.length>2) {
		var activeMenu = getCookie('cms.frontmenu');
		if (activeMenu) activeMenu=parseInt(activeMenu);
		if (activeMenu) {
			var obj=dynObjects[activeMenu];
			if (obj) {
				obj.state=1;
				obj.movEnd=1;
				updateDynObjects([1],true);
			};
		};
  };
};

function flashArrow() {
	var obj=dynObjects[1];
	if ((obj.arrowFlashCount>0) || (!obj.arrowState)) {
		obj.arrowFlashCount--;
		obj.arrowState = !(obj.arrowState);
	  var arrow = document.getElementById('arrow_'+obj.menu); 
	  arrow.style.display = (obj.arrowState?'block':'none');
	  obj.arrowFlashTimer = window.setTimeout('flashArrow()',100);
	} else {
		obj.arrowFlashTimer = null;
	};
};
 
	
var dynObjects = [null];

function setMenuPos(done) {
  var sectionPos = getAbsPos(this.section), offset=menuContentOffset;
  if ((dynObjects.length==2) && (this.menu)) offset=0;
  var newHeight = Math.round((this.height+offset)*this.pos);
  this.spacer.style.height = newHeight+'px';
  this.content.style.top = (sectionPos.y+40+newHeight-this.height-offset)+'px';	      
  this.content.style.clip = 'rect('+ (this.height+offset-newHeight) + 'px ' + this.width + 'px '+(this.height)+'px 0px)';
  this.content.style.visibility = 'visible';
};

function collapseMenus() {
	toggleDynObject(null);
};

function dynObj(update) {
	this.pos = 0;
	this.movStart = 0;
	this.movEnd = 0;
	this.state = -2; // closed
	this.update = update;
	this.setState = function(s) {
		this.state = s;
		if (Math.abs(this.state)==1) {
			if (this.onchange) this.onchange();
			if ((this.state==-1) && (this.oncollapse)) this.oncollapse();
			this.movStart = this.pos;
			this.movEnd = ((this.state==1)?1:0);
		};
	};
};

function toggleMenu() {
	toggleDynObject(this.menu);
};

function updateMenuArrow() {
	if (this.menu) setMenuArrow(this.menu, this.state>0);
};

function collapseMenus() {
	var stateChange = false;
	for (var i=0;i<dynObjects.length;i++) {
		var obj = dynObjects[i];
		if (obj) {
		  var oldState=obj.state;
		  obj.setState((obj.state>-2?-1:-2));
		  stateChange = ((stateChange) || (oldState!=obj.state));
		};
	};
	if (stateChange) SlideDynObjects();
};

function SlideDynObjects() {
	StartSlider([[0,1]],updateDynObjects,easeOut_Circle,0,6,'slidedynobjects')
};

function toggleDynObject(o) {
	var state = 0;
	if (o!=null) state=(dynObjects[o].state>0?-1:1);
	setDynObjectDisplay(o,state);
}; 

function setDynObjectDisplay(o,state) {
	resetSlider('slidedynobjects');
	for (var i=0;i<dynObjects.length;i++) {
		var obj = dynObjects[i];
		if (obj) obj.setState(((i==o)?state:((obj.state>-2)?-1:-2)));
	};
	SlideDynObjects();   
};

function updateDynObjects(pos,done) {
	var activeMenu;
	for (var i=0;i<dynObjects.length;i++) {
		var obj = dynObjects[i];
		if ((obj) && (Math.abs(obj.state)==1)) {
		  obj.pos = obj.movStart + (obj.movEnd-obj.movStart)*pos[0];
			obj.update(done);
		  if (done) {
				obj.state = obj.state*2;
				if (obj.state==2) activeMenu=obj.menu;
			};
		};
	};
  if ((done) && (dynObjects.length>2)) {
		setCookie('cms.frontmenu',(activeMenu?activeMenu:0),null,'/');		
	};
};
  
function setMenuArrow(i,open){
  var arrow = document.getElementById('arrow_' + i);
  var sep = arrow.src.lastIndexOf('/')+1;
  arrow.src = arrow.src.substring(0,sep+7) + (open?'.open':'') + '.gif';
};
 
function opacity(id, start, end, millisec) { 
  var speed = Math.round(millisec / 100); 
  var timer = 0; 
  if(start > end) { 
    for(i = start; i >= end; i--) {         
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
      timer++; 
    } 
  } else if(start < end) {
    for(i = start; i <= end; i++) { 
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
      timer++; 
    } 
  } 
};

function initImageOverlay() {
	var overlay=document.getElementById('imageOverlay');
	if (overlay) {
		overlay.overlayText=document.getElementById('imageOverlayText');
		overlay.offset = -45;
		overlay.slider = new dynObj(updateImageOverlay);
		overlay.slider.overlay = overlay;

		overlay.slider.reposition = function () {
			this.overlay.style.top = (parseInt(getHeight())-parseInt(this.overlay.overlayText.offsetHeight)*overlay.slider.pos+overlay.offset)+'px';
		};
		
		overlay.slider.reposition();
		
		overlay.slider.menu = dynObjects.length;

		//overlay.slider.click = toggleMenu;
		
		var overlayHeader=document.getElementById('imageOverlayHeader')

		//addEventHandler(overlayHeader, overlay.slider, 'click', false);
		//addEvent(overlay.overlayText,'click',stopProp,true);
		
		dynObjects[dynObjects.length]=overlay.slider;
		
		document.reposition.add(overlay.slider);
		
		overlay.style.visibility='visible';
	};
};

function updateImageOverlay(done) {
	var overlay=document.getElementById('imageOverlay');
	if (overlay) {
		overlay.slider.reposition();
		setOpacity(overlay,60+this.pos*20);
		setOpacity(document.getElementById('container'),100-this.pos*80);
	};
};

function setImageOverlay(on) {
	var overlay=document.getElementById('imageOverlay');
	if ((overlay) && (overlay.slider)) {
		if ((overlay.slider.state==2) && (!on) || (overlay.slider.state==-2) && (on)) {
			setDynObjectDisplay(overlay.slider.menu,(on?1:-1));
		};
	};
};


function setOpacity(elem, opacity) {
  elem.style.opacity = (opacity / 100); 
  elem.style.MozOpacity = (opacity / 100); 
  elem.style.KhtmlOpacity = (opacity / 100); 
  elem.style.filter = "alpha(opacity=" + opacity + ")"; 
};

var currentPopup;

function ShowPopup(elemName) {
  var div = document.getElementById(elemName)
  currentPopup=elemName;
  StartSlider([[2,70]],setOpacity,ease_Sinus,20,30,elemName);
};

function SetHighlight(clickedSection,on) { 
  var content = document.getElementById('section_'+clickedSection)
   content.style.backgroundColor = (on?'#303030':'#202020');
};

function shortcutHandler(keyCode,action) {
	this.href = (typeof(action)=='string'?action:null);
	this.func = (typeof(action)!='string'?action:null);
	this.keyCode = keyCode;
	this.keydown = function(e) {
		if (window.event) e=window.event;
		if (e.keyCode==this.keyCode) {
			if (this.href) document.location.href=this.href;
			else this.func();
		};
	};
};

function installShortcut(elem,key,action) {
	addEventHandler(elem,new shortcutHandler(key,action),'keydown',false);
};

// AJAX STUFF

function AJAXObject(onreadyHandler,errorHandler) {
	this.httpRequest = 0;
	this.errorHandler=errorHandler;
	this.onreadyHandler = onreadyHandler;
	this.initialize();
};

AJAXObject.prototype.initialize = function() {
	if (window.ActiveXObject) { // IE
		try {
			this.httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (err) {
			try {
				this.httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (err) {return this.raiseError(err)}
		}
	} else if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		this.httpRequest = new XMLHttpRequest();
		if (this.httpRequest.overrideMimeType) {
			this.httpRequest.overrideMimeType('text/xml');
		}
	}; 
	if (!this.httpRequest) return this.raiseError('Unable to initialize AJAX');
	this.httpRequest.onreadystatechange = this.onreadyHandler;
	return true;
};

AJAXObject.prototype.raiseError = function(message) {
	if (this.errorHandler) {
		this.errorHandler(message)
	} else {
		alert(message);
	};
	return false;
};

AJAXObject.prototype.open = function(url) {
	if (this.initialize()) {
		try {
			this.httpRequest.open('GET',url,true);
			this.httpRequest.send(null);
		} catch (err) {
			this.raiseError(err);
		};
	};
};

AJAXObject.prototype.idle = function() {
	return (this.httpRequest.readyState==0) || (this.httpRequest.readyState==4);
};

AJAXObject.prototype.ready = function() {
	var rq=this.httpRequest;
	if (rq.readyState==4) {
		if (rq.status==200) {
			this.xml = rq.responseXML;
			return true;
		} else {
			if (rq.status!=0) return this.raiseError('Fejl ' + rq.status + ' ved kald af service');
		};
	} else {
		return false;
	};
};

AJAXObject.prototype.xPathSearch = function(expr,node) {
	var sNode = (node?node:this.xml.documentElement),sDoc = this.xml.documentElement;
	if ((window.XMLHttpRequest) && (this.xml.evaluate)) {
		try {
			//var xpathEvaluator = new XPathEvaluator(sDoc);
			//var nsResolver = xpathEvaluator.createNSResolver(sDoc);
			var xpathResult = this.xml.evaluate(expr, sNode, null, 0, null);
			var nodeList = [], res;
			while (res = xpathResult.iterateNext()) nodeList.push(res);
			return nodeList;
		} catch (e) {
			return this.raiseError(e.description);
		}
	} else {
		try {
			this.xml.setProperty("SelectionLanguage", "XPath");
			return sNode.selectNodes(expr);
		} catch (e) {
			return this.raiseError(e.description);
		}
	};
};

AJAXObject.prototype.selectSingleNode = function(expr,node) {
  var nl = this.xPathSearch(expr,node);
   if (nl.length){
     return nl[0];
   }
};





function insertadr(mail){
 document.write('<a href="mailto:'+deCrypt(mail)+'">'+deCrypt(mail)+'</a>');
};

function deCrypt(encryptedstring){
  var x, i, tmp
  tmp=''
     encryptedstring = StrReverse(encryptedstring );
    for (i=0; i<encryptedstring.length; i++)
    {    
      x = Mid(encryptedstring,i,1);      
      tmp = tmp +(Chr(Asc(x) - 1))    
    }
    return tmp;
}

function Chr(CharCode) {
	return String.fromCharCode(CharCode);
};

function Asc(string)
{
	var symbols = " !\"#$%&'()*+'-./0123456789:;<=>?@";
	var loAZ = "abcdefghijklmnopqrstuvwxyz";
	symbols += loAZ.toUpperCase();
	symbols += "[\\]^_`";
	symbols += loAZ;
	symbols += "{|}~";
	var loc;
	loc = symbols.indexOf(string);
	if (loc > -1)
	{ 
		Ascii_Decimal = 32 + loc;
		return (32 + loc);
	}
	return (0);
}

function Mid(str, start, len) {
// Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
};

function StrReverse(str) { 
   var retStr = ""; 
   for (i=str.length - 1 ; i > - 1 ; i--){ 
      retStr += str.substr(i,1); 
   } 
   return retStr; 
};

//malthe
function musover() {
    event.srcElement.style.background = '#000000';
    event.srcElement.style.color = '#FFFFFF';
 };
 
function musout() {
  event.srcElement.style.background = 'transparent';
  event.srcElement.style.color = '#000000';
};
var sifuSlideActive 



function sifuSlide() {
 if(sifuSlideActive){   
   if(sifuSlideActive==event.srcElement.id){     
      document.getElementById(sifuSlideActive+'_Sub').style.display='none'   
      sifuSlideActive=''
   }else{
    document.getElementById(sifuSlideActive+'_Sub').style.display='none'
    document.getElementById(event.srcElement.id+'_Sub').style.display='block'
    sifuSlideActive=event.srcElement.id
   }
 }else{   
   document.getElementById(event.srcElement.id+'_Sub').style.display='block'
   sifuSlideActive=event.srcElement.id
 } 
};

function bottomSlide(){
  var elem = document.getElementById('bottomSlide')
  elem.style.height='200px'
}