var http_reqs = new Array();
function http_req_callback()
{
    for (var i = 0; i < http_reqs.length; i++) {
        if (http_reqs[i].http_request.readyState == 4) {
//            alert("found req");
            if (http_reqs[i].http_request.status == 200 || http_reqs[i].http_request.status == 304) {
                var obj = http_reqs[i];
                http_reqs.splice(i, 1);
                i--;
                if (typeof(obj.callback) == "undefined") {
                    window.alert("ERROR: No callback defined.");
                } else {
                    obj.callback(obj.http_request.responseText);
                }
            } else {
                http_reqs.splice(i, 1);
                i--;
            }
        }
    }
}
function ajax()
{
    if (window.XMLHttpRequest) {
        this.http_request = new XMLHttpRequest();
        this.IE = false;
    } else if (window.ActiveXObject) {
        this.IE = true;
    } else {
        window.alert("ERROR: Cannot initialize XMLHTTP object.");
    }
    this.get = get;
    this.post = post;
    function get(url, param, callback)
    {
//        alert("will get");
        if (this.IE) {
            this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
        var _url = url;
        if (typeof(param) != "undefined" && param !== "") {
            _url += "?" + param;
        }
        if (typeof(callback) != "undefined") {
            this.callback = callback;
        }
        this.http_request.onreadystatechange = http_req_callback;
        this.http_request.open("GET", _url, true);
        this.http_request.send(null);
        http_reqs.push(this);    
    }
    function post(url, param, callback)
    {
        if (this.IE) {
            this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (typeof(param) == "undefined") {
            window.alert("ERROR: post called with no params.");
            return;
        }
        if (typeof(callback) != "undefined") {
            this.callback = callback;
        }
        this.http_request.onreadystatechange = http_req_callback;
        this.http_request.open("POST", url, true);
        this.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        this.http_request.setRequestHeader("Content-length", param.length);
        this.http_request.setRequestHeader("Connection", "close");
        this.http_request.send(param);
        http_reqs.push(this);
    }
}