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

function picturewidth() {
	var divs=document.getElementsByTagName('div');
	for (i=0;i<divs.length;i++) {
		if (divs[i].className=='caption') {
			var picture=divs[i].parentNode;
			var images=picture.getElementsByTagName('img');
			picture.style.width=images[0].offsetWidth+'px';
		}	
	}
}


function links() {
	var zoekvergrootglasLink=document.getElementById("zoekvergrootglas");
	if(zoekvergrootglasLink) {
		zoekvergrootglasLink.onclick=function() {
			zoekform = document.getElementById("searchForm");
			if(zoekform) {
				zoekform.submit();
			}
			return false;
		}
	}
	var printlink=document.getElementById("printpagina");
	if(printlink) {
		printlink.onclick=function() {
			print();
			return false;
		}
	}
	var referlink=document.getElementById("referpagina");
	if(referlink) {
		referlink.onclick=function() {
			var theWidth = 700;
			var theLeft = Math.ceil((screen.width-theWidth)/2);
			var winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0,scrollbars=no,resizable=yes,width="+theWidth+",height=800,top=0,left="+theLeft;
			openPopup(this.href,winopts);
			return false;
		}
	}
	var links=document.getElementsByTagName("a");
	for(i=0;i<links.length;i++) {
		if (links[i].className.indexOf("extLink") >= 0) {
			links[i].onclick=function() {
				openPopup(this.href,"");
				return false;
			}
		}
	}
}

function openPopup(href,winopts) {
	smallwindow=window.open(href,"Popup",winopts);
	smallwindow.focus();
}

addLoadEvent(picturewidth);
addLoadEvent(links);
