
function getHttpObject()
{
	var xhr = false;
	if (window.XMLHttpRequest) {
		try {xhr = new XMLHttpRequest();}
		catch(e) { };
	} else if (window.ActiveXObject) {
		try	{xhr = new ActiveXObject("Microsoft.XMLHTTP");} 
		catch(e) {
			try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
			catch(E) { };
		}
	}
	return xhr;
}

function addClick(url, id)
{
	var httpObject = getHttpObject();
	if (httpObject) {
		httpObject.onreadystatechange = function()
		{
			if (httpObject.readyState) {
				if (httpObject.readyState==4) {
					// alert('Test. Normal behavior will return momentarily.');
					top.location.href = url;
				}
			}
		}
		var countit = 'http://www.catholicity.com/js/track.php?id=' + id + '&url=' + encodeURIComponent(url);
		httpObject.open('GET', countit, true);
		httpObject.send(null);
	}
}

window.onload = function()
{
	var links = null;

	if (document.getElementById('news') && document.getElementById('news').getElementsByTagName("a"))
	{
		var links = document.getElementById('news').getElementsByTagName("a");
		for (i = 0; i < links.length; i++) {
			links[i].onclick = function()
			{
				// var href = this.href;
				addClick(this.href, "news");
				return false;
			}
		}
		
		var links = null;
		var i = 0;

		var links = document.getElementById('commentary').getElementsByTagName("a");
		for (i = 0; i < links.length; i++) {
			links[i].onclick = function()
			{
				// var href = this.href;
				addClick(this.href, "commentary");
				return false;
			}
		}				
	}



}
