function AJAXRequest (file) {
	this.xhr=null;
	
	this.reset = function() {
//PROPERTIES
		this.method = "POST";		// the method to send the request.
		this.asynchronous = true;	// send the request in a synchronous or asynchronous way.
		this.queryStart = "?";		// the character indicating the beginning of the query (at the end of the URL).
		this.parametersSeparator = "&";	// the character used to separate the parameters in the URL.
		this._query = "";
		this._parameters = new Object();
		this.responseStatus = "";
		this.responseStatusText = "";
		this.file = file;		// the file to which the request will be sent.
  		this.execute = false;	// if the response must be executed, shift to "true".
  		this.elementID = null;	// if you want the response to be displayed in a HTML element, indicate its ID here.
		this._elementObject = null;	
		this.response = null;
//METHODS
		this.onLoading = function() { };  // function called when XMLHttpRequest.readyState = 1.
  		this.onLoaded = function() { };	// function called when XMLHttpRequest.readyState = 2.
  		this.onInteractive = function() { };	// function called when XMLHttpRequest.readyState = 3.
  		this.onComplete = function() { };	// function called when XMLHttpRequest.readyState = 4.
  		this.onError = function() { };	// function called when there is an error in the response to the request.
		this.onFail = function() { };	// function called when the XMLHttpRequest Object can't be created.
		};
	
	this.getXhr = function() { //create an XMLHttpRequest Object
		if(window.XMLHttpRequest) // Firefox and others
			this.xhr = new XMLHttpRequest(); 
		else if(window.ActiveXObject) { // Internet Explorer 
			try {
				this.xhr = new ActiveXObject("Msxml2.XMLHTTP");
				} 
			catch (e) {
				this.xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
		else { // XMLHttpRequest not supported by the browser
			this.xhr = null; 
			this.failed = true;
			} 
		};
	
	this.addParameter = function (name,value) {	// function to use to add parameters to send with the request
		this._parameters[name] = value;
		};
		
	this._encodeParameterToObject = function (name,value) {	// function that encode a parameter and set it within this.parameters. Don't use it.
		this._parameters[encodeURIComponent(name)] = encodeURIComponent(value);
		};
	
	this._encodeParameterToArray = function (name,value) {		// function that encode a parameter and return an Array. Don't use it.
		return Array(encodeURIComponent(name), encodeURIComponent(value));
		};
	
	this._createQuery = function() {		// function that build the string used to make the request.
		tempQuery = new Array();		// don't use it.
		tempParam = this._parameters;
		for (key in tempParam) {
			encParam = this._encodeParameterToArray(key, tempParam[key]);
			tempQuery[tempQuery.length] = key + "=" + tempParam[key];
			delete tempParam[key];
			}
		this._query = tempQuery.join(this.parametersSeparator);
		};

	this.getHeader = function(header) {
		return (this.xhr.getResponseHeader(header));
		}
	
	this.getAllHeaders = function() {
		return this.xhr.getAllResponseHeaders();
		}
	
	this.abort = function() {
		try {
			this.xhr.abort();
			}
		catch(e) { }
		this.getXhr();
		}
	
	this.setHeader = function(label,value) {
		this.xhr.setRequestHeader(label, value);
		}
	
	this.sendRequest = function () {	// function to send the AJAX request
		if (this.failed) {
			this.onFail();
			} 
		else {
			this._createQuery();
			if (this.elementID) {
				this._elementObject = document.getElementById(this.elementID);
				}
			if(this.xhr) {
				var self = this;
				this.xhr.onreadystatechange = function() {
					switch (self.xhr.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xhr.responseText;
							self.responseXML = self.xhr.responseXML;
							self.responseStatus = self.xhr.status;
							self.responseStatusText = self.xhr.statusText;
							if (self.execute) {
								eval(this.response);
								}
							if (self._elementObject) {
								NodeName = self._elementObject.nodeName;
								NodeName.toLowerCase();
								if (NodeName == "input" || NodeName == "select" || NodeName == "option" || NodeName == "textarea") {
									self._elementObject.value = self.response;
									} 
								else {
									self._elementObject.innerHTML = self.response;
									}
								}
							
							if (self.responseStatus == "200") {
								self.onComplete();
								}
							else {
								self.onError();
								}
							self.query = "";
							break;
						}
					};
				
				if (this.method == "GET") {
					URL = this.file + this.queryStart + this._query;
					this.xhr.open(this.method, URL, this.asynchronous);
					this.xhr.send(null);
					} 
				else {
					this.xhr.open(this.method, this.file, this.asynchronous);
					try {
						this.xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
						} 
					catch (e) { }
					this.xhr.send(this._query);
					}
				}
			}
		};
	this.reset();
	this.getXhr();
	}
