function XhrResponse(type, message, html, challenge)
{
	this.type = type;
	this.message = message;
	this.html = html;
	this.challenge = challenge;
}

XhrResponse.prototype.getType = function ()
{
	return this.type;
}

XhrResponse.prototype.isFailure = function ()
{
	return this.type == 'failure';
}

XhrResponse.prototype.isSuccess = function ()
{
	return this.type == 'success';
}

XhrResponse.prototype.getMessage = function ()
{
	return this.message;
}

XhrResponse.prototype.getHTML = function ()
{
	return this.html;
}

XhrResponse.prototype.getChallenge = function ()
{
	return this.challenge;
}

var XhrResponseParser = {
	parse : function (doc) {
		if (doc.firstChild && doc.firstChild.nodeName == 'xml' && doc.firstChild.nextSibling && doc.firstChild.nextSibling.nodeName == 'response') {
			var response = doc.firstChild.nextSibling;
		} else if (doc.firstChild && doc.firstChild.nodeName == 'response') {
			var response = doc.firstChild;
		}
		
		var type = response.getAttribute('type');
		var challenge = response.getAttribute('challenge');
		
		var html = '';
		var message = '';
		
		var child = response.firstChild;
		while (child) {
			if (child.nodeName == 'message') {
				message = child.nodeValue;
			}
			if (child.nodeName == 'html') {
	            if (child.firstChild.nodeType == 4) { // CDATA
	                html = child.firstChild.nodeValue;
	            } else if (child.firstChild.nodeType == 3) { // TEXT
	                html = child.nodeValue;
	            }
			}
			child = child.nextSibling;
		}
		
		return new XhrResponse(type, message, html, challenge);
	}
}
