/* Check the fields of the comment form are valid */
function checkCommentForm(FormRef) {
	if (FormRef.Comments.value=="") {alert("Du skal skrive en kommentar i feltet."); FormRef.Comments.focus(); return false}
	if (FormRef.Em.value=="") {alert("Venligst anfør e-mailadresse."); FormRef.Em.focus(); return false}
	if (FormRef.Em.value=="E-mailadresse...") {alert("Venligst anfør e-mailadresse."); FormRef.Em.focus(); return false}
	if (FormRef.Comments.value=="") {alert("Du skal skrive en kommentar i feltet."); FormRef.Comments.focus(); return false}
	return true;
	}

/* Clear form field on click */
function clearbox(thebox)
	{
  	thebox.value = "";
	}

/* Configure the TEXTAREA character restriction below */

var count = "250";
function limiter(){
var tex = document.commentForm.Comments.value;
var len = tex.length;
if(len > count){
        tex = tex.substring(0,count);
        document.commentForm.Comments.value =tex;
        return false;
}
document.commentForm.limit.value = count-len;
}

/* Print pop-up box */

function popup(url) 
{
 var width  = 520;
 var height = 500;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=yes';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}

/* Check Search Field isn't blank */

function checkSearchForm(FormRef) {
	if (FormRef.SearchText.value=="") {alert("Anfør venligst søgeord i søgefeltet."); FormRef.SearchText.focus(); return false}
	return true;
	}
	
/* This is for the image rotation in the header */

var images = new Array(
	'/images/carousel-header/image00.jpg',
	'/images/carousel-header/image01.jpg',
	'/images/carousel-header/image02.jpg',
	'/images/carousel-header/image03.jpg',
	'/images/carousel-header/image04.jpg',
	'/images/carousel-header/image05.jpg',
	'/images/carousel-header/image06.jpg',
	'/images/carousel-header/image07.jpg',
	'/images/carousel-header/image08.jpg',
	'/images/carousel-header/image09.jpg',
	'/images/carousel-header/image10.jpg',
	'/images/carousel-header/image11.jpg',
	'/images/carousel-header/image12.jpg',
	'/images/carousel-header/image13.jpg',
	'/images/carousel-header/image14.jpg',
	'/images/carousel-header/image15.jpg',
	'/images/carousel-header/image16.jpg',
	'/images/carousel-header/image17.jpg');

var imageWidth = 520;
var imageHeight = 210;
var imageTimeout = 6000;
var nextImage = 1;

function pageLoad() {

  var el = document.getElementById('fading_image_container');
  while (el.firstChild) { el.removeChild(el.firstChild); }

  el.style.width = imageWidth + 'px';
  el.style.height = imageHeight + 'px';

  for(var i=0; i<images.length; i++) {

    var t = document.createElement('IMG');
    t.setAttribute('src',images[i]);
    t.setAttribute('width',imageWidth);
    t.setAttribute('height',imageHeight);
    t.style.position = 'absolute';
    t.style.visibility = 'hidden';
    el.appendChild(t);

  }

  el.firstChild.style.visibility = 'visible';

  window.setTimeout(startFading, imageTimeout);

}

function startFading() {

  var el = document.getElementById('fading_image_container').childNodes[nextImage];

  el.style.visibility = 'visible';
  el.style.zIndex = 2;
  setOpacity(el, 0);
  fadeImage(el,0);

  nextImage = (nextImage < images.length-1) ? nextImage + 1 : 0;

}

function fadeImage(el, currentOpacity) {

  currentOpacity += 5;

  if (currentOpacity > 100) {
    setOpacity(el, 100);
    var prevEl = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
    prevEl.style.visibility = 'hidden';
    el.style.zIndex = 1;
    window.setTimeout(startFading, imageTimeout);
  }
  else {
    setOpacity(el, currentOpacity);
    window.setTimeout(function() { fadeImage(el, currentOpacity); }, 50);
  }

}

function setOpacity(el, opacity) {

	opacity /= 100;

	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";

}

window.onload = pageLoad;