(function ($) { //for search

    SearchController.prototype.SetupSearch = function () {
        $(document).ready(function () {
            var SEARCH_INPUT = "#searchTerm";
            var SEARCH_BUTTON = "#btnSearch";
            var SEARCH_URL = "/search/starz/";
            $(SEARCH_INPUT).keyup(function (event) {//for enter
                if (event.keyCode == '13') {
                    var term = $(SEARCH_INPUT).val();
                    term = term.replace(/[^a-zA-Z0-9_ ]/, '');
                    window.location.href = window.location.href = SEARCH_URL + term;
                }
            });
            $(SEARCH_BUTTON).click(function () {//for click
                var term = $(SEARCH_INPUT).val();
                term = term.replace(/[^a-zA-Z0-9_ ]/, '');
                window.location.href = window.location.href = SEARCH_URL + term;
            });
        });
    }

    function SearchController() {
        this.name = ("SearchController-" + (new Date()).getTime());
        this.SetupSearch();
    }

    // Create and return new instance of the SearchController and store it in the window.
    window.searchController = new SearchController();
    return (window.searchController);

})(jQuery);

/*
//for icon search
function searchKeyPress(SearchTerm, URL) {
    var searchVal = SearchTerm.value.gsub(/[^a-zA-Z0-9_ ]/, '');
    if (searchVal.length > 0) {
        window.location.href = URL + searchVal;
        return false;
    }
}
*/
