﻿function fnSetResultCount(spanID, count) {
    if ($(spanID) != null) {
        $(spanID).text('(' + count + ')');
    }
}

function doSearch() {
    //                    window.location = "/" + $("#LocalNodeUrl").attr("value") + "/search.aspx?search=" + ($("#txbSearch").attr("value"));
    var searchPhrase = ($("#txbSearch").attr("value"));

    if (searchPhrase != "" && searchPhrase != null && searchPhrase != "Hledání...") {

        try { pageTracker._trackEvent('Global', 'search', searchPhrase); } catch (err) { }
        window.location = "/productlist.aspx?search=" + searchPhrase;
    }
};

function handleEnter(inField, e) {
    var charCode;

    if (e && e.which) {
        charCode = e.which;
    } else if (window.event) {
        e = window.event;
        charCode = e.keyCode;
    }

    if (charCode == 13) {
        doSearch();
        return false;
    }
}

$(document).ready(function () {
    // Define what happens when the textbox comes under focus
    // Remove the watermark class and clear the box
    $("#txbSearch").focus(function () {
        $(this).filter(function () {

            // We only want this to apply if there's not 
            // something actually entered
            return $(this).val() == "" || $(this).val() == "Hledání...";

        }).removeClass("watermarkOn").val("");

    });

    // Define what happens when the textbox loses focus
    // Add the watermark class and default text
    $("#txbSearch").blur(function () {

        $(this).filter(function () {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == ""

        }).addClass("watermarkOn").val("Hledání...");

    });

    $("#txbSearch").keydown(function (event) {
        var key = event.keyCode || event.charCode || 0;
        if (key == 13) {
            event.preventDefault();
            doSearch();
        }
    });
    $("#imgSearch").click(function(event) {
            event.preventDefault();
            doSearch();
    });
});