searchBox = {

        currentSelectedTab : 'aol_help',
        searchDocType : '',
        prevSearches : new Array(),

        /**
         * Changes the selected tab atop the search box
         */
        switchTabs : function( newTab ) {
                if (document.getElementById( newTab ).className == 'isp_tab'){
                    document.getElementById( this.currentSelectedTab ).className = '';
                    document.getElementById( newTab ).className = 'isp_tab selected';
                    this.currentSelectedTab = newTab;
                }else if (document.getElementById( this.currentSelectedTab ).className == 'isp_tab selected'){
                    document.getElementById( this.currentSelectedTab ).className = 'isp_tab';
                    document.getElementById( newTab ).className = 'selected';
                    this.currentSelectedTab = newTab;
                }else{
                    document.getElementById( this.currentSelectedTab ).className = '';
                    document.getElementById( newTab ).className = 'selected';
                    this.currentSelectedTab = newTab;
                }
                
                //var form = document.getElementById( 'sw_menu_top_h_search' );
                //var action = form.action.split( "?" )[ 0 ] + '?';
                //form.action = action;

                docType = document.getElementById( 'document' );

                var advSrch = document.getElementById( 'adv_search_button' );

                if ( newTab != "aol_help" ) {
                        if ( advSrch != null ) {
                            advSrch.className = "";
                            //action += "document=" + newTab;
                            document.getElementById('adv_search_tab').style.display="none";
                        }
                        docType.value = newTab;
                }
                else {
                        if ( advSrch != null ) {
                                advSrch.className = "visible";
                        }
                        docType.value = "";
                }
        		var tabs = document.getElementById('search_tabs').getElementsByTagName('div');
        		for(var i in tabs){
        			if(tabs[i].id == newTab){
        				imgs = tabs[i].getElementsByTagName('img');
        				for(var x in imgs){
        					if(imgs[x].className == 'l_corner'){
        						imgs[x].src = '/help/img/sel_tab_ltc.gif';
        					}else if(imgs[x].className == 'r_corner'){
        						imgs[x].src = '/help/img/sel_tab_rtc.gif';
        					}
        				}
        			}else if(tabs[i].id){
        				imgs = tabs[i].getElementsByTagName('img');
        				for(var x in imgs){
        					if(imgs[x].className == 'l_corner'){
        						imgs[x].src = '/help/img/tab_ltc.gif';
        					}else if(imgs[x].className == 'r_corner'){
        						imgs[x].src = '/help/img/tab_rtc.gif';
        					}
        				}
        			}
        		}
                var blurTab = document.getElementById(newTab);
                try { blurTab.blur(); } catch( e ) {}
        },

        /**
         * Reruns the currect search term when a tab is clicked, using the new
         * tab's document type in place of the original.
         */
        searchSwitchTabs : function( tab, searchString ) {

            // switch the tabs
            this.switchTabs( tab );

            // set up the search form
            document.getElementById( 'help_search' ).value = searchString;

            //set up the form action
            var form = document.getElementById( 'sw_menu_top_h_search' );
            form.action = '/help/search.do?';

            if ( tab == 'aol_help' ) {
                form.action += 'document=DT_AOL_FAQs&document=DT_AOL_How_To&document=DT_AOL_Troubleshooting';
            }
            else {
                form.action += 'document=' + tab;
            }

            //run the search
            this.runSearch( searchString, true );
        },

        /**
         * resets the target of the search form every time the Help Catagories
         * drop down menu is clicked.
         */
        setHelpCategoryAction : function() {
                var searchForm = document.getElementById( 'sw_menu_top_h_search' );
                var helpCategory = document.getElementById( 'temp_product' );


                searchForm.action = searchForm.action.split( '?' )[ 0 ] + '?product=' + 
                    helpCategory.value;
                if ( helpCategory.value == '' ) {
                        searchForm.action += 'document=DT_AOL_FAQs&document=DT_AOL_How_To&document=DT_AOL_Troubleshooting';
                }
        },

        /**
         *  Submits the form defined in this JSP with the given search string.
         */
        runSearch : function ( searchString, submit ) {
            var srchBar = document.getElementById( 'help_search' );
            srchBar.value = searchString;

            if ( submit ) {
                var searchForm = document.getElementById( 'sw_menu_top_h_search' );
                searchFailureCheck();
                searchForm.submit();
            }
            else {
                redirectSearchInnerElements( 'sw_menu_top_h_search', true );
            }
        },


        /**
         * Sets the "product" value of the form before submition
         *
         * Also checks the search form to make sure a keyword was entered
         */
        submitSearchForm : function () {

            // Checks for an emptry string or only white space in the search
            // keyword field
            searchField = document.getElementById( 'search' );
            if ( searchField.value.replace( /^\s*(.*)\s*$/, '$1' ) == '' ) {
                alert( 'Please enter a keyword or phrase' );
                return false;
            }

            product = document.getElementById( "product" );

            if ( product != null ) {
                ver = document.getElementById( "version" );
                //// Connection has been removed.  Always use 'Broadband'
                //con_type = document.getElementById( 'con_type' );
                help_type = document.getElementById( 'help_type' );

                product.value = ver.value + ',' + 'Broadband' + ',' + help_type.value;
                // removes excess white space and commas, so we don't submit
                // something like 'product=SG_Movies,,'
                product.value = product.value.replace( /^[,\s]*(.*)[,\s]*$/, '$1');
            }
            return true;
        },

        /**
         * Taken from Header Footer.JS to change the alert string
         */
        validateSearch : function ( tID, submit ) {
            s =$(tID).searchString.value;
            s = s.replace(/^\s*(.*?)\s*$/,"$1");
            $(tID).searchString.value = s;
            if (s.replace(/ /g, '') == '') { 
                alert( 'Please enter a keyword or phrase' );
                return false;
            }
            else {
                if ( submit ) {
                        var form = document.getElementById( 'sw_menu_top_h_search' );

                        // Check to see which tab is selected.  If it's the
                        // default tab, check the advanced search to see if a
                        // specific doctype was chosen
                        if ( document.getElementById( 'aol_help' ) && 
                             document.getElementById( 'aol_help' ).className == 'selected' &&
                             document.getElementById( 'document' ) &&
                             document.getElementById( 'document' ).value != '' ) {
                                form.action = "/help/search.do?document=" + document.getElementById( 'document' ).value;
                        }
                        else if ( this.currentSelectedTab != "aol_help" ) {
                            form.action = "/help/search.do?document=" + this.currentSelectedTab;
                        }
                        else {
                                form.action = '/help/search.do?document=DT_AOL_FAQs&document=DT_AOL_How_To&document=DT_AOL_Troubleshooting';
                        }
                        if ( document.getElementById( 'temp_product' ) &&
                             document.getElementById( 'temp_product' ).value != '' ) {
                                form.action += '&product=' + document.getElementById( 'temp_product' ).value;
                        }
                        if ( document.getElementById( 'ver' ) ) {
                                var sal = document.getElementById( 'ver' ).value + 'Broadband'; //document.getElementById( 'con_type' ).value;
                                form.action += '&sal=' + sal;
                        }
                        
                        $(tID).submit();
                }
                return true;
            }
        },

        /**
         * On load of the search results page, call this function to highlight the correct tab.
         */
        setResultsTab : function() {
                if ( this.searchDocType != '' ) {
                        this.switchTabs( this.searchDocType );                        
                }
        },

        /**
         * Sets the AOL Version select box to a default value.
         */
        setSelectedAolVersion : function() {
            version = document.getElementById( 'ver' );
            if ( document.selectedAolVersion ) {
                version.value = document.selectedAolVersion;
            }
            else {
                version.value = 'SAL_9_0_Security_Ed__';
            }
        }

}
