var old_str;
var icnt = 0;
var iwait=1000;
var keywordIndex = 0;
var tag_dbon=false;
var need_update=true;
var http_request = false;
String.prototype.trim= function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
function searchAll() {
	//document.all.msg_log.insertAdjacentText("AfterBegin","searchAll\n")
	var chk_error=false;
	var k = document.all.keywordall.value.trim();
	if (k.length==0) {
		alert("Å°¿öµå¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä");
		document.all.keywordall.focus();return;
	}
	need_update=false;
	if (keywordIndex!=0) {
		s=eval("document.all.tn"+keywordIndex+".value");
		if (s=="none") {
			chk_error=true;
		} else {
			document.all.keywordall.value=s;
		}
	}
	if (chk_error==false) {
		document.xxform.dText.value = document.all["keywordall"].value;
//		document.all["keywordall"].value="";
		document.all["KeywordBox"].innerHTML="";
		fn_srch_hide();
		need_update=true;
		document.xxform.submit();
	} else {
		need_update=true;
	}
}
function makeRequest(url) {
	//document.all.msg_log.insertAdjacentText("AfterBegin","makeRequest, "+url+"\n")
	http_request = false;
	if (window.ActiveXObject) { // IE
		try {
			// here used
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	}
	if (!http_request) {
		return false;
	}
	http_request.onreadystatechange = makeTextBox;
	http_request.open('GET', url, true);
	http_request.send(null);
	makeTextBox();
}
function setTextBox(n) {
	var srch_type="";
	if (xxform.dSearch(0).checked==true) {
		srch_type="t";
	} else if (xxform.dSearch(1).checked==true) {
		srch_type="d";
	} else if (xxform.dSearch(2).checked==true) {
		srch_type="a";
	}
	//document.all.msg_log.insertAdjacentText("AfterBegin","setTextBox, "+n+", "+document.all.keywordall.value+", c="+srch_type+ "\n")
	if (tag_dbon==false && old_str != document.all.keywordall.value.toString()) {
		old_str=document.all.keywordall.value;
		tag_dbon=true;
		if (event.keyCode == 38) {
		} else if (event.keyCode == 40) {
		} else if (n==1) {
			try {
			//document.all.msg_log.insertAdjacentText("AfterBegin","===== DB Connection =====\n")
			makeRequest("/dvd/srch.asp?k="+document.all["keywordall"].value+"&c="+srch_type);
			} catch(e) {}
		} else {
			fn_srch_hide();
		}
		tag_dbon=false;
	}
	if (tag_dbon==true) window.setTimeout("setTextBox(1)",iwait);
}
function setText(val) {
	//document.all.msg_log.insertAdjacentText("AfterBegin","setText, "+val+"\n")
	need_update=false;
	keywordIndex=0;
	document.all.keywordall.value = val;
	searchAll()
}
function makeTextBox() {
	if (http_request.readyState==4) {
		if (http_request.status == 200) {
			if (need_update==true)	{
				icnt = 0;
				var xmldoc = http_request.responseXML;
				var kw_node= new Array();
				var tn_node= new Array();
				var tmpStr = ""
				for (m=0; m<=14; m++ ) {
					kw_node[m]= xmldoc.getElementsByTagName('kw')[m];
					if (kw_node[m]) {
						icnt++;
						tn_node[m]=xmldoc.getElementsByTagName('tn')[m];
					}
				}
				var kkk = document.all["KeywordBox"];
				if (icnt > 0) {
					tmpStr=""
					tmpStr=tmpStr+"<table width='500' border='0' cellspacing='0' cellpadding='0'>"
					tmpStr=tmpStr+"<tr>"
					tmpStr=tmpStr+"<td height='27' width='100' align='left' valign='middle'><img src='/dvd/images/img_01.gif' width='114' height='27'></td>"
					tmpStr=tmpStr+"<td height='27' align='center' valign='middle' width='301' background='/dvd/images/img_02.gif'>&nbsp;</td>"
					tmpStr=tmpStr+"<td height='27' align='center' valign='middle' width='45'><img src='/dvd/images/img_03.gif' width='45' height='27'></td>"
					tmpStr=tmpStr+"<td height='27' align='right' valign='middle' width='44'><a href='javascript:fn_srch_hide();'><img src='/dvd/images/img_04.gif' width='44' height='27' border='0'></a></td>"
					tmpStr=tmpStr+"</tr>"
					tmpStr=tmpStr+"<tr>"
					tmpStr=tmpStr+"<td colspan='4'>"
					tmpStr=tmpStr+"<table width='500' border='0' cellspacing='0' cellpadding='0'>"
					tmpStr=tmpStr+"<tr>"
					tmpStr=tmpStr+"<td width='4' bgcolor='#9BC5FF'>&nbsp;</td>"
					tmpStr=tmpStr+"<td width='492'>"
					tmpStr=tmpStr+"<table border='0' align=center width=492 cellpadding='2' cellspacing='0' bgcolor='#FFFFFF'>"
					for (j=0; j < icnt; j++) {
						v = document.all["keywordall"].value;
						var k2 = kw_node[j].childNodes[0].nodeValue;	//real value
						var k3 = k2
						var k4= tn_node[j].childNodes[0].nodeValue
						tmpStr = tmpStr + "<tr><td width=492 id='kw" + (j+1) + "' name=\"" + k2 + "\" onMouseOver=\"setBg(" + (j+1) +")\" onMouseOut=\"this.style.background='';\" onmousedown=\"javascript:setText('"+k4+"')\" style='";
						if (j != (icnt-1)) {
							tmpStr = tmpStr + "border-bottom:1px dotted #DCDCEF;";
						}
						tmpStr=tmpStr + "font-color:666666;cursor:hand'>&nbsp;" + k3 + "</td>"
						tmpStr=tmpStr + "<input type=hidden id='tn" + (j+1) +"' value='" + k4 + "'></tr>"
					}
					tmpStr=tmpStr+"</table>"
					tmpStr=tmpStr+"</td>"
					tmpStr=tmpStr+"<td width='4' bgcolor='#9BC5FF'>&nbsp;</td>"
					tmpStr=tmpStr+"</tr>"
					tmpStr=tmpStr+"<tr>"
					tmpStr=tmpStr+"<td height='4' bgcolor='#9BC5FF'></td>"
					tmpStr=tmpStr+"<td height='4' bgcolor='#9BC5FF'></td>"
					tmpStr=tmpStr+"<td height='4' bgcolor='#9BC5FF'></td>"
					tmpStr=tmpStr+"<td height='4' bgcolor='#9BC5FF'></td>"
					tmpStr=tmpStr+"</tr>"
					tmpStr=tmpStr+"</table>"
					tmpStr=tmpStr+"</td>"
					tmpStr=tmpStr+"</tr>"
					tmpStr=tmpStr+"</table>"
					kkk.innerHTML = tmpStr
					fn_srch_show();
				} else {
					kkk.innerHTML = '';
					fn_srch_hide();
				}
			}
		} else {
		}
	}
	//document.all.msg_log.insertAdjacentText("AfterBegin","makeTextBox, "+http_request.readyState+"\n")
}
function fn_srch_show() {
	if (document.all.hide_toggle) document.all.hide_toggle.style.display="none";
	if (document.all.hide_toggle2) document.all.hide_toggle2.style.display="none";
	if (document.all.hide_toggle3) document.all.hide_toggle3.style.display="none";
	if (document.all.hide_toggle4) document.all.hide_toggle4.style.display="none";
	if (document.all.hide_toggle5) document.all.hide_toggle5.style.display="none";
	document.all.KeywordBox.style.display = "";
}
function fn_srch_hide() {
	if (document.all.hide_toggle) document.all.hide_toggle.style.display="inline";
	if (document.all.hide_toggle2) document.all.hide_toggle2.style.display="inline";
	if (document.all.hide_toggle3) document.all.hide_toggle3.style.display="inline";
	if (document.all.hide_toggle4) document.all.hide_toggle4.style.display="inline";
	if (document.all.hide_toggle5) document.all.hide_toggle5.style.display="inline";
	document.all.KeywordBox.style.display="none";
}
function checkLeftSearch(item) {
	//document.all.msg_log.insertAdjacentText("AfterBegin","checkLeftSearch, "+item+"\n")
	var k = item.value;
	if (event.keyCode == 13 && k.length > 0) {
		need_update=false;
		searchAll();
	} else if (event.keyCode == 27 && document.all.KeywordBox && document.all.KeywordBox.style.display=='') {
		document.all.KeywordBox.style.display = 'none';
	} else if (event.keyCode == 40 && icnt > 0) {
		if (keywordIndex == icnt) {
			eval("document.all.kw"+keywordIndex+".style.background='CEE3FE';");
		} else if (keywordIndex < icnt) {
			keywordIndex++;
			setBg(keywordIndex);
		}
	} else if (event.keyCode == 38 && icnt > 0) {
		if (keywordIndex == 1) {
			keywordIndex--;
			for (m=1; m<=icnt;m++) {
				eval("document.all.kw"+m+".style.background='';");
			}
		} else if (keywordIndex > 0) {
			keywordIndex--;
			setBg(keywordIndex);
		}
	} else {
		keywordIndex = 0
	}
}
function setBg(n) {
	for (m=1; m<=icnt;m++) {
		eval("document.all.kw"+m+".style.background='';");
	}
	eval("document.all.kw"+n+".style.background='CEE3FE';");
}

