Ajax.LtgSuggest = Class.create();
Object.extend(Object.extend(Ajax.LtgSuggest.prototype, Autocompleter.Base.prototype), {
  initialize: function(element, update, url, options) {
    this.baseInitialize(element, update, options);
    this.options.asynchronous  = true;
    this.options.onComplete    = this.onComplete.bind(this);
    this.options.defaultParams = this.options.parameters || null;
    this.url                   = url;
  },

  getUpdatedChoices: function() {
    entry = encodeURIComponent(this.options.paramName) + '=' + 
      encodeURIComponent(this.getToken());

    this.options.parameters = this.options.callback ?
      this.options.callback(this.element, entry) : entry;

    if(this.options.defaultParams) 
      this.options.parameters += '&' + this.options.defaultParams;
    
    if( this.options.suggest )
    {
        /* this.options.suggest could be the id of a field which contains the value
         * if so, we use that value
         */
        var suggestinputobj = document.getElementById( this.options.suggest );
        if( suggestinputobj )
            this.options.parameters += '&suggest=' + suggestinputobj.value ;
        else
            this.options.parameters += '&suggest=' + this.options.suggest ;
    }
    if( this.options.countryid )
        this.options.parameters += '&country=' + $F(this.options.countryid) ;
    if( this.options.provinceid )
        this.options.parameters += '&province=' + $F(this.options.provinceid) ;
    if( this.options.cityid )
        this.options.parameters += '&city=' + $F(this.options.cityid) ;
    if( this.options.cityzoneid )
        this.options.parameters += '&cityzone=' + $F(this.options.cityzoneid) ;

    new Ajax.Request(this.url, this.options);
  },

  onComplete: function(request) {
    this.updateChoices(request.responseText);
  }

});


