	
	// global object variable
	var thisy;
	
	// instantiation function: "url" is a required argument, which is the URL of the site to connect to
	function ajax (url) {
		// store the new object in the global object variable
		thisy = this;
		// 
		this.url = url;
		this.parameters = (ajax.arguments.length>1) ? ajax.arguments[1] : null;
		this.method = (ajax.arguments.length>2) ? ajax.arguments[2].toUpperCase() : 'GET';
		
		this.httpObj = null;
		this.responseText = null;
		this.responseXML = null;
		this.parameterString = null;
		
		this.doneFunction = null;
		
		this.connect = function () {
			if (!thisy.url) return false;
			if (window.XMLHttpRequest) {  
				try {  
					thisy.httpObj = new XMLHttpRequest();  
				}
				catch(e) { }
			}
			else if (window.ActiveXObject) {
				try {
					thisy.httpObj = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) { }
			}
			
			if (!thisy.httpObj) return errorOut('AJAX Connection Failed');
			
			if (thisy.method=='POST' && !thisy.parameters) return false;
			
			thisy.httpObj.open(thisy.method,thisy.url,true);
			
			if (thisy.method=='POST' && typeof(thisy.parameters)=='object' && thisy.parameters.length) {
				thisy.httpObj.setRequestHeader("Content-type","application/x-www-form-urlencoded");
				param = "";
				for (var i in thisy.parameters) {
					if (param) param += "&";
					param += i+"="+thisy.parameters[i];
				}
				if (param) thisy.parameterString = param;
			}
		}
		
		this.process = function () {
			thisy.httpObj.send(thisy.parameterString);
			thisy.httpObj.onreadystatechange = thisy.handle;
		}
		
		this.handle = function () {
			var rs;
			var st;
			
			try {
				rs = thisy.httpObj.readyState;
			}
			catch (e) { }
			try {
				st = thisy.httpObj.status;
			}
			catch (e) { }
			
			if (rs!=4) return true;
			if (st!=200 && st!==0) return errorOut('AJAX Error: Status '+st+' returned.');
			
			if (typeof(thisy.httpObj.responseText)=='undefined') return errorOut('AJAX Error: No response text returned.');
			thisy.responseText = thisy.httpObj.responseText;
			if (typeof(thisy.httpObj.responseXML)!='undefined' && thisy.httpObj.responseXML) thisy.responseXML = thisy.httpObj.responseXML;
			
			if (thisy.doneFunction) thisy.doneFunction();
		}
		
	}

