
	Event.observe( window, 'load', function() {
		updateDynamicTimeAndDate();
		new PeriodicalExecuter( function(pe) { updateDynamicTimeAndDate(pe) }, 60 );
	} );

	function inputDefaultText(el, text ) {
		
		if( ! $(el) || $(el).hasAttribute('_default_text') ) return;

		if( ! text && el.hasAttribute('defaultText') ) {
			text		= el.getAttribute('defaultText');
		}
		
		var el_text		= Builder.node('div', {className:'input_default', style:'display : none'}, [ text ] );
		
		el.parentNode.insertBefore( el_text, el );
		
		var padLeft	= 5;
		var padTop	= 3;
		var d		= $(el).getDimensions();
		var w		= d.width;
		var h		= d.height - padTop;
		var mb		= -d.height + padTop;
		var mt		= parseInt( $(el).getStyle('marginTop') );
		var ml		= parseInt( $(el).getStyle('marginLeft') );
		mb			-= mt + padTop;
		w			-= padLeft;
		
		el_text.setStyle( {
			width		: w + 'px',
			height		: h + 'px',
			marginTop	: mt + 'px',
			marginLeft	: ml + 'px',
			marginBottom: mb + 'px',
			paddingTop	: padTop + 'px',
			paddingLeft	: padLeft + 'px',
			float		: $(el).getStyle('float'),
			fontSize	: $(el).getStyle('fontSize')
		} );
		
		if( ! el.value.strip() )
			el_text.show();
		
		Event.observe( el_text, 'click', function() {
			el.focus();
		} );
		
		Event.observe( el, 'focus', function(e) {
			//el_text.hide();
			Effect.Fade( el_text, { duration : 0.1 } );
		} );
		
		Event.observe( el, 'blur', function(e) {
			if( ! e.target.value.strip() ) {
				el_text.show();
			}
		} );
		
		$(el).setAttribute('_default_text', 1 );
	}
	
	function showNotice( msg, is_error ) {

		is_error		= is_error ? true : false;
		effect_duration	= is_error ? 0.2 : 0.5;

		if( $('notice') ) {
			$('notice').insert('<li>- ' + msg + '</li>' );
			
			if( is_error )
				$('notice').addClassName('error');
			
			Effect.Appear( $('notice'), { duration: effect_duration } );
		}
	}
	
	function hideNotice() {
		if( $('notice') ) {
			$('notice').update('').removeClassName('error').hide();
		}
	}
	
	function showError( msg ) {
		showNotice( msg, true );
	}
	
	function updateDynamicTimeAndDate(pe) {
		
		$$('.dynamictime').each( function(el) {
			
			if( ! el.getAttribute('timestamp') ) return;
			
			if( ! el.getAttribute('raw') )
				el.setAttribute('raw', el.innerHTML );
			
			var is_date			= el.hasClassName('date');
			var timestamp		= parseInt( el.getAttribute('timestamp') );
			var a				= new Date( timestamp * 1000 );
			var now				= new Date();
			var isToday			= ( a.getFullYear() == now.getFullYear() && a.getMonth() == now.getMonth() && a.getDate() == now.getDate() );
			var now				= now.getTime().toString().substring(0, 10);
			var sec				= now - timestamp;
			var output			= el.getAttribute('raw');

			if( el.hasClassName('date') ) {

				if( sec < 172800 ) // less than 48hours
					output		= 'i går';
				
				if( isToday )
					output		= 'i dag';
			}
		
			if( el.hasClassName('time') && isToday && sec >= 0 ) { // only change timestamp for todays date
				
				if( sec < 46800 )
					output		= 'ca ' + Math.floor( sec / 60 / 60 ) + ' timer siden';

				if( sec < 7200 )
					output		= 'ca 1½ time siden';
				
				if( sec < 5400 )
					output		= 'ca 1 time siden';
				
				if( sec < 3600 )
					output		= 'ca ' + Math.floor( sec / 60 ) + ' minutter siden';
				
				if( sec < 120 )
					output		= 'ca 1 minut siden';
				
				if( sec < 60 )
					output		= 'få sekunder siden';
			}
			el.innerHTML		= output;
		})
	}
	
	function userLoggedOff() {
		alert('Du er ikke logget ind.\n\nDu bliver sendt videre til forsiden, hvor du kan logge ind');
		location	= '/';
	}
	
	function addBreadcrumb( items ) {
	
		if( !$('breadcrumb') ) return;
		
		var first_link		= ( items.length > 1 ) ? items[ items.length - 2 ][0] : items[0][0];
		var first_label		= ( items.length > 1 ) ? 'Tilbage' : items[ items.length - 1 ][1];
		
		$('breadcrumb').appendChild( 
			Builder.node('li', { className:'first' }, [ Builder.node('a', { href: first_link }, [ first_label ] ) ] )
		);
		
		if( items.length > 1 ) {
		
			for( var i=0; i < items.length; i++ ) {
				$('breadcrumb').appendChild( 
					Builder.node('li', { }, [ Builder.node('a', { href: items[i][0] }, [ items[i][1] ] ) ] )
				);
				
				if( i < ( items.length - 1 ) )
					$('breadcrumb').appendChild( Builder.node('li', { }, [ '>' ] ) );
			}
		}
		
		$('breadcrumb').appendChild( Builder.node('br', { style:'clear : both' } ) );
		
		Element.show( $('breadcrumb') );
	}
	
	function popupPage( urlname ) {
		window.open("/vis/" + urlname + "?layout=plain", "popupPage","width=500,height=550,status=0,toolbar=0,location=0,menubar=0,resizable=1,scrollbars=1");	
	}
	
	function getUrlParameter( name ) {
		name 			= name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var str	 	= "[\\?&]"+name+"=([^&#]*)";
		var regex 	= new RegExp( str );
		var results 	= regex.exec( window.location.href );
		if( results == null )
			return "";
		else
			return results[1];
	}
	
	function popupImage( imageid, width, height, crop ) {
		doCrop	= crop ? '?crop=1' : '';
		var popupImageWin = window.open("/fil/popup/" + imageid + "/" + width + "/" + height + doCrop, "popupImage","width=" + ( width + 0) + ",height=" + ( height - 35) + ",status=0,toolbar=0,location=0,menubar=0,resizable=1,scrollbars=0");
	}
	
