Wtf.KWLQuickSearch = function(config){
    Wtf.KWLQuickSearch.superclass.constructor.call(this, config);
}
Wtf.extend(Wtf.KWLQuickSearch, Wtf.form.TextField, {
    Store: null,
    StorageArray: null,
    initComponent: function(){
        Wtf.KWLQuickSearch.superclass.initComponent.call(this);
        this.addEvents({
            'SearchComplete': true
        });
    },
    onRender: function(ct, position){
        Wtf.KWLQuickSearch.superclass.onRender.call(this, ct, position);
        this.el.dom.onkeyup = this.onKeyUp.createDelegate(this);
    },
    onKeyUp: function(e){
        if (this.getValue() != "") {
            this.Store.removeAll();
            var i = 0;
            while (i < this.StorageArray.length) {
                var str=new RegExp("^"+this.getValue()+".*$","i");
                if (str.test(this.StorageArray[i].get(this.field))) {
                    this.Store.add(this.StorageArray[i]);
                }
                i++;
            }
            //dsSearch.add(this.Storage.getAt(this.Storage.find('Name',this.quickSearchTF.getValue()))); 
        }
        else {
            this.Store.removeAll();
            for (i = 0; i < this.StorageArray.length; i++) {
                this.Store.insert(i, this.StorageArray[i]);
            }
        }
        this.fireEvent('SearchComplete', this.Store);
    },
    StorageChanged: function(store){
        this.Store = store;
        this.StorageArray = this.Store.getRange();
    }
});
Wtf.reg('KWLQuickSearch', Wtf.KWLQuickSearch);



Wtf.KWLTagSearch = function(config){
    Wtf.KWLTagSearch.superclass.constructor.call(this, config);
}
Wtf.extend(Wtf.KWLTagSearch, Wtf.form.TextField, {
    Store: null,
    StorageArray: null,
    limit: 15,
    initComponent: function(){
        Wtf.KWLTagSearch.superclass.initComponent.call(this);
        this.addEvents({
            'SearchComplete': true
        });
    },
    timer:new Wtf.util.DelayedTask(this.callKeyUp),
    setPage: function(val) {
        this.limit = val;
    },
    onRender: function(ct, position){
        Wtf.KWLTagSearch.superclass.onRender.call(this, ct, position);
        this.el.dom.onkeyup = this.onKeyUp.createDelegate(this);
    },
    onKeyUp: function(e){
        if(this.Store) {
            if (this.getValue() != "") {
                this.timer.cancel();
                this.timer.delay(1000,this.callKeyUp,this);
            }
            else {
                this.Store.reload({
                    params: {
                        start: 0,
                        limit: this.limit,
                        ss: ""
                    }
                });
            }
            this.fireEvent('SearchComplete', this.Store);
        }
    },
    callKeyUp: function() {
        
      this.Store.reload({
          params: {
              start: 0,
              limit: this.limit,
              ss: this.getValue()
          }
      });
    },
    StorageChanged: function(store){
        this.Store = store;
        this.StorageArray = this.Store.getRange();
    }
});

Wtf.reg('KWLTagSearch', Wtf.KWLTagSearch);
