
//class parseResponse
function ParseResponse(httpRequest) {
	
	this.response = "";
	this.dataGrid = new Array();
	this.isResponseError = false;
	
	this.initDataGrid = function () {	
		var xmldoc = httpRequest.responseXML;
	    var rootNodeName = xmldoc.firstChild.nodeName;
	    if (rootNodeName == "xml") rootNodeName = xmldoc.firstChild.nextSibling.nodeName; //windows
	    this.response = xmldoc.getElementsByTagName(rootNodeName).item(0);
		
		if (this.response == null) {
			alert("Server Error : HTTP Response invalid!");
			return false;
		}
	
		//this.dataGrid = decodeURI(this.dataGrid);
	
		if (rootNodeName == "query") {	
			this.dataGridFromXMLQuery();
		}
		else if (rootNodeName == "error") {
			this.dataGridFromXMLError();
		}
		else if (rootNodeName == "other_tag") {
			this.dataGrid = this.dataGridFromXMLQuery();
		}
		else {
			alert("Server Error : Parsing XML failed!");
			return false;
		}
	}	
	
	this.dataGridFromXMLQuery = function () {
	
		nbRows = this.response.getElementsByTagName("row").length;
		
		for (var i = 0; i < nbRows; i++) {
			this.dataGrid[i] = new Array();
			rowNode = this.response.getElementsByTagName("row").item(i);

			var j = 0;
			var nodesChildren = rowNode.firstChild;
			if (nodesChildren.nodeName == "col") {
				while (nodesChildren != null) {
					this.dataGrid[i][j] = unescape(nodesChildren.childNodes[0].nodeValue);
					nodesChildren = nodesChildren.nextSibling;
					j++;
				}
			}
		}

	}
	
	this.dataGridFromXMLError = function () {
		this.isResponseError = true;
		this.dataGrid[0] = new Array();
		this.dataGrid[0][0] = "";
		this.dataGrid[0][1] = unescape(this.response.getElementsByTagName("label")[0].childNodes[0].nodeValue);
	}
	
	this.initDataGrid();
}





