function UCL_Search(event, type)
{
    // This variable will hold the URL we will browse to
    var URL = "";

    // This variable will tell us whether our search box is empty or not
    var isEmpty = false;

    // Get a handle to our search terms box (the <menulist> element)
    var searchTermsBox = document.getElementById("UCL-SearchTerms");
    
    // Get the value in the search terms box, trimming whitespace as necessary
    // See the TutTB_TrimString() function farther down in this file for details
    // on how it works.
    var searchTerms = UCL_TrimString(searchTermsBox.value);

    if(searchTerms.length == 0) // Is the search terms box empty?
        isEmpty = true;         // If so, set the isEmpty flag to true
    else                        // If not, convert the terms to a URL-safe string
        searchTerms = UCL_ConvertTermsToURI(searchTerms);

    // Now switch on whatever the incoming type value is
    // If the search box is empty, we simply redirect the user to the appropriate
    // place at the Google website. Otherwise, we search for whatever they entered.

    switch(type)
    {
    // Build up the URL for an image search
    case "one":
        if(isEmpty) { URL = "http://aj2vr6xy7z.cs.serialssolutions.com/"; }
        else        { URL = "http://aj2vr6xy7z.cs.serialssolutions.com/results?SS_LibHash=AJ2VR6XY7Z&dbIDList=&searchType=basic&action=start&catGroupList=default&searchBy=Category&field=Keyword&term="+ searchTerms + "&catID=19851"; }
        break;


    // Build up the URL for a web search
    case "web":
        if(isEmpty) { URL = "http://aj2vr6xy7z.cs.serialssolutions.com/"; }
        else        { URL = "http://aj2vr6xy7z.cs.serialssolutions.com/results?SS_LibHash=AJ2VR6XY7Z&dbIDList=&searchType=basic&action=start&catGroupList=default&searchBy=Category&field=Keyword&term="+ searchTerms + "&catID=19851"; }
        break;

    case "catalog":
        if(isEmpty) { URL = "http://http://uclid.uc.edu/search/X/"; }
        else        { URL = "http://uclid.uc.edu/search/X?("+ searchTerms + ")&b=&l=&Da=&Db=&m=&s=&v=&c=&SORT=D&searchscope=39"; }
        break;

    case "journals":
        if(isEmpty) { URL = "http://aj2vr6xy7z.search.serialssolutions.com/"; }
        else        { URL = "http://aj2vr6xy7z.search.serialssolutions.com/?V=1.0&N=100&L=AJ2VR6XY7Z&S=AC_T_B&C="+ searchTerms; }
        break;


    case "oljournals":
        if(isEmpty) { URL = "http://journals.ohiolink.edu/lsearch/"; }
        else        { URL = "http://journals.ohiolink.edu./lsearch/search.do?query="+ searchTerms +"&field=contents"; }
        break;


    case "olcatalog":
        if(isEmpty) { URL = "http://olc1.ohiolink.edu/search/"; }
        else        { URL = "http://olc1.ohiolink.edu/search/~?searchtype=X&searcharg="+ searchTerms +"&SORT=D"; }
        break;

    case "ulweb":
        if(isEmpty) { URL = "http://www.googlesyndicatedsearch.com/u/UCincinnati"; }
        else        { URL = "http://www.googlesyndicatedsearch.com/u/UCincinnati?q="+ searchTerms; }
        break;


    case "google":
        if(isEmpty) { URL = "http://scholar.google.com/"; }
        else        { URL = "http://scholar.google.com/scholar?q="+ searchTerms +"&hl=en&lr="; }
        break;

    case "public":
        if(isEmpty) { URL = "http://catalog.cincinnatilibrary.org/uhtbin/cgisirsi/78X2IlE54s/MAIN/37552003/38/1/X/BLASTOFF"; }
        else        { URL = "http://catalog.cincinnatilibrary.org/uhtbin/cgisirsi/x/0/0/123?searchdata1="+ searchTerms +"&srchfield1=GENERAL%5ESUBJECT%5EGENERAL%5E%5Ewords+org+phrase"; }
        break;

    }
    
    // Load the URL in the browser window using the UCL_LoadURL function
    UCL_LoadURL(URL);
}

////////////////////////////////////////////////////////////////////////////////
// The TutTB_TrimString() function will trim all leading and trailing whitespace
// from the incoming string, and convert all runs of more than one whitespace
// character into a single space. The altered string gets returned.
////////////////////////////////////////////////////////////////////////////////
function UCL_TrimString(string)
{
    // If the incoming string is invalid, or nothing was passed in, return empty
    if (!string)
        return "";

    string = string.replace(/^\s+/, ''); // Remove leading whitespace
    string = string.replace(/\s+$/, ''); // Remove trailing whitespace

    // Replace all whitespace runs with a single space
    string = string.replace(/\s+/g, ' ');

    return string; // Return the altered value
}

////////////////////////////////////////////////////////////////////////////////
// The TutTB_ConvertTermsToURI() function converts an incoming string of search
// terms to a safe value for passing into a URL.
////////////////////////////////////////////////////////////////////////////////
function UCL_ConvertTermsToURI(terms)
{
    // Create an array to hold each search term
    var termArray = new Array();

    // Split up the search term string based on the space character
    termArray = terms.split(" ");

    // Create a variable to hold our resulting URI-safe value
    var result = "";

    // Loop through the search terms
    for(var i=0; i<termArray.length; i++)
    {
        // All search terms (after the first one) are to be separated with a '+'
        if(i > 0)
            result += "+";

        // Encode each search term, using the built-in Firefox function
        // encodeURIComponent().
        result += encodeURIComponent(termArray[i]);
    }

    return result; // Return the result
}

////////////////////////////////////////////////////////////////////////////////
// The TutTB_LoadURL() function loads the specified URL in the browser.
////////////////////////////////////////////////////////////////////////////////
function UCL_LoadURL(url)
{
    // Set the browser window's location to the incoming URL
    window._content.document.location = url;

    // Make sure that we get the focus
    window.content.focus();
}

function UCL_KeyHandler(event)
{
    if(event.keyCode == event.DOM_VK_RETURN)
        UCL_Search(event, 'web');
}

function UCL_ToggleWebSearchButton()
{
    var button = document.getElementById("UCL-LinksMenu");
    var value = button.disabled;
    if(value == true)
        button.disabled = false;
    else
        button.disabled = true;
}




