// @(#) $Id: lastSearch.js 1107 2005-09-27 09:27:20Z dom $

// If we have a search query, then insert it into the search form.
function useLastSearch () {
    var last_search = new Cookie( document, 'last_search' );
    last_search.load();
    if ( !last_search.q )
        return;

    var query_box = document.getElementById( 'query' );
    if ( ! query_box )
        return;

    query_box.value = last_search.q;
}

function setLastSearch (e) {
    // This cross browser chicanery taken from
    // http://www.quirksmode.org/js/events_access.html
    if (!e) e = window.event;

    var query_box = document.getElementById( 'query' );
    if ( ! query_box )
        return;

    var last_search = new Cookie( document, 'last_search', false, '/' );
    last_search.q = query_box.value;

    // Record for posterity.
    last_search.store()
}

// This has to be called at page load time, not the time that this piece
// of code is loaded.  So it's in a separate function which goes into
// the onload handler.
function assignSubmitHandler () {
    var search_form = document.getElementById( 'searchform' );
    if ( !search_form )
        return;

    search_form.onsubmit = function () {
        setLastSearch();
        // To ensure the real submit goes ahead.
        return true;
    }
}

addLoadEvent( useLastSearch );
addLoadEvent( assignSubmitHandler );

// vim: set ai et sw=4 :
