Ajax.AutocompleterExtended = Class.create();
Object.extend(Object.extend(Ajax.AutocompleterExtended.prototype, Autocompleter.Base.prototype), {
  initialize: function(element, update, url, options, extra_params, static_params) {
    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;
    this.extra_params			= extra_params;
    this.static_params			= static_params;
  },

  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;

	var tmp = "";
	if (this.extra_params && this.extra_params.length > 0) {
		//tmp += "?";
		for (i=0;i<this.extra_params.length;i++) {
			if (i > 0) {
				tmp+="&";
			}
			for(j=0;j<this.element.form.elements.length;j++) {
				if (this.element.form.elements[j].name == this.extra_params[i]) {
					if (this.element.form.elements[j].type == "text" || this.element.form.elements[j].type == "hidden") {
						tmp += encodeURIComponent(this.extra_params[i]) + "=" + encodeURIComponent(this.element.form.elements[j].value);
					}
				}
			}
		}
		this.options.parameters += '&' + tmp;
	}
	var tmp = "";
	if (this.static_params && this.static_params.length > 0) {
		for (sp in this.static_params) {
			if (this.static_params.propertyIsEnumerable(sp)) {
				//alert(sp);
				tmp += "&" + encodeURIComponent(sp) + "=" + encodeURIComponent(this.static_params[sp]);
			}
		}
		this.options.parameters += '&' + tmp;
	}

	//alert(this.static_params.length);
	//alert(tmp);

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

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

