var timer_h;

window.addEvent('domready', function(){

	/*
	* FancyForm 0.94
	* By Vacuous Virtuoso, lipidity.com
	* ---
	* Checkbox and radio input replacement script.
	* Toggles defined class when input is selected.
	*/

	var FancyForm = {
		start: function(elements, options){
			FancyForm.initing = 1;
			if($type(elements)!='array') elements = $$('input');
			if(!options) options = [];
			FancyForm.onclasses = ($type(options['onClasses']) == 'object') ? options['onClasses'] : {
				checkbox: 'checked',
				radio: 'selected'
			}
			FancyForm.offclasses = ($type(options['offClasses']) == 'object') ? options['offClasses'] : {
				checkbox: 'unchecked',
				radio: 'unselected'
			}
			if($type(options['extraClasses']) == 'object'){
				FancyForm.extra = options['extraClasses'];
			} else if(options['extraClasses']){
				FancyForm.extra = {
					checkbox: 'f_checkbox',
					radio: 'f_radio',
					on: 'f_on',
					off: 'f_off',
					all: 'fancy'
				}
			} else {
				FancyForm.extra = {};
			}
			FancyForm.onSelect = $pick(options['onSelect'], function(el){});
			FancyForm.onDeselect = $pick(options['onDeselect'], function(el){});
			var keeps = [];
			FancyForm.chks = elements.filter(function(chk){
				if( $type(chk) != 'element' ) return false;
				if( chk.get('tag') == 'input' && (FancyForm.onclasses[chk.getProperty('type')]) ){
					var el = chk.getParent();
					if(el.getElement('input')==chk){
						el.type = chk.getProperty('type');
						el.inputElement = chk;
						this.push(el);
					} else {
						chk.addEvent('click',function(f){
							if(f.event.stopPropagation) f.event.stopPropagation();
						});
					}
				} else if( (chk.inputElement = chk.getElement('input')) && (FancyForm.onclasses[(chk.type = chk.inputElement.getProperty('type'))]) ){
					return true;
				}
				return false;
			}.bind(keeps));
			FancyForm.chks = FancyForm.chks.combine(keeps);
			keeps = null;
			FancyForm.chks.each(function(chk){
				var c = chk.inputElement;
				c.setStyle('position', 'absolute');
				c.setStyle('left', '-9999px');
				chk.addEvent('selectStart', function(f){f.stop()});
				chk.name = c.getProperty('name');
				FancyForm.update(chk);
			});
			FancyForm.chks.each(function(chk){
				var c = chk.inputElement;
				chk.addEvent('click', function(f){
					f.stop(); f.type = 'prop';
					c.fireEvent('click', f, 1);
				});
				chk.addEvent('mousedown', function(f){
					if($type(c.onmousedown) == 'function')
						c.onmousedown();
					f.preventDefault();
				});
				chk.addEvent('mouseup', function(f){
					if($type(c.onmouseup) == 'function')
						c.onmouseup();
				});
				c.addEvent('focus', function(f){
					if(FancyForm.focus)
						chk.setStyle('outline', '1px dotted');
				});
				c.addEvent('blur', function(f){
					chk.setStyle('outline', 0);
				});
				c.addEvent('click', function(f){
					if(f.event.stopPropagation) f.event.stopPropagation();
					if(c.getProperty('disabled')) // c.getStyle('position') != 'absolute'
						return;
					if (!chk.hasClass(FancyForm.onclasses[chk.type]))
						c.setProperty('checked', 'checked');
					else if(chk.type != 'radio')
						c.setProperty('checked', false);
					if(f.type == 'prop')
						FancyForm.focus = 0;
					FancyForm.update(chk);
					FancyForm.focus = 1;
					if(f.type == 'prop' && !FancyForm.initing && $type(c.onclick) == 'function')
						 c.onclick();
				});
				c.addEvent('mouseup', function(f){
					if(f.event.stopPropagation) f.event.stopPropagation();
				});
				c.addEvent('mousedown', function(f){
					if(f.event.stopPropagation) f.event.stopPropagation();
				});
				if(extraclass = FancyForm.extra[chk.type])
					chk.addClass(extraclass);
				if(extraclass = FancyForm.extra['all'])
					chk.addClass(extraclass);
			});
			FancyForm.initing = 0;
			$each($$('form'), function(x) {
				x.addEvent('reset', function(a) {
					window.setTimeout(function(){FancyForm.chks.each(function(x){FancyForm.update(x);x.inputElement.blur()})}, 200);
				});
			});
		},
		update: function(chk){
			if(chk.inputElement.getProperty('checked')) {
				chk.removeClass(FancyForm.offclasses[chk.type]);
				chk.addClass(FancyForm.onclasses[chk.type]);
				if (chk.type == 'radio'){
					FancyForm.chks.each(function(other){
						if (other.name == chk.name && other != chk) {
							other.inputElement.setProperty('checked', false);
							FancyForm.update(other);
						}
					});
				}
				if(extraclass = FancyForm.extra['on'])
					chk.addClass(extraclass);
				if(extraclass = FancyForm.extra['off'])
					chk.removeClass(extraclass);
				if(!FancyForm.initing)
					FancyForm.onSelect(chk);
			} else {
				chk.removeClass(FancyForm.onclasses[chk.type]);
				chk.addClass(FancyForm.offclasses[chk.type]);
				if(extraclass = FancyForm.extra['off'])
					chk.addClass(extraclass);
				if(extraclass = FancyForm.extra['on'])
					chk.removeClass(extraclass);
				if(!FancyForm.initing)
					FancyForm.onDeselect(chk);
			}
			if(!FancyForm.initing)
				chk.inputElement.focus();
		},
		all: function(){
			FancyForm.chks.each(function(chk){
				chk.inputElement.setProperty('checked', 'checked');
				FancyForm.update(chk);
			});
		},
		none: function(){
			FancyForm.chks.each(function(chk){
				chk.inputElement.setProperty('checked', false);
				FancyForm.update(chk);
			});
		}
	};

	window.addEvent('domready', function(){
		FancyForm.start();
	});



	/**
	 * Autocompleter
	 *
	 * http://digitarald.de/project/autocompleter/
	 *
	 * @version		1.1.2
	 *
	 * @license		MIT-style license
	 * @author		Harald Kirschner <mail [at] digitarald.de>
	 * @copyright	Author
	 */

	// Remplace toutes les occurences d'une chaine
	function replaceAll(str, search, repl) {
		while (str.indexOf(search) != -1)
			str = str.replace(search, repl);
		return str;
	}

	// Remplace les caractères accentués
	function AccentToNoAccent(str) {
		var norm = new Array('À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï', 'Ð','Ñ','Ò','Ó','Ô','Õ','Ö','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß', 'à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ', 'ò','ó','ô','õ','ö','ø','ù','ú','û','ü','ý','ý','þ','ÿ');
		var spec = new Array('A','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I', 'D','N','O','O','O','0','O','O','U','U','U','U','Y','b','s', 'a','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','d','n', 'o','o','o','o','o','o','u','u','u','u','y','y','b','y');
		for (var i = 0; i < spec.length; i++)
			str = replaceAll(str, norm[i], spec[i]);
		return str;
	}

	var Autocompleter = new Class({

		Implements: [Options, Events],

		options: {/*
			onOver: $empty,
			onSelect: $empty,
			onSelection: $empty,
			onShow: $empty,
			onHide: $empty,
			onBlur: $empty,
			onFocus: $empty,*/
		minLength: 0,
		markQuery: true,
		width: 'inherit',
		maxChoices: 10,
		injectChoice: null,
		customChoices: null,
		emptyChoices: null,
		visibleChoices: true,
		className: 'autocompleter-choices',
		zIndex: 42,
		delay: 400,
		observerOptions: {},
		fxOptions: {},

		autoSubmit: false,
		overflow: true,
		overflowMargin: 25,
		selectFirst: false,
		filter: null,
		filterCase: false,
		filterSubset: false,
		forceSelect: false,
		selectMode: true,
		choicesMatch: null,

		multiple: false,
		separator: ', ',
		separatorSplit: /\s*[,;]\s*/,
		autoTrim: false,
		allowDupes: false,

		cache: true,
		relative: false,
		noValueText: 'Indifférent'
	},

	initialize: function(element, hidden, options) {
		this.element = $(element);
		this.hidden =  $(hidden);
		this.setOptions(options);
		this.element.set('value',this.options.noValueText);
		this.build();
		this.observer = new Observer(this.element, this.prefetch.bind(this), $merge({
			'delay': this.options.delay
		}, this.options.observerOptions));
		this.queryValue = null;
		if (this.options.filter) this.filter = this.options.filter.bind(this);
		var mode = this.options.selectMode;
		this.typeAhead = (mode == 'type-ahead');
		this.selectMode = (mode === true) ? 'selection' : mode;
		this.cached = [];
	},

	/**
	 * build - Initialize DOM
	 *
	 * Builds the html structure for choices and appends the events to the element.
	 * Override this function to modify the html generation.
	 */
	build: function() {
		if ($(this.options.customChoices)) {
			this.choices = this.options.customChoices;
		} else {
			this.choices = new Element('ul', {
				'class': this.options.className,
				'styles': {
				'zIndex': this.options.zIndex
			}
			}).inject(document.body);
			this.relative = false;
			if (this.options.relative) {
				this.choices.inject(this.element, 'after');
				this.relative = this.element.getOffsetParent();
			}
			this.fix = new OverlayFix(this.choices);
		}
		if (!this.options.separator.test(this.options.separatorSplit)) {
			this.options.separatorSplit = this.options.separator;
		}
		this.fx = (!this.options.fxOptions) ? null : new Fx.Tween(this.choices, $merge({
			'property': 'opacity',
			'link': 'cancel',
			'duration': 200
		}, this.options.fxOptions)).addEvent('onStart', Chain.prototype.clearChain).set(0);
		this.element.setProperty('autocomplete', 'off')
		.addEvent((Browser.Engine.trident || Browser.Engine.webkit) ? 'keydown' : 'keypress', this.onCommand.bind(this))
		.addEvent('click', this.onCommand.bind(this, [false]))
		.addEvent('focus', this.toggleFocus.create({bind: this, arguments: true, delay: 100}));
		//.addEvent('blur', this.toggleFocus.create({bind: this, arguments: false, delay: 100}));
		document.addEvent('click', function(e){
			if (e.target != this.choices) this.toggleFocus(false);
		}.bind(this));
	},

	destroy: function() {
		if (this.fix) this.fix.destroy();
		this.choices = this.selected = this.choices.destroy();
	},

	toggleFocus: function(state) {
		this.focussed = state;

		if (!state){
			var found = null;
			this.choices.getElements('li').each(function(item){
				//alert(item.getElement('div').get('text'));
				var item_value = AccentToNoAccent(item.getElement('div').get('text').toLowerCase());
				var observer_value = AccentToNoAccent(this.observer.value.toLowerCase());
				if ( this.observer.value != '' && item_value.toLowerCase().indexOf(observer_value.toLowerCase())==0 && !found){
					found = item;
				}
			}.bind(this));

			if (!this.selected){
				if ( found ){
					this.selected = found;
					this.observer.setValue(found.getElement('div').get('text'));
					this.hidden.set('value', this.selected.retrieve('id'));
				}else{
					this.selected = null;
					this.observer.setValue(this.options.noValueText);
					this.hidden.set('value','');
				}
			}

			this.hideChoices(true);

		}
		this.fireEvent((state) ? 'onFocus' : 'onBlur', [this.element]);
	},


	onCommand: function(e) {

		if (!e) return this.prefetch();
		if (e && e.key && !e.shift) {
			switch (e.key) {
			case 'enter':
				if (this.element.value != this.opted) return true;
				if (this.selected && this.visible) {
					this.choiceSelect(this.selected);
					return !!(this.options.autoSubmit);
				}
				break;
			case 'up': case 'down':
				if (!this.prefetch() && this.queryValue !== null) {
					var up = (e.key == 'up');
					this.choiceOver((this.selected || this.choices)[
					                                                (this.selected) ? ((up) ? 'getPrevious' : 'getNext') : ((up) ? 'getLast' : 'getFirst')
					                                                		](this.options.choicesMatch), true);
				}
				return false;
			case 'esc': case 'tab':
				this.hideChoices(true);
				break;
			}
		}
		return true;
	},

	setSelection: function(finish) {
		var input = this.selected.inputValue, value = input;
		var start = this.queryValue.length, end = input.length;
		if (input.substr(0, start).toLowerCase() != this.queryValue.toLowerCase()) start = 0;
		if (this.options.multiple) {
			var split = this.options.separatorSplit;
			value = this.element.value;
			start += this.queryIndex;
			end += this.queryIndex;
			var old = value.substr(this.queryIndex).split(split, 1)[0];
			value = value.substr(0, this.queryIndex) + input + value.substr(this.queryIndex + old.length);
			if (finish) {
				var tokens = value.split(this.options.separatorSplit).filter(function(entry) {
					return this.test(entry);
				}, /[^\s,]+/);
				if (!this.options.allowDupes) tokens = [].combine(tokens);
				var sep = this.options.separator;
				value = tokens.join(sep) + sep;
				end = value.length;
			}
		}
		this.observer.setValue(value);
		this.hidden.set('value', this.selected.retrieve('id'));
		this.opted = value;
		if (finish || this.selectMode == 'pick') start = end;
		this.element.selectRange(start, end);
		this.fireEvent('onSelection', [this.element, this.selected, value, input]);
	},

	showChoices: function() {
		//alert('test');
		this.element.addClass('p_list_selected');
		var match = this.options.choicesMatch, first = this.choices.getFirst(match);
		this.selected = this.selectedValue = null;
		if (this.fix) {
			var pos = this.element.getCoordinates(this.relative), width = this.options.width || 'auto';
			this.choices.setStyles({
				'left': pos.left,
				'top': pos.bottom,
				'width': (width === true || width == 'inherit') ? pos.width : width
			});
		}

		if (!first) return;
		if (!this.visible) {
			this.visible = true;
			this.choices.setStyle('display', '');
			if (this.fx) this.fx.start(1);
			this.fireEvent('onShow', [this.element, this.choices]);
		}
		if (this.options.selectFirst || this.typeAhead || first.inputValue == this.queryValue) this.choiceOver(first, this.typeAhead);
		var items = this.choices.getChildren(match), max = this.options.maxChoices;
		var styles = {'overflowY': 'hidden', 'height': ''};
		this.overflown = false;
		if (items.length > max) {
			var item = items[max - 1];
			styles.overflowY = 'scroll';
			styles.height = item.getCoordinates(this.choices).bottom;
			this.overflown = true;
		};
		this.choices.setStyles(styles);
		this.fix.show();
		if (this.options.visibleChoices) {
			var scroll = document.getScroll(),
			size = document.getSize(),
			coords = this.choices.getCoordinates();
			if (coords.right > scroll.x + size.x) scroll.x = coords.right - size.x;
			if (coords.bottom > scroll.y + size.y) scroll.y = coords.bottom - size.y;
			window.scrollTo(Math.min(scroll.x, coords.left), Math.min(scroll.y, coords.top));
		}
	},

	hideChoices: function(clear) {
		this.element.removeClass('p_list_selected');
		if (clear) {
			var value = this.element.value;
			if (this.options.forceSelect) value = this.opted;
			if (this.options.autoTrim) {
				value = value.split(this.options.separatorSplit).filter($arguments(0)).join(this.options.separator);
			}
			this.observer.setValue(value);
		}

		if (!this.visible) return;
		this.visible = false;

		if (this.selected){
			this.selected.removeClass('autocompleter-selected')
		}

		this.observer.clear();
		var hide = function(){
			this.choices.setStyle('display', 'none');
			this.fix.hide();
		}.bind(this);
		if (this.fx) this.fx.start(0).chain(hide);
		else hide();
		this.fireEvent('onHide', [this.element, this.choices]);
	},

	prefetch: function() {
		if (this.element.value==this.options.noValueText){
			this.element.value='';
		}
		var value = this.element.value, query = value;
		if (this.options.multiple) {
			var split = this.options.separatorSplit;
			var values = value.split(split);
			var index = this.element.getSelectedRange().start;
			var toIndex = value.substr(0, index).split(split);
			var last = toIndex.length - 1;
			index -= toIndex[last].length;
			query = values[last];
		}
		if (query.length < this.options.minLength) {
			this.hideChoices();
		} else {

			if (query === this.queryValue || (this.visible && query == this.selectedValue)) {
				if (this.visible) return false;
				this.showChoices();
			} else {
				this.queryValue = query;
				this.queryIndex = index;
				if (!this.fetchCached()) this.query();
			}
		}
		return true;
	},

	fetchCached: function() {
		return false;
		if (!this.options.cache
				|| !this.cached
				|| !this.cached.length
				|| this.cached.length >= this.options.maxChoices
				|| this.queryValue) return false;
		this.update(this.filter(this.cached));
		return true;
	},

	update: function(tokens) {
		this.choices.empty();
		this.cached = tokens;
		var type = tokens && $type(tokens);
		if (!type || (type == 'array' && !tokens.length) || (type == 'hash' && !tokens.getLength())) {
			(this.options.emptyChoices || this.hideChoices).call(this);
		} else {
			if (this.options.maxChoices < tokens.length && !this.options.overflow) tokens.length = this.options.maxChoices;

			var choice = new Element('li', {'html': '<div>'+this.options.noValueText+'</div>'});
			choice.inputValue = choice.getElement('div').get('text');
			choice.store('id', null);
			this.addChoiceEvents(choice).inject(this.choices);


			tokens.each(this.options.injectChoice || function(token, key){
				var choice = new Element('li', {'html': token});
				if (choice.getElement('div') != null) {
					choice.getElement('div').set('html', this.markQueryValue(choice.getElement('div').get('text')));
					choice.inputValue = choice.getElement('div').get('text');
					choice.store('id', key);
					this.addChoiceEvents(choice).inject(this.choices);
				}
			}, this);
			this.showChoices();
		}
	},

	choiceOver: function(choice, selection) {
		if (!choice || choice == this.selected) return;
		if (this.selected) this.selected.removeClass('autocompleter-selected');
		this.selected = choice.addClass('autocompleter-selected');
		this.fireEvent('onSelect', [this.element, this.selected, selection]);
		if (!this.selectMode) this.opted = this.element.value;
		if (!selection) return;
		this.selectedValue = this.selected.inputValue;
		if (this.overflown) {
			var coords = this.selected.getCoordinates(this.choices), margin = this.options.overflowMargin,
			top = this.choices.scrollTop, height = this.choices.offsetHeight, bottom = top + height;
			if (coords.top - margin < top && top) this.choices.scrollTop = Math.max(coords.top - margin, 0);
			else if (coords.bottom + margin > bottom) this.choices.scrollTop = Math.min(coords.bottom - height + margin, bottom);
		}
		if (this.selectMode) this.setSelection();
	},

	choiceSelect: function(choice) {
		if (choice) this.choiceOver(choice);
		this.setSelection(true);
		this.queryValue = false;
		this.hideChoices();
	},

	filter: function(tokens) {
		return (tokens || this.tokens).filter(function(token) {
			return this.test(token);
		}, new RegExp(((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp(), (this.options.filterCase) ? '' : 'i'));
	},

	/**
	 * markQueryValue
	 *
	 * Marks the queried word in the given string with <span class="autocompleter-queried">*</span>
	 * Call this i.e. from your custom parseChoices, same for addChoiceEvents
	 *
	 * @param		{String} Text
	 * @return		{String} Text
	 */
	markQueryValue: function(str) {
		return (!this.options.markQuery || !this.queryValue) ? str
				: str.replace(new RegExp('(' + ((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp() + ')', (this.options.filterCase) ? '' : 'i'), '<span class="autocompleter-queried">$1</span>');
	},

	/**
	 * addChoiceEvents
	 *
	 * Appends the needed event handlers for a choice-entry to the given element.
	 *
	 * @param		{Element} Choice entry
	 * @return		{Element} Choice entry
	 */
	addChoiceEvents: function(el) {
		return el.addEvents({
			'mouseover': this.choiceOver.bind(this, [el]),
			'click': this.choiceSelect.bind(this, [el])
		});
	}
	});

	var OverlayFix = new Class({

		initialize: function(el) {
		if (Browser.Engine.trident) {
			this.element = $(el);
			this.relative = this.element.getOffsetParent();
			this.fix = new Element('iframe', {
				'frameborder': '0',
				'scrolling': 'no',
				'src': 'javascript:false;',
				'styles': {
				'position': 'absolute',
				'border': 'none',
				'display': 'none',
				'filter': 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
			}
			}).inject(this.element, 'after');
		}
	},

	show: function() {
		if (this.fix) {
			var coords = this.element.getCoordinates(this.relative);
			delete coords.right;
			delete coords.bottom;
			this.fix.setStyles($extend(coords, {
				'display': '',
				'zIndex': (this.element.getStyle('zIndex') || 1) - 1
			}));
		}
		return this;
	},

	hide: function() {
		if (this.fix) this.fix.setStyle('display', 'none');
		return this;
	},

	destroy: function() {
		if (this.fix) this.fix = this.fix.destroy();
	}

	});

	Element.implement({

		getSelectedRange: function() {
		if (!Browser.Engine.trident) return {start: this.selectionStart, end: this.selectionEnd};
		var pos = {start: 0, end: 0};
		var range = this.getDocument().selection.createRange();
		if (!range || range.parentElement() != this) return pos;
		var dup = range.duplicate();
		if (this.type == 'text') {
			pos.start = 0 - dup.moveStart('character', -100000);
			pos.end = pos.start + range.text.length;
		} else {
			var value = this.value;
			var offset = value.length - value.match(/[\n\r]*$/)[0].length;
			dup.moveToElementText(this);
			dup.setEndPoint('StartToEnd', range);
			pos.end = offset - dup.text.length;
			dup.setEndPoint('StartToStart', range);
			pos.start = offset - dup.text.length;
		}
		return pos;
	},

	selectRange: function(start, end) {
		if (Browser.Engine.trident) {
			var diff = this.value.substr(start, end - start).replace(/\r/g, '').length;
			start = this.value.substr(0, start).replace(/\r/g, '').length;
			var range = this.createTextRange();
			range.collapse(true);
			range.moveEnd('character', start + diff);
			range.moveStart('character', start);
			range.select();
		} else {
			this.focus();
			this.setSelectionRange(start, end);
		}
		return this;
	}

	});

	/* compatibility */

	Autocompleter.Base = Autocompleter;



	/**
	 * Autocompleter.Request
	 *
	 * http://digitarald.de/project/autocompleter/
	 *
	 * @version		1.1.2
	 *
	 * @license		MIT-style license
	 * @author		Harald Kirschner <mail [at] digitarald.de>
	 * @copyright	Author
	 */

	Autocompleter.Request = new Class({

		Extends: Autocompleter,

		options: {/*
			indicator: null,
			indicatorClass: null,
			onRequest: $empty,
			onComplete: $empty,*/
		postData: {},
		ajaxOptions: {},
		postVar: 'value',
		fields_to_empty: new Array(),
		field_values: new Array()

	},

	query: function(){
		//alert(this.queryValue);
		this.old_bg = this.element.getParent().getStyle('background-image');
		this.element.getParent().setStyle('background-image','url("/style/interface/loader1.gif")');
		var data = $unlink(this.options.postData) || {};
		data[this.options.postVar] = this.queryValue;
		this.options.field_values.each(function(item, key){
			data['field'+key] = item.get('value');
		});
		this.options.fields_to_empty.each(function(item){
			item.set('value', '');
		});
		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': data});
	},

	/**
	 * queryResponse - abstract
	 *
	 * Inherated classes have to extend this function and use this.parent()
	 */
	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, hidden, url, options) {
		this.parent(el, hidden, options);

		this.request = new Request.JSON($merge({
			'url': url,
			'link': 'cancel'
		}, this.options.ajaxOptions)).addEvent('onComplete', this.queryResponse.bind(this));
	},

	queryResponse: function(response) {
		this.parent();

		var tokens = new Hash();

		for (var i in response) {
			var item = response[i];
			tokens.include(i, item);
		}

		this.update(tokens);
		this.element.getParent().setStyle('background-image',this.old_bg);
	}

	});

	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();
		}

	}

	});

	/* compatibility */

	Autocompleter.Ajax = {
			Base: Autocompleter.Request,
			Json: Autocompleter.Request.JSON,
			Xhtml: Autocompleter.Request.HTML
	};



	/**
	 * Observer - Observe formelements for changes
	 *
	 * - Additional code from clientside.cnet.com
	 *
	 * @version		1.1
	 *
	 * @license		MIT-style license
	 * @author		Harald Kirschner <mail [at] digitarald.de>
	 * @copyright	Author
	 */
	var Observer = new Class({

		Implements: [Options, Events],

		options: {
		periodical: false,
		delay: 2000
	},

	initialize: function(el, onFired, options){
		this.element = $(el) || $$(el);
		this.addEvent('onFired', onFired);
		this.setOptions(options);
		this.bound = this.changed.bind(this);
		this.resume();
	},

	changed: function() {
		var value = this.element.get('value');
		if ($equals(this.value, value)) return;
		this.clear();
		this.value = value;
		this.timeout = this.onFired.delay(this.options.delay, this);
	},

	setValue: function(value) {
		this.value = value;
		this.element.set('value', value);
		return this.clear();
	},

	onFired: function() {
		this.fireEvent('onFired', [this.value, this.element]);
	},

	clear: function() {
		$clear(this.timeout || null);
		return this;
	},

	pause: function(){
		if (this.timer) $clear(this.timer);
		else this.element.removeEvent('keyup', this.bound);
		return this.clear();
	},

	resume: function(){
		this.value = this.element.get('value');
		if (this.options.periodical) this.timer = this.changed.periodical(this.options.periodical, this);
		else this.element.addEvent('keyup', this.bound);
		return this;
	}

	});

	var $equals = function(obj1, obj2) {
		return (obj1 == obj2 || JSON.encode(obj1) == JSON.encode(obj2));
	};





	/* homepage.js
	 * -----------
	 *
	 * gestion de l'outil "quoi ou"...
	 *
	 * L'ordre est important (homepage doit être chargé après les autocompleter (il en a besoin))
	 */

	$('result_search_content_links').set('tween', {duration:500, link:'chain'});
	$('result_search').setStyle('left', $('quoiou').getCoordinates().right-120);
	$('result_search').setStyle('top', $('search').getCoordinates().top-25);
	$('result_search').setStyle('opacity', 0);
	$('result_search').setStyle('display', 'block');
	$('result_search').set('tween', {duration: 300})


	new Autocompleter.Request.JSON('type', 'type_hidden', '/types.ajax', {
		'postVar': 'search', 'noValueText' : 'Tous les types'
	});

	$('result_search_close').addEvent('click', function(){
		$('result_search').tween('opacity', 0);
		//$('result_search').setStyle('display','none');
	});

	$('quoiou').getElements('label').addEvent('click', function(){
		$('result_search').tween('opacity', 0);
		//$('result_search').setStyle('display','none');
	});

	$('quoiou').getElements('input').addEvent('click', function(){
		$('result_search').tween('opacity', 0);
		//$('result_search').setStyle('display','none');
	});

	function results_search(html){
		$('result_search_content_links').set('html', html);
		$('result_search').tween('opacity', 1);
		//$('result_search').setStyle('display','block');
	}

	function search(more){
		new Request({
			url: '/ou.ajax',
			data: 'search='+$('search').value+'&all='+more+'&type='+$('type_hidden').value
			+'&animaux='+$('animaux').checked+'&piscine='+$('piscine').checked
			+'&internet='+$('internet').checked+'&handicape='+$('handicape').checked,
			onComplete: function(ret){
			var json = JSON.decode(ret);
			if (json){
				if (json.length>2){
					var vil='';
					var dep='';
					var reg='';
					var ann='';
					var vil_nb=0;
					var dep_nb=0;
					var reg_nb=0;
					var ann_nb=0;
					json.each(function(item, id){
						if (id>0){
							switch(item['type']){
							case 0:
								vil_nb++;
								vil += "<li>"+item['a']+"</li>"
								break;
							case 1:
								vil_nb++;
								vil += "<li>"+item['a']+"</li>"
								break;
							case 2:
								dep_nb++;
								dep += "<li>"+item['a']+"</li>"
								break;
							case 3:
								reg_nb++;
								reg += "<li>"+item['a']+"</li>"
								break;
							case 4:
								ann_nb++;
								ann += "<li>"+item['a']+"</li>"
								break;
							}
						}
					});

					if (vil!=''){
						if (vil_nb>1){
							var nom = 'villes';
						}else{
							var nom = 'ville';
						}
						vil='<p class="title">'+vil_nb+' '+nom+' :</p><ul>'+vil+'</ul>';
					}

					if (dep!=''){
						if (dep_nb>1){
							var nom = 'départements';
						}else{
							var nom = 'département';
						}
						dep='<p class="title">'+dep_nb+' '+nom+' :</p><ul>'+dep+'</ul>';
					}

					if (reg!=''){
						if (reg_nb>1){
							var nom = 'régions';
						}else{
							var nom = 'région';
						}
						reg='<p class="title">'+reg_nb+' '+nom+' :</p><ul>'+reg+'</ul>';
					}

					if (ann!=''){
						if (ann_nb>1){
							var nom = 'annonces';
						}else{
							var nom = 'annonce';
						}
						ann='<p class="title">'+ann_nb+' '+nom+' :</p><ul>'+ann+'</ul>';
					}

					results_search(ann+vil+dep+reg);

					if (json[0]==1){
						$('more_results').setStyle('display', 'block');
					}else{
						$('more_results').setStyle('display', 'none');
					}
				}else{
					window.location = json[1]['url'];
				}
			}else{
				results_search('<p class="info">Cette destination ne donne pas de r&eacute;sultats, &ecirc;tes-vous s&ucirc;r de l&rsquo;orthographe ?</p>')
			}
			$('result_search_content_links').tween('opacity', '1');
		}
		}).send();
	}

	function more_results_interface(){
		$('search').value = AccentToNoAccent($('search').value);
		$('result_search_content_links').setStyles({'overflow-x' : 'hidden',
			'overflow-y' : 'scroll'});

		$('result_search_content_links').setStyle('height', $('result_search_content_links').getSize().y);
		$('result_search_content_links').tween('height', '350px');
	}

	function less_results_interface(){
		$('search').value = AccentToNoAccent($('search').value);
		$('result_search_content_links').setStyles({'height':'auto',
			'overflow-x' : 'hidden',
			'overflow-y' : 'hidden'});
	}

	$('type').addEvent('keypress', function(e){
		if(e.key == 'enter') {
			less_results_interface();
			search(0);
		}
	});

	$('search').addEvent('keypress', function(e){
		if(e.key == 'enter') {
			less_results_interface();
			search(0);
		}
	});

	$('search_button').addEvent('click', function(e){
		e.stop();
		less_results_interface();
		search(0);
	});

	$('more_results').addEvent('click', function(e){
		e.stop();
		$('result_search_content_links').tween('opacity', '0');
		$('result_search_content_links').get('tween').addEvent('complete', function(){
			if ($('result_search_content_links').getStyle('opacity')==0){
				more_results_interface();
				search(1);
				$('result_search_content_links').get('tween').removeEvents();
			}
		})

	});

	$$('.p_listbox').addEvent('click', function(e){
		e.stop();
		if (!this.getElement('input').hasClass('p_list_selected')){
			this.getElement('input').focus();
			this.getElement('input').fireEvent('click');
		}
	});

	$$('.fake_link').addEvent('mouseover', function(){
		this.setStyle('cursor', 'pointer');
	});
	
	new ShapeHover($('map_france'), {
		fill: {
			type: 'color',
			content: '#F00'
		},
		stroke: false
	});

	$('homepage_qui').addEvent('click',function(r){
		$('video_homepage-wrapper').setStyle('display','block');
		var flashvars = {file: "/style/homepage/Homepage.flv",autostart: "true",controlbar:"none",allowfullscreen:"true",bufferlength:"2",stretching:"uniform"};
		var params = {wmode: "transparent"};
		var attributes = {};
		var obj = new Swiff('/style/player.swf', {
		    id: 'homepage_qui_somme_nous',
		    width: 240,
		    height: 500,
			container :$('video_homepage'),
		    params: {
		        wMode: "transparent"
		    },
		    vars: {
		        src: "/style/homepage/Homepage.flv",autostart: "true",ei_prefix: "hom_"
		    }
		});
	});
	$$('#video_homepage-wrapper #close').addEvent('click',function(r) {
		hide_swf();
	});
	
    // Facebook like button
   var facebookLikeButtonPlaceholder = document.getElementById("fLike");
   facebookLikeButtonPlaceholder.innerHTML = '<iframe  src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.7enlocation.com%2F&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=21&amp;" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>';
});

function hom_onComplete() {
	hide_swf();
}

function hide_swf() {
	$('video_homepage-wrapper').setStyle('display','none');
	$('video_homepage').set('html','');
}

// Remplace toutes les occurences d'une chaine
function replaceAll(str, search, repl) {
 while (str.indexOf(search) != -1)
  str = str.replace(search, repl);
 return str;
}

// Remplace les caractères accentués
function AccentToNoAccent(str) {
 var norm = new Array('À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
'Ì','Í','Î','Ï', 'Ð','Ñ','Ò','Ó','Ô','Õ','Ö','Ø','Ù','Ú','Û','Ü','Ý',
'Þ','ß', 'à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î',
'ï','ð','ñ', 'ò','ó','ô','õ','ö','ø','ù','ú','û','ü','ý','ý','þ','ÿ');
var spec = new Array('A','A','A','A','A','A','A','C','E','E','E','E',
'I','I','I','I', 'D','N','O','O','O','0','O','O','U','U','U','U','Y',
'b','s', 'a','a','a','a','a','a','a','c','e','e','e','e','i','i','i',
'i','d','n', 'o','o','o','o','o','o','u','u','u','u','y','y','b','y');
 for (var i = 0; i < spec.length; i++)
  str = replaceAll(str, norm[i], spec[i]);
 return str;
 }
