// Make document.all[id] work like document.getElementById("id"), so we can actually make shit work in IE < 6 as well.
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

// Links within divs with id="ext" will open in new windows
function opensidelinks() {
	// Checking for compatibility. If methods doesn't work, bail out.
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	// locating the ext div.
	var ext = document.getElementById("ext");
	// locating links within ext div
	var links = ext.getElementsByTagName("a");
	//	loop through them and make them open in a new window
	for (var i=0; i<links.length; i++) {
			links[i].onclick = function () {
				window.open(this.getAttribute("href"));
				return false;
			}
	}
}


// Find externallinks from blogposts and open in a new window always;
function openexternallinks() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	var contentwrapper = document.getElementById("container");
	var bloglinks = contentwrapper.getElementsByTagName("a");
	var regex = /^http:\/\/rapspot.dk/;
	for (var i=0; i < bloglinks.length; i++) {
		if(!regex.exec(bloglinks[i].href)) {
			bloglinks[i].onclick = function () {
				window.open(this.getAttribute("href"));
				return false;
			}
		}
	}
}

// Load more than one function at window.onload
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(opensidelinks); // addding opensidelinks function
addLoadEvent(openexternallinks); // adding openexternallinks function