var track = {
	recordHit: function() {
		this.initpath = '/track/track.php';
		var path	= this.initpath + '?cookie=' + this.getCookie('dlcsites');
		var allresults = new Object();
		for (var extension in this)
			if (this[extension] && this[extension].recordHit)
				for(var key in (results = this[extension].recordHit()))
					allresults[key] = results[key];
		for (var key in allresults) path += '&' + key + '=' + escape(allresults[key]);
		
		document.write('<img src="'+path+'" alt="" style="position: absolute; right: 0px; top:0px;" onload="this.parentNode.removeChild(this);" />');
		//this.addLoadEvent(this.formatAnchors);
	},

	addLoadEvent: function (func) {
		if (typeof window.onload != 'function') {
			window.onload = func;
		}
		else { 
			var oldonload = window.onload;
			window.onload = function(){ oldonload(); func(); }
		}
	},	
	
	getCookie: function(cookiename) {
		if (document.cookie.length == 0) return null;
		if ((begin = document.cookie.indexOf(cookiename + "=")) !=  -1) {
			begin += cookiename.length + 1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); 
		}
		return null;
	},
	
	recordOutbound: function(href) {
		return this.initpath + '?cookie=' + this.getCookie('dlcsites') + '&outbound=1&requesturi=' + escape(href) + '&referer=' + escape(this.useragent.getURI());
	},
	
	formatAnchors: function() {
  	var anchors = document.getElementsByTagName('A');
  	for(z=0;z<anchors.length;z++)
  		if(typeof anchors[z].onclick == 'function') {
  			var oldonclick = anchors[z].onclick;
	  		anchors[z].onclick = function() {
	  			oldonclick();
	  			this.href = track.recordOutbound(this.href);
	  		};
  		}
			else {
	  		anchors[z].onclick = function() {
	  			this.href = track.recordOutbound(this.href);
	  		};
	  	}
	},
	
	useragent: {
		getURI: function() {
			return (window.decodeURI) ? window.decodeURI(document.URL) : document.URL;
		},
		getReferer: function() {
			return (window.decodeURI) ? window.decodeURI(document.referrer) : document.referrer;
		},
		recordHit: function() {
			var results = new Object();
			results['requesturi'] = this.getURI();
			results['referer'] = this.getReferer();
			results['title'] = document.title;
			return results;
		}
	},
	
	menuid: {
		recordHit: function() {
			var results = new Object();
			results['menuid'] = gmid;
			return results;
		}
	}
}

track.recordHit();
