function Xercel_JsHttpRequest(varName) {
	this.name = varName;
	this.readyState = 0;
	this.status = 0;
	this.responseText = null;
	this.responseXML = null;
	this.onreadystatechange = null;
	this.url = null;
	this.asychronized = true;
	this.content = null;
	this.method = "GET";
	return this;
}
Xercel_JsHttpRequest.prototype = {
	open: function(method, url, asychronized) {
		if (method != null && method != '') this.method = method;
		if (asychronized != null) this.asychronized = asychronized;
		if (this.method == 'GET') {
			var urlPair = this.parseRequestParameter(url);
			this.url = urlPair[0];
			this.content = urlPair[1];
		} else {
			this.url = url;
		}
	},
	send: function(content) {
		if (content != null) {
			if (this.content == null) this.content = content;
			else this.content += '&' + content;
		}
		if (this.content == null) this.content = 'js_httprequest=' + this.name;
		else this.content += '&js_httprequest=' + this.name;
		this.deleteFromHead('js_httprequest=' + this.name);
		var script = document.createElement('script');
		script.type = "text/javascript";
		script.src = this.url + '?' + this.content;
		document.getElementsByTagName('head')[0].appendChild(script);
	},
	parseRequestParameter: function(url) {
		var indexPath = url.indexOf('?');
		var result = new Array('', '');
		if (indexPath >= 0) {
			if (indexPath == 0) {
				result[0] = null;
				result[1] = url.substring(1);
			} else {
				result[0] = url.substring(0, indexPath);
				if (indexPath + 1 < url.length) result[1] = url.substring(indexPath + 1);
				else result[1] = null;
			}
		} else {
			result[0] = url;
		}
		return result;
	},
	deleteFromHead: function(requestName) {
		var scripts = document.getElementsByTagName('head')[0].childNodes;
		for (var i = 0; i < scripts.length; ++ i) {
			if (scripts[i].nodeName.toUpperCase() == 'SCRIPT' && scripts[i].src.indexOf(requestName) > 0) {
				var parent = scripts[i].parentNode;
				parent.remove(scripts[i]);
				return true;
			}
		}
		return false;
	}
};

function Xercel_XMLElement(name, attributes, children, value) {
	this.name = name;
	this.attributes = attributes;
	this.children = children;
	this.value = value;
}
Xercel_XMLElement.prototype = {
	equals: function(name) {
		return this.name == name;
	},
	getAttribute: function(name) {
		if (this.attributes == null) return null;
		return this.attributes.getAttribute(name);
	},
	setAttribute: function(name, value) {
		if (this.attributes == null) this.attributes = new Xercel_XMLAttribute(name, value);
		else this.attributes.setAttribute(name, value);
	},
	addElement: function(element) {
		if (this.children == null) this.children = [];
		this.children[this.children.length] = element;
	},
	getChildNodes: function() {
		return (this.children != null && this.children.length == 0? null: this.children);
	},
	getElementsByTagName: function(name) {
		if (this.children == null || this.children.length == 0) return null;
		var res = [];
		var buffer = this.children;
		while (buffer.length > 0) {
			var tmp = [];
			for (var i = 0; i < buffer.length; ++ i) {
				if (buffer[i].equals(name)) res[res.length] = buffer[i];
				var chlds = buffer[i].getChildNodes();
				if (chlds != null) {
					for (var j = 0; j < chlds.length; tmp[tmp.length] = chlds[j ++]);
				}
			}
			buffer = tmp;
		}
		return (res.length == 0? null: res);
	},
	getNodeValue: function() { return this.value; },
	getNodeName: function() { return this.name; }
};

function Xercel_XMLAttribute(name, value) {
	this.attributes = [];
	this.attributes[name] = value;
}
Xercel_XMLAttribute.prototype = {
	setAttribute: function(name, value) {
		this.attributes[name] = value;
	},
	getAttribute: function(name) {
		return this.attributes[name];
	}
};
