            
var SearchWidget = Class.create({
    params: {
        searchFormId: "searchForm",
        paramName: "locFor",
        locationField: "locFor",
        locationHiddenField: "loc",
        searchField: "search_for",
        searchHiddenField: "Ntk",
        actionButton: "searchActionButton",
        autocompleteUrl: "/s/searchlocation.do",
        locationChoicesDiv: "location-choices"
    },
    
    initialize: function(params) {
        this.params = Object.extend(this.params, params);
        var thisObj = this;
        Event.observe($(thisObj.params.searchFormId), 'submit', function(event) {
            event.stop();
            $(thisObj.params.actionButton).disable();
            var proceed = false;
            if ($(thisObj.params.locationField).getValue() != $(thisObj.params.locationField).defaultValue) {
                proceed = true;
            }
            if ($(thisObj.params.searchField).getValue() != $(thisObj.params.searchField).defaultValue) {
                proceed = true;
            }
            if (proceed) {
                if ($(thisObj.params.locationField).getValue() == $(thisObj.params.locationField).defaultValue) {
                    $(thisObj.params.locationField).setValue("");
                }
                if ($(thisObj.params.searchField).getValue() == $(thisObj.params.searchField).defaultValue) {
                    $(thisObj.params.searchField).setValue("");
                }
            } else {
                $(thisObj.params.locationField).setValue("");
                $(thisObj.params.searchField).setValue("");
            }
            $(thisObj.params.searchFormId).submit();
        });

        if ($(thisObj.params.locationField) !== null) {

            new Ajax.Autocompleter(
                thisObj.params.locationField,
                thisObj.params.locationChoicesDiv,
                thisObj.params.autocompleteUrl,
                {
                    paramName: thisObj.params.paramName,
                    minChars: 2,
                    afterUpdateElement: function(text, li) {
                        $(thisObj.params.locationHiddenField).value = li.id;
                    },
                    onShow: function(element, update) {
                        if (!update.style.position || update.style.position == 'absolute') {
                            update.style.position = 'absolute';

                            var pos = Position.positionedOffset(element);
                            update.style.left = pos[0] + 'px';
                            update.style.top = element.offsetHeight + pos[1] + 'px';


                        }
                        Effect.Appear(update, {duration: 0.15});
                    }
                }
            );
        }
    }
});
