
	function clickAutoCombo(obj)
	{
		doQuery(obj);
	}

	function keyDown(event, obj)
	{
		if (event.keyCode == 13) 
		{
			doQuery(obj);
			return false;
		}

		return true;
	}

	function keyUp(event, obj)
	{
		if (obj.value.length == 0)
		{
			id = obj.id.substr(2);
			objH = document.getElementById(id);
			objH.value = '';
		}
	}

	function doQuery(obj)
	{
		id = 'query' + obj.name;
		query = document.getElementById(id).value;

		frameObj = window.frames["uiAuto" + obj.name];

		query = query.replace('#', obj.value);
		frameObj.document.forms[0].query.value = query;
		frameObj.document.forms[0].submit();

		cnt = 0;
		frameObj.onLoad = parseResult(obj, obj.id);
	}

	var cnt = 0;
	function parseResult(obj, id)
	{
		if (typeof(obj) != 'object') obj = document.getElementById(id);
		frameObj = window.frames["uiAuto" + obj.name];
		root = frameObj.document;

		listID = 'lst' + obj.id.substring(2);
		objList = document.getElementById(listID);

		if ((typeof(root) == 'undefined') || (root.childNodes[0].nodeName.toLowerCase() != 'root'))
		{
			cnt++;

			if (cnt > 15)
			{
				clearItems(objList);
				showList(objList);		
				resetIFrame("uiAuto" + id);
 
				//alert("Nu a mers");
				return;
			}
			setTimeout("parseResult('', '" + obj.id + "')", 100);
			return;
		}		

		clearItems(objList);

		//varianta HTML
		if (root.childNodes.length >= 2)
		{
			for(it = 1; it < root.childNodes.length - 1; it++)
			{
				oitem = root.childNodes[it];
				if (oitem.nodeName.substring(0, 1) == '/') continue;
				addItem(objList, oitem.getAttribute('e0'), oitem.getAttribute('e1'));
			}
		}

		//varianta XML
		if (root.childNodes.length == 1)
		{
			root = root.childNodes[0];		

			for(it = 0; it < root.childNodes.length; it++)
			{
				item = root.childNodes[it];
				addItem(objList, item.getAttribute('e0'), item.getAttribute('e1'));
			}
		}

		showList(objList);		
		resetIFrame("uiAuto" + id);
	}

	function showList(obj)
	{
		id = obj.id.substr(3);
		obj2 = document.getElementById('UI' + id);

		obj.style.top = getTop(obj2) + getHeight(obj2) + 'px';
		obj.style.left = getLeft(obj2) + 'px';
		obj.style.width = (getWidth(obj2) + 0) + 'px';
		obj.style.display = "";
		obj.selectedIndex = 0;
		obj.focus();
	}

	function hideList(obj)
	{
		obj.style.display = "none";
	}

	function clearItems(obj)
	{
		while(obj.options.length) obj.options[0] = null;
	}

	function addItem(obj, id, text)
	{
		obj.options[obj.length] = new Option(text, id);
	}

	function resetIFrame(id)
	{
		window[id].document.location = "ui/query.php";
		//window[id].document.innerHTML = '<form name="ui" action = "query.php"><input type="input" name="query"></form>';
	}

	function selectItem(obj, keyCode)
	{
		if ((keyCode != 13) && (keyCode != 27)) return;		

		id = obj.id.substr(3);
		objH = document.getElementById(id);
		objT = document.getElementById('UI' + id);
		if ((keyCode == 13) && (obj.options.length > 0))
		{
			objH.value = obj.options[obj.selectedIndex].value;
			objT.value = obj.options[obj.selectedIndex].text;
		}

		if (keyCode == 27)
		{
			objH.value = '';
			objT.value = '';
		}

		if (objT.value.length == 0) objH.value = '';
		hideList(obj);
	}
