///////////////////////////////////////////////////////////////
// Performance Strategies
// Christopher McCulloh
// 5/9/07
//
// Half of AJAX connection. Connects to AJAX/authorization.jsp
// recieves back success>results variable indicating if
// the username is taken or not.
//
// The techniques used here are taken from "Head Rush AJAX" 
// from O'Reilly press as well as from the JQuery library.
///////////////////////////////////////////////////////////////

function checkDBForUserName(userName) {
	document.body.style.cursor = "wait";

	var url = ("AJAX/checkDBForUserName.jsp");//Tells what page to send the request to
	request.open("POST", url, true); //opens the request. [method], [url], [asynchronous or not]
	request.onreadystatechange = successOrNot; //function to call once page recieves a response back from the server
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //url encode it so the data functions like get without it actually being sent through the url (make it so the jsp can read it)
	request.send("username=" + userName); //send it!!! (allows the passing of a variable)
}

function successOrNot() {
	if (request.readyState == 4) {//make sure the server is done processing the request...
	        if (request.status == 200) {//make sure it was successfull

			//get the xml response data
			var xmlDoc = request.responseXML;//create a variable to hold the response text from the request
			var xmlData = new Array();
			xmlData = xmlDoc.getElementsByTagName("results");
			
			//put the results into a variable
			var results = xmlData[0].childNodes[0].firstChild.nodeValue;

			if(results == "no"){
				$("#unTaken").css({ display: "block" });
			}else if(results == "yes"){
				$("#unTaken").css({ display: "none" });
			}else{
				$("#unTaken").css({ display: "block" });
			}
		} else {//end if 200
			$("#unTaken").css({ display: "block" });
		}
		
		document.body.style.cursor = "auto";
	}//end if 4
}//end function*/
