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

addLoadEvent(fotos);
addLoadEvent(zoomwindow);
addLoadEvent(links);
addLoadEvent(plan);

function plan() {
	var links=document.getElementsByTagName("a");
	for(i=0;i<links.length;i++) {
		if (links[i].className.indexOf("planlink") >= 0) {
			links[i].onmouseover=function() {
				var sString = this.id;
				sString = sString.substring(1, sString.length);
				getFlashMovie("themovie").ShowInfo(parseInt(sString));
			}
			links[i].onmouseout=function() {
				document.themovie.HideInfo();	
			}
		}
	}

}
function showActive(str) {
	showInActive();
	var link = document.getElementById(str);
	if (link) {
		link.className = "active";
	}
}
function showInActive() {
	var ol = document.getElementById("locationol");
	if (ol) {
		var lis=ol.getElementsByTagName("li");
		for(i=0;i<lis.length;i++) {
			lis[i].className = "";
		}
	}	
}
function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }

function links() {

	var printfriendlylink = document.getElementById("print");
	if(printfriendlylink) {
		printfriendlylink.onclick = function () {
			popup(this.href, 750, 600, "Printpreview", "yes", "yes");
			return false;
		}	
	}

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

	var lnkZoek = document.getElementById("linkZoek");
	if(lnkZoek) {
		lnkZoek.onclick = function () {
			theForm = document.getElementById("zoek");
			if(theForm) {
				theForm.submit();
			}
			return false;
		}	
	}
	
	var BtnKalenderVan = document.getElementById("ButtonKalenderVan");
	if(BtnKalenderVan) {
		BtnKalenderVan.onclick = function () {
			popup(this.href, 200, 220, 'kalender', "yes", "auto");
			return false;
		}	
	}
	
	var BtnKalenderTot = document.getElementById("ButtonKalenderTot");
	if(BtnKalenderTot) {
		BtnKalenderTot.onclick = function () {
			popup(this.href, 200, 220, 'kalender', "yes", "auto");
			return false;
		}	
	}
	
	var lnkPlan = document.getElementById("linkPlan");
	if(lnkPlan) {
		lnkPlan.onclick = function () {
			popup(this.href, 980, 700, 'plan', "yes", "yes");
			return false;
		}	
	}
		
}

function putDate(veld, dag, maand, jaar) {
	veld_dag = document.getElementById(veld+"_dag");
	veld_maand = document.getElementById(veld+"_maand");
	veld_jaar = document.getElementById(veld+"_jaar");
	if(veld_dag) { veld_dag.value = dag; }
	if(veld_maand) { veld_maand.value = maand; }
	if(veld_jaar) { veld_jaar.value = jaar; }
}

function fotos() {
	var listFotos = document.getElementById("fotos");
	if(listFotos) {
		var As = listFotos.getElementsByTagName("a");
		for (i=0;i<As.length;i++){
			As[i].onclick = function() {
				popup(this.href, 650, 590, "zoom", "yes", "yes");
				return false;
			}
		}
	}
}

function zoomwindow() {
	var theZoomwindow = document.getElementById("zoom");
	if(theZoomwindow) {
		var linkClose = document.getElementById("closeLink");
		if(linkClose) {
			linkClose.onclick=function() {
				window.close();
				return false;
			}
		}
		
		var theImg = document.getElementById("zoomImg");
		if(theImg) {
			var theWidth = theImg.width + 50;
			var theHeight = theImg.height + 110;
			window.resizeTo(theWidth,theHeight);
		}
	}
}

function popup(url, width, height, name, resizable, scrollbars) {

	pWidth = width;
	pHeight = height;
	
	pTop = Math.ceil((screen.height-pHeight*1.5)/2);
	pLeft = Math.ceil((screen.width-pWidth)/2);
	
	if(resizable != "") {
		pResizable = resizable;
	} else {
		pResizable = "no";
	}
	
	if(scrollbars != "") {
		pScrollbars = scrollbars;
	} else {
		pScrollbars = "no";
	}
	
	if(name != "") {
		pName = name;
	} else {
		pName = "Popup";
	}
	
	winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0,scrollbars="+pScrollbars+",resizable="+pResizable+",width="+pWidth+",height="+pHeight+",top="+pTop+",left="+pLeft;
	smallwindow=window.open(url, pName, winopts);
	smallwindow.focus();
}

function validateEmail(email) {
	
	if (email != null && email != "") {
		a = email.lastIndexOf("@");
		b = email.lastIndexOf(".");
		c = email.indexOf(":");
		d = email.indexOf("/");
		e = email.substring(0,a);
		f = e.indexOf("@");
		g = email.substring(a+1,email.length);
		h = g.indexOf("[");
		i = g.indexOf("]");
		j = g.indexOf("<");
		k = g.indexOf(">");
		l = email.substring(a+1,b);
		m = email.substring(b+1,email.length);
		n = email.substring(0,a);
		p = email.indexOf("'");
		q = email.indexOf("\"");
		o = 0;
		if (a > b) {o++};
		if (c != -1) {o++};
		if (d != -1) {o++};
		if (f != -1) {o++};
		if (h != -1) {o++};
		if (i != -1) {o++};
		if (j != -1) {o++};
		if (k != -1) {o++};
		if (l.length < 2) {o++};
		if (m.length < 2) {o++};
		if (n.length < 1) {o++};
		if (p != -1) {o++};
		if (q != -1) {o++};
		if (o != 0) {
			return false;
		}
	}
	return true;
}
