/*********************************************************************
 * Выпадающий список с поиском совпадений при наборе 
 * Разработано WebInside,RU (c) 2007
 *
 * Использование:
 * <HTML>
 * <script src="subselect.js" type="text/javascript"></script>
 * <script>
 *	var myArray;
 *	myArray = new Array();
 *	myArray[0] = "One";
 *	myArray[1] = "Two";
 * </script>
 *
 *
 *
 * <input type="text" id="seltext" onkeyup="subselect(this.id, myArray);">
 * </HTML>
 ***********************************************************************/
function get_cityes(contname)
	{
	document.getElementById("citi").value = "";	
	myArray2 = tmpar[contname];	
	//alert (contname);
	}



function subselect(id1, fields)
	{
	document.getElementById("subselect0").style.display = (document.getElementById("subselect0").style.display=="block") ? "none" : "block"; 
	
	document.getElementById("subselect0").style.left = getLeft(document.getElementById(id1));	
	document.getElementById("subselect0").style.top = getTop(document.getElementById(id1))+16;
	
	var opt = '';
	for(n in fields)
		{
		//var str = fields[n].toLowerCase();	
		//if (str.indexOf(document.getElementById(id1).value.toLowerCase())!=-1)	
			{	
			opt += "<a class='sel' style='font-family: Arial; margin: 0px 0px 0px 10px; font-size: 11px; color: #000;' href='#' onclick='item1(\"" + fields[n] + "\", \"" + id1 + "\");'>" + fields[n] + "</a><br>";
			}
		}
	
	document.getElementById("subselect0").innerHTML = opt;
	if (opt.length == 0)
	document.getElementById("subselect0").style.display = "none";
	
	}
function item1(opt, id1)
	{
	document.getElementById(id1).value = opt;
	document.getElementById("subselect0").style.display = "none";
	if (document.getElementById(id1).name=="cont") get_cityes(	document.getElementById(id1).value ) // Эта строка индивидуальна для этого проекта связывает два списка
	}	
function getLeft(obj)
{
  var left = obj.offsetLeft

  if (obj.offsetParent)
    left += getLeft(obj.offsetParent)

  return left
}

function getTop(obj)
{
  var top = obj.offsetTop

  if (obj.offsetParent)
    top += getTop(obj.offsetParent)

  return top
}
document.write('<div id="subselect0" style="display: none; position: absolute; overflow-y: scroll; width: 217px; height: 100px; border: 1px solid #000; background-color: #FFF;"></div>');
