// 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 getColors(p_bpa_free,p_dishwashersafe,p_handles,p_color,p_character,p_age,p_manufacturer,p_brand,p_material) {

 // 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', 'http://www.buyersguide.com/includes/interactiveResultsSippyCups.php?p_bpa_free=' + encodeURIComponent(p_bpa_free)
	  + '&p_dishwashersafe=' + encodeURIComponent(p_dishwashersafe)
	  + '&p_handles=' + encodeURIComponent(p_handles) 
	  + '&p_color=' + encodeURIComponent(p_color) 
	  + '&p_character=' + encodeURIComponent(p_character)
	  + '&p_age=' + encodeURIComponent(p_age)
	  + '&p_manufacturer=' + encodeURIComponent(p_manufacturer)
	  + '&p_brand=' + encodeURIComponent(p_brand)
         + '&p_material=' + encodeURIComponent(p_material)

	 );





// Function that handles the response:
 ajax.onreadystatechange = handle_check;

 // Send the request:
 ajax.send(null);

 } else { // Can't use Ajax!
 document.getElementById('targetDiv').innerHTML = 'The results will be returned upon submitting this form.';
 }

 }
 
 
 // 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('targetDiv').innerHTML = ajax.responseText;

 }

 } // End of handle_check() function.
