﻿$(document).ready(function () {
    SetupWatermark($('#txtSearch'), "SEARCH");

    //Setup enterkey detection in header search
    $('#txtSearch').keypress(function (e) {
        if (e.which == 13 || e.keyCode == 13) {
            Search();
            return false;
        }
    });

    $(".searchBtn .btn").click(Search);
});


function Search() {
    var terms = document.getElementById("txtSearch").value;
    if (terms.length > 0) {
        window.open('search.aspx?q=' + terms,'_self','');
    }

    return false;
}

function SetupWatermark(jqueryElementObject, waterMarkText) {
    // Define what happens when the textbox comes under focus
    // Remove the watermark class and clear the box
    jqueryElementObject.focus(function () {

        $(this).filter(function () {

            // We only want this to apply if there's not 
            // something actually entered
            return $(this).val() == "" || $(this).val() == waterMarkText

        }).removeClass("watermarkOn").val("");

    });

    // Define what happens when the textbox loses focus
    // Add the watermark class and default text
    jqueryElementObject.blur(function () {

        $(this).filter(function () {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == ""

        }).addClass("watermarkOn").val(waterMarkText);

    });
}
