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

//======================== W3C compliant Popup script
function popupLauncher() {
	var links = document.getElementsByTagName('a');
	for(i=0;i<links.length;i++) {
		if (links[i].rel == "external") {
			links[i].onclick = function tmp() { window.open(this.href,'_blank'); return false; }
		}	
	}
}

//======================== Login overlay to show 'wachtwoord'
function loginOverlay() {
	var overlayWrapper = document.getElementById('overlay-wrapper');
	var gebrnaam = document.getElementById('gebrnaam');

	if (gebrnaam) {
		gebrnaam.onclick = function() {
			gebrnaam.value = "";
		}
	}
	if (overlayWrapper) {
		overlayWrapper.innerHTML = "<span id=\"ww-overlay\">Wachtwoord</span>" + overlayWrapper.innerHTML;
		var ww = document.getElementById('ww');
	}
	var wwOverlay = document.getElementById('ww-overlay');
	if (wwOverlay) {
		wwOverlay.onclick = function() {
			wwOverlay.style.display = "none";			
			if (ww) {
				ww.focus();
			}
		}
		ww.onfocus = function() {
			wwOverlay.style.display = "none";
		}
	}
}

//======================== IE6 antiflicker
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

//======================== Serve safari 3 a separate style sheet
var isSafari3 = false; 
//window.devicePixelRatio &&  window.getMatchedCSSRules is only implemented by Safari 3 now.
if(window.devicePixelRatio && window.getMatchedCSSRules && !window.Opera){
	//you need 	put html {list-style-image:none;} in yout Safari 3 only stylesheet first
	//we detect whether if it's Safari 3 by checking if it read some Safari 3 only styles 
	isSafari3 = !!window.getMatchedCSSRules(document.documentElement,'');
	document.write("<link rel='stylesheet' type='text/css' href='css/safari3.css'>");
}

addLoadEvent(popupLauncher);
addLoadEvent(loginOverlay);