// JavaScript Document

var _ajax = { handler: {}, idCounter: 0 };

function makeHttpRequest(url, send_n_load, params, meth){ 
	
	this.id = ++_ajax.idCounter;
	_ajax.handler[this.id] = this;
	this.meth = meth ? meth : 'GET';
	this.url = url;
	this.params = this.meth == 'POST' ? params : null;
	this.paramsforGet = this.meth == 'GET' ? '?'+params : '';
	this.http_request = false;
	this.oReturn = send_n_load;

	this.init = function(){
		if (window.XMLHttpRequest) {
			this.http_request = new XMLHttpRequest();
		} else {
			if (window.ActiveXObject) {
				try { 
					this.http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
				} catch (e) {
					this.http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
				}
			}
		}
	}

	this.init();

	if (!this.http_request) {
		alert('No browser support'); 
		return false;
	}

	this.http_request.onreadystatechange = new Function("_ajax.handler["+this.id+"].onChange();");   

	this.onChange = function() {
		if ( this.http_request.readyState == 4 ) {
			if (this.http_request.status == 200) {
			   new Function("_ajax.handler["+this.id+"].oReturn(_ajax.handler["+this.id+"].http_request.responseText);")();
			} else {
				alert('There was a problem with the request.(Code: ' + this.http_request.status + ')'); 
			}
		}
	}

	this.http_request.open(this.meth, this.url+this.paramsforGet, true);

	if(this.meth == "POST"){
		this.http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");   
		this.http_request.send(this.params);
	}
}



function ajax(doc,retfunc,params,meth){
	myAjax = new makeHttpRequest(doc, retfunc, params, meth);
}


