<script>
    function highlightMatch(html, query) {
        if (!html) {
            return html;
        }

        const cssClass = 'bg-header-darker'
        let arQuery = query.split(' ');
        let arSpecialChars = [
            {'key': 'a', 'value': '(à|â|ą|a)'},
            {'key': 'c', 'value': '(ç|č|c)'},
            {'key': 'e', 'value': '(è|é|ė|ê|ë|ę|e)'},
            {'key': 'i', 'value': '(î|ï|į|i)'},
            {'key': 'o', 'value': '(ô|o)'},
            {'key': 's', 'value': '(š|s)'},
            {'key': 'u', 'value': '(ù|ü|û|ū|ų|u)'}
        ];

        arQuery.forEach(function (word) {
            word = word.trim();

            if (word) {
                word = word.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
                arSpecialChars.forEach(function (match) {
                    word = word.replace(new RegExp(match.key, 'g'), match.value);
                });

                if ("span".indexOf(word.toLowerCase()) === -1) {
                    html = html.replace(new RegExp('(' + word + '(?![^<>]*>))', 'ig'), function ($1, match) {
                        return '<span class="' + cssClass + '">' + match + '</span>';
                    });
                }
            }
        });

        return html;
    }
</script>
