Varien.searchForm = Class.create();
Varien.searchForm.prototype = {
    initialize : function(form, field, emptyText){
        this.form   = $(form);
        this.field  = $(field);
        this.emptyText = emptyText;
        Event.observe(this.form,  'submit', this.submit.bind(this));
        Event.observe(this.field, 'focus', this.focus.bind(this));
        Event.observe(this.field, 'blur', this.blur.bind(this));
        this.blur();
    },
    submit : function(event){
        if (this.field.value == this.emptyText || this.field.value == ''){
            this.field.value = "";
            /*Event.stop(event);
            return false;*/
        }
        return true;
    },
    focus : function(event){
        if(this.field.value==this.emptyText){
            this.field.value='';
        }
    },
    blur : function(event){
        if(this.field.value==''){
            this.field.value=this.emptyText;
        }
    },
    initLivesearch : function(url, destinationElement, charstostart){
        var form  = this.form;
        new Ajax.Autocompleter(this.field, destinationElement, url, {
            paramName: this.field.name,
            minChars: 2,
            indicator: 'lsloading',
            updateElement: this._selectLivesearchItem.bind(this),
            onShow : function(element, update) {
                if(!update.style.position || update.style.position=='absolute') {
                    update.style.position = 'absolute';
                    Position.clone(element, update, {
                        setHeight: false,
                        offsetTop: element.offsetHeight
                    });
                    setTimeout( function() {
                        Element.clonePosition('search_autocomplete', 'search', {
                            'setWidth': false,
                            'setHeight': false,
                            'offsetTop': $('search').offsetHeight
                        } );
                    }, 300);
                }
                Effect.Appear(update,{
                    duration:0
                });
                jQuery('#link-go').click(function(){
                    jQuery("#search").attr("name","name");
                    form.submit();
                });
            }
        } );
    },
    _selectLivesearchItem : function(element){
        if(element.title){
            window.location = element.title;
        }
    }
}
