currentRequests=new Array();
currentHandlers=new Array();

function sendRequest(docUrl,returnHandler) {
    now=new Date();
    docUrl+="&rand="+now.valueOf();
    if (window.XMLHttpRequest){
        thisRequest=new XMLHttpRequest();
        currentHandlers.push(returnHandler);
        thisRequest.onreadystatechange=requestReceived;
        thisRequest.open("GET",docUrl,true);
        thisRequest.send(null);
        currentRequests.push(thisRequest);
    }else if (window.ActiveXObject){
        thisRequest=new ActiveXObject("Microsoft.XMLHTTP");
        currentRequests.push(thisRequest);
        currentHandlers.push(returnHandler);
        if (thisRequest){
            thisRequest.onreadystatechange=requestReceived;
            thisRequest.open("GET",docUrl,true);
            thisRequest.send();
        }
    }
}
function sendPostRequest(docUrl,parameters,returnHandler) {
    now=new Date();
    docUrl+="?rand="+now.valueOf();
    if (window.XMLHttpRequest){
        thisRequest=new XMLHttpRequest();
        currentHandlers.push(returnHandler);
        thisRequest.onreadystatechange=requestReceived;
        thisRequest.open("POST",docUrl,true);
		thisRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        //thisRequest.setRequestHeader("Content-length", parameters.length);
        currentRequests.push(thisRequest);
        thisRequest.send(parameters);
    }else if (window.ActiveXObject){
        thisRequest=new ActiveXObject("Microsoft.XMLHTTP");
        currentRequests.push(thisRequest);
        currentHandlers.push(returnHandler);
        if (thisRequest){
            thisRequest.onreadystatechange=requestReceived;
            thisRequest.open("POST",docUrl,true);
			thisRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
            //thisRequest.setRequestHeader("Content-length", parameters.length);
            thisRequest.send(parameters);
        }
    }
}
function requestReceived() {
    reply="";
    for (requestIndex=currentRequests.length-1;requestIndex>=0;requestIndex--) {
        if (currentRequests[requestIndex].readyState==4) {
            reply=currentRequests[requestIndex].responseText;
			currentRequests[requestIndex].getAllResponseHeaders()
            if (currentRequests[requestIndex].status==200) {
                reply=currentRequests[requestIndex].responseText;
            }
            currentRequests[requestIndex]=null;
            currentRequests.splice(requestIndex,1);
            thisHandler=currentHandlers[requestIndex];
            currentHandlers.splice(requestIndex,1);
            thisHandler(reply);
        }
    }
}