﻿/**
 * Adds debugdata to debug-element, creates element when not exists
 * @param string
 * @return void
 */
function debug(msg)
{
	var debugEl = document.getElementById('debug');
	if( !debugEl )
	{
		debugEl = document.createElement('div');
		debugEl.id = 'debug';
		document.body.appendChild(debugEl);
	}
	
	var report = document.createElement('p');
	report.appendChild( document.createTextNode(msg) );
	debugEl.appendChild( report );
}



/* Create a new XMLHttpRequest object to talk to the Web server
NEEDS CLEANING UP, SOME DAY...
*/
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}





/*--- ARRAY PROTOTYPE FUNCTIONS ---*/

// -- Standard functions

// Array.concat() - Join two arrays
if( typeof Array.prototype.concat==='undefined' ) {
 Array.prototype.concat = function( a ) {
  for( var i = 0, b = this.copy(); i<a.length; i++ ) {
   b[b.length] = a[i];
  }
  return b;
  };
}

// Array.copy() - Copy an array
if( typeof Array.prototype.copy==='undefined' ) {
 Array.prototype.copy = function() {
  var a = [], i = this.length;
  while( i-- ) {
   a[i] = typeof this[i].copy!=='undefined' ? this[i].copy() : this[i];
  }
  return a;
 };
}

// Array.pop() - Remove and return the last element of an array
if( typeof Array.prototype.pop==='undefined' ) {
 Array.prototype.pop = function() {
  var b = this[this.length-1];
  this.length--;
  return b;
 };
}

// Array.push() - Add an element to the end of an array, return the new length
if( typeof Array.prototype.push==='undefined' ) {
 Array.prototype.push = function() {
  for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
   this[b+i] = a[i];
  }
  return this.length;
 };
}

// Array.shift() - Remove and return the first element
if( typeof Array.prototype.shift==='undefined' ) {
 Array.prototype.shift = function() {
  for( var i = 0, b = this[0], l = this.length-1; i<l; i++ ) {
   this[i] = this[i+1];
  }
  this.length--;
  return b;
 };
}

// Array.slice() - Copy and return several elements
if( typeof Array.prototype.slice==='undefined' ) {
 Array.prototype.slice = function( a, c ) {
  var i, l = this.length, r = [];
  if( !c ) { c = l; }
  if( c<0 ) { c = l + c; }
  if( a<0 ) { a = l - a; }
  if( c<a ) { i = a; a = c; c = i; }
  for( i = 0; i < c - a; i++ ) { r[i] = this[a+i]; }
  return r;
 };
}

// Array.splice() - Remove or replace several elements and return any deleted elements
if( typeof Array.prototype.splice==='undefined' ) {
 Array.prototype.splice = function( a, c ) {
  var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
  if( !c ) { c = l - a; }
  for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
  for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
  this.length -= c - e.length + 2;
  return d.slice( f, f + c );
 };
}

// Array.unshift() - Add an element to the beginning of an array
if( typeof Array.prototype.unshift==='undefined' ) {
 Array.prototype.unshift = function() {
  this.reverse();
  var a = arguments, i = a.length;
  while(i--) { this.push(a[i]); }
  this.reverse();
  return this.length;
 };
}

// -- 4umi additional functions

// Array.forEach( function ) - Apply a function to each element
Array.prototype.forEach = function( f ) {
 var i = this.length, j, l = this.length;
 for( i=0; i<l; i++ ) { if( ( j = this[i] ) ) { f( j ); } }
};

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
Array.prototype.insert = function( i, v ) {
 if( i>=0 ) {
  var a = this.slice(), b = a.splice( i );
  a[i] = v;
  return a.concat( b );
 }
};

// Array.lastIndexOf( value, begin, strict ) - Return index of the last element that matches value
Array.prototype.lastIndexOf = function( v, b, s ) {
 b = +b || 0;
 var i = this.length; while(i-->b) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// Array.random( range ) - Return a random element, optionally up to or from range
Array.prototype.random = function( r ) {
 var i = 0, l = this.length;
 if( !r ) { r = this.length; }
 else if( r > 0 ) { r = r % l; }
 else { i = r; r = l + r % l; }
 return this[ Math.floor( r * Math.random() - i ) ];
};

// Array.shuffle( deep ) - Randomly interchange elements
Array.prototype.shuffle = function( b ) {
 var i = this.length, j, t;
 while( i ) {
  j = Math.floor( ( i-- ) * Math.random() );
  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 }
 return this;
};

// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique = function( b ) {
 var a = [], i, l = this.length;
 for( i=0; i<l; i++ ) {
  if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
 }
 return a;
};

// Array.walk() - Change each value according to a callback function
Array.prototype.walk = function( f ) {
 var a = [], i = this.length;
 while(i--) { a.push( f( this[i] ) ); }
 return a.reverse();
};


// Array.remove( value ) - Removes value
Array.prototype.remove = function( v ) {
    var a = [], i, l = this.length;
    for( i=0; i<l; i++ ) {
	  if( this[i] != v ) { a.push( this[i] ); }
	  else{ i++; }
    }
    return a;
};




Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=this[i++]);
	return sum;
}
Array.prototype.max = function(){
	return Math.max.apply({},this)
}
Array.prototype.min = function(){
	return Math.min.apply({},this)
}




Array.prototype.indexOfMax = function( v, b, s ) {
 var maxV = 0;
 var maxIndex = -1;
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i] >= maxV){ maxV = this[i]; maxIndex = i; }
 }
 return maxIndex;
};







function printfriendly(){
var tmpStr = window.location.toString();
if (tmpStr.indexOf('&layout=') == -1) {
  var tmpIx = tmpStr.indexOf('#');
  if (tmpIx != -1) { tmpStr = tmpStr.slice(0,tmpIx); }
  tmpStr = tmpStr + '&layout=1';
  window.open(tmpStr,'print','width=660, height=460, scrollbars=yes');
  }
}

function TipAFriend (pageid) {

url = escape (window.location.toString());

pagetitle = escape (window.document.title); 

headertext = escape ("Et tip: ")+escape (window.document.title);

window.open ("/page2184.aspx?urlsideid="+pageid+"&urllink="+url+"&urlsidetitel="+pagetitle+"&urloverskrift="+headertext, 'tipafriend', "dependent=yes,width=500,height=350,scrollbars=no,resizable=no");

}

Tangora.Events.AddHandler(window, "onload", InvokeLoadHandlers);

function InvokeLoadHandlers() 
{
	if (typeof(curpageid)!="undefined")
	{
		if (curpageid==2169) {FixKursusPlan();}
	}
}

function FixKursusPlan()
{
	var coll = Tangora.DOM.GetCollectionByClassName('maincell','table','kursusbox');
	var le = "";
	for(var i=0; i<coll.length;i++)
	{
		var pE = coll[i].childNodes[0].childNodes[0].childNodes[0];
		if (pE.childNodes.length>0) {
			var curE = pE.childNodes[0];
			if (curE.innerHTML==le) {le=curE.innerHTML; curE.innerHTML = "";} else {le=curE.innerHTML}
		}
	}
}







function getPos(elm) {
	for(var zx=zy=0;elm!=null;zx+=elm.offsetLeft,zy+=elm.offsetTop,elm=elm.offsetParent);
	return {x:zx,y:zy}
}





function showhide(div){
	if (document.getElementById(div).style.display=='none'){
		document.getElementById(div).style.display = 'block';
	}else{
		document.getElementById(div).style.display = 'none';
	}
}

function showhide_witharrow(div,arrow,folder){
	folder = folder || "/media/";//default value for folder
	if (document.getElementById(div).style.display=='none'){
		document.getElementById(div).style.display = 'block';
		document.getElementById(arrow).src = folder + "open.gif"
	}else{
		document.getElementById(div).style.display = 'none';
		document.getElementById(arrow).src = folder + "closed.gif";
	}
}



function getQueryVariable(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];
		}
	}
	return false;
}




// Get a style property (name) of a specific element (elem)
function getStyle( elem, name ) {
    // If the property exists in style[], then it’s been set recently (and is current)
    if (elem.style[name])
	  return elem.style[name];

    // Otherwise, try to use IE’s method
    else if (elem.currentStyle)
	  return elem.currentStyle[name];

    // Or the W3C’s method, if it exists
    else if (document.defaultView && document.defaultView.getComputedStyle) {
	  // It uses the traditional ‘text-align’ style of rule writing, instead of textAlign
	  name = name.replace(/([A-Z])/g,"-$1");
	  name = name.toLowerCase();

	  // Get the style object and get the value of the property (if it exists)
	  var s = document.defaultView.getComputedStyle(elem,"");
	  return s && s.getPropertyValue(name);

    // Otherwise, we’re using some other browser
    } else
	  return null;
}







function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - corrige o bug do InnerHTML em selects no IE
* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Versão: 2.1 - 04/09/2007
* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
* @objeto(tipo HTMLobject): o select a ser alterado
* @innerHTML(tipo string): o novo valor do innerHTML

Slightly modified by Sjoerd
2007.11.16
- innerHTML.toLowerCase().replace(/<option/g,.. ->innerHTML.replace(/<option/gi,..	
2008.11.06
- commented out "//getting styles" - block								- 
*******/
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
	  innerHTML = "<option>" + innerHTML + "</option>"
    }
    //innerHTML = innerHTML.toLowerCase().replace(/<option/g,"<span").replace(/<\/option/g,"</span")
	innerHTML = innerHTML.replace(/<option/gi,"<span").replace(/<\/option/gi,"</span")
    selTemp.innerHTML = innerHTML
	
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
	  if(spantemp.tagName){     
		opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }	 
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
	opt.setAttribute(attrName,attrVal);
	opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   /*
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   */
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}




/*--- formdata loading --*/
function formIsLoading(e,form,statusfield,statusHTML){
//	if (!e) var e = window.event;
	document.getElementById(statusfield).innerHTML = statusHTML;
}




/*--- Shopping Tabs - Indkøbskurv med fane-sider --*/
function initShoppingTabs(){
	var currentTab=null, nextTab=null, prevTab=null;
	
	// Where are we in the procedure
	// variable 'shopStep' is defined in each step (tab) under "Shoppingcart->Edit layout Text below paragraph", in a single line of JS
	var curShopStep = shopStep || '';
	
	// Define which tab is current, previous and next
	var steps = document.getElementById('orderSteps').getElementsByTagName('li');
	for( var i=0; i<steps.length; i++ )
	{
		if( steps[i].getAttribute('shopstep') == curShopStep )
		{
			currentTab = steps[i];
			if( i>0 ) prevTab = steps[i-1];
			if( i<(steps.length-1) ) nextTab = steps[i+1];
			break;
		}
/*		
		else
		{
			// Add mouseevents
			tsCompat.addEvent(steps[i], 'mouseover', slideShopTab_on);
		}
*/		
	}
	
	// Make current tab active
	if( currentTab ) currentTab.className = 'active';

	
	// Read out hooks and their actions
	var prev_container = document.getElementById('backbutton_container');
	var next_container = document.getElementById('orderbutton_container');
	
	// Set previoius action on tab
	if( prev_container && prevTab )
	{
		var prevHref = prev_container.getElementsByTagName('a')[0].getAttribute('href');
		prevTab.getElementsByTagName('a')[0].href = prevHref;
	}
	// Set next action on tab
	if( next_container && nextTab )
	{
		var nextHref = next_container.getElementsByTagName('a')[0].getAttribute('href');
		nextTab.getElementsByTagName('a')[0].href = nextHref;
	}
	// Set action on very first tab, since it always should be there (Show Cart)
	var pageId = getQueryVariable('pageid');
	var listId = getQueryVariable('listid');
	var showCartUrl = 'page' + pageId +'.aspx?isbasket=1&pageid=' + pageId + '&listid=' + listId + '&orgorderid=0';
	steps[0].getElementsByTagName('a')[0].href = showCartUrl;
}


/*--- Sees if any help tekst is set, and moves it to the rightCol box, else it hides the rightCol ---*/
function moveShopHelp(){
	var curr = document.getElementById('shopHelp');
	if( !curr ){
		document.getElementById('rightCol_container').innerHTML = '';
		return;
	}
	if( curr.innerHTML != '' ) moveHTML( 'shopHelp' , 'rightCol_content' );
	else document.getElementById('rightCol_container').innerHTML = '';
}


/*--- Moves html content from one element (and empties it) to another ---*/
function moveHTML( curr , move2 ){
	var currObj, move2Obj, html;
	
	if( typeof curr == 'string' ) currObj = document.getElementById(curr);
	else if( typeof curr == 'object' ) currObj = curr;
	else return;
	
	if( typeof move2 == 'string' ) move2Obj = document.getElementById(move2);
	else if( typeof move2 == 'object' ) move2Obj = move2;
	else return;
	
	html = currObj.innerHTML;
	
	currObj.innerHTML = '';
	move2Obj.innerHTML = html;
}


/*
 * Returns x & y value (& unit) for an elements background-position
 * @return array;
 */
function getBGpos( el ){
	var myStyle = getStyle( el, 'backgroundPosition' );
	var myVals = myStyle.split(" ");
	alert(myStyle+'\n'+myVals.length);
	var x = getStyleValueAndUnit( myVals[0] );
	var y = getStyleValueAndUnit( myVals[1] );
	
	return { 'x':x , 'y':y }
}



/*
 * Returns value and unit for given value (fx. "100px" => {'va':100,'unit':'px'})
 * @return array;
 */
function getStyleValueAndUnit( styleVal ){
	var un = null;
	var val = parseInt(styleVal);
	
	if( styleVal == '0' )
		un = 'px';// make it easy
	else
	if( styleVal.substr( styleVal.length - 2 ) == 'px' )
		un = 'px;'
	else
	if( styleVal.substr( styleVal.length - 2 ) == 'pt' )
		un = 'pt;'
	else
	if( styleVal.substr( styleVal.length - 2 ) == 'em' )
		un = 'em';
	else
	if( styleVal.substr( styleVal.length - 1 ) == '%' )
		un = '%';
	else
	if( isNaN(styleVal) )
		un = 'none';// like fx "center"
	
	return {'val':val,'unit':un};
}



/*
 * Slides out tab, for shopping-steps
 * @return void;
 */
function slideShopTab_on (e){
	var myA = this.getElementsByTagName('a')[0];
	var mySpan = this.getElementsByTagName('span')[0];
	alert(getStyle(myA,'backgroundPositionX'));
	alert( getBGpos(myA).x.val );
}



/**
 * Submits Kviknummer-searches
 * @return void
 */
function submitQuicksearch(e)
{
	// Stop default action
	if(e.preventDefault) e.preventDefault();//W3C
	e.returnValue = false;//Microsoft
	
	// Some config
	var recordIdSep = '.';
	var anchorIdSep = '#';
	
	var pageId,recordId,anchorId
	var myPage = myDetail = myAnchor = '';
	
	// Get string
	var qs_code = document.getElementById('quicksearch_q').value;
	
	var recordIdSepPos = qs_code.indexOf(recordIdSep);
	var anchorIdSepPos = qs_code.indexOf(anchorIdSep);
	
	if( recordIdSepPos != -1 && anchorIdSepPos != -1 )//has both recordId and anchor : 1234.789#anchor
	{
		pageId = qs_code.substr(0,recordIdSepPos);
		recordId = qs_code.substr(recordIdSepPos + 1,anchorIdSepPos - recordIdSepPos - 1);
		anchorId = qs_code.substr(anchorIdSepPos + 1);
	}
	else if( recordIdSepPos == -1 && anchorIdSepPos != -1 )//No recordid, but an anchor : 1234#anchor
	{
		pageId = qs_code.substr(0,anchorIdSepPos);
		anchorId = qs_code.substr(anchorIdSepPos + 1);
	}
	else if( recordIdSepPos != -1 && anchorIdSepPos == -1 )//has recordid : 1234.789
	{
		pageId = qs_code.substr(0,recordIdSepPos);
		recordId = qs_code.substr(recordIdSepPos + 1);
	}
	else//just a page : 1324
	{
		pageId = qs_code;
	}
	
	myPage = '/page' + pageId + '.aspx';
	if( recordId ) 	myDetail = '?recordid' +  pageId + '=' + recordId;
	if( anchorId ) 	myAnchor = '#' + anchorId;
	
	location.href = myPage + myDetail + myAnchor;
}



function initQuicksearch()
{
	var container = document.getElementById('quicksearch_c');
	if( !container ) return;
	
	var wrapper = document.createElement('div');
	wrapper.className = 'wrapper';
	var form = document.createElement('form');
	form.id = 'quicksearch_f';
//	form.onsubmit = submitQuicksearch;//IE complains...
	Tangora.Events.AddHandler(form,'onsubmit',submitQuicksearch);
	var text = document.createElement('p');
	text.appendChild(document.createTextNode('Kviknummer'));
	var searchbox = document.createElement('input');
	searchbox.id = 'quicksearch_q';
	searchbox.type = 'text';
	searchbox.className = 'field';
	var button = document.createElement('input');
	button.type = 'submit';
	button.value = 'Vis';
	button.className = 'btn';
	
	form.appendChild( text );//add elem to form
	form.appendChild( searchbox );//add elem to form
	form.appendChild( button );//add elem to form
	wrapper.appendChild( form );//add form to wrapper
	container.appendChild( wrapper );//add wrapper to DOM (=container)
	
	container.style.display = 'block';
}
Tangora.Events.AddHandler(window,'onload',initQuicksearch);




/**
 * Converts bytes to hmna understandable values and units
 * @param {int} in bytes
 * @return {string}
 */
function bytes2human(bytesize){   
		
		var returnString = "0 Kb";
		
		// Tester om bytesize er 0, ellers er det ligefedt
	  if (bytesize == 0){return returnString;}


	  // Hvis bytesize er kortere end 4 tal, må formatet være bytes
	  if (bytesize < 1000){	 
	  	returnString = bytesize + " bytes";   
	  }
		    // Bytesize er altså længere end 3 tal, men hvis den er
		    // kortere end 7 tal, må formatet være kilobytes
		    else if (bytesize < 1000000){
					var kbsize = bytesize/1024;
					kbsize = parseInt(kbsize);//Ikke ønsker at have komma-tal i kb
					//kbsize = parseInt((kbsize * 10) + 0.5) / 10;
					returnString = kbsize + " Kb";
		    }
				 
				// Bytesize er altså længere end 5 tal, men hvis den er
				// kortere end 10 tal, må formatet være megabytes
				else if (bytesize < 1000000000){
							var mbsize = (bytesize/1024)/1024;
							mbsize = parseInt((mbsize * 10) + 0.5) / 10;
							returnString = mbsize + " Mb";
				}
				// Bytesize er altså længere end 9 tal, men hvis den er
				// kortere end 13 tal, må formatet være gigabytes
					  else if (bytesize < 100000000000){
									var gbsize = ((bytesize/1024)/1024)/1024;
									gbsize = parseInt((gbsize * 10) + 0.5) / 10;
									returnString = gbsize + " Gb";
					  }
					  // Bytesize er altså længere end 12 tal, men hvis den er
					  // kortere end 16 tal, må formatet være terabytes
						    else if (bytesize < 1000000000000000){
											var tbsize = (((bytesize/1024)/1024)/1024)/1024;
											tbsize = parseInt((tbsize * 10) + 0.5) / 10;
											returnString = tbsize + " Tb";
						    }
		    
	  //Returnerer værdi og målenhed som sat i den rigtige return variabel
	  return (returnString);
}

Tangora.Custom = new Object();

function xTimeLine(wrapId)
{
	var wrapper = null;

	this._todaysDay = 30;
	this._todaysMonth = 10;
	this._todaysYear = 2009;

	this._currentDate = 1;
	this._currentMonth = 0;
	this._currentYear = 2009;

	this._events = new Array();
	this._handlers = new Array();

	this.Init = function()
	{
		wrapper = document.getElementById(wrapId);
		if(wrapper == null) alert("Wrapper \"" + wrapId + "\" not found!");
	}

	this.Render = function()
	{
		wrapper.innerHTML = "";

		var wrap = document.createElement("ul");
		wrap.id = "timeline";

		var weeks = Tangora.Custom.CalendarHelper.GetNumberOfWeeks(this._currentMonth,this._currentYear);
		var days = 7;
		var firstDay = Tangora.Custom.CalendarHelper.GetFirstDayOfMonth(this._currentMonth,this._currentYear);
		var monthLength = Tangora.Custom.CalendarHelper.GetMonthLength(this._currentMonth,this._currentYear);
		var day = this._currentDate;
		var week = Tangora.Custom.CalendarHelper.GetWeekNumber(day,this._currentMonth,this._currentYear);

		var daysWrapper = null;
		var weekWrapper = null;

		var j = 0;
		if(firstDay == 0) j = -1;

		var overFlowDate = 1;
		var overFlowedMonth = 0;
			var overFlowedYear = this._currentYear;

		var dayWrapper = null;
		var d = null;

		var overFlowed = false;

		for(var x = 1; x <= days; x++)
		{
			dayWrapper = document.createElement("li");
			dayWrapper.className = "day";
			if(x == 1) dayWrapper.className += " first";
			if(x == 7) dayWrapper.className += " last";
			if((day == this._todaysDay) && this._currentMonth == this._todaysMonth && this._currentYear == this._todaysYear) dayWrapper.className += " today";
			
			if (day <= monthLength)
			{
				dayWrapper.innerHTML = this.RenderDateString(day, this._currentMonth, this._currentYear);
				dayWrapper.Date = day + "-" + this._currentMonth + "-" + this._currentYear;

				var prefixedDay = Tangora.Custom.CalendarHelper.EnsurePrefix(day);
				var prefixedMonth = Tangora.Custom.CalendarHelper.EnsurePrefix(this._currentMonth+1);

				var evts = this.FindEventsByDate(prefixedDay + "-" + prefixedMonth+ "-" + this._currentYear);

				this.RenderEvents(dayWrapper, evts);

				day++;
			}
			else if(day > monthLength)
			{
				if(!overFlowed) 
				{
					overFlowedMonth = this._currentMonth+1;
					if(overFlowedMonth >= 12)
							    {
								overFlowedMonth = 0;
								overFlowedYear++;
							    }
							    overFlowedDate = Tangora.Custom.CalendarHelper.GetFirstDayOfMonth(overFlowedMonth,overFlowedYear);
					overFlowed = true;
				}

				dayWrapper.innerHTML = this.RenderDateString(overFlowDate, overFlowedMonth , overFlowedYear);
				dayWrapper.Date = overFlowDate + "-" + overFlowedMonth + "-" + this._currentYear;

				var prefixedDay = Tangora.Custom.CalendarHelper.EnsurePrefix(overFlowDate);
				var prefixedMonth = Tangora.Custom.CalendarHelper.EnsurePrefix(overFlowedMonth+1);
				var evts = this.FindEventsByDate(prefixedDay + "-" + prefixedMonth + "-" + this._currentYear);

				this.RenderEvents(dayWrapper, evts);

				overFlowDate++;

				dayWrapper.className += " overflow_month";
			}
			else if((j == -1 && x < 7) || (j == 0 && x < firstDay))
			{
				if(!overFlowed)
				{
					overFlowedMonth = this._currentMonth-1;

					overFlowed = true;
				}

				dayWrapper.innerHTML = this.RenderDateString(overFlowDate, overFlowedMonth, this._currentYear);
				dayWrapper.Date = overFlowDate + "-" + overFlowedMonth + "-" + this._currentYear;

				var prefixedDay = Tangora.Custom.CalendarHelper.EnsurePrefix(overFlowDate);
				var prefixedMonth = Tangora.Custom.CalendarHelper.EnsurePrefix(overFlowedMonth);
				var evts = this.FindEventsByDate(prefixedDay + "-" + prefixedMonth + "-" + this._currentYear);
				this.RenderEvents(dayWrapper, overFlowDate + "-" + overFlowedMonth + "-" + this._currentYear);

				overFlowDate++;

				dayWrapper.className += " overflow_month";	
			}
	
			wrap.appendChild(dayWrapper);
		}

		wrapper.appendChild(wrap);

		var fb = document.createElement("div");
		fb.className = "floatbreaker";
		fb.innerHTML = " ";
		wrapper.appendChild(fb);

		this.ExecuteHandlers("onrender");
	}

	this.RenderEvents = function(wrap, events)
	{
		if(events.length > 0)
		{
			var evList = document.createElement("ul");
			evList.className = "events";

			var lastTime = "00";

			for(var i = 0; i < events.length; i++)
			{
				var eTime = events[i].Time.split(":")[0];

				if(lastTime != eTime)
				{
					var evt = document.createElement("li");
					evt.className = "event t" + events[i].Time.split(":")[0];

					var timeEvents = this.FindEventsByDateAndTime(events[i].Date, events[i].Time);

					this.RenderHoverLayer(evt, timeEvents);

					evList.appendChild(evt);
					
				}

				lastTime = eTime;
			}
		
			wrap.appendChild(evList);
		}
	}

	this.RenderHoverLayer = function(wrap, events)
	{
		if(events.length > 0)
		{
			var hoverLayer = document.createElement("div");
			hoverLayer.className = "tip";

			for(var i = 0; i < events.length; i++)
			{
				var desc = document.createElement("div");
				desc.innerHTML = "<h2>" + events[i].Name + "</h2>";
				desc.innerHTML += "<p class='details'><span class='time'>" + events[i].OrgTime + "</span> <span class='category'>" + events[i].Category+ "</span></p>"; 
				desc.innerHTML += "<p>" + events[i].Text + "</p>";
				hoverLayer.appendChild(desc);
			}

			wrap.appendChild(hoverLayer);
		}
	}

	this.RenderDateString = function(day, month, year)
	{
		var date = new Date(year, month, day);

		return "<span>" + Tangora.Custom.CalendarHelper.GetDayName(date.getDay()) + " " + day + "/" + (month+1) + "</span>";
	}

	this.RegisterEvent = function(date, time, name, text, cat)
	{
		var orgTime = time;
		time = (!isNaN(time.substring(0,2))) ? time : "25";
		var o = new Object();
		o.Date = date;
		o.Time = time.replace(".",":") ;
		o.OrgTime = orgTime;
		o.Category = cat;
		o.Name = name;
		o.Text = text;
		this._events.push(o);
	}

	this.RegisterHandler = function(name, handler)
	{
		var o = new Object();
		o.Name = name;
		o.Handler = handler;
		this._handlers.push(o);
	}

	this.ExecuteHandlers = function(name)
	{
		for(var i = 0; i < this._handlers.length; i++)
		{
			if(this._handlers[i].Name == name) this._handlers[i].Handler();
		}
	}

	this.FindEventsByDateAndTime = function(date, time)
	{
		var arr = new Array();

		for(var i = 0; i < this._events.length; i++)
		{
			if(this._events[i].Date == date && this._events[i].Time.split(":")[0] == time.split(":")[0])
			{
				arr.push(this._events[i]);
			}
		}

		return arr;
	}

	this.FindEventsByDate = function(date)
	{
		var arr = new Array();

		for(var i = 0; i < this._events.length; i++)
		{
			if(this._events[i].Date == date) arr.push(this._events[i]);		
		}

		return arr;
	}

	this.SetMonth = function(month)
	{
		var o = Tangora.Custom.CalendarHelper.AddMonths(month, this._currentMonth, this._currentYear);

		this._currentMonth = o.Month;
		this._currentYear = o.Year;
	}
}
Tangora.Custom.TimeLine = xTimeLine;

function xCalendarHelper()
{
	this._dayNames = ['Søndag','Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'];
	this._monthNames = ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December']; 

	this.GetMonthLength = function(monthIndex,year)
	{
		var d = new Date(year, monthIndex + 1, 0);
		return(d.getDate());
	}

	this.GetMonthName = function(monthIndex)
	{
		return this._monthNames[parseInt(monthIndex+1)];
	}
	
	this.GetDayName = function(dayIndex)
	{
		return this._dayNames[dayIndex];
	}

	this.GetFirstDayOfMonth = function(monthIndex,year)
	{
		var d = new Date(year,monthIndex,1);
		return(d.getDay());
	}

	this.GetNumberOfWeeks = function(monthIndex, year)
	{
		var weeks = Math.ceil((this.GetMonthLength(monthIndex, year) + this.GetFirstDayOfMonth(monthIndex, year)) / 7);

		return weeks;
	}

	this.GetWeekNumber = function(day,month,year)
	{
		month = parseInt(month) + 1;
		var a = Math.floor((14-(month))/12);
		var y = year+4800-a;
		var m = (month)+(12*a)-3;
		var jd = day + Math.floor(((153*m)+2)/5) + (365*y) + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) - 32045;

		var d4 = (jd+31741-(jd%7))%146097%36524%1461;
		var L = Math.floor(d4/1460);
		var d1 = ((d4-L)%365)+L;
		NumberOfWeek = Math.floor(d1/7) + 1;

		return NumberOfWeek;	  
	}

	this.AddDays = function(numberOfDays, day, month, year)
	{
		var monthLength = Tangora.Custom.CalendarHelper.GetMonthLength(month,year);
		
		var newDay = 0;

		newDay = (parseInt(numberOfDays) > 0) ? day+numberOfDays : (day+numberOfDays);

		if(newDay > monthLength)
		{
			newDay = newDay-monthLength;
			var o = this.AddMonths(1, month, year);
			month = o.Month;
			year = o.Year;
		}
		if(newDay < 1)
		{
			var newMonth = (month - 1);
			if(newMonth < 0) newMonth = 11;
			var newYear = year;
			if(newMonth == 11) year = (year - 1);
			var newMonthLength = Tangora.Custom.CalendarHelper.GetMonthLength(newMonth,newYear);
			newDay = newMonthLength+newDay;
			month = newMonth;
			year = newYear;
		}
		
		
		var o = new Object();
		o.Day = newDay;
		o.Month = month;
		o.Year = year;

		return o;
	}

	this.AddMonths = function(numberOfMonths, currentMonth, currentYear)
	{
		var newMonth = currentMonth;
		newMonth = newMonth + numberOfMonths;

		var newYear = currentYear;
		
		if(newMonth > 11)
		{
			newMonth = 0;
			newYear = parseInt(newYear)+1;
		}
		else if(newMonth < 0)
		{
			newMonth = 11;
			newYear = parseInt(newYear)-1;
		}

		var o = new Object();
		o.Month = newMonth;
		o.Year = newYear;

		return o;
	}

	this.GetFirstDayOfWeek = function(date)
	{
		var found = false;

		while(!found)
		{
			if(date.getDay() == 1) found = true;
			else if(date.getDay() < 1)
			{
				var dObj = Tangora.Custom.CalendarHelper.AddDays(1,date.getDate(),date.getMonth(),date.getFullYear());
				date = new Date(dObj.Year, dObj.Month, dObj.Day);				
			}
			else if(date.getDay() > 1)
			{
				var dObj = Tangora.Custom.CalendarHelper.AddDays(-1,date.getDate(),date.getMonth(),date.getFullYear());
				date = new Date(dObj.Year, dObj.Month, dObj.Day);
			}
		}

		return date;
	}

	this.EnsurePrefix = function(number)
	{
		if(number < 10) return "0" + number.toString();
		return number.toString();
	}
}
Tangora.Custom.CalendarHelper = new xCalendarHelper;

function RenderWeatherWidget()
{
	var html = tsAjax.innerHTML("/page4268.aspx?daxx=DAXX0044&rnd=" + Math.random(10000));
	document.write(html);
	var html = tsAjax.innerHTML("/page4268.aspx?daxx=DAXX0056&rnd=" + Math.random(10000));
	document.write(html);
	var html = tsAjax.innerHTML("/page4268.aspx?daxx=DAXX0036&rnd=" + Math.random(10000));
	document.write(html);
}

function GetActions(srcElm, targetId, actionId, callback)
{
	var url ="/page4276.aspx?actionid=" + actionId + "&rnd=" + Math.random(1000);
	var html = tsAjax.innerHTML(url,null,null,null,null,callback);

	var target = document.getElementById(targetId);

	target.innerHTML = html;

	if(callback != null) callback(srcElm);

	return false;
}
Tangora.Custom.GetActions = GetActions;

function AjaxFormPoster(formPageId)
{
	this.CallbackHandler = null;
	var values = new Array();
	var callBackArgs = new Array();
	   
	this.RegisterValue = function(name, val)
	{
		var val = new this.Value(name,val);
		values.push(val);
	}

	this.RegisterArgument = function(arg)
	{
		callBackArgs.push(arg);
	}

	this.Value = function(name, val)
	{
		this.Name = name;
		this.Value = val;
	}

	this.DoPost = function(recId, listId)
	{
		var url = location.protocol + "//" + location.host + "/page" + formPageId + ".aspx?action=post&layoutid=1&action99=write&action103=send&rndkey=" + Math.random(100);
    
			if(recId != null && listId != null) url += "&listid=" + listId + "&recid=" + recId;

		var params = "";
		
		for(var i = 0; i < values.length; i++)
		{
			if(params != "") params += "&";
			params += values[i].Name + "=" + encodeURIComponent(values[i].Value);
		}

		var storage = tsAjax.createInstance("bgsave");
		storage.method="post";
		storage.postData = params + "&previouscontent=";
		storage.Poster = this;
		storage.CallbackArguments = callBackArgs;
		if(this.CallbackHandler != null) storage.callback = this.GenericCallbackHandler;

		if(this.CallbackHandler != null) tsAjax.innerHTML(url,"tsAjax","bgsave",null,null,this.GenericCallbackHandler);
		else return tsAjax.innerHTML(url,null,"bgsave",null,null,null);
	}

	this.GenericCallbackHandler = function()
	{
		if (this.ajaxObj!=null) {
			if (this.ajaxObj.readyState==4) {
				var RT = this.ajaxObj.responseText;
				var poster = this.Poster;

				poster.CallbackHandler(RT, this.CallbackArguments);
											
				if (this.statusElement!=null) {this.statusElement.innerHTML = this.statusText_Done;}
				if (this.resultElement!=null) {this.resultElement.innerHTML = RT}
			} else {
			
		}			
		} else {
			var RT = this.IF.innerHTML;
			if (this.statusElement!=null) {this.statusElement.innerHTML = this.statusText_Done;}
			if (this.resultElement!=null) {this.resultElement.innerHTML = RT}
		}
	}
}
Tangora.Custom.AjaxFormPoster = AjaxFormPoster;

function AjaxPostComment(actionId)
{
	var comment = document.getElementById("comment-" + actionId);
	if(!comment) alert(comment);

	var ap = new Tangora.Custom.AjaxFormPoster(4278);
	ap.RegisterValue("action",actionId);
	ap.RegisterValue("comment",comment.value);
	ap.CallbackHandler = AjaxPostCommentCallback;
	ap.RegisterArgument(actionId);
	ap.DoPost();
}

function AjaxPostCommentCallback(RT, args)
{
	if(RT.indexOf("Tak for din indsendelse")==-1)
	{
		var sString = '<div class="errormsg">';
		var sIndex =RT.indexOf(sString) + sString.length;
		var eIndex = RT.indexOf("</div>");
		var errMsg = RT.substring(sIndex,eIndex);

		alert(errMsg);
	}
	else
	{
		GetActions(null, "comment" + args[0], args[0], null);
		var cList = document.getElementById("comment" + args[0]);
		$.fn.insertComment(cList.childNodes[0]);
		document.getElementById("comment-" + args[0]).value = "";
	}
}