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();
}