var keydownpress = false; var keyuppress = false; var pointer = null; var searchingText; var loadingContent; var itemBg = '#FFF6D5'; Array.prototype.contains = function(key) { for (var i = 0; i < this.length; i++) { if (this[i] == key) return true; } return false; }; String.prototype.trim = function () { return this.replace(/^\s*/, '').replace(/\s*$/, ''); }; function isIllegalKey(key) { var illegalKeys = new Array(33,34,37,39); return (illegalKeys.contains(key)) ? true : false; } function detectKey(e,input) { var keynum; keynum = (window.event) ? e.keyCode : e.which; if (isIllegalKey(keynum)) return; keydownpress = (keynum == 40) ? true : false; keyuppress = (keynum == 38) ? true : false; if (keynum == 13) { if (resultContainsOneRow()) pointer = $('#searchresult ul li:first')[0]; if (pointer == null) return; handleLi(pointer); return; } if (!(keydownpress || keyuppress)) pointer = null; if ((keydownpress || keyuppress) && ($('#searchresult').html() != '')) setActive(); else { if ($(input).val().length > 0) checkPattern($(input).val()); else { $('#searchresult').hide(); pointer = null; } } } function resultContainsOneRow() { return ($('#searchresult ul li').size() == 2) ? true : false; } function setActive() { if (pointer == null) { if (keydownpress) li = $('#searchresult ul li:first'); else if (keyuppress) li = $('#searchresult ul li:last'); $(li).css('background-color',itemBg); pointer = $(li)[0]; } else { var size = $('#searchresult ul li').size(); $('#searchresult ul li').each(function(i){ if ($(this)[0] == pointer) { setNonActive($(this)); if ((keydownpress) && (i < size-1)){ $(this).next().css('background-color',itemBg); pointer = $(this).next()[0]; } if ((keydownpress) && (i == size-1)){ $('#searchresult ul li:first').css('background-color',itemBg); pointer = $('#searchresult ul li:first')[0]; } if ((keyuppress) && (i == 0)){ $('#searchresult ul li:last').css('background-color',itemBg); pointer = $('#searchresult ul li:last')[0]; } if ((keyuppress) && (i > 0)){ $(this).prev().css('background-color',itemBg); pointer = $(this).prev()[0]; } return false; } }); } setWindowStatus(pointer); } function setNonActive(li) { $(li).css('background-color','white'); } function callbackPatternCheck(data) { if ($('.header .search input').val() == '') return; $('#searchresult')[0].innerHTML = data; if (data.indexOf('
  • -1) { $('#searchresult').show(); } else { $('#searchresult').hide(); pointer = null; } } function checkPattern(value) { $.ajax({ url: 'https://www.reisen.cz//ajax/q_search.php?q='+encodeURIComponent(value), success: function(data){ callbackPatternCheck(data); $('#loading').html(loadingContent); $('#loading').css('background',"url('https://www.reisen.cz/templates/default/img/wait_bg.png')"); }, beforeSend: function() { loadingContent = $('#loading').html(); $('#loading').html(''); $('#loading').css('background','none'); } }); searchingText = encodeURIComponent(value); } function handleLi(li) { var script = eval('('+getScript(li)+')'); logResult(script['p1'],li); top.document.location.href = decodeURIComponent(script['p1']); $("#searchresult").hide(); } function logResult(link,li) { var order = 1; $('#searchresult ul li').each(function(i){ if ($(this)[0] === pointer) order = i+1; }); var data = { keyword : searchingText, link : link, text : $(li).text().replace(/\(\{.*\}\)/,''), count : $('#searchresult ul li').size(), order : order }; $.post( 'https://www.reisen.cz//ajax/q_log.php', data ); } function handleMouseOver(li) { pointer = $(li)[0]; $(li).css('background-color',itemBg); setWindowStatus(li); setLisNonActive(); } function getScript(li) { var script = $(li).find('script').html(); return script; } function setWindowStatus(li) { var script = eval('('+getScript(li)+')'); window.status = unescape(script['p1']); } function setLisNonActive() { if ($('#searchresult ul').size() == 0) return; $('#searchresult ul li').each(function(){ var item = $(this)[0]; if (($(item).css('background-color') != 'white') && (item != pointer)) setNonActive(item); }); } $(document).ready(function(){ $('#search-input').focus(function(){ checkPattern($(this).val()) }); $('*').click(function(e){ if (e.target.id != 'search-input') { $('#searchresult').hide(); } pointer = null; setLisNonActive(); }); });