var searchInterval = null; var $currIdx = null; var currIdx = -1; var $sRes = null; $("#mainSearchKey").keyup(function(event) { if(event.which==13) { setCurrent($currIdx); setSearchKey($currIdx.attr('title')); } else if(event.which==38) { // alert('UP key'); setPrev(); } else if(event.which==40) { // alert('DOWN key'); setNext(); } else { if($("#mainSearchKey").val().length > 1) { clearTimeout(searchInterval); searchInterval = setTimeout('getSearchResult()', 100); // getSearchResult(); } else { $("#searchHelp").hide(); } } }); function getSearchResult() { $.ajax({ type: "GET", contentType: "text/html; chaset=EUC-KR", url: "top_search.inner.php", data: "search_key=" + $("#mainSearchKey").val(), success: function(html) { $("#searchHelp").hide(); $("#searchHelp").html(html); $("#searchHelp").show(); $currIdx = null; currIdx = -1; $sRes = $("P.topSearchResult"); } }); } function getSearchResult2() { sKey = $("#mainSearchKey").val(); reg = new RegExp(sKey, 'i'); res = ''; limitNum = 20; gNameExist = 0; gModelExist = 0; for(var st = 0, en = goodsNameArr.length; st < en; st++) { if(goodsNameArr[st].match(reg)) { gNameExist++; if(gNameExist >= limitNum) { st = en; continue; } matchIdx = goodsNameArr[st].indexOf(sKey, 0); // if(!mpAlert) { alert('mp : ' + matchIdx); mpAlert = true;} // res += goodsNameArr[st] + "
"; res += "

"; res += goodsNameArr[st].slice(0,matchIdx); res += '' + goodsNameArr[st].slice(matchIdx, matchIdx+sKey.length) + ''; res += goodsNameArr[st].slice(matchIdx+sKey.length); res += "

"; } } res2 = ''; for(var st2 = 0, en2 = goodsModelArr.length; st2 < en2; st2++) { if(goodsModelArr[st2].match(reg)) { gModelExist++; if(gModelExist >= limitNum) { st2 = en2; continue; } matchIdx = goodsModelArr[st2].indexOf(sKey, 0); res2 += "

"; res2 += goodsModelArr[st2].slice(0,matchIdx); res2 += '' + goodsModelArr[st2].slice(matchIdx, matchIdx+sKey.length) + ''; res2 += goodsModelArr[st2].slice(matchIdx+sKey.length); res2 += "

"; } } var result = ''; if(gNameExist > 0 || gModelExist > 0) { if(gNameExist > 0) { result += '
'; result += '

Á¦Ç°¸í

'; result += '
´Ý±â
'; result += res; result += '
'; } if(gNameExist > 0 && gModelExist > 0) result += '
'; if(gModelExist > 0) { result += '
'; result += '

ÇÁ¸°Å͸í

'; result += res2; result += '
'; } } else { result += '

°Ë»ö °á°ú°¡ ¾ø½À´Ï´Ù.

'; } $("#searchHelp").hide(); $("#searchHelp").html(result); $("#searchHelp").show(); $currIdx = null; currIdx = -1; $sRes = $("P.topSearchResult"); } function setSearchKey(str, type) { $("#mainSearchKey").val(str); if(type==1) $("#topSearchType").val('goods'); $("#searchHelp").hide(); $('#topSearchForm').submit(); } function setCurrent(obj) { if(obj !== null && typeof(obj)=='object' && typeof(obj.attr())!='undefined') { $("#keyIdx").text("index " + ( $sRes.index( $("#tsr" + currIdx) ) )) ; // currIdx = obj.index(); $sRes.css('background-color', '#FFFFFF'); obj.css('background-color', '#C0E0F0'); // currIdx = obj.substr(3); // alert(currIdx+"is current Index number"); // alert(obj.attr('title')); return true; } else { return false; } // alert($("P.topSearchResult").index(obj)); } function setPrev() { if(parseInt(currIdx)=='NaN' || currIdx < 1) { currIdx = 0; setCurrent($("P.topSearchResult").eq(0)); } else { $("#keyIdx").text($("P.topSearchResult").length); setCurrent($("P.topSearchResult").eq(--currIdx)); } } function setNext() { if(parseInt(currIdx)=='NaN' || currIdx==-1) { currIdx = 0; setCurrent($sRes.eq(0)); } else if(currIdx >= $sRes.length) { setCurrent($sRes.eq(++curridx)); } else if($currIdx == $sRes.last()) { setCurrent($sRes.eq($sRes.length - 1)); } else { setCurrent($sRes.eq(++currIdx)); } // if(setCurrent($currIdx.next())) return; // else setCurrent($("P.topSearchResult").last()); }