var timeout = null;
var kw = $("SK").value;
var bClick = false;

function doClick(str)
{
	if (timeout != null){window.clearInterval(timeout);timeout=null;}
	$('SK').value=str;
	$("KeyList").style.display = "none";
}

function showKey(ajax)
{
	var str = ajax.responseText;
	var strList = "<style>.kdiv{height:18px;}.kdiv a{display:block;}.kdiv a:hover{height:18px;color:white;background:#456;}</style>";
	var arrTmp = str.split("|");
	for(var i=0;i<arrTmp.length-1;i++)
	{กก
		strList += "<div class=\"kdiv\"><a href=\"javascript:;\" onclick=\"doClick('"+arrTmp[i]+"');\">"+arrTmp[i]+"</a></div>";
	}
	var pos = getAbsolutePosition($("SK"));
	$("KeyList").style.left =  pos.left + "px";
	$("KeyList").style.top =  (pos.top+pos.height) + "px";
	$("KeyList").style.width =  (pos.width-2) + "px";
	$("KeyList").innerHTML = strList;
	$("KeyList").style.display = "";
}

$("KeyList").onmouseover = function (){bClick = true;}
$("KeyList").onmouseout = function (){bClick = false;}

$("SK").onblur = function ()
{
	if (!bClick)
	{
		$("KeyList").style.display = "none";
	}
}

function getkey()
{	
	if ($("SK").value=="")
	{
		kw = "";
		$("KeyList").style.display = "none";
		return;
	}
	
	if ($("SK").value == kw)
	{
		return;
	}
	kw = $("SK").value;
	AjaxMethod('/Ajax.ashx', null, 'method=GetKeyword&k='+kw, showKey);
}

$("SK").onkeydown = function(event)
{
	var e = event ? event : (window.event ? window.event : null);
	if ($("ST").value=="C")
	{
		if (timeout != null)
		{
			window.clearInterval(timeout);
			timeout=null;
		}
		$("KeyList").style.display = "none";
	}
	else
	{
		if (timeout == null)
		{
			//timeout = window.setInterval("getkey()", 500);
		}
	}
	
	if (e.keyCode == 13)
	{
		SearchSub();
		e.returnValue = false;
		return;
	}
}

