//*******************************************************************
//  signup.js
//  Functions created for XML-Http-Requests
//
// Created: 4/13/2005
// Author: Christopher Wong
// Based on documentation found here:
// http://developer.apple.com/internet/webcontent/xmlhttpreq.html
//
//*******************************************************************

function checkName(name){
	//Firefox & other browsers like it
		d = new Date();
		url = "checkname.php?name="+name+"&time="+ d.getTime();
		//alert("opening" + url);
	if (window.XMLHttpRequest){
		xmlResponse = new XMLHttpRequest();
		xmlResponse.onreadystatechange = handleStateChange;
		xmlResponse.open("GET", url, true);
		xmlResponse.send(null);
	}
	// IE
	else if(window.ActiveXObject){
		xmlResponse = new ActiveXObject ("Microsoft.XMLHTTP");
		if(xmlResponse){
			xmlResponse.onreadystatechange = handleStateChange;
			xmlResponse.open("GET", url, true);
			xmlResponse.send();
		}
	}
}

function handleStateChange(){
	if (xmlResponse.readyState == 4){
		if(xmlResponse.status == 200){
			//everything went fine output results
			
			response = xmlResponse.responseXML.documentElement;
			if(response.getElementsByTagName('taken')[0].firstChild.data == "true"){
			   document.getElementById("check").innerHTML = "<a tabindex=\"-1\" href=\"#\"><img tabindex=\"-1\" border=0 height=\"18\" width=\"20\" src=\"images/redx.gif\" title=\"Click here to check the username again\"></a>";
			   document.getElementById("errormessage").innerHTML = "Username is already in use or is invalid.  Please choose another username.";
			   document.getElementById("register").disabled = true;
			}  else {
				document.getElementById("check").innerHTML = "<img tabindex=\"-1\" height=\"18\" width=\"20\" src=\"images/greencheck.gif\">";
				document.getElementById("errormessage").innerHTML = "&nbsp;";
				document.getElementById("register").disabled = false;
			}
		}	else{
			//broken... try again
			//alert("ERROR");
		}
			
	}
}



