function doLiveSearch(e,d){return 38!=e.keyCode&&40!=e.keyCode&&($("#livesearch_search_results").remove(),updown=-1,!(""==d||d.length<2)&&(d=encodeURI(d),$.ajax({url:$("base").attr("href")+"index.php?route=product/search/ajax&keyword="+d,dataType:"json",success:function(e){if(e.length>0){var n=document.createElement("ul");n.id="livesearch_search_results";var o,r;for(var t in e)o=document.createElement("li"),(r=document.createElement("a")).appendChild(document.createTextNode(e[t].name)),void 0!==e[t].href?r.href=e[t].href:r.href=$("base").attr("href")+"index.php?route=product/product&product_id="+e[t].product_id+"&keyword="+d,o.appendChild(r),n.appendChild(o);$("#livesearch_search_results").length>0&&$("#livesearch_search_results").remove(),$("#search").append(n)}}}),!0))}function upDownEvent(e){var d=document.getElementById("livesearch_search_results");$("#search").find("[name=search]").first();if(d){var n=d.childNodes.length-1;if(-1!=updown&&void 0!==d.childNodes[updown]&&$(d.childNodes[updown]).removeClass("highlighted"),38==e.keyCode?updown=updown>0?--updown:updown:40==e.keyCode&&(updown=updown<n?++updown:updown),updown>=0&&updown<=n){$(d.childNodes[updown]).addClass("highlighted");var o=d.childNodes[updown].childNodes[0].text;void 0===o&&(o=d.childNodes[updown].childNodes[0].innerText),$("#search").find("[name=search]").first().val(new String(o).replace(/(\s\(.*?\))$/,""))}}return!1}var updown=-1;$(document).ready(function(){$("#search").find("[name=search]").first().keyup(function(e){doLiveSearch(e,this.value)}).focus(function(e){doLiveSearch(e,this.value)}).keydown(function(e){upDownEvent(e)}).blur(function(){window.setTimeout("$('#livesearch_search_results').remove();updown=0;",1500)}),$(document).bind("keydown",function(e){try{13==e.keyCode&&$(".highlighted").length>0&&(document.location.href=$(".highlighted").find("a").first().attr("href"))}catch(e){}})});