document.write("<script type=\"text/javascript\" src=\"/assets/scripts/HTTP.js\"></script>");

// wrapper for XMLHttpRequest
// usage example:
// myvar = new Ajax();
// myvar.makeRequest("GET", "http://www.edeptive.com/item_rss.aspx", onXmlResponse);
function EdeptiveAjax() {
	this.toString = function() { return "EdeptiveAjax"; }
	this.http = new HTTP();
	
	this.makeRequest = function(_method, _url, _callbackMethod) {
		this.request = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP"); 
		this.request.onreadystatechange = _callbackMethod;
		this.request.open(_method, _url, true);
		this.request.send(_url);	
	}
	
	this.postRequest = function(_url, _params, _callbackMethod) {
		this.request = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP"); 
		this.request.onreadystatechange = _callbackMethod;
		this.request.open("POST", _url, true);
		this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.request.send(_params);	
	}
	
	this.checkReadyState = function(_id, _1, _2, _3) {
		switch(this.request.readyState) {
			case 1:
				if(document.getElementById(_id) && _1) {
					document.getElementById(_id).innerHTML = _1;
				}
				break;
			case 2:
				if(document.getElementById(_id) && _2) {
					document.getElementById(_id).innerHTML = _2;
				}
				break;
			case 3:
				if(document.getElementById(_id) && _3) {
					document.getElementById(_id).innerHTML = _3;
				}
				break;
			case 4:
				return this.http.status(this.request.status);
		}
	}
}
// wrapper to return the text from an XML node
// IE has a .text attribute which returns all text with a node and all it's children
// this does the equivalent for other browsers
function getText(oNode) {
	var sText = "";
	
	if(oNode.text) {
		sText = oNode.text;
	} else {
		for(var i = 0; i < oNode.childNodes.length; i++) {
			if(oNode.childNodes[i].hasChildNodes()) {
				sText += getText(oNode.childNodes[i]);
			} else {
				sText += oNode.childNodes[i].nodeValue;
			}
		}
	}
	return sText;
}