/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(window.ActiveXObject){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 



function chkUsername(){ 
unameVal=document.register.username.value;
len=unameVal.length;
unme=unameVal.split(" ");
if(unme.length<2){
if(len > 0){
http.open('get','ckUname.php?uname='+ unameVal);
http.onreadystatechange = handleDiv;
http.send(null);
}else{
alert("Kindly enter username");
document.register.username.focus();
}
}else{
alert("Please don't include spaces in your username");
}
}
	

function handleDiv(){
	if(http.readyState == 1){};

	if(http.readyState == 4){ //Finished loading the response 
 		var response = http.responseText;
		
			if (response!="")
			{ 
				document.register.username.value="";
				document.register.username.focus();
				//alert(response);
				alert("Username Already Exists")
			}else{
				alert("Username is Available")
				}

		
	}
}