// Test project
// Ver 2009-04-22-1
// Copyright 2009 Maximized Software. All rights reserved. Do not use or copy.

if (document.getElementsByTagName)
{
	// Init
	var AllLinks = document.getElementsByTagName("a");
	var i = AllLinks.length - 1;
	while (i >= 0)
	{
		MxAttach(AllLinks[i--]);
	}
}



function MxAttach(TheTag)
{

	if (TheTag.addEventListener)
	{
		TheTag.addEventListener("click", MxClickHandler, false);
	}
	else if (TheTag.attachEvent)
	{
		TheTag.attachEvent("onclick", MxClickHandler);
	}

}  // MxAttach()



function MxClickHandler(ClickEvent)
{

	var DestUri = "";
	var DestHostNameLower = "";


	// Init
	var TheTag = (ClickEvent.srcElement) ? ClickEvent.srcElement : this;
	while (TheTag.nodeType == 3)
	{
		// Workaround Safari 3 bug: if TEXT_NODE was selected, then get the parent element instead
		TheTag = TheTag.parentNode;
	}
	var FullHref = TheTag.href;
	if (FullHref == "")
	{
		// Empty tag or anchor
		return;
	}

	// Determine what type of link it is (protocol, internal/external, etc)
	if (TheTag.protocol == "")
	{
		// Empty tag
		return;
	}
	else if (TheTag.protocol == "file:")
	{
		// Not supported, exit now
		return;
	}
	else if (  (TheTag.protocol == "http:")  ||  (TheTag.protocol == "https:")  )
	{
		// Standard http/https link, determine internal or external
		DestHostNameLower = TheTag.hostname.toLowerCase();
		if (Nh(DestHostNameLower) == Nh(location.host.toLowerCase()))
		{
			// Internal; see if it's for a file type that we care about
			var b = TheTag.pathname.match(/\.(?:exe|msi|ini|doc|jpg|png|pdf|zip|txt|js|css|wma|mov|avi|wmv|mp3)$/i);
			if (b)
			{
				// Matched a desired extension!
				// Use the pathname (make sure it starts with '/')
				DestUri = (TheTag.pathname.charAt(0) == "/") ? TheTag.pathname : "/" + TheTag.pathname;
				// And append any search phrase
				if (TheTag.search)
				{
					DestUri += TheTag.search;
				}
			}
			// else, it's an internal link that we don't want to track, so don't set DestUri
		}
		else {
			// External link
    		DestHostNameLower = document.location.host.toLowerCase();
			DestUri = "/outbound/" + FullHref;
		}
	}
	else if (TheTag.protocol == "mailto:")
	{
		DestHostNameLower = document.location.hostname.toLowerCase();
		DestUri = "/mailto/" + FullHref.substring(7);
	}
	// else, unknown/unsupported protocol


	// Did we build a string to be tracked?
	if (DestUri != "")
	{
		try
		{
			var s="";

			DestUri = DestUri.toLowerCase();
			var DestUriEs = _uES(DestUri);
			// Set new random URL number
			s+="&utmn="+ (Math.round(Math.random() * 2147483647));
			// Set browser characteristics
			if (_ufsc)
				s+=_uBInfo();
			if (_uctm)
				s+=_uCInfo();
			if (_utitle && _ubd.title && _ubd.title!="")
			{
				// Set page title to just the path
				s+="&utmdt=" + DestUriEs;
			}
			if (DestHostNameLower!="")
				s+="&utmhn=" + DestHostNameLower;
			if (_usample && _usample != 100)
				s+="&utmsp="+_uES(_usample);
			s+="&utmhid="+_uGH();
			// Referrer is current page
			s+="&utmr="+ _uES(document.location.href);
			// Path
			s+="&utmp=" + DestUriEs;

			// Load it!
			var TempImg=new Image(1,1);
			TempImg.src=_ugifpath2 + "?" + "utmwv=" + _uwv + s + "&utmac=" + _uacct + "&utmcc=" + _uGCS();
			TempImg.onload=function() { _uVoid(); }

		}
		catch (ex)
		{ }


	}

}  // MxClickHandler()



function Nh(h)
{
return h.replace(/^(www\.)/, '');
}  // Nh()

