﻿var cspSearchIndex = 1;
var cspSearchCount = 1;
function cspSearchHighlight(txt) {
    if (txt != '') {
        var contentControls = document.getElementsByTagName("div");
        for (i = 0; i < contentControls.length; i++) {
            var control = contentControls[i];
            if (control.getAttribute("name") == "cspContent") {
                var bt = '<span name="cspSearchTerm" id="cspSearchTerm';
                var mt = '" class="cspSearchTerm">';
                var et = '</span>';
                var conTxt = control.innerHTML;
                txt = txt.replace(/(?!"[^" ][^"]*) (?![^"]*[^" ]")/gi, '|');
                txt = txt.replace(/"/gi, '');
                var codeRegExp = new RegExp('(?!\\<[^\\<\\>]*)\\b(' + txt + ')\\b(?![^\\<\\>]*\\>)', 'gi');
                conTxt = conTxt.replace(codeRegExp, function($0, $1) { return bt + (cspSearchCount++) + mt + $1 + et });
                control.innerHTML = conTxt;
            }
        }
    }
    cspSearchCount--;
    cspSearchHighlightArray(0);
}
function cspSearchUnHighlight() {
    while (dObj('cspSearchTerm')) dObj('cspSearchTerm').removeNode(0);
    if (dObj('searchHits')) dObj('searchHits').style.display = 'hidden';
}
function cspSearchHighlightArray(dir) {
    dObj('cspSearchTerm' + cspSearchIndex).className = 'cspSearchTerm';
    cspSearchIndex = cspSearchIndex + dir;
    if (cspSearchIndex > cspSearchCount) cspSearchIndex = 1;
    if (cspSearchIndex < 1) cspSearchIndex = cspSearchCount;
    dObj('cspSearchTerm' + cspSearchIndex).className = 'cspSearchTerm-selected';
    dObj('cspSearchTerm' + cspSearchIndex).scrollIntoView();
    dObj('cspSearchCountDisplay').innerHTML = (cspSearchIndex + '/' + cspSearchCount);
}