/*
 * this file depends on lib.js
 */

function Request()
{
    var r; //the XMLHttpRequest object, or something like one.
    var externalObj, externalHandler;

    /*
    this.r = window.XMLHttpRequest ?
            new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    */
}

Request.prototype.query = function(url, externalHandler,
        externalObj) {
    //remember the externals
    this.externalObj = externalObj;
    this.externalHandler = externalHandler;

    this.r = window.XMLHttpRequest ?
            new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

    //set the callback handler function
    setEvent(this, this.r, 'onreadystatechange', this.handler);

    //setup and send the request
    this.r.open('GET', url, true);
    this.r.send(null);
}

Request.prototype.squery = function(url, externalObj)
{
	// contrary to the A in AJAX, this is a synchronous query
	this.externalObj = externalObj;
	
    this.r = window.XMLHttpRequest ?
            new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

    //setup and send the request
    this.r.open('GET', url, false);
    this.r.send(null);
    
	return this.r.responseText;
}

Request.prototype.handler = function() {
    //if the httprequest is complete...
    if(this.r.readyState==4) {
        //and the response was 200 OK...
        if(this.r.status==200) {
            //call the requested handler, possibly in the requested context
            if(this.externalObj!=null) {
                this.externalHandler.call(this.externalObj);
            } else {
                this.externalHandler();
            }
        } else {
            alert("Uh oh, I did not receive a response status of 200.");
        }
    }
}

Request.prototype.response = function() { return(this.r.responseText); };
Request.prototype.responseXML = function() { return (this.r.responseXML); };
