/**
 *  Javascript functions used in simple search box
 *
 *  @version    $Id: simplesearch.js,v 1.10 2005/03/30 16:47:30 kjurecka Exp $
 *  @author     $Author: kjurecka $
 *  @date       $Date: 2005/03/30 16:47:30 $
 *  @copyright  Copyright (c)2005, Hoover's, Inc.
*/

// CheckSearchType - displays burn pages for premium searches on free sites
function CheckSearchType(the_form, the_country) {
    if (the_country == 74) {
        // UK
        if (the_form.which.options[the_form.which.selectedIndex].value == "hduns") {
            javascript:launch("/free/burn.xhtml?dest=%2Ffreeuk%2Fsearch%2Fduns%2Findex.xhtml");
            the_form.action = "";
            return false;
        } else if (the_form.which.options[the_form.which.selectedIndex].value == "cokw") {
            javascript:launch("/free/burn.xhtml?dest=%2Ffreeuk%2Fsearch%2Fkeyco%2Findex.xhtml");
            the_form.action = "";
            return false;
        } else {
            return true;
        }
    } else {
        // US
        if (the_form.which.options[the_form.which.selectedIndex].value == "hduns") {
            javascript:launch("/free/burn.xhtml?dest=%2Ffree%2Fsearch%2Fduns%2Findex.xhtml");
            the_form.action = "";
            return false;
        } else if (the_form.which.options[the_form.which.selectedIndex].value == "cokw") {
            javascript:launch("/free/burn.xhtml?dest=%2Ffree%2Fsearch%2Fkeyco%2Findex.xhtml");
            the_form.action = "";
            return false;
        } else {
            return true;
        }
    }
}

// PopulateLastSearch - preselects and prefills previous search in search box
function PopulateLastSearch(the_form,display_mode) {
    var last_searched = GetCookie('HoovWhatWasSearchedSession');
    var search_text = "";
    var search_type = '';
    var i;

    if(last_searched != "" && last_searched != null){
        var SearchArray = last_searched.split("_");
        search_text = SearchArray[1];
        search_type = SearchArray[0];

        the_form.query_string.value = search_text;

        // the quick search form is on the home pages and has radio's for 'which'
        if (the_form.name == 'quick_search_form') {
            the_form.which[0].checked = true;  // default which to company
            for (i=0; i<the_form.which.length; i++) {
                if (the_form.which[i].value == search_type) {
                    // hduns and cokw are in valid free searches so dont set these
                    if(display_mode != 'Free' || (search_type != 'hduns' && search_type != 'cokw')) {
                        the_form.which[i].checked = true;
                    }
                    break;
                }
            }
        // the search form is on all other pages besides the home pages and uses a select for 'which'
        } else {
            the_form.which.selectedIndex = 0;  // default which to company
            for (i=0; i<the_form.which.options.length; i++) {
                if (the_form.which.options[i].value == search_type) {
                    // hduns and cokw are in valid free searches so dont set these
                    if(display_mode != 'Free' || (search_type != 'hduns' && search_type != 'cokw')) {
                        the_form.which.selectedIndex = i;
                    }
                    break;
                }
            }
        }
    } else {
        if (the_form.name == 'quick_search_form') {
            the_form.which[0].checked = true;
        } else {
            the_form.which.selectedIndex = 0;
        }
    }
}

/**
* @changelog
* $Log: simplesearch.js,v $
* Revision 1.10  2005/03/30 16:47:30  kjurecka
* HBN-1476:  Added default search type selection in absence of search cookie.
*
* Revision 1.9  2005/03/24 14:38:35  stevem
* HBN-1476 Fixed issue with submitting search and hitting enter to submit.  Consolidated and normalized use of javascript in the different xsl's.
*
*/
