function fnSetResultCount(spanID, count) {
    if ($(spanID) != null) {
        $(spanID).text('(' + count + ')');
    }
}

function doSearch() {
    //                    window.location = "/" + $("#LocalNodeUrl").attr("value") + "/search.aspx?search=" + ($("#txbSearch").attr("value"));
    var searchTerm = $("#txbSearch").val();
    var searchTermWatermark = $("#txbSearchWatermark").val();
    
    if (searchTerm != "" && searchTerm != searchTermWatermark)
    {
		window.location = "/search.aspx?search=" + ($("#txbSearch").val());
		return true;
	}
	else
    {
		return false;
    }
};

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() == $("#txbSearchWatermark").val();

        }).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($("#txbSearchWatermark").val());

    });

    $("#txbSearch").keydown(function(event) {
        var key = event.keyCode || event.charCode || 0;
        if (key == 13) {
            event.preventDefault();
            doSearch();
        }
    });
});
