
window.addEvent('domready', function() {

	// Track document downloads through google analytics by adding onClick event to document links
	var resourcePageSelector = '#dm_docs .dm_row .dm_title a';
	var productPageSelector = '.doclink';
	//$$(resourcePageSelector, productPageSelector).setStyle('background-color', '#0C0'); // test code by displaying the affected elements in green
   
	$$(resourcePageSelector, productPageSelector).each(function(el) {
		var href = el.getProperty('href');

		// remove "/resources/" from the front of the url so it's not sent to google analytics
		var prefixRegex = "^/resources/"; // matches "/resources/" at the beginning of the url
		if (href.test(prefixRegex)) {
			href = href.substring("/resources/".length);
		}

		// remove "/download" from the end of the url so it's not sent to google analytics
		var suffixRegex = "/download[^/]*$"; // matches "/download", "/download-2", or "/download" and any non-slash at the end of the url
		if (href.test(suffixRegex)) {
			href = href.substring(0, href.lastIndexOf("/"));
		}
	   
		//el.setProperty('onClick', "window.alert('" + href + "');"); // test code by displaying trackEvent label param
		el.setProperty('onClick', "pageTracker._trackEvent('Documents', 'Downloads', '" + href + "');");
	});
});
