/*
	THIS FUNCTION adds an onclick event to any link which points to an external host
	If an onclick event is already present, it prepends the new event and the old event follows a semicolon
	
	if "www." precedes the current host name, it is removed for purposes of comparison
	
	If the link is local to this website, and the link ends in ".doc", ".ppt", ".xls", or ".pdf", then it is assumed to be a binary/non-html document whose access should be logged.
	
attachEvent explained
Unlike the standard DOM method, this method still requires us to add the word 'on' to the front of the event name. Also there is no third parameter because this method always passes the event outwards from the most specific object.

Also unlike the standard DOM method, the event is not passed to the function as a parameter. Instead IE supplies a standard window.event object to hold the details relating to the latest event. Most of the commonly used properties of this object are similar enough to the standard ones to allow for cross browser processing. One that is sligfhtly different is window.event.button which contains '1' for the left button, '2' for the right button, and '4' for the centre button with other values up to '7' representing combinations of two or three buttons pressed at the same time. 

Revised 10/8/2009: Trellist added .ashx extension and removed $ from regex to support querystrings on links
*/

function exitLink(){
		if (typeof window.event != 'undefined')
			{
			var thiselement=window.event.srcElement;
			}
		else	
			{
			var thiselement=this;
			}
		var logString="/exit-links/" + thiselement.href;
		logString = logString.replace(/https*\:\/\//i,"");
		pageTracker._trackPageview(logString);
	}

function blobView(){
		if (typeof window.event != 'undefined')
			{
			var thiselement=window.event.srcElement;
			}
		else	
			{
			var thiselement=this;
			}
		var logString=thiselement.pathname;
		if (logString.search(/^\//i) == -1)
			{logString = "/" + logString;
			}
		pageTracker._trackPageview(logString);
	}

function registerEvent(obj, type, listener, useCapture){
	if (typeof obj.addEventListener != 'undefined')
		{
		//standard
		obj.addEventListener(type, listener, useCapture);
		}
	else if (typeof obj.attachEvent != 'undefined')
		{
		//win/ie
		obj.attachEvent('on' + type, listener);
		}
	else //other browsers
		{
		var existing = obj['on' + type];
		if (typeof existing == "function"){
			obj['on' + type] = function()
				{
				existing();
				listener();
				}
			}
		else
			{
			obj['on' + type] = listener;
			}
		}
	}

function ga_addFunc()
	{
	var e = document.getElementsByTagName('a');
	var PageHostname = document.location.hostname.replace(/^www\./,'');
	for(var i=0;i<e.length;i++)
		{
		var thehref = e[i].href;
		if (thehref.indexOf(PageHostname) == -1)
			{
			registerEvent(e[i], "click", exitLink, false);
			}
		else if (thehref.search(/\.doc/i) != -1)
			{
			registerEvent(e[i], "click", blobView, false);
			}
		else if (thehref.search(/\.xls/i) != -1)
			{
			registerEvent(e[i], "click", blobView, false);
			}
		else if (thehref.search(/\.pdf/i) != -1)
			{
			registerEvent(e[i], "click", blobView, false);
			}
		else if (thehref.search(/\.ppt/i) != -1)
			{
			registerEvent(e[i], "click", blobView, false);
			}
		else if (thehref.search(/\.ashx/i) != -1)
			{
			registerEvent(e[i], "click", blobView, false);
			}
		}
	}
