function createRequestObject() {
    var A;
    try {
        A=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            A=new ActiveXObject("Microsoft.XMLHTTP");
        } catch (oc) {
            A=null;
        }
    }
    if(!A && typeof XMLHttpRequest != "undefined")
        A = new XMLHttpRequest();
    if (!A)
        alert("Could not create connection object.");
    return A;
}

var http = createRequestObject();
var form_is_ok=true;

// this function should be called for user input
// it opens up a php page with a querystring of 'action'
// this function could probably be adapted to POST
function sndReq(action)
{
	http.open("get", "ajax.php?action=" + action);
	http.onreadystatechange = handleResponse;
	http.send(null);
}

// the response in this case is formatted as follows:
// object|text
// where object is the id of the HTML element we are going to update
// and text is what it will be updated to
// this could obviously work a lot better with some XML
function handleResponse()
{
	if(http.readyState == 4) {
		var response = http.responseText;
    	var update = new Array();

	    if(response.indexOf('|')!= -1) {
	    	update = response.split("|");
            if(update[1]) {
            	document.getElementById(update[0]).innerHTML = eval(update[1]);
            	form_is_ok=false;
            }
            else {
            	document.getElementById(update[0]).innerHTML = '';
            	form_is_ok=true;
            }
    	}
  	}
}


// this function should be called for user input
// it opens up the usercheck.asp page with a querystring of 'action'
function sndUserCheck(action,value)
{
	http.open("get","ajax_check.php?a=" + action + "&value=" + value);
	http.onreadystatechange = handleResponse;
	http.send(null);
}
