﻿

// Google download link tracking - HS 11.11.2010 and AC 31.03.2011

function ModifyLinks(ppcValue)
{
	var hyperlinks = document.getElementsByTagName('a');
	for (var i = 0; i < hyperlinks.length; i++)
	{
		var link = hyperlinks[i].href;
		link = link.toLowerCase();
		if (link.indexOf("pdf") > 0 )
		{
			if (ppcValue == null || ppcValue == "")
			{
			    //hyperlinks[i].setAttribute("onclick", "pageTracker._trackPageview('/' + this.href )");
			    hyperlinks[i].setAttribute("onclick", "javascript:_gaq.push(['_trackPageview', '/' + this.href]);"); 
			}
			else
			{
			    //hyperlinks[i].setAttribute("onclick", "pageTracker._trackPageview('/' + this.href + '" + ppcValue + "')");
			    hyperlinks[i].setAttribute("onclick", "javascript:_gaq.push(['_trackPageview', '/' + this.href + '" + ppcValue + "']);"); 
			}
		}
		
		if(link.indexOf("downloadfile.aspx") > 0)
		{
			if(ppcValue == null || ppcValue == "")
			{
            var indexstart = link.indexOf("name=");
            var name = link.substring(indexstart + 5);
                hyperlinks[i].setAttribute("onclick", "pageTracker._trackPageview('/" + name + "')");
                //console.log('download');
			}
			else
			{
			var indexstart = link.indexOf("name=");
            var name = link.substring(indexstart + 5);
                hyperlinks[i].setAttribute("onclick", "pageTracker._trackPageview('/" + name + "_" + ppcValue + "')");
			}
		}
	}
}
