// tracking of external URLs 
// unobstrusive DHTML/JS
// no changes to the HTML source of a webpage needed
// May 2005 Martin Spernau (martin AT traumwind DOT de)
// just include this script in the head section of a page
// external links will be tracked via a 
// request for a dummy GIF with the actual URL as path-param


// Add an eventListener to browsers that can do it somehow.
function addEvent(obj, evType, fn){
        if (obj.addEventListener){
                obj.addEventListener(evType, fn, true);
                return true;
        } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
        } else {
                return false;
        }
}

function trackInit() {
	var links = document.getElementsByTagName("a");
	var externalRex = /http[s]*:/i;
	for (var i = 0; i < links.length; i++) {
		var link = links[i];
		if (externalRex.exec(link.href)) {
			eval( 
			"var fn = function () {"
			+ "track(this);"
			+ "return false;"
			+ "}" 
			);
			addEvent(link,"click", fn );
		}
	}
}


function track(link) {
        var url = link.href;
        var trImg = new Image();
        var now = new Date();
//      trImg.src = "/tracking/dummy.gif/"+url+"?"+now.getTime();
        trImg.src = "/tracking/dummy.gif/"+url;
}

//addEvent(window,'load', trackInit);