0; j < item.kw.length; j++) { var k = item.kw[j]; if (n.indexOf(k) !== -1 && k.length > bestScore) { bestScore = k.length; best = item; } } } return best ? best.r : FALLBACK; } function handleInput(text) { if (!text || !text.trim()) return; addMsg(text, 'user'); input.value = ''; botReply(findAnswer(text)); } QUICK.forEach(function(q) { var b = document.createElement('button'); b.innerHTML = q.icon + '' + q.text + ''; b.onclick = function() { addMsg(q.text, 'user'); var item = KB.find(function(x) { return x.id === q.id; }); botReply(item ? item.r : FALLBACK); }; quick.appendChild(b); }); sendBtn.onclick = function() { handleInput(input.value); }; input.addEventListener('keypress', function(e) { if (e.key === 'Enter') handleInput(input.value); }); var opened = false; function openChat() { win.classList.add('open'); badge.style.display = 'none'; if (!opened) { opened = true; setTimeout(function() { addMsg('Dobrý den, jsem virtuální asistent NKM Advisory.

Můžu vám představit naše služby, předat kontakt nebo pomoci s domluvením schůzky. Klikněte na jedno z tlačítek pod chatem, nebo napište, co potřebujete.', 'bot'); }, 200); } setTimeout(function() { input.focus(); }, 300); } function closeChat() { win.classList.remove('open'); } bubble.onclick = function() { if (win.classList.contains('open')) closeChat(); else openChat(); }; closeBtn.onclick = closeChat; } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })(); } function closeChat() { win.classList.remove('open'); } bubble.onclick = function() { if (win.classList.contains('open')) closeChat(); else openChat(); }; closeBtn.onclick = closeChat; } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();