function quicksearch_submit(id) {
    try {
        // determine HTML elements
        var form = $('#form_' + id);
        if (!form) throw "Form '#form_" + id + "' not found.";        
        var selectElem = $("select", form).get(0);    
        if (!selectElem) throw "Element '#form_" + id + " select' not found.";
        
        // read user input
        if (selectElem.selectedIndex < 0) throw "Search area not selected";
        var selection = selectElem.options[selectElem.selectedIndex].value;
        if (!selection) throw "Selected search area has no value in option tag!";
        var query = $("input[type=text]", form).get(0).value;
        if (!query) return false;
        
        // determine configuration
        var config = window['quicksearch_config_' + id][selection];
        if (!config) throw "No quicksearch configuration available for " + selection;
        
        // apply configuration
        form.attr("action", config.action);
        
        // replace hidden elements
        $('input[type=hidden]', form).remove();
        for ( key in config.hidden ) {
            var hiddenElem = document.createElement("INPUT");
            hiddenElem.type="hidden";
            hiddenElem.name = key;
            hiddenElem.value = config.hidden[key];
            form.append( $(hiddenElem) );
        }
        
        $('input[type=text]', form).attr( "name", config.varname );
        
        return true;
    }
    catch(e) {
        //alert("quicksearch_submit: " + e);
        return false;
    }
}

function quicksearch_init(id) {
    var form = $('#form_' + id);
    var select = $("select", form);
    var config = window['quicksearch_config_' + id];
    var select = $("select", form);
    for(setting in config) {
        var option = $(document.createElement("OPTION"));
        option.html(config[setting].description);
        option.attr("value", setting);
        if(config[setting].title) {
            option.attr("title", window.dictionary["SEARCH_IN_AREA"] + " \"" + config[setting].title) + "\"";
        }
        if(config[setting].selected) {
            option.attr( "selected", "selected" );
        }
        select.append(option);
    }
    form.get(0).onsubmit=function() {
        return quicksearch_submit(id);
    }
    select.get(0).onchange=function() {
        quicksearch_update_title(id);
    }
    quicksearch_update_title(id);
    jQuery().ready(function(){
        // $('input[type=text]', form).attr( "value", "" );
    });
}

function quicksearch_update_title(id) {
    var form = $('#form_' + id);
    var selectElem = $("select", form).get(0);
    if (selectElem.selectedIndex<0) {
        form.attr("title", "");
        return;
    }
    var selection = selectElem.options[selectElem.selectedIndex].value;
    var config = window['quicksearch_config_' + id];
    if ( !config[selection].title ) {
        form.attr("title", "");
        return;
    }
    form.attr( "title", window.dictionary["SEARCH_IN_AREA"] + " \"" + config[selection].title + "\"" );
}