/* ******************************* */
/* * Aggiunta metodi classi base * */
/* ******************************* */

Function.prototype.bind = function(object) {
	
  var __method = this;
	
  return function() {
    __method.apply(object, arguments);
  }
}
if (!Function.prototype.apply) {
  Function.prototype.apply = function(oScope, args) {
    var sarg = [];
    var rtrn, call;
    if (!oScope) oScope = window;
    if (!args) args = [];
    for (var i = 0; i < args.length; i++) {
      sarg[i] = "args["+i+"]";
    }     call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
    oScope.__applyTemp__ = this;
    rtrn = eval(call);
    return rtrn;
  }
}

/* ******************************* */




function e3Ajax(){
	
	this.done = null;
	this.http_request = null;
	this.error = "";

	this.load = function(uri,toDo,loading) {

		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			this.http_request = new XMLHttpRequest();
			if (this.http_request.overrideMimeType) {
				this.http_request.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				this.http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
				this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!this.http_request){
			alert("Il browser è da aggiornare!");
			return false;
		}
		if (typeof(loading) == "function") loading();
		this.done = toDo;
		this.http_request.onreadystatechange = this.onStateChange.bind(this);
		this.xmlDom = null;
    this.http_request.open('GET', uri, true);
    this.http_request.send(null);
	};
	
  this.onStateChange = function() {
    if(this.http_request.readyState!=4)
		  return;
		
		var status=this.http_request.status;
		
		if ((status!=200)&&(status!=0)) {
		  alert("errore di caricamento! status:"+status);
		  return;
		}

		this.responseText = this.http_request.responseText;		
		var objDom = new XMLDoc(this.responseText,this.errorFn);

		this.xmlDom = objDom.docNode
		

		this.done(this);
  }
  
	this.errorFn = function() {
		alert("errore di caricamento!");
		return false;
	}
}

