function findTabs(tabs) {
    var selection = [];

    clearNodes(listZone);
    if (searchBar.value != "") {
        for (let tab of tabs) {
            var title = tab.title;
            if (title.toLowerCase().includes(searchBar.value.toLowerCase())) {
                selection.push(tab);
            }
        }
        if (selection.length > 1) {
            for (let sel of selection) {
                createContainer(sel)
            }
            errHandler.style.display = "none";
            clearNodes(errHandler);
        } else {
            if (selection[0] != undefined) {
                errHandler.style.display = "none";
                clearNodes(errHandler);
                loadSelTab(selection[0].id);
            } else {
                errHandler.style.display = "block";
                errHandler.appendChild(notFoundText);
            }
        }
    } else { logTabs(tabs); }
}

function clearNodes(targetNode) {
    while (targetNode.firstChild) {
        targetNode.removeChild(targetNode.firstChild);
    }
}

function loadSelTab(id) { browser.tabs.update(id, { active: true }); }

function searchTabs() {
    tabsAction.query({currentWindow: true})
              .then(findTabs, onError);
}
