/*
 * Shared Javascript functions
 *
 * All functions and other javascript code are available under GPL. Feel free
 * to do what you want with them (as long as the GPL license isn't violated).
 * 
 * Author:  Örjan Persson <o@42mm.org>
 * License: GPL
 * Version: $Id: shared.js 495 2005-12-03 23:23:52Z orange $
 */

/*
 * Create and returns an element
 *
 * IE doesn't support createElementNS.
 */
function createElement(element)
{
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	} else if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}

function addOnloadEvent(fnc){
	if ( typeof window.addEventListener != "undefined" ) {
		window.addEventListener( "load", fnc, false );
	} else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", fnc );
	} else {
		if ( window.onload != null ) {
			var oldOnload = window.onload;
			window.onload = function ( e ) {
				oldOnload( e );
				window[fnc]();
			};
		} else
			window.onload = fnc;
	}
}

function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
			anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

addOnloadEvent(externalLinks);
