Ajax.Autocompleter_own = Class.create(Autocompleter.Base, {
  initialize: function(element, element2, 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;
	try {
		this.element2 = $($(element2));
	}catch(e) {}
  },
 
 
 updateElement: function(selectedElement) {
    if (this.options.updateElement) {
      this.options.updateElement(selectedElement);
      return;
    }
    var value = '';
	var value2 = '';
    if (this.options.select) {      
	  var nodes = $(selectedElement).select('.' + this.options.select) || [];
      if(nodes.length>0) {
		$text = Element.collectTextNodes(nodes[0], this.options.select);		
		$text = $text.split(" | ");
		value = $text[0].strip();
		value2 = $text[1].strip();
		}
    } else {		
		$text = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
		$text = $text.split(" | ");
		value = $text[0].strip();
		value2 = $text[1].strip();    
	
	}	
	this.element.value = value;
	try {
		this.element2.value = value2;
	}catch(e) {}
	
	
    this.oldElementValue = this.element.value;
    this.element.focus();
 
    if (this.options.afterUpdateElement)
      this.options.afterUpdateElement(this.element, selectedElement);
  },
 
  getUpdatedChoices: function() {
    this.startIndicator();
 
    var 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;
 
    new Ajax.Request(this.url, this.options);
  },
 
  onComplete: function(request) {
    this.updateChoices(request.responseText);
  }
});

Ajax.Autocompleter_own_leeren = Class.create(Autocompleter.Base, {
  initialize: function(element, element2, 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;
	try {
		this.element2 = $($(element2));
	}catch(e) {}
  },
 
 
 updateElement: function(selectedElement) {
    if (this.options.updateElement) {
      this.options.updateElement(selectedElement);
      return;
    }
    var value = '';
	var value2 = '';
    if (this.options.select) {      
	  var nodes = $(selectedElement).select('.' + this.options.select) || [];
      if(nodes.length>0) {
		$text = Element.collectTextNodes(nodes[0], this.options.select);		
		$text = $text.split(" | ");
		value = $text[0].strip();
		value2 = $text[1].strip();
		}
    } else {		
		$text = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
		$text = $text.split(" | ");
		value = $text[0].strip();
		value2 = $text[1].strip();    
	
	}	
	this.element.value = value;
	try {
		this.element2.value = "";
	}catch(e) {}
	
	
    this.oldElementValue = this.element.value;
    this.element.focus();
 
    if (this.options.afterUpdateElement)
      this.options.afterUpdateElement(this.element, selectedElement);
  },
 
  getUpdatedChoices: function() {
    this.startIndicator();
 
    var 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;
 
    new Ajax.Request(this.url, this.options);
  },
 
  onComplete: function(request) {
    this.updateChoices(request.responseText);
  }
});

