// Ajax

var xmlHttpNewAccount;

function CheckNewUser(username, email, form)
{
	var xmlHttpNewAccount=null;
	
	try
	 {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttpNewAccount=new XMLHttpRequest();
	 }
	 
	catch (e)
	 {
		 //Internet Explorer
		 try
		  {
			xmlHttpNewAccount=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		 catch (e)
		  {
			xmlHttpNewAccount=new ActiveXObject("Microsoft.XMLHTTP");
		  }
	 }
	
	if (xmlHttpNewAccount==null)
	{
		 alert ("Browser does not support HTTP Request");
		 return
	}

	var url = '/ask/includes/php/checknewuser.php?username=' + username + '&email=' + email; 
	
	xmlHttpNewAccount.onreadystatechange=function()
	{
		if (xmlHttpNewAccount.readyState==4 || xmlHttpNewAccount.readyState=="complete")	
		{
			if(document.getElementById('ajax_new_account'))
			{
				if(xmlHttpNewAccount.responseText == 'user found and email not found')
				{
					document.getElementById('ajax_new_account').innerHTML = '<span style="color:#FF0000;">That username is already in use. Please choose another one.</span>';
				}
				else if(xmlHttpNewAccount.responseText == 'user and email found') 
				{
					document.getElementById('ajax_new_account').innerHTML = '<span style="color:#FF0000;">That username is already in use. Please choose another one.<br />That e-mail is already in use, choose another.</span>';
				}
				else if(xmlHttpNewAccount.responseText == 'user not found and email found') 
				{
					document.getElementById('ajax_new_account').innerHTML = '<span style="color:#FF0000;">That e-mail is already in use, choose another.</span>';
				}					
				else if(xmlHttpNewAccount.responseText == 'user and email not found') 
				{
					document.getElementById('ajax_new_button').innerHTML = '<img src="/graphics/loadingAnimation.gif" />';
					form.submit();
				}
				else {}
	
			}	
		}	
		else {}
	}
	
	xmlHttpNewAccount.open("GET",url,true);
	xmlHttpNewAccount.send(null);
}