// Holds an instance of XMLHttpRequest
var xmlHttp = createXMLHttpRequestObject();

// Creates an XMLHttpRequest instance
function createXMLHttpRequestObject()
{
	var xmlHttp;
	
	try {
		// This should work for all browsers except IE6 and older
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Assume IE6 or older
		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
										'MSXML2.XMLTTTP.5.0',
										'MSXML2.XMLHTTP.4.0',
										'MSXML2.XMLHTTP.3.0',
										'MSXML2.XMLHTTP',
										'Microsoft.XMLHTTP');
		// Try all versions until one works
		for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) {
			try {
				// Try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {} // Ignore errors
		}
	}
	
	return xmlHttp;
}

// Function called when the state of the HTTP request changes
function handleRequestStateChange()
{
	// When readyState is 4 we are ready to read the server response
	if (xmlHttp.readyState == 4) {
		// Continue only if HTTP status is OK
		if (xmlHttp.status == 200) {
			try {
				handleServerResponse();
			} catch (e) {
				alert("Error reading the response: " + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data:\n" +
				  xmlHttp.statusText);
		}
	}
}

// Handles the response received from the server
function handleServerResponse()
{
	var sResponse = xmlHttp.responseText;
}

function logScreenInfo()
{
	if (xmlHttp) {
		try {
			var widthParam = "width=" + screen.width;
			var heightParam = "height=" + screen.height;
			var colorDepthParam = "colorDepth=" + screen.colorDepth;
			var params = widthParam + '&' + heightParam + '&' + colorDepthParam;
			
			// Initiate the asynchronous HTTP request
			xmlHttp.open("GET", "logScreenSettings.php?" + params, true);
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.send(null);
		} catch (e) {
			alert("Can't connect to the server:\n" + e.toString());
		}
	}
}

window.onload = logScreenInfo;