Ajax.prototype.setXmlHttpRequest = function() {
	try {this.itsXmlHttpRequest = new XMLHttpRequest(); return this.itsXmlHttpRequest;} catch(e) {};
	try {this.itsXmlHttpRequest = new ActiveXObject("MSXML3.XMLHTTP"); return this.itsXmlHttpRequest;} catch(e) {};
	try {this.itsXmlHttpRequest = new ActiveXObject("MSXML2.XMLHTTP.3.0"); return this.itsXmlHttpRequest;} catch(e) {};
	try {this.itsXmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); return this.itsXmlHttpRequest;} catch(e) {};
	try {this.itsXmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); return this.itsXmlHttpRequest;} catch(e) {};
	
	return false;
};

Ajax.prototype.reload = function(obj, url, interval) {
	this.itsObject = obj;
	
	if (typeof(interval) != "undefined") 
		this.timer = setTimeout("this.itsObject.outerHTML = this.getResponse(" + url + ")", interval);
	else 
		this.itsObject.outerHTML = this.getResponse(url);
}

Ajax.prototype.stopReload = function() {
	clearTimeout(this.timer);
};

Ajax.prototype.getResponse = function(url, method) {
	method = (typeof(method) != "undefined" ? method : "GET");
	
	this.itsXmlHttpRequest.open(method, url, false);
	this.itsXmlHttpRequest.send(null);
	
	if (!this.itsXmlHttpRequest.getResponseHeader("Date")) {
		var cached = this.itsXmlHttpRequest;
		this.setXmlHttpRequest();
		ifModifiedSince = (ifModifiedSince = cached.getResponseHeader("Last-Modified")) ? ifModifiedSince : new Date(0); // January 1, 1970
		this.itsXmlHttpRequest.open(method, url, false);
		this.itsXmlHttpRequest.setRequestHeader("If-Modified-Since", ifModifiedSince);
		this.itsXmlHttpRequest.send(null);
		if(this.itsXmlHttpRequest.status == 304) 
			this.itsXmlHttpRequest = cached;
	}
	
	return this.itsXmlHttpRequest.responseText;
};

function Ajax() {
	this.itsXmlHttpRequest;
	this.itsObject;
	this.timer;
	
	this.setXmlHttpRequest();
}

// outerHTML alternative for FF
var _emptyTags = {
   "IMG":   true,
   "BR":    true,
   "INPUT": true,
   "META":  true,
   "LINK":  true,
   "PARAM": true,
   "HR":    true
};

HTMLElement.prototype.__defineGetter__("outerHTML", function () {
   var attrs = this.attributes;
   var str = "<" + this.tagName;
   for (var i = 0; i < attrs.length; i++)
      str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";

   if (_emptyTags[this.tagName])
      return str + " />";

   return str + ">" + this.innerHTML + "</" + this.tagName + ">";
});

HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
   var r = this.ownerDocument.createRange();
   r.setStartBefore(this);
   var df = r.createContextualFragment(sHTML);
   this.parentNode.replaceChild(df, this);
});
