var searchBar = {
    whitespacePattern : /^\s*$/,
    trimPattern : /^\s+|\s+$/g,
    search_string_input_id : 'searchString',
    search_form_id : 'search_form',
    /**
    * resets the target of the search form every time the Help Catagories
    * drop down menu is clicked.
    */
    setHelpCategoryAction : function () {
        var search_form = document.getElementById(this.search_form_id);
        var helpCategory = document.getElementById('temp_product');
        search_form.action = search_form.action.split('?')[0] + '?product=' + helpCategory.value;
        if (helpCategory.value == '') {
            search_form.action += 'document=DT_AOLFAQS_1_1&document=DT_AOLHOW_TO_1_1&document=DT_AOLTROUBLESHOOTING_1_1';
        }
    },
    /**
    * Checks for an empty search box
    */
    checkEmptySearch : function () {
        //var searchString = document.getElementById(this.search_string_input_id).value;
        var searchString = document.forms[this.search_form_id].searchString.value;        //
        var isNotWhiteSpace = !(searchString.match(this.whitespacePattern));
        return isNotWhiteSpace;
    },
    /**
    * Trims leading and trailing whitespace from the search string
    */
    trimSearchString : function (input_element) {
        input_element.value = input_element.value.replace(this.trimPattern, '');
        return input_element.value;
    },
    /**
    * Checks the to make sure there is a valid search string then proceeds with submit
    */
    submitSearch : function () {
        var search_form = document.getElementById(this.search_form_id);
        var search_string_input = document.getElementById(this.search_string_input_id);
        this.trimSearchString(search_string_input);
        if (this.checkEmptySearch()) {
            searchFailureCheck();
            search_form.submit();
        } else {
            alert('Please enter a keyword or phrase');
        }
        return false;
    }
}
