// JavaScript AJAX class

function AJAX(name) {
    this._name = name;
}

AJAX.prototype._name;

AJAX.prototype.getName = function() {
    return this._name;
}

AJAX.prototype.getXMLHttpReqObject = function() {
	var xmlHttpReq = null;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttpReq = new XMLHttpRequest();

		if (xmlHttpReq.overrideMimeType) {
			xmlHttpReq.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	return xmlHttpReq;
}

AJAX.prototype.sendXMLData = function(urlstring, func, parentobj) {
	var xmlHttpReq;

	xmlHttpReq = this.getXMLHttpReqObject();
	if (xmlHttpReq == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url = urlstring;
	var thisOBJ = this;

	// For XML Data Only


	xmlHttpReq.onreadystatechange = function() { thisOBJ.sendXMLData_Response(xmlHttpReq, func, parentobj); };
	xmlHttpReq.open("GET", url, true);
	xmlHttpReq.setRequestHeader("Content-Type", "text/xml");
	xmlHttpReq.send(null);
}

AJAX.prototype.sendData = function(urlstring, func, parentobj) {
	var xmlHttpReq;

	xmlHttpReq = this.getXMLHttpReqObject();
	if (xmlHttpReq == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url = urlstring;
	var thisOBJ = this;

	xmlHttpReq.onreadystatechange = function() { thisOBJ.sendData_Response(xmlHttpReq, func, parentobj); };
	xmlHttpReq.open("GET", url, true);
	xmlHttpReq.send(null);
}

AJAX.prototype.sendData_Response = function(xmlHttpReq, func, parentobj) {
	if (xmlHttpReq.readyState==4) {
		if (xmlHttpReq.status==200) {
			func(xmlHttpReq.responseText, xmlHttpReq.status, parentobj);
		} else {
			func("There was a problem retrieving the data:\n" + xmlHttpReq.statusText, xmlHttpReq.status);
		}
	}
}

AJAX.prototype.sendXMLData_Response = function(xmlHttpReq, func, parentobj) {
	if (xmlHttpReq.readyState==4) {
		if (xmlHttpReq.status==200) {
			func(xmlHttpReq.responseXML, xmlHttpReq.status, parentobj);
			//func("Test", 200, parentobj);
		} else {
			func("There was a problem retrieving the XML data:\n" + xmlHttpReq.statusText, xmlHttpReq.status);
		}
	}
}
