
function AJAX() {
	this.url = false;
	this.req = false;
	this.req_callback = false;
}

AJAX.prototype.loadXML = function(u,rc){
	var that = this;
	this.url = u;
	this.req = false;
	this.req_callback = rc;
	
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			this.req = new XMLHttpRequest();
        } catch(e) {
			this.req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	this.req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		this.req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		this.req = false;
        	}
		}
    }

	if(this.req) {
		this.req.onreadystatechange = function(){
			that.processReqChange();
		}
		this.req.open("GET", u, true);
		this.req.send("");
	}
	
}
//
AJAX.prototype.postRequest = function(u,q,rc){
	var that = this;
	this.url = u;
	this.req = false;
	this.req_callback = rc;
	
	qstr = "";
	for(var p in q){
		qstr += p+"="+q[p]+"&";
	}
	
	
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			this.req = new XMLHttpRequest();
        } catch(e) {
			this.req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	this.req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		this.req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		this.req = false;
        	}
		}
    }

	if(this.req) {
		this.req.onreadystatechange = function(){
			that.processReqChange();
		}
		this.req.open("POST", u, true);
		this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.req.setRequestHeader("Content-length", qstr.length);
		this.req.setRequestHeader("Connection", "close");
		this.req.send(qstr);
	}
	
}

//
AJAX.prototype.processReqChange = function() {
	// only if req shows "loaded"
	if (this.req.readyState == 4) {
		// only if "OK"
		if (this.req.status == 200) {
			this.req_callback(this.req);
		} else {
			alert('There was a problem retrieving the data:\n' +this.req.statusText+'\n'+this.req.status+ '\n Many apologies, please try again later.');
		}
	}
}
