var last_modified = "Thu, 01 Jun 1970 00:00:00 GMT";
var cachedContentText = '';
var cachedContentXml = null;

function createXMLHttpRequest() {
	var XMLhttpObject = "";
	try {
		XMLHttpRequest.prototype.contents = "";
		XMLhttpObject = new XMLHttpRequest();
	} catch (e) {
		try {
			ActiveXObject.prototype.contents = "";
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ActiveXObject.prototype.contents = "";
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				return "";
			}
		}
	}
	return XMLhttpObject;
}

function load(fileName, objClass, args, method, param) {
	var req = "";
	req = createXMLHttpRequest();
	var obj = new objClass(req, args);
	with ({req: req, obj: obj}) {
		req.onreadystatechange = function() {
			if (obj.req.readyState == 4 && obj.req.responseText) {
				if (obj.req.getAllResponseHeaders().match("Last-Modified")) {
					last_modified = req.getResponseHeader("Last-Modified");
				}
				if (obj.req.responseText.length == 0) {
					obj.setResponseText(cachedContentText);
					obj.setResponseXml(cachedContentXml);
				} else {
					cachedContentText = obj.getResponseText();
					cachedContentXml = obj.getResponseXml();
				}
				obj.execute();
			}
		};
		if (req) {
			req.open((method ? method : "GET"), fileName, true);
			if (last_modified) {
				req.setRequestHeader("If-Modified-Since", last_modified);
			}
			req.send(param ? param : "");
		}
	}
	return obj.returnValue;
}

/**
 * Ajax pNX
 */

function Ajax(req, args) {
	this.returnValue = "";
	this.req = req;
	this.args = args;
	this.responseXml = null;
	this.responseText = '';
}

function Ajax_setResponseXml(responseXml) {
	this.responseXml = responseXml;
}

function Ajax_getResponseXml() {
	if (this.req.responseXML && !this.responseXml) {
		return this.req.responseXML;
	}
	return this.responseXml;
}

function Ajax_setResponseText(responseText) {
	this.responseText = responseText;
}

function Ajax_getResponseText() {
	if (this.req.responseText && !this.responseText) {
		return this.req.responseText;
	}
	return this.responseText;
}

new Ajax();
Ajax.prototype.setResponseXml = Ajax_setResponseXml;
Ajax.prototype.getResponseXml = Ajax_getResponseXml;
Ajax.prototype.setResponseText = Ajax_setResponseText;
Ajax.prototype.getResponseText = Ajax_getResponseText;
