// °Ë»ö ºÐ·ù »ý¼º
function onScate(){
	var objAjax = new Ajax(false);
	var url = "/common/ajax/exec_getCategory.asp";
	var returnExec = "execScate";
	objAjax.execute("POST", url, "depth=1", returnExec);
}

function execScate(value){

	if (value.stripspace() != "") {
		objJson = JSON.parse(value);
		if (objJson != false){
			var form = document.tsFrm;
			var html = "<table width='92' border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff'>";
			html += "<tr height='20' onclick=\"selectScate(0, '')\" onmouseover=\"this.style.backgroundColor = '#FFFFFF';\" onmouseout=\"this.style.backgroundColor = '';\" style='cursor:hand'><td align='center' style='color:#666666' id='tdScate'>ÀüÃ¼°Ë»ö</td></tr>";

			for (var i=0; i<objJson.item.cateList.length; i++) {
				if(objJson.item.cateList[i].code == form.scate.value) document.all.scateVal.innerHTML = objJson.item.cateList[i].name;
				html += "<tr height='20' onclick=\"selectScate(" +(i+1)+ ", '" +objJson.item.cateList[i].code+ "')\" onmouseover=\"this.style.backgroundColor = '#FFFFFF';\" onmouseout=\"this.style.backgroundColor = '';\" style='cursor:hand'><td align='center' style='color:#175594' id='tdScate'>" +objJson.item.cateList[i].name+ "</td></tr>";
			}
			html += "</table>";
		}
		objJson = null;
		document.all.divScate.innerHTML = html;
	}
}

// °Ë»ö ºÐ·ù ·¹ÀÌ¾î ¼û±è/º¸ÀÓ
function viewScate(){
	var obj = document.all.divScate;
	obj.style.display = obj.style.display == "none" ? "" : "none";
	if(obj.style.display == "") showNaviCate("none");

}
// ºÐ·ù ¼±ÅÃ Click
function selectScate(i, val){
	var obj = document.all.divScate;
	var form = document.tsFrm;
	form.scate.value = val;
	document.all.scateVal.innerHTML = document.all.tdScate[i].innerHTML;
	obj.style.display = "none";
}

// À¯»ç°Ë»ö¾î °ü·Ã ÇÔ¼ö
var selectValue = 0;
var orgValue;
var arrKey = new Array();

// À¯»ç°Ë»ö¾î °ü·Ã ½ºÅ©¸³Æ®
function shDiv(obj, show){
	obj.style.display = show;
}
function moveCursor(){
	if(trResult){
		var objDiv = document.all.divAutoKey;
		var objTr = document.all.trResult;
		var form = document.tsFrm;

		objDiv.style.display = '';
		if(event.keyCode == 38 && selectValue > 0) selectValue--;
		if(event.keyCode == 40 && selectValue <= arrKey.length-1) selectValue++;
		if(selectValue == 0) objDiv.style.display = "none";
		if(selectValue == 0) form.sword.value = orgValue;

		if(trResult.length){
			for(i=0; i<arrKey.length; i++){
				if(selectValue-1 == i){
					objTr[i].style.backgroundColor = '#EFEFEF';
					inputValue(i, "");
				}else{
					objTr[i].style.backgroundColor = '#FFFFFF';
				}
			}
		}else{
			if(selectValue-1 == 0){
				form.sword.value = arrKey[0];
				objTr.style.backgroundColor = '#EFEFEF';
				document.all.tdResult0.focus();
				objDiv.style.display = "";
			}else{
				objTr.style.backgroundColor = '#FFFFFF';
			}
		}
		form.sword.focus();
	}
}
function inputValue(i, show){
	var form = document.tsFrm;
	form.sword.value = arrKey[i];
	//////document.all["tdResult"+i].focus();
	document.all.divAutoKey.style.display = show;
}
function onAutoKey(){
	var form = document.tsFrm;
	if(checkEmpty(form.sword)==false){
		if(event.keyCode == 38 || event.keyCode == 40){
			moveCursor();
		}else{
//			var param = "scate=" +form.scate.value+ "&key=" +form.sword.value;
			var param = "key=" +form.sword.value;
			orgValue = form.sword.value;
			new ajax2.xhr.Request("/common/ajax/exec_getAutoKeyword.asp", param, sendAutoKey, "GET");
			showNaviCate("none");
		}
	}else{
		shDiv(document.all.divAutoKey, "none");
	}
}
// Ä«Å×°í¸® °æ·Î(³×ºñ°ÔÀÌ¼Ç) ¼û±è
function showNaviCate(show){
	var arrNaviCate = new Array("naviCate_1", "naviCate_2", "naviCate_3");
	for(i=0; i<arrNaviCate.length; i++){
		var obj = eval("document.all."+arrNaviCate[i]);
		if(obj) obj.style.display = show;
	}
	var arrNaviCate = new Array("cate_1", "cate_2", "cate_3");
	for(i=0; i<arrNaviCate.length; i++){
		var obj = eval("document.all."+arrNaviCate[i]);
		if(obj) obj.style.display = show;
	}
}
function sendAutoKey(req){
	var form = document.tsFrm;
	if(req.readyState == 4){
		if(req.status == 200){
			var docXML = req.responseXML;
			var xData = eval("("+docXML.getElementsByTagName("searchList").item(0).firstChild.nodeValue+")");

			arrKey = new Array(); selectValue = 0;
			var html = "<div style='width:241;height:100px;border: 0px solid blue;background:#FFFFFF; overflow: auto;scrollbar-shadow-color: #ffffff; scrollbar-highlight-color: #ffffff; scrollbar-face-color: #d9d9d9; scrollbar-3dlight-color: #d9d9d9; scrollbar-darkshadow-color: #d9d9d9; scrollbar-track-color: #ffffff; scrollbar-arrow-color: #ffffff;'>";
			html += "<table width='100%' border='0' cellpadding='2' cellspacing='0'>";
			if(xData.length > 0){
				for(var i=0; i<xData.length; i++){
					html += "<tr height='20' id='trResult' onmouseover=\"this.style.backgroundColor = '#EFEFEF';\" onmouseout=\"this.style.backgroundColor = '#FFFFFF';\" style='cursor:hand' onclick=\"inputValue("+i+", 'none');\"><td style='font-size:11px' id='tdResult"+i+"'>"+xData[i].value+"</td></tr>";
					arrKey[i] = xData[i].keyValue;
				}
			}else{
				html += "<tr bgcolor='#FFFFFF' height='25' align='center' id='trResult'><td>°ü·ÃµÈ °Ë»ö¾î°¡ ¾ø½À´Ï´Ù.</td></tr>";
			}
			html += "</table></div>";
			shDiv(document.all.divAutoKey, "");
			document.all.divAutoKey.innerHTML = html;
		}
	}
}
function sendSearch(){
	var form = document.tsFrm;
	if (checkEmpty(form.sword)) {
		alert("°Ë»ö¾î¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		form.sword.focus();
		return false;
	}
}
function hideAutoKey(){
	document.all.divAutoKey.style.display = "none";
	document.all.divScate.style.display = "none";
	showNaviCate("")
}

document.onmouseup = hideAutoKey;
