// JavaScript Document

function createRequestObject() {
	//Q: http://www.admin-wissen.de/tutorials/eigene-tutorials/webentwicklung/ajax-tutorial/ajax-hello-world-im-detail/
	var ro;
	try{           
		ro = new XMLHttpRequest();      
	}      
	catch (e){          
		try{               
			ro = new ActiveXObject("Msxml2.XMLHTTP");          
		}           
		catch (e){             
			try{                 
				ro = new ActiveXObject("Microsoft.XMLHTTP");            
			}             
			catch (failed){                
				ro = null;            
			}         
		}        
	}
	return ro;
}

var http = createRequestObject();

function checkUsername() {
	document.getElementById('antwort1').innerHTML = 'Bitte warten1...';
	var input = document.getElementById('username').value;
	//Q: http://www.ajax-community.de/javascript/2906-javascript-timestamp.html
	var timestamp = new Date().getTime();
	var input2=escape(input);
	var input3=input2.replace(/\+/, "%2b");
	http.open('get', 'ajax_checkusername.php?input='+input3+'&time='+timestamp);
	http.onreadystatechange = handleResponseUsername;
	http.send(null);
}

function handleResponseUsername() {
	if(http.readyState == 4){
		var response = http.responseXML;
		var antwort = response.getElementsByTagName('antwort').item(0);
		document.getElementById('antwort1').innerHTML = antwort.firstChild.data;
	}
}



function checkEmail() {
	document.getElementById('antwort2').innerHTML = 'Bitte warten2...';
	var input = document.getElementById('email').value;
	//Q: http://www.ajax-community.de/javascript/2906-javascript-timestamp.html
	var timestamp = new Date().getTime();
	var input2=escape(input);
	var input3=input2.replace(/\+/, "%2b");
	http.open('get', 'ajax_checkemail.php?input='+input3+'&time='+timestamp);
	http.onreadystatechange = handleResponseEmail;
	http.send(null);
}

function handleResponseEmail() {
	if(http.readyState == 4){
		var response = http.responseXML;
		var antwort = response.getElementsByTagName('antwort').item(0);
		document.getElementById('antwort2').innerHTML = antwort.firstChild.data;
	}
}
