var ajax = false;

if (window.XMLHttpRequest) {

	ajax = new XMLHttpRequest();
	
} else if (window.ActiveXObject) { // Older IE browsers

	try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e1) { // Create the older type instead:
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) { }
	}
	
}

if (!ajax) {
	alert ('Some page functionality is unavailable.');
}
/*---------------------------------------------------*/
// Function that starts the Ajax process:
function check_username(username) {

	// Confirm that the object is usable:
	if (ajax) { 
		
		// Call the PHP script.
		// Use the GET method.
		// Pass the username in the URL.
		ajax.open('get', 'action.user/check.php?username=' + encodeURIComponent(username));
		
		// Function that handles the response:
		ajax.onreadystatechange = handle_check;
		
		// Send the request:
		ajax.send(null);

	} else { // Can't use Ajax!
		document.getElementById('username_label').innerHTML = 'The availability of this username will be confirmed upon form submission.';
	}
	
} // End of check_username() function.

// Function that handles the response from the PHP script:
function handle_check() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

		// Assign the returned value to a document element:
		//document.getElementById('username_label').innerHTML = ajax.responseText;
		alert(ajax.responseText);
		
	}
	
} // End of handle_check() function.
