Autocompleter.Request = new Class(
{ Extends: Autocompleter, options:
{ postData: {}, ajaxOptions: {}, postVar: 'value' }, query: function() {
var data = $unlink(this.options.postData) || {};
data[this.options.postVar] = this.queryValue;
var indicator = $(this.options.indicator);
if (indicator) indicator.setStyle('display', '');
var cls = this.options.indicatorClass;
if (cls) this.element.addClass(cls);
this.fireEvent('onRequest', [this.element, this.request, data, this.queryValue]);
this.request.send({ 'data': JSON.encode(data) });
}
       , queryResponse: function() { var indicator = $(this.options.indicator); if (indicator) indicator.setStyle('display', 'none'); var cls = this.options.indicatorClass; if (cls) this.element.removeClass(cls); return this.fireEvent('onComplete', [this.element, this.request]); } });



Autocompleter.Request.JSON = new Class(
    { Extends: Autocompleter.Request,
        initialize: function(el, url, options)
        {
            this.parent(el, options);
            this.request = new Request.JSON({ 'url': url, 'link': 'cancel', 'urlEncoded': false, 'encoding': 'utf-8', 'method': 'post', headers: { "Content-type": "application/json; charset=utf-8"} }).addEvent('onComplete', this.queryResponse.bind(this));
        }, queryResponse: function(response) {
        this.parent(); 
        this.update(response.d); }
    });
    
    
    
    
     Autocompleter.Request.HTML = new Class({ Extends: Autocompleter.Request, initialize: function(el, url, options) { this.parent(el, options); this.request = new Request.HTML($merge({ 'url': url, 'link': 'cancel', 'update': this.choices }, this.options.ajaxOptions)).addEvent('onComplete', this.queryResponse.bind(this)); }, queryResponse: function(tree, elements) { this.parent(); if (!elements || !elements.length) { this.hideChoices(); } else { this.choices.getChildren(this.options.choicesMatch).each(this.options.injectChoice || function(choice) { var value = choice.innerHTML; choice.inputValue = value; this.addChoiceEvents(choice.set('html', this.markQueryValue(value))); }, this); this.showChoices(); } } }); Autocompleter.Ajax = { Base: Autocompleter.Request, Json: Autocompleter.Request.JSON, Xhtml: Autocompleter.Request.HTML };


    Autocompleter.Local = new Class({

        Extends: Autocompleter,

        options: {
            minLength: 0,
            delay: 200
        },

        initialize: function(element, tokens, options) {
            this.parent(element, options);
            this.tokens = tokens;
        },

        query: function() {
            this.update(this.filter());
        }

    });