var xmlHttp // xmlHttp variable

function GetXmlHttpObject() {

    var objXMLHttp = null;

    if( window.XMLHttpRequest )
    {
        try
        {
            objXMLHttp = new XMLHttpRequest();
        }
        catch( e )
        {
            objXMLHttp = false;
        }
    }
    else if( window.createRequest )
    {
        try
        {
            objXMLHttp = new window.createRequest();
        }
        catch( e )
        {
            objXMLHttp = false;
        }
    }
    else if( window.ActiveXObject )
    {
        try
        {
            objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch( e )
        {
            try
            {
                objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch( e )
            {
                objXMLHttp = false;
            }
        }
    }

    return objXMLHttp;
}


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 ("Sorry, your browser does not support this function.") // Alert Them!
		return // Returns.
	} // End If.

	var url="check_username.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
		} // End If.
	}; // Close Function
	xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.


function InsertRefNumber(refNumber){ // This function we will use to record a ref number in DB.

	xmlHttp=GetXmlHttpObject() 

	if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
		alert ("Sorry, your browser does not support this function.") // Alert Them!
		return // Returns.
	} // End If.

	var url="insert_ref_number.php?ref_num="+refNumber 
	xmlHttp.open("GET",url,true) // Opens the URL using GET

	xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

