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

addLoadEvent(algemeen);
addLoadEvent(stageboekje);
addLoadEvent(helpinfo);

function helpinfo() {
	var lnk = document.getElementById("helplink");
	if(lnk) {
		lnk.onclick = function() {
			show_popup(this.href,500,200);
			return false;
		}
	}
}


function algemeen() {
	var frmZoek = document.getElementById("searchform");
	if(frmZoek) {
		frmZoek.onsubmit = function () {
			if(frmZoek.q.value.length==0) {
				alert("Gelieve een zoekterm in te vullen.");
				return false;
			}
			return true;
		}
	}
	var DIVs = document.getElementsByTagName("div");
	for(var j=0; j<DIVs.length; j++) {
		if(DIVs[j].className=="sidebarItem") {
			As = DIVs[j].getElementsByTagName("a");
			if(As.length > 0) {
				DIVs[j].onmouseover = function() {
					this.style.cursor = "pointer";
				}
				DIVs[j].onclick = function () {
					As = this.getElementsByTagName("a");
					if(As.length > 0) {
						document.location = As[0].href;
					}
				}
			}
		}
	}
}

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

function stageboekje() {
	var lnk = document.getElementById("lnk_mijnstagiaires");
	if(lnk) {
		lnk.onclick = function() {
			show_popup(this.href,1024,800);
			return false;
		}
	}
	var lnk2 = document.getElementById("lnk_mijnstageboekje");
	if(lnk2) {
		lnk2.onclick = function() {
			show_popup(this.href,1024,800);
			return false;
		}
	}
}
