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

function openWindow(myURL, myWidth, myHeight, showScrollbars, windowName){
	showScrollbars = (showScrollbars == true) ? 'yes' : 'no';
	posX = parseInt((screen.width - myWidth) / 2);
	posY = parseInt((screen.height - myHeight) / 2);

	if (windowName == 'undefined' || windowName == '' || windowName == null) {
		windowName = 'kuva';
	}

	dummy = window.open(myURL, windowName, 'top=' + posY + ',left=' + posX + ',width=' + myWidth + ',height=' + myHeight + ',toolbar=no,statusbar=no,scrollbars=' + showScrollbars);
	return false;
}

// This is for popups
function prepareLinks() {
    var links = document.getElementsByTagName("a");
    for (var i=0; i<links.length; i++) {
        if (links[i].className == "popup") {
            links[i].onclick = function() {
                openWindow(this.getAttribute("href"), 800, 600, true, 'Taulukko');
                return false;
            }
        }

    }
}
addLoadEvent(prepareLinks);