// JavaScript Document
function loadXMLDoc(url) {
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processReqChange() {
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			response  = req.responseXML.documentElement;
			method = response.getElementsByTagName('method')[0].firstChild.data;
			result = response.getElementsByTagName('result')[0].firstChild.data;
			eval(method + '(\'\', result)');
		}
	}
}

function checkUsername(input, response){
	if (response != ''){ 
		// Response mode
		/*
		message   = document.getElementById('usernameCheckFailed');
		if (response == 1){
			message.className = 'error';
		}else{
			message.className = 'hidden';
		}
		*/
		alert ('user found');
	}else{
		// Input mode
		url = 'http://localhost:82/puru/custom/xml/checkUserName.php?q=' + input;
		loadXMLDoc(url);
	}
}

function checkEmail(input, response){
	if (response != ''){ 
		// Response mode
		message   = document.getElementById('emailCheckFailed');
		if (response == 1){
			message.className = 'error';
		}else{
			message.className = 'hidden';
		}
	}else{
		// Input mode
		url = 'http://dev.anothercrap.com/xml/checkEmail.php?q=' + input;
		loadXMLDoc(url);
	}
}