<!--
Outbound and file tracking script for Google Analytics

Author: Rod Jacka 
Company: Panalysis Pty Ltd www.panalysis.com
Version 1.0.1

Copyright Panalysis Pty Ltd 2006 all rights reserved
You may freely modify, use and distribute this script provided that this message is retained.

Description: Automatically captures clicks to specified non HTML documents and 
links to other websites and feeds these into the Google Analytics tracking code

To install this script:

1) Cut and paste the section between the Start Source JavaScript and End Source secion of this file
into a new text file and rename this outbound.js

2) Add the following reference to your web pages. It is VERY important that this is placed below your 
existing Google Analytics tracking code:

E.g.
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXXX-1";
urchinTracker();

</script>

<script src="/path/to/outbound.js" type="text/javascript"></script>

3) Test the script to check that it doesn't interfere with other scripts on the site. It is 
important to note that as this script interupts the event model of the browser that thorough checking 
is done to identify incompatibilities

4) Optionally you can also specify a separate Google Analytics profile to record these events. To do this 
alter the code above to add the variable var _uacct2 = "UA-XXXXXX-2"; where this is the account code
for the anternative Google Analytics account. This is useful if you don't want to bias variables such
as the number of page views per visitor. E.g.:

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXXX-1";
urchinTracker();

var _uacct2 = "UA-XXXXXX-2";
</script>

<script src="/path/to/outbound.js" type="text/javascript"></script>

*********************** Start Script  ************************************
-->

/*
*      Outbound and file tracking script for Google Analytics
*      
*      Author: Rod Jacka 
*      Company: Panalysis Pty Ltd www.panalysis.com
*      
*      Panalysis are Authorised Google Analytics Consultants and can assist you to 
*      correctly implement and interpret the reports from Google Analytics. 
*      
*      See http://googleanalytics.panalysis.com/ for details
*      
       Copyright Panalysis Pty Ltd 2006-2007 all rights reserved
*      You may freely modify, use and distribute this script provided that
*      this message is retained. The use of this software is subject to the terms of the
*      GNU General Public License which can be viewed at http://www.gnu.org/copyleft/gpl.html
*
*      Description: Automatically captures clicks to specified non HTML documents and 
*      links to other websites and feeds these into the Google Analytics tracking code
*      version 1.02
*
*      To install download this file to your web site and save to a known location e.g. 
*      root level of the site or an includes directory. Be sure to save the file as outbound.js
*      
*      Add the following line below your current Google Analytics code 
*      <script type="text/javascript" src="/outbound.js"></script>
*      
*      Be sure to change the src="/outbound.js" value to match your own installation
*      
*      For a modest fee, Panalysis can install and configure this script for you.
*      Version 1.0.1 - Added function to record transaction in an alternative Google Analytics account
*      
*/

var whoami=navigator.userAgent.toLowerCase(); //use lower case name
var is_firefox = (whoami.indexOf("firefox") != -1); //does name contain 'firefox'?
var is_ie = (whoami.indexOf("msie") != -1); //does name contain 'msie'?


function getOutBoundLink(e){
	var targ;
	var url,dest;
	var base = "/outbound/";
	var includeTypes = Array("pdf","doc","rtf","swf","exe","xls","csv","tsv","ppt","mov","mp3","wmv","html");
	
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	
	if(targ.ELEMENT_NODE != undefined)
	{
		while(targ.nodeType != targ.ELEMENT_NODE)
			targ = targ.parentNode;
	}

	// handle whether the link is an image based link
	if(targ.nodeName == "IMG")
	{
		targ = targ.parentNode;
	}

	if(targ.href != undefined)
		url = targ.href;
	else if(! is_ie && ! is_firefox && targ.target != undefined)
		url = targ.target;

	if(self.urchinTracker && url != undefined)
	{
		var re1 = new RegExp("http[s]?:\/\/([^\/]*?)(\/.*)");
		var re2 = new RegExp("file:\/\/(.*)");
		var m = re1.exec(url);
		if(m)
		{
			if(m[1] != window.location.host)
				dest = base + m[1] + m[2];
			else
			{
				var testURL = m[2]; // it is an internal link
				
				var el = testURL.split(".");
				var ln = el.length - 1;
				var testEx = el[ln].toLowerCase();
				var isOK = false;
				for(var x=0; x<includeTypes.length; x++)
				{
					if(includeTypes[x] == testEx)
						isOK = 1;
				}
				
				if(isOK == 1)
				{
					dest = testURL;
				}
				
			}
		}
		else
		{
			m = re2.exec(url);
			if(! m)
			{
				dest = url;
			}
		}
		
		if(dest != undefined)
		{
			if(_uacct2 != "")
			{
				var _uacct3 = _uacct;
				_uacct = _uacct2;
			}
			
			var rs = urchinTracker(dest);
			_uacct = _uacct3;
			return rs;
		}
	}
	
	return true;
}

try
{
	document.onclick=getOutBoundLink ;
	document.ondoubleclick=getOutBoundLink ;

}
catch(err)
{
 
}
