/*	This page creates an Ajax request object.
 *	This page is included by other pages that 
 *	need to perform an XMLHttpRequest.
 */

// Initialize the object:
var ajax = false;

// Create the object...

// Choose object type based upon what's supported:
if (window.XMLHttpRequest) {

	// IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
	ajax = new XMLHttpRequest();
	
} else if (window.ActiveXObject) { // Older IE browsers

	// Create type Msxml2.XMLHTTP, if possible:
	try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e1) { // Create the older type instead:
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) { }
	}
	
}

// Send an alert if the object wasn't created.
if (!ajax) {
	alert ('Some page functionality is unavailable.');
}




// START OF FORENAME


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

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

	} else { // Can't use Ajax!
		document.getElementById('forename_label').innerHTML = '';
	}
	
} 


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

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

	} else { // Can't use Ajax!
		document.getElementById('surname_label').innerHTML = '';
	}
	
}

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

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

	} else { // Can't use Ajax!
		document.getElementById('add1Box_label').innerHTML = '';
	}
	
} 

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

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

	} else { // Can't use Ajax!
		document.getElementById('add3Box_label').innerHTML = '';
	}
	
} 


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

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

	} else { // Can't use Ajax!
		document.getElementById('add4Box_label').innerHTML = '';
	}
	
} 


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

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

	} else { // Can't use Ajax!
		document.getElementById('postcodeBox_label').innerHTML = '';
	}
	
} 


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

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

	} else { // Can't use Ajax!
		document.getElementById('phoneBox_label').innerHTML = '';
	}
	
} 

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

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

	} else { // Can't use Ajax!
		document.getElementById('emailBox_label').innerHTML = '';
	}
	
} 


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

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

	} else { // Can't use Ajax!
		document.getElementById('findusBox_label').innerHTML = '';
	}
	
} 


/*	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 check_username(usernameBox) {

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

	} else { // Can't use Ajax!
		document.getElementById('username_label').innerHTML = '';
	}
	
} // End of check_username() function.


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

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

	} else { // Can't use Ajax!
		document.getElementById('passwordBox_label').innerHTML = '';
	}
	
}

//  END OF REGISTER


// START OF CONTACT US

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

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

	} else { // Can't use Ajax!
		document.getElementById('name_label').innerHTML = '';
	}
	
}


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

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

	} else { // Can't use Ajax!
		document.getElementById('telephone_label').innerHTML = '';
	}
	
}


// END OF CONTACT US














// START OF REGISTER

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

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

		// Assign the returned value to a document element:
		document.getElementById('forename_label').innerHTML = ajax.responseText;
		
	}
	
} 



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

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

		// Assign the returned value to a document element:
		document.getElementById('surname_label').innerHTML = ajax.responseText;
		
	}
	
} 


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

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

		// Assign the returned value to a document element:
		document.getElementById('add1Box_label').innerHTML = ajax.responseText;
		
	}
	
} 

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

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

		// Assign the returned value to a document element:
		document.getElementById('add3Box_label').innerHTML = ajax.responseText;
		
	}
	
} 



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

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

		// Assign the returned value to a document element:
		document.getElementById('add4Box_label').innerHTML = ajax.responseText;
		
	}
	
} 

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

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

		// Assign the returned value to a document element:
		document.getElementById('postcodeBox_label').innerHTML = ajax.responseText;
		
	}
	
} 

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

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

		// Assign the returned value to a document element:
		document.getElementById('phoneBox_label').innerHTML = ajax.responseText;
		
	}
	
} 

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

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

		// Assign the returned value to a document element:
		document.getElementById('emailBox_label').innerHTML = ajax.responseText;
		
	}
	
} 

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

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

		// Assign the returned value to a document element:
		document.getElementById('findusBox_label').innerHTML = ajax.responseText;
		
	}
	
} 




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

	// 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;
		
	}
	
} 


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

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

		// Assign the returned value to a document element:
		document.getElementById('password_label').innerHTML = ajax.responseText;
		
	}
	
} 


// END OF REGISTER



// START OF CONTACT US

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

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

		// Assign the returned value to a document element:
		document.getElementById('name_label').innerHTML = ajax.responseText;
		
	}
	
} 


function handle_check_telephone() {

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

		// Assign the returned value to a document element:
		document.getElementById('telephone_label').innerHTML = ajax.responseText;
		
	}
	
} 

// END OF CONTACT US

