///////////////////////////////////////////////////////////////////////////
//University of Illinois Extension                                       //
//Office of Web Development                                              //
//Alessandro Bellina - bellina@uiuc.edu                                  //
//Copyright 2007 - Board of Trustees                                     //
//                                                                       //
//This code is not open source, and is protected by copyright law.       //
//Any use other than in U of I Extension websites is strictly prohibited.//
///////////////////////////////////////////////////////////////////////////

//XHTTPRequest object
function XHTTP (method){
	this.method = method || "GET";
	this.arguments = new Array();
	
	if (window.XMLHttpRequest) {
		this.req = new XMLHttpRequest();
	   
	}else if (window.ActiveXObject) {
		this.req = new ActiveXObject("Microsoft.XMLHTTP");
	  
	}else { //Using an old browser. Go to the non ajax version.
		alert ("This browser is not compatible with the Web Manager!");
	}	
}
XHTTP.prototype.load = function (url,callback){
	this.lasturl = url;
	var argString = new String();
	
	for (var i=0; i<this.arguments.length; i++){
		if (argString != "")
			argString += "&";
		argString += this.arguments[i][0]+"="+this.arguments[i][1];
	}
	if (this.method == "GET"){
		if (argString.length > 0)
			this.req.open (this.method, this.lasturl+"?"+argString, true);
		else
			this.req.open (this.method, this.lasturl, true);
		this.req.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
		this.req.send (null);
	}else{
		this.req.open (this.method, this.lasturl, true);
		this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		this.req.send (argString);
	}
}
XHTTP.prototype.addArgument = function (label,value){
	this.arguments.push (new Array (label,value));
}
XHTTP.prototype.flush = function (){
	this.arguments.length = 0;
}
XHTTP.prototype.getDocumentElement = function (){
	return this.req.responseXML.documentElement;	
}