﻿function searchbox_blur() {
    var searchBox = document.getElementById('cms-search');
    if (searchBox.value == '') {
        searchBox.className = 'searchBoxEmpty';
        searchBox.value = 'Search...';
    } else {
        searchBox.className = 'searchBoxNonEmpty';
    }
}

function showAutoComplete(obj) {
    //check which items should be visible
    var val = obj.value;
    var ac = $($(obj)[0].parentNode).find(".autocomplete");
    ac.find("li").each(function () {
        if ($(this).html().trim().indexOf(val) != 0) {
            $(this).hide();
        }
        else {
            $(this).show();
        }
    }
    );
    if (!$(ac).is(":visible")) {
        $(ac).fadeIn(250);
    }

}
function hideAutoComplete(f) {
    var ac = $($(f)[0].parentNode).find(".autocomplete");
    ac.fadeOut(500);
}
function selectAutoComplete(obj) {
    var ac = $($(obj)[0].parentNode.parentNode.parentNode).find(".autocomplete");
    var f = $($(obj)[0].parentNode.parentNode.parentNode).find(".field_a")[0];
    f.value = $(obj).html();
    ac.hide();
}


function searchbox_focus() {
    var searchBox = document.getElementById('cms-search');
    if (searchBox.className == 'searchBoxEmpty') {
        searchBox.value = '';
    }
    searchBox.className = 'searchBoxFocus';
}

function setSearchPage(pageNumber) {
    var resultsPage = document.getElementById('search_resultsPage');
    var searchForm = document.getElementById('searchForm');
    resultsPage.value = pageNumber;
    searchForm.submit();
}

function searchForm_submit() {
    var searchBox = document.getElementById('cms-search');
    if (searchBox.className == 'searchBoxEmpty') {
        searchBox.value = '';
    }
}


