
var AutoCompleterDoubleArray = new Class({
    Extends:Autocompleter.Local,
    initialize: function(source,tokens,tokenobj,options){
        
        this.parent(source,tokens,options);
        this.tokensobj = tokenobj;
    },
    setSelection: function(finish) {
        var input = this.selected.inputValue, value = input;
        var start = this.queryValue.length, end = input.length;
        if (input.substr(0, start).toLowerCase() != this.queryValue.toLowerCase()) start = 0;
        if (this.options.multiple) {
            var split = this.options.separatorSplit;
            value = this.element.value;
            start += this.queryIndex;
            end += this.queryIndex;
            var old = value.substr(this.queryIndex).split(split, 1)[0];
            value = value.substr(0, this.queryIndex) + input + value.substr(this.queryIndex + old.length);
            if (finish) {
                var tokens = value.split(this.options.separatorSplit).filter(function(entry) {
                    return this.test(entry);
                }, /[^\s,]+/);
                if (!this.options.allowDupes) tokens = [].combine(tokens);
                var sep = this.options.separator;
                value = tokens.join(sep) + sep;
                end = value.length;
            }
        }
        this.observer.setValue(value);
        this.opted = value;
        if (finish || this.selectMode == 'pick') start = end;
        this.element.selectRange(start, end);
        this.fireEvent('onSelection', [this.element, this.selected, value, input]);
    },
    markQueryValue: function(str) {
        //return str;
        return (!this.options.markQuery || !this.queryValue) ? str : str.replace(new RegExp('(' + ((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp() + ')', (this.options.filterCase) ? '' : 'i'), '<span class="autocompleter-queried">$1</span>');
    },
    filter: function(tokens) {

        var ret1 = (this.tokensobj).filter(function(token) {
            return this.test(token.name);
        }, new RegExp(((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp(), (this.options.filterCase) ? '' : 'i'));

        var arr = new Array();
        ret1.each(function(item,index){
            arr.push(item.name);
        });
        var ret2 = (this.tokensobj).filter(function(token) {
            return this.test(token.code);
        }, new RegExp(((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp(), (this.options.filterCase) ? '' : 'i'));
        var arr2 = new Array();
        ret2.each(function(item,index){
            arr2.push(item.name);
        });
      
        return arr.combine(arr2);
    }
     
    
});

