var otm = otm ? otm : {}
otm.xml = otm.xml ? otm.xml : {}

otm.xml.XMLUtil = function() {
	function getXMLHttpRequest() {
		if(window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else {
			return new ActiveXObject('Msxml2.XMLHTTP');
		}
	}

	function processStateChange(xmlProcessDataObj, callbackFunction, failureCallbackFunction) {
		return function() {
			if(xmlProcessDataObj.request.readyState == 4) {
				if(xmlProcessDataObj.request.status == 200) {
					callbackFunction(xmlProcessDataObj);
				} else if(xmlProcessDataObj.request.status == 500 && failureCallbackFunction != null) {
					failureCallbackFunction(xmlProcessDataObj);
				}
			}
		};
	}


	function sendXMLHttpRequest(reqType, postURL, callbackFunction, xmlProcessDataObj, failureCallbackFunction) {
		var request = getXMLHttpRequest();
		request.open(reqType, postURL, true);

		if(xmlProcessDataObj == null) {
			xmlProcessDataObj = new XMLProcessData();
		}

		xmlProcessDataObj.request = request;

		request.onreadystatechange = processStateChange(xmlProcessDataObj, callbackFunction, failureCallbackFunction);

		request.send(null);
	}

	this.sendPostXMLHttpRequest = function(postURL, callbackFunction, xmlProcessDataObj) {
		sendXMLHttpRequest("POST", postURL, callbackFunction, xmlProcessDataObj, null);
	}

	this.sendPostXMLHttpRequest = function(postURL, callbackFunction, xmlProcessDataObj, failureCallbackFunction) {
		sendXMLHttpRequest("POST", postURL, callbackFunction, xmlProcessDataObj, failureCallbackFunction);
	}

	this.sendGetXMLHttpRequest = function(postURL, callbackFunction, xmlProcessDataObj) {
		sendXMLHttpRequest("GET", postURL, callbackFunction, xmlProcessDataObj, null);
	}

	this.getNodeAttributeValue = function(node, attribute) {
		return node.attributes.getNamedItem(attribute).nodeValue;
	}

	this.getNodeText = function(node) {
		return node.firstChild.nodeValue;
	}
	
}

var XMLUtil = new otm.xml.XMLUtil();

// XMLProcessData is an object which will maintain reference to the XMLHttpRequest object
// Access the "request" member variable for access to the XMLHttpRequest object
// Also acts as a aggregator for data required for processing of the response
// Create member variables(other than "request") for data as necessary
function XMLProcessData() {

}


