//Auto Download & Exit Link Tracking
/*Regex list of download file extensions, pipe and backslash delimited. Looks for the period before the file type so it will work on download links with query parameters after it */
var downloadTypes = /\.pdf|\.doc|\.xls|\.zip|\.csv|\.ppt|\.rtf|\.pptx|\.docx|\.xlsx|\.wmv|\.mpg|\.mov|\.avi|\.exe|\.mp3|\.wma|\.txt|\.rar|\.wav/i; 

/*Regex list of on-site domains, pipe and backslash delimited. */
var onsiteDomains = /www\.lojack\.com|store\.lojack\.com|dealer\.lojack\.com|my\.lojack\.com|police\.lojack\.com|www\.lojack25thanniversary\.com|lojack25thanniversary\.com|www\.lojackforclassics\.com|lojackforclassics\.com|javascript|#/i;

/*Used to unobtrusivly add events to objects*/
function unobtrusiveAddEvent (element,event,fn) {
   var old = (element[event]) ? element[event] : function () {};
   element[event] = function () {fn(); old();};
}

function downloadLink(i) {
	return function () { 
		if (typeof(_gaq) == "object")
			_gaq.push(['_trackPageview', escape( links[i] )]);
			_gaq.push(['_trackEvent', 'Downloads', 'Download From: ' + escape( location.hostname + location.pathname ), 'Download File: ' + escape( links[i] )]);
	};
}

function exitLink(i) {
	return function () { 
		if (typeof(_gaq) == "object")
			_gaq.push(['_trackEvent', 'Exit Links', 'Exit From: ' + escape( location.hostname + location.pathname ), 'Exit To: ' + escape( links[i] )]);
	};
}

var links = document.links;
if ( links ){
	for(var i=0; i<links.length; i++) {
		if( links[i].href.match(downloadTypes) ){
		unobtrusiveAddEvent( links[i], 'onclick' , downloadLink(i));
		}
		if( !links[i].href.match(onsiteDomains) ){
		unobtrusiveAddEvent( links[i], 'onclick' , exitLink(i));
		}
	}
}
