// Script 13.3 - checkusername.js

/*	This page does all the magic for applying
 *	Ajax principles to a registration form.
 *	The users's chosen username is sent to a PHP 
 *	script which will confirm its availability.
 */

// Function that starts the Ajax process:
function form_sub() {

	document.getElementById('results').innerHTML = ''; //ajax waiting
	document.getElementById('results').style.backgroundColor = '#fff'; 
	document.getElementById('results').innerHTML = '<div id="ajax2"><img src="loading.gif"></div><div id="ajax2"><img src="loading.gif"></div>'; //ajax waiting
	// Confirm that the object is usable:
	if (ajax) { 
		
		// Call the PHP script.
		// Use the GET method.
		// Pass the username in the URL.
		ajax.open('POST', 'upload.php', true);
	
		// Function that handles the response:
		ajax.onreadystatechange = get_data;
		
		// Send the request:
		ajax.send(stuff);

	} else { // Can't use Ajax!
		document.getElementById('results').innerHTML = 'Cannot bring up any details at present.';
	}
	
} // End of check_username() function.

// Function that handles the response from the PHP script:
function get_data() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

		// Assign the returned value to a document element:
		//document.getElementById('info-box').style.border = 'none'; 
		document.getElementById('results').style.backgroundColor = '#A99380'; 
		document.getElementById('results').innerHTML = '';
		document.getElementById('results').innerHTML = ajax.responseText;		
		//jQuery.noConflict();
		
	}	
} // End of handle_check() function.
