/*
This is our function to use xmlhttp requrests, i did not write this part w3 schools did
[url=http://www.w3schools.com/ajax/ajax_browsers.asp]http://www.w3schools.com/ajax/ajax_browsers.asp[/url]
This was quicker than just making my own :)
*/
var xmlHttp // xmlHttp variable

function GetXmlHttpObject(){ // This function we will use to call our xmlhttpobject.
var objXMLHttp=null // Sets objXMLHttp to null as default.
if (window.XMLHttpRequest){ // If we are using Netscape or any other browser than IE lets use xmlhttp.
objXMLHttp=new XMLHttpRequest() // Creates a xmlhttp request.
}else if (window.ActiveXObject){ // ElseIf we are using IE lets use Active X.
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") // Creates a new Active X Object.
} // End ElseIf.
return objXMLHttp // Returns the xhttp object.
} // Close Function







function account_test(username,method){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="ajax_login.php?user_login_name="+username+"&method="+method // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
var data = xmlHttp.responseText;


if(data=='yesname') //if correct login detail
		  {
		  document.getElementById('resultyesname').innerHTML='Login Name Available';
		  document.getElementById('resultnoname').style.display = 'none';
		  document.getElementById('resultyesname').style.display = 'inherit';
		  exit();
		  }
		  else if(data=='noname') 
		  {
		  document.getElementById('resultnoname').innerHTML='Login Name Already Exist';
		  document.getElementById('resultyesname').style.display = 'none';
		  document.getElementById('resultnoname').style.display = 'inherit';
		  exit();
          }
		 else if(data=='yesemail') //if correct login detail
		  {
		  document.getElementById('resultyesemail').innerHTML='Email Available';
		  document.getElementById('resultnoemail').style.display = 'none';
		  document.getElementById('resultyesemail').style.display = 'inherit';
		  exit();
		  }
		  else if(data=='noemail') 
		  {
		  document.getElementById('resultnoemail').innerHTML='Email Already Exist';
		  document.getElementById('resultyesemail').style.display = 'none';
		  document.getElementById('resultnoemail').style.display = 'inherit';
		  exit();
          }
} // End If.
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.






function CheckUsername(username){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="check.php?username="+username // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("usernameresult").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
var str = xmlHttp.responseText;
if(str.indexOf('Not Available!') != -1)
{
 document.getElementById("user").value="";	
 document.getElementById("user").focus();
}
} // End If.
}; // Close Function

xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function CheckEmail(username){ // This function we will use to check to see if an email is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="check.php?email="+username // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("emailresult").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
var str = xmlHttp.responseText;
if(str.indexOf('Not Available!') != -1)
{
 document.getElementById("email").value="";	
 document.getElementById("email").focus();
}
} // End If.
}; // Close Function

xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function CheckEmailEdit(username,uid){ // This function we will use to check to see if an email is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="ajax_login.php?email="+username+"&userid="+uid // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("emailresult").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
var str = xmlHttp.responseText;

if(str.indexOf('Not Available!') != -1)
{ 
 document.getElementById("email").value="";	
 document.getElementById("email").focus();
}
} // End If.
}; // Close Function

xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function CheckUsernameEdit(username,uid){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="check.php?username="+username+"&userid="+uid // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("usernameresult").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
var str = xmlHttp.responseText;
if(str.indexOf('Not Available!') != -1)
{
 document.getElementById("user").value="";	
 document.getElementById("user").focus();
}
} // End If.
}; // Close Function

xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

 
 
