function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
}
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 
//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

var teller = 1;
function doSlideBanners() {
	shiftOpacity("foto"+teller+"A",3000);
	teller++;
	if (teller == 4) { teller = 1; }
	shiftOpacity("foto"+teller+"A",3000);
}

function detectMacXFF2() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}

function doBanners() {
	var d =  detectMacXFF2();
	if (!d) {
		var theswitch = document.getElementById("switch");
		if (theswitch) {
			var foto3 = document.getElementById("foto3A");
			if (foto3) {
				foto3.style.opacity = 0; 
			    foto3.style.MozOpacity = 0; 
			    foto3.style.KhtmlOpacity = 0; 
			    foto3.style.filter = "alpha(opacity=0)"; 
			}
			var foto2 = document.getElementById("foto2A");
			if (foto2) {
				foto2.style.opacity = 0; 
			    foto2.style.MozOpacity = 0; 
			    foto2.style.KhtmlOpacity = 0; 
			    foto2.style.filter = "alpha(opacity=0)"; 
			}
			var foto1 = document.getElementById("foto1A");
			if (foto1) {
				foto1.style.opacity = 1; 
			    foto1.style.MozOpacity = 1; 
			    foto1.style.KhtmlOpacity = 1; 
			    foto1.style.filter = "alpha(opacity=100)"; 
			}
			setInterval("doSlideBanners()",5000);
			
		}	
	}	
}	
	
//addLoadEvent(doBanners);
addLoadEvent(init);
addLoadEvent(initScroller);
addLoadEvent(vakantie);
addLoadEvent(faq);
addLoadEvent(buttons);
addLoadEvent(flashNav);
addLoadEvent(tooltips);
addLoadEvent(boeken);
addLoadEvent(brochure);
addLoadEvent(fotoalbum);

var language = "";

function init() {
	language = document.getElementsByTagName("body")[0].className;
}

function fotoalbum() {
	var frmFoto = document.getElementById("formFoto");
	if(frmFoto) {
		frmFoto.onsubmit = function() {
			return validateFotoForm(this);
		}
		var lnkNogFoto = document.getElementById("linkNogFoto");
		var divFotos = document.getElementById("fotos");
		if(lnkNogFoto && divFotos) {
			lnkNogFoto.onclick = function() {
				if(language=="nl") { foto = "Foto"; }
				if(language=="fr") { foto = "Photo"; }
				var inputs = divFotos.getElementsByTagName("input");
				nr = inputs.length+1;
				fotoinput = "<div>";
				fotoinput += "<label for=\"foto"+nr+"\">"+foto+" "+nr+"<\/label>";
				fotoinput += "<input type=\"file\" size=\"60\" name=\"foto"+nr+"\" id=\"foto"+nr+"\" value=\"\">";
				fotoinput += "<\/div>"
				new Insertion.Bottom('fotos', fotoinput);
				this.scrollIntoView(false);
				return false;
			}
		}
	}
	var dropdowns = getElementsByClass("changePage");
	for(var i=0; i<dropdowns.length; i++) {
		dropdowns[i].onchange = function () { this.parentNode.parentNode.submit(); }
	}
}
function validateFotoForm(theForm) {
	if(theForm.dag.value=="" || theForm.maand.value=="" || theForm.jaar.value=="" || !validate_date(theForm.dag.value,theForm.maand.value,theForm.jaar.value)) {
		if(language=="nl") { msg = "Gelieve een geldige datum in te vullen."; }
		if(language=="fr") { msg = "Veuillez inscrire une date correcte."; }
		alert(msg);
		return false;
	}
	if(theForm.titel.value=="") {
		if(language=="nl") { msg = "Gelieve de titel in te vullen."; }
		if(language=="fr") { msg = "Veuillez inscrire le titre."; }
		alert(msg);
		return false;
	}
	var divFotos = document.getElementById("fotos");
	if(divFotos){
		var notJPG = false;
		var inputs = divFotos.getElementsByTagName("input");
		for(i=0; i<inputs.length; i++) {
			if(inputs[i].value!="") {
				var test = inputs[i].value.toLowerCase() + "#";
				if(test.indexOf(".jpg#") < 0) {
					notJPG = true;
					i = inputs.length;
				}
			}
		}
		if(notJPG) {
			if(language=="nl") { msg = "Gelieve enkel JPG bestanden op te laden"; }
			if(language=="fr") { msg = "Veuillez transmettre seulement des fichiers JPG."; }
			alert(msg);
			return false;
		}
	}
	var btnFotoAlbumSubmit = document.getElementById("fotoAlbumSubmit");
	if(btnFotoAlbumSubmit) {
		btnFotoAlbumSubmit.disabled = true;
	}
	return true;
}

function brochure() {
	var brochureLinks = getElementsByClass("linkBrochure");
	for(var i =0; i<brochureLinks.length; i++) {
		brochureLinks[i].onclick = function() {
			popup(this.href, 1000, 680);
			return false;
		}
	}
}

function popup(url, width, height) {
	theWidth = width;
	theHeight = height;
	theTop = Math.ceil((screen.height-theHeight*1.5)/2);
	theLeft = Math.ceil((screen.width-theWidth)/2);
	winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,copyhistory=0,width="+theWidth+",height="+theHeight+",top="+theTop+",left="+theLeft;
	smallwindow=window.open(url,"Popup",winopts);
	smallwindow.focus();
}

function boeken() {
	var frmBoeken1 = document.getElementById("formBoeken1");
	if(frmBoeken1) {
		frmBoeken1.onsubmit = function () {
			if(frmBoeken1.med_mutualiteit.selectedIndex > 0 && frmBoeken1.mgm_vriend.value!= "") {
				return confirm(lbl_mutualiteit_en_mgm);
			}
		}
		var dropdownMutualiteit = document.getElementById("med_mutualiteit");
		var textAndereMutualiteit = document.getElementById("med_andere_mutualiteit");
		if(dropdownMutualiteit && textAndereMutualiteit) {
			dropdownMutualiteit.onchange = function() {
				textAndereMutualiteit.value = "";
			}
			textAndereMutualiteit.onkeyup = function() {
				dropdownMutualiteit.selectedIndex = 0;
			}
		}
	}
}

function tooltips() {	
	var frmBoeken1 = document.getElementById("formBoeken1");
	if(frmBoeken1) {
		var tips = getElementsByClass("tooltip", frmBoeken1, "div");
		for(var i =0; i<tips.length; i++) {
			tips[i].onmouseover = function() {
				var content = this.getElementsByTagName("div")[0];
				if(content) {
					content.style.display="block";
				}
			}
			tips[i].onmouseout = function() {
				var content = this.getElementsByTagName("div")[0];
				if(content) {
					content.style.display="none";
				}
			}
		}
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function buttons() {
	var btnPrint = document.getElementById("print");
	if(btnPrint) {
		btnPrint.onclick = function() { print(); return false; }
	}
}

function vakantie() {
	var divBegeleiding = document.getElementById("begeleiding");
	var divBegeleiderFotos = document.getElementById("begeleiderFotos");
	var pBegeleiders = document.getElementById("begeleiders");
	if(divBegeleiding && divBegeleiderFotos && pBegeleiders) {
		var As = pBegeleiders.getElementsByTagName("a");
		for(var i=0; i<As.length; i++) {
			As[i].onclick = function() {
				return false;
			}
			As[i].onmouseover = function() {
				var fotos = divBegeleiderFotos.getElementsByTagName("div");
				for(var j=0; j<fotos.length; j++) {
					fotos[j].style.display="none";
				}
				var foto = document.getElementById("f"+this.id);
				if(foto) {
					foto.style.display="block";
				}
			}
		}
	}
	var divAndereData = document.getElementById("andere_data");
	if(divAndereData) {
		divAndereData.style.display = "block";
		var aSwitch = document.getElementById("adSwitch");
		if(aSwitch) {
			aSwitch.onclick = function() {
				var aList =  document.getElementById("adList");
				if(aList.style.display == "none" || aList.style.display == "") {
					aList.style.display = "block";
				} else {
					aList.style.display = "none";
				}
				return false;
			}
		}
	}
}

function faq() {
	var ulVragen = document.getElementById("vragen");
	if(ulVragen) {
		h2s = ulVragen.getElementsByTagName("h2");
		for(var i=0; i<h2s.length; i++) {
			var A = h2s[i].getElementsByTagName("a")[0];
			if(A) {
				A.onclick = function() {
					var antwoord = document.getElementById("a"+this.id);
					if(antwoord) {
						if(antwoord.style.display!="block") {
							antwoord.style.display="block";
							this.parentNode.parentNode.className="active";
						}else{
							antwoord.style.display="none";
							this.parentNode.parentNode.className="";
						}
					}
					return false;
				}
			}
		}
	}
}

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" : "");
}

/*********** scroller ***************/

var scrollerSpeed=6;
var pauseScroller=1;
// Change nothing below!
scrollerSpeed=(document.all)? scrollerSpeed : Math.max(1, scrollerSpeed-1); //slow speed down by 1 for NS
var copySpeed = scrollerSpeed;
var content, frame, scrollerWidth, frameWidth;
var pauseSpeed=(pauseScroller==0)? copySpeed: 0;

function initScroller(){
	frame = document.getElementById("scrollerFrame");
	content = document.getElementById("scrollerContent");
	buttonLeft = document.getElementById("scrollLeft");
	buttonRight = document.getElementById("scrollRight");
	
	if(frame && content && buttonLeft && buttonRight) {

		buttonLeft.onclick = function () {
			return false;
		}
		buttonLeft.onmouseover = function () {
			leftTimeLeft=setInterval('scrollLeft()',20);
		}
		buttonLeft.onmouseout = function () {
			clearTimeout(leftTimeLeft);
		}
	
		buttonRight.onclick = function () {
			return false;
		}
		buttonRight.onmouseover = function () {
			leftTimeRight=setInterval('scrollRight()',20);
		}
		buttonRight.onmouseout = function () {
			clearTimeout(leftTimeRight);
		}

		scrollerWidth = content.offsetWidth;
		frameWidth = frame.offsetWidth;
		content.style.left="0px";
	}	
	
}
function scrollRight(){
	scrollerWidth=content.offsetWidth;
	
	/*
	alert(frameWidth);
	alert(scrollerWidth);
	alert(parseInt(content.style.left));
	*/
	
	if (parseInt(content.style.left) > (frameWidth-scrollerWidth)) {
		content.style.left=parseInt(content.style.left)-copySpeed+"px"
	}		
}
function scrollLeft(){
	if (parseInt(content.style.left) < 0) {
			content.style.left=parseInt(content.style.left)+copySpeed+"px"
	} 
}
	
/*********** /scroller ***************/

function validate_date(day,month,year) {
	var error = 0;
	
	if (isNaN(day) || isNaN(month) || isNaN(year)) {
		error++;
	}
	if(year < 1800) {
		error++;
	}
	if(month < 1 || month > 12) {
		error++;
	}
	if(day < 1 || day > 31) {
		error++;
	}

	if(((month==4)||(month==6)||(month==9)||(month==11))&&(day > 30)) {
		error++;
	}
	if(((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))&&(day > 31)) {
		error++;
	}
	if(month==2) {
		var schrikkeljaar = false;
		if ((year % 4 == 0) ^ (year % 100 == 0) ^ (year % 400 == 0)) {
			 schrikkeljaar = true;
		}
		if ((schrikkeljaar == false)&&(day>28)) {
			error++;
		}
		if ((schrikkeljaar == true)&&(day>29)) {
			error++;
		}
	}	
	if (error > 0) {
		return false;
	}else{
		return true;
	}
}

function showNav() {
	var nav1 = document.getElementById("navnoflash");
	if (nav1) {
		nav1.style.display = "block";
	}
	var nav2 = document.getElementById("slapen");
	if (nav2) {
		nav2.style.display = "block";
	}
}