function setSearch() {
    try {
        $('input').each(function () {
            if ((this.id).match(/InputKeywords$/)) {
                var filterValue = gqp('k');
                var currentValue = $(this).val();

                // Set the search box to the value "Search"
                if (filterValue == "" && currentValue == "") {
                    $(this).val("Search");
                }
            }

            // Set the advanced search box value
            if ((this.id).match(/ASB_TQS_AndQ_tb$/)) {
                var filterValue = gqp('k');

                $(this).val(filterValue);

                $('#ctl00_SearchBox input').val(filterValue);
            }
        });

    }
    catch (err) {
    }
}

function removeSearchWord() {
    try {
        $('input').each(function () {
            if ((this.id).match(/InputKeywords$/)) {

                // Removes the "search" word from the search box
                if ($(this).val() == "Search") {
                    $(this).val('');
                }
            }
        });
    }
    catch (err) {
    }
}

//function get querystring parameter (k=keyword)
function gqp(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#)]*)";
    var regexS2 = "ALL\\(([^)]*)";

    var regex = new RegExp(regexS);
    var regex2 = new RegExp(regexS2);

    try {
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";   // return "Search" if nothing can be found.
        else {
            if (results[1].indexOf("ALL") != -1)
                return unescape(regex2.exec(unescape(results[1]))[1]).trim();
            else
                return unescape(results[1]);
        }
    }
    catch (err) { }
    return "";
}

$(document).ready(function () {
    try {
        // when you click on the magnifier glass left to the search box in the blue header, submit the search 
        $('#ctl00_SearchBox').click(function (e) {
            var x = e.pageX - $(this).offset().left;
            var y = e.pageY - $(this).offset().top;

            if (x < 20) {
                S6F789EBA_Submit();
            }
        });

        // replace the sharepoint OOB navigateTo function with a custom implementation
        // the following implementation does not use the click method on a newly created <a> tag.
        // fix for Firefox 5 (it worked in FF4...)
        $('.ms-advsrchbutton input').click(function () {
            navigateTo = function (url) {
                window.location = url;
                return;
            }
        });
    }
    catch (err) {
    }
});

