var outp; var oldins; var posi = -1; var items; var input; var key; var s_lock = true; function setVisible(visi) { var x = document.getElementById("shadow"); var o = document.getElementById("output"); var t = document.getElementById(txtField); x.style.position = 'absolute'; x.style.top = (findPosY(t) + 3) + "px"; x.style.left = findPosX(t) + "px"; //x.style.left = (findPosX(t) + 2) + "px"; //x.style.top = "30px"; //x.style.left = "198px"; //o.style.width = t.offsetWidth - 8; if(s_lock == false) { x.style.visibility = visi; } if(visi != "hidden" && s_lock == false) { $("srch_bt").src = "images/srch_arrow2.gif"; } else { $("srch_bt").src = "images/srch_arrow.gif"; } } function findPosX(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; return curleft; } function findPosY(obj) { var curtop = 0; if (obj.offsetParent) { curtop += obj.offsetHeight; while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj.y) { curtop += obj.y; curtop += obj.height; } return curtop; } function lookAt() { var ins = document.getElementById(txtField).value; //alert(oldins); //alert(ins); if (oldins == ins) return; // 이전에 입력된 값과 같으면 다시 확인안한다. else if (posi > -1) { ; } else if (ins.length > 0) { //getWord(ins); // 자동완성 단어만 제시할때 getWordWithAutomata(ins); // 자판변환+자동완성 제시 } else { setVisible("hidden"); posi = -1; } oldins = ins; } function addWord(label, word) { //alert(label); var sp = document.createElement("div"); sp.innerHTML = label; sp.onmouseover = mouseHandler; sp.onmouseout = mouseHandlerOut; sp.onclick = mouseClick; sp.word = word; outp.appendChild(sp); } function clearOutput() { while (outp.hasChildNodes()) { noten = outp.firstChild; outp.removeChild(noten); } posi = -1; } ///////////////////////////////////////////////////////////////////////////// function getWord(beginning) { var url = urlAjax + encodeURIComponent(beginning); var req = new Ajax.Request(url, { method :'get', asynchronous :true, onSuccess :onSucess }); } function onSucess(request) { //alert(request.responseText); var retobj = eval("(" + request.responseText + ")"); items = retobj.items; if (items.length > 0) { clearOutput(); // 기존 값을 지운다. var label; for ( var ni = 0; ni < items.length; ni++) { label = ""+items[ni].query+""; //addWord(items[ni].label, items[ni].word); addWord(label, items[ni].query); } setVisible("visible"); input = document.getElementById(txtField).value; } else { setVisible("hidden"); posi = -1; } } ///////////////////////////////////////////////////////////////////////////// //영문자판입력->한글자판 입력으로 변환한 글자도 자동완성으로 제공한다. var sc_english2hangul=""; function getWordWithAutomata(beginning) { if ( smIsEnglish(beginning)==true ) { sc_english2hangul=smCvtEnglishToHangul2(beginning); ////한글이 제대로 구성되지 않은경우 찿기=>창이 열였다 닫혀서 보기 싫다. //if ( smIsHangul(sc_english2hangul)==false ) sc_english2hangul=""; } else { sc_english2hangul=""; //영어 이외의 글자가 있는 경우 } var url = urlAjax + encodeURIComponent(beginning); var req = new Ajax.Request(url, { method :'get', asynchronous :true, onSuccess :onSucessWithAutomata }); } function onSucessWithAutomata(request) { //KAY_MODIFY_2008_0602 //alert(request.responseText); //var retobj = eval("(" + request.responseText + ")"); //items = retobj.items; var szItems=request.responseText; if ( sc_english2hangul.length > 0 ) { // 자동완성 객체에 자판변환한 단어를 추가한다. if ( szItems.indexOf("query")<0 ) { szItems=szItems.replace("[", "[{query:\""+sc_english2hangul+"\"}"); } else { szItems=szItems.replace("[", "[{query:\""+sc_english2hangul+"\"},"); } } //KAY_MODIFY_END var retobj = eval("(" + szItems + ")"); items = retobj.items; clearOutput(); // 기존 제시한 단어들을 지운다. if ( items.length > 0 ) { var label; for ( var ni = 0; ni < items.length; ni++) { label = ""+items[ni].query+""; //addWord(items[ni].label, items[ni].word); addWord(label, items[ni].query); } setVisible("visible"); input = document.getElementById(txtField).value; } else { setVisible("hidden"); posi = -1; } } ///////////////////////////////////////////////////////////////////////////// function setColor(_posi, _color, _forg) { outp.childNodes[_posi].style.background = _color; outp.childNodes[_posi].style.color = _forg; } function keygetter(event) { if (!event && window.event) event = window.event; if (event) key = event.keyCode; else key = event.which; } function s_lock_pass() { s_lock = false; if((location + "").indexOf("selectSearchIntergrating.htm") != -1) { document.getElementById("shadow").style.width = "305"; document.getElementById("border").style.width = "297"; document.getElementById("output").style.width = "305"; } } function showAutoWord() { if(!$("txtQuery").value || s_lock == true) return; return; if($("srch_bt").src.indexOf("srch_arrow2") != -1) { $("srch_bt").src = "images/srch_arrow.gif"; document.getElementById("shadow").style.visibility = "hidden"; } else { $("srch_bt").src = "images/srch_arrow2.gif"; document.getElementById("shadow").style.visibility = ""; } } function keyHandler(event) { if (document.getElementById("shadow").style.visibility == "visible") { var textfield = document.getElementById(txtField); var ScOffSet = document.getElementById("output"); var nHeightPerLine = 15; if (key == 40) { // Key down // alert (words); if (items.length > 0 && posi < items.length - 1) { if (posi >= 0) setColor(posi, "#fff", "black"); else input = textfield.value; setColor(++posi, "#99CCEE", "white"); textfield.value = outp.childNodes[posi].childNodes[0].innerHTML; } } else if (key == 38) { // Key up if (items.length > 0 && posi >= 0) { if (posi >= 1) { setColor(posi, "#fff", "black"); setColor(--posi, "#99CCEE", "white"); textfield.value = outp.childNodes[posi].childNodes[0].innerHTML; } else { setColor(posi, "#fff", "black"); textfield.value = input; textfield.focus(); posi--; } } } else if (key == 27) { // Esc textfield.value = input; setVisible("hidden"); posi = -1; oldins = input; } else if (key == 8) { // Backspace posi = -1; oldins = -1; } //alert(posi); //alert(ScOffSet.scrollTop); //alert((posi-4)*nHeightPerLine); if (posi > 4) { if ( ScOffSet.scrollTop < ((posi-4)*nHeightPerLine) ) ScOffSet.scrollTop = (posi-4)*nHeightPerLine; } else if (posi <= 4) { if ( ScOffSet.scrollTop > 0 && ((posi-4)*nHeightPerLine) <= 0 ) ScOffSet.scrollTop = ScOffSet.scrollTop - nHeightPerLine; } } } mouseHandler = function() { for ( var i = 0; i < items.length; ++i) setColor(i, "white", "black"); this.style.background = "#99CCEE"; } mouseHandlerOut = function() { this.style.background = "white"; this.style.color = "black"; } mouseClick = function() { var dvNode = this.firstChild.parentNode; document.getElementById(txtField).value = dvNode.childNodes[0].innerHTML; setVisible("hidden"); posi = -1; oldins = dvNode.childNodes[0].innerHTML; document.getElementById(txtField).focus(); suggest_search_submit(); }