// 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 search_products(search_string) {
	//document.getElementById('searchresults').innerHTML = "Searching...";

	// 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', 'scripts/search_products.php?search_string=' + encodeURIComponent(search_string));
		
		// Function that handles the response:
		ajax.onreadystatechange = handle_check;
		
		// Send the request:
		ajax.send(null);

	} else { // Can't use Ajax!

		document.getElementById('searchresults').innerHTML = 'Search Faild';
	}
	
} // 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('searchresults').innerHTML = ajax.responseText;
		
		//document.getElementById('issue_update_desc').form.description.display='none';
		
		
	}else{
	
	
	}
	
} // End of handle_check() function.
