var undefined;

function blockError() {
	return true;
}
window.onerror = blockError; // PC, please remove! Can't find errors in other js files with this in place

function AJAXPost(strURL, queryString) {
	try {
		var req = new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e) {
		try {
			var req = new ActiveXObject('Microsoft.XMLHTTP');
		} catch(oc) {
			var req = null;
		}
	}
	// Mozailla/Safari
	if ( !req && typeof XMLHttpRequest != "undefined" ) {
		req = new XMLHttpRequest();
	}

	if (!req) return;

	req.onreadystatechange = function() { }
	req.open('POST', strURL, true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(queryString);
}

function clickCoords(e, site, page) {
//	if (window.scrollX !== undefined) return;
//	if (window.event === undefined) return;
//	if (!navigator.appName) return;
//	if (navigator.appName != 'Microsoft Internet Explorer') return;
//	if (!navigator.appVersion) return;
///	if (navigator.appVersion.indexOf('Windows NT 5.1') < 0) return;
//	if (!window.ActiveXObject) return;
	if (!e) e = window.event;
//	if (!document.getElementById) return;
//	var id_fontTest = document.getElementById('fonttest');
//	if (!id_fontTest) return;
//	if (id_fontTest.offsetHeight != 19) return;
	/// AJAX the co-ordinates
	var ProcessURL = "/coords.php";
	///// Get mouse co-ordinates
	var posx = 0;
	var posy = 0;
	// Get the coordinates of the click.
	posx = (e.pageX || (e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft));
	posy = (e.pageY || (e.clientY + document.body.scrollTop  + document.documentElement.scrollTop));
	
	// Now work out where the click was relative to the main "all" div
	// The following is to take account of the various layout divs on various sites.
	var allObj = document.getElementById('all');
	if (!allObj) {
		var allObj = document.getElementById('main_wrapper');
		if (!allObj) {
			var allObj = document.getElementById('contentbody');
			if (!allObj) {
				var allObj = document.getElementById('pageContainer');
				if (!allObj) {
					var allObj = document.getElementById('info');
					if (!allObj) {
						var allObj = document.getElementById('border');
						if (!allObj) {
							var allObj = document.getElementById('page');
							if (!allObj) {
								return;
							}
						}
					}
				}
			}	
		}
	}
	var offsetX = findPosX (allObj);
	
	posx -= offsetX;

	if (posy < 0) return;
//	if ((posx > document.body.clientWidth) || (posy > document.body.clientHeight)) return;
	
	if ((document.body.scrollLeft) || (document.body.scrollTop)) {
		posx += document.body.scrollLeft;
		posy += document.body.scrollTop;											
	}
	// posx and posy contain the mouse position relative to the document
	var QString = "x=" + posx + "&y=" + posy + "&page=" + page + "&site=" + site; // NOTE: no '?' before querystring	
	/// Ajax Function
	AJAXPost(ProcessURL,QString);
	//// End AJAX
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

