var xmlHttp;
	
function checkEmail(input, response) {
 		if (response != ''){ 
   		// Response mode
   		message   = document.getElementById('emailCheckFailed');
   		if (response == 1){
			// già registrata
			message.className = 'errore';
   		}else{
			message.className = 'hidden';
   		} 
 		}else{
   		// Input mode
 		url  = 'http://'+ location.hostname +'/get_email.php?q=' + input;
   		loadXMLDoc(url);
 		}
}

function loadXMLDoc(url) {
   	xmlHttp = false;
   	var xmlHttp = new XMLHttpRequest();
	xmlHttp.onreadystatechange = processReqChange;
	xmlHttp.open("GET", url, 1);
	xmlHttp.send(null);
	function processReqChange() {
   			// only if xmlHttp shows "complete"
 		if (xmlHttp.readyState == 4) {
    			// only if "OK"
   			 if (xmlHttp.status == 200) {
       			// ...processing statements go here...
   				checkEmail('', xmlHttp.responseText)
			} else {
       			alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
  			}
		}
	}
}	
