Ajax.AutocompleterViessmann = Class.create();
Object.extend(Object.extend(Ajax.AutocompleterViessmann.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;
		
		new Ajax.Request(this.url, this.options);
	},
	
	onComplete: function(request) {
		this.updateChoices(request.responseText);
	},
	
	render: function() {
		if(this.entryCount > 0) {
			for (var i = 0; i < this.entryCount; i++)
				this.index==i ? 
				Element.addClassName(this.getEntry(i),"selected") : 
				Element.removeClassName(this.getEntry(i),"selected");
			
			if(this.hasFocus) {
				this.show();
				this.active = true;
			}
			
			// Debut de liste, on affiche les 10 premiers elements
			if (!this.index)
				for (var i = this.index; (i < this.entryCount) && (i <= this.index+9); i++ )
					Element.show(this.getEntry(i));
			
			// Changement "page suivante"
			else if ((this.index) && (this.index % 10 == 9))
			{
				for (var i = this.index-9; i < this.index+1; i++ )
					Element.hide(this.getEntry(i));
				for (var i = this.index+1; (i < this.entryCount) && (i <= this.index+10); i++ )
					Element.show(this.getEntry(i));
				this.index = this.index+2;
				this.render();
			}
			
			// Changement "page precedente"
			else if ((this.index) && (this.index % 10 == 0))
			{
				for (var i = this.index; (i < this.entryCount) && (i < this.index+1); i++ )
					Element.hide(this.getEntry(i));
				for (var i = this.index-10; i < this.index; i++ )
					Element.show(this.getEntry(i));
				this.index = this.index-2;
				this.render();
			}
			
		}
		else
			this.hide();
	}
});