<!--
// global flags
var isIE = false;
// global objects
var http;
var cache = new Object();

// Create HTTP object
function createHttp() {
	// branch for native XMLHttpRequest object
	if (!http)
		if (window.XMLHttpRequest)
			try {
				http = new XMLHttpRequest();
			} catch(e) {}
	// branch for IE/Windows ActiveX version
	if (!http)
		if (window.ActiveXObject)
			try {
				http = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {}
			if (!http)
				try {
					http = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {}
			if (!http)
				try {
					http = new ActiveXObject("Microsoft.XMLDOM");
				} catch(e) {}
	return (typeof http == "object");
}

// Send lookup request to a server in the background. When a response comes back
// from the server, the function passed in the handler parameter is fired off.
function loadHttp(url, method, async, handler) {
	// check cache
	if (cache[url]) return cache[url];
	// send request
	if (typeof http == "undefined") createHttp();
	if (!http) return null;
	if (http.readyState != 0) http.abort()
	if (handler) http.onreadystatechange = handler;
	if (!method) method = "get";
	if (!async) async = false;
	http.open(method, url, async);
//	http.setRequestHeader("content-type", "text/xml; charset=windows-1251;");
	http.send();
	if (http.readyState == 4 && http.status == 200) {
		var xml = http.responseXml;
		if (xml.parseError.errorCode == 0) {
			cache[url] = xml;
			return xml;
		}
	}
}

// Fills select list with items from the XML document
//	Flags:
//		0bit	delete all options
//		1bit	delete options with ID > 0
function buildList(obj, xml, flags) {
	var nodes, atrs, opt, i, j;
	// Remove old elements
	if (flags & 3)
		for (i = obj.options.length - 1; i >= 0; i--) {
			if ((flags & 1) || (obj.options(i).value > 0)) obj.remove(i);
		}
	// Parse XML
	nodes = xml.getElementsByTagName("root/record");
	for (i = 0; i < nodes.length; i++) {
		atrs = nodes(i).childNodes;
		opt = document.createElement("option");
		for (j = 0; j < atrs.length; j++) {
			switch (atrs(j).nodeName.toLowerCase()) {
				case "id": opt.value = atrs(j).text; break;
				case "name": opt.text = atrs(j).text; break;
			}
		}
		obj.options.add(opt);
	}
}
//-->

