	window.addEvent('domready', function() {
		if ($('content-form') != null) {
			var myForm = new Formulaire('content-form');
		}
		
		if (Browser.Engine.name == 'trident' && Browser.Engine.version == 4) {
			$$('#mainNav > li').each(function(i, e) {
				i.addEvents({
					'mouseenter': function () {
						this.set('class', this.get('class')+'_over over');
					},
					'mouseleave' : function () {
						this.set('class', this.get('class').replace(/^(.*)_over\sover$/,'$1'));
					}
				});
			});
		}
	});	


	var StationsTab = new Class ({
		Implements: Options,

		options	:	{
			ind1: "/templates/04/images/ind1.gif",
			ind2: "/templates/04/images/ind2.gif"
		},
		
		initialize : function (container, options) {
			this.setOptions(options);
			this.container = $(container);

			// Répartie les différentes parties du tableau
			this.initBody();

			// Initialise les évènements des pathologies et récupère les éléments this.pathologie
			this.pathologie = this.initPathologies();
			
			// Initialise les évènements liés aux stations et récupère les éléments dans le tableau this.stations
			this.stations = this.initStations();
			
			// Ajoute les évènements supplémentaires pour les pathologies
			this.pathologie.each(function (e,i) {
				if ($chk(e))
					e.addEvents({
						'mouseover' :	function () {
												this.pathologie[i].fireEvent("up");
												this.affStation(i, "on");
										}.bind(this),
						'mouseleave':	function () {
											this.pathologie[i].fireEvent("down");
											this.affStation(i, "off");
										}.bind(this)
					});
			}, this);
		},
		
		initBody: function () {
			(this.container.getElements('tbody')).each(function(item, index) { 
				if (item.get('class') == "head")
					this.pathologie = item;
				else this.stations = item;
			}, this);
		},
		
		initPathologies : function () {
			var path = [];

			(this.pathologie.getElements('td')).each(function(elt, index) { 
				if ($chk(elt.getElement("a"))) {
					elt.addEvents({
						'up' : function() { this.addClass('overp'); },
						'down':function() { this.removeClass('overp');}
					});
					path[index] = elt; 
				}
			}, this);

			return path;
		},
		
		initStations : function () {
			var tr = this.stations.getElements('tr');

			tr.each(function (elt, i) {  
				this.initStationsLib (elt);
			}, this);
			
			return tr;
		},

		initStationsPath : function (id, tr) {
			var temp = [];
			tr.getElements('td').each(function(elt, i) { 
				if (elt.getElement("a")) temp[i] = elt;  
			});

			return temp;
		},
		
		initStationsLib : function (elt) {
			elt.addEvents({
				'mouseover'	:	function () { 
									var tmp = elt.getElements("td"); 
									tmp.each(function(e,i) { 
										img = e.getElement("img");
										if ($chk(img)) {
											img.set('src',this.options.ind2); 
											this.pathologie[i].fireEvent("up");
										}
									}, this);
									elt.getFirst('td').addClass('over');
								}.bind(this),

				'mouseleave':	function () { 
									var tmp = elt.getElements("td"); 
									tmp.each(function(e,i) { 
										img = e.getElement("img");
										if ($chk(img)) {
											img.set('src',this.options.ind1); 
											this.pathologie[i].fireEvent("down");
										}
									}, this);
									elt.getFirst('td').removeClass('over');
								}.bind(this),
				
				'upCell'	:	function (index) {
									var bool = false;
									var tmp = elt.getElements("td");
									tmp.each(function(e,i) {
										img = e.getElement("img");
										if ($chk(img) && index == i) {
											img.set('src',this.options.ind2); 
											bool = true;
										}
									}, this);
									if (bool == true) elt.getFirst('td').addClass('over');
								}.bind(this)
			});
		},
		
		
		affStation : function (index, mode) {
			this.stations.each(function(e,i) {
				if (mode == "on")
					e.fireEvent("upCell", index);
				else e.fireEvent("mouseleave");
			});
		}
		
	});



	var StationsCarte = new Class({
		Implements: Options,
		
		options: {
			backgroundItem : "#3eb4b4",
			colorItem : "#fff",
			heightItem : "15px",
			paddingItem : "2px",
			puceItem : '/templates/03/images/carte-puce3.png'
		},
		
		initialize : function (container, target, options) {
			this.setOptions(options);
			this.container = $(container);
			this.target = $(target);
			this.area = [];
			this.puce = this.createPuce();
			
			this.target.grab(this.puce);
			
			var cntArea = this.container.getElements("area").length;
			(this.container.getElements("area")).each(function (e,i) {
				if (i < cntArea-1) {
					var temp = e.coords.split(',');
					var coordElt = {'x' : temp[0].toInt(), 'y' : temp[1].toInt()};

					this.area[i] = {'elt' : e, 'lib' : this.createLib(e.alt,coordElt), 'x' : coordElt.x, 'y' : coordElt.y};
					this.target.grab(this.area[i].lib);

					this.area[i].elt.addEvents({
						'mouseover': function () { 
							if (this.area[i].lib.getStyle('display') != 'block')
								this.area[i].lib.style.display = 'block'; 
							}.bind(this),
						'mouseleave': function () { 
							this.area[i].lib.style.display = 'none'; 
							this.puce.style.display = 'none';
							}.bind(this) }
						);
				}
			}, this);
		},
		
		createLib : function (libelle, coord) {
			return new Element ('div', {
				'html'		:	libelle,
				'styles'	:	{
					'position': 'absolute',
					'display' : 'none',
					'left' : (coord.x-20)+"px",
					'top' : ((coord.y > 100)?(coord.y-30):(coord.y+20))+"px",
					'background-color' : this.options.backgroundItem,
					'color' : this.options.colorItem,
					'height': this.options.heightItem,
					'padding': '2px 4px',
					'font-family' : 'Georgia, "Times New Roman", Times, serif', 
					'font-size' : '10px',
					'text-transform' : 'uppercase',
					'font-weight' : 'bolder',
					'z-index': 20
				}
			});
		},
		
		createPuce : function () {
			return new Element ('img', {
				'src' : this.options.puceItem,
				'class' : 'carte-puce'
			});
		}
	});


	var Pathologies = new Class ({
		initialize : function (container) {
			this.container = $(container);
			this.pathList = [];

			(this.container.getElements('a')).each(function (elt, i) {
				elt.addEvents({
					'mouseover' : function (event) {
						$('path-'+this.get('class')).toggleClass('on');
					},
					'mouseleave' : function () {
						$('path-'+this.get('class')).toggleClass('on');
					}
				});
			}); 
		}
	});


	var Formulaire = new Class ({
		Implements: Options,
		
		options : {
			formValidInput : 'valid-form',
			errorClass : 'error'
		},

		initialize : function (container, options) {
			this.setOptions(options);
			this.validForm = $(this.options.formValidInput);
			
			this.container = $(container);

			this.obl = [];
			this.initUrl();
			this.initPopup();

			
			this.container.addEvent('submit', function(event) { 
				this.obl.empty();
				this.parseInput(this.container); 
				if (this.obl.length > 0) {
					event.preventDefault(); 
					this.displayObl();
				}
			}.bind(this));
		},
		
		initUrl : function () {
			this.action = this.container.get('action');
		},
		
		initPopup : function () {
			this.popup = new Element ('div', {'id' : 'popup'});
			this.popup.inject(document.body, 'top');
			
			this.popup.addEvents({
				'show' : function () { this.toggleClass('show'); },
				'hide' : function () { this.toggleClass('show'); }
			});
		},
		
		parseInput : function (container) {
			var bool = true;
			(container.getElements('input, textarea, select')).each(function (elt, i) {
				if (elt.hasClass('obligatoire') && this.testInput(elt) == false) {
					elt.addClass(this.options.errorClass);
					this.obl.push(elt);
				}else if (elt.hasClass('error')) elt.removeClass('error');
			}, this);
		},
		
		testInput : function (tag) {
			var result =  true;

			switch (tag.get('tag')) {
				case 'input'	:	if (tag.get('type') == 'text') {
										if (tag.get('value').trim() == '')
											result = false;
										tag.addEvent('click', function() { this.select(); });
									}
									else if (tag.get('type') == 'checkbox' && tag.checked == false) result = false;
									else if (tag.get('type') == 'radio' && tag.checked == false) result = false
									break;

				case "textarea"	:	if (tag.get('value').trim() == '') result = false;
									break;

				case "select"	:	if (tag.get('value') == 0) result = false;
									break
			}
			
			return result;
		},

		displayObl : function () {
			this.popup.empty();
			
			var background = new Element('div', {'class': 'background'});
			background.inject(this.popup);
			
			var message = new Element('div', {'class': 'message'});
			message.addEvent('click', function () { this.popup.fireEvent('hide'); }.bind(this));

			if (this.obl.length > 0) {
				(new Element('p', {'html' : 'Les champs du formulaire qui apparaissent en <span class="orange">orange</span> contiennent des erreurs ou ne sont pas remplis correctement'})).inject(message);
//				this.obl.each(function(elt, i) { (new Element('p', {'html' : elt.title})).inject(div); }, this);
				(new Element('p', {'html' : '&gt;&gt; Revenir sur le formulaire', 'class' : 'link'})).inject(message);
				(new Element('p', {'class' : 'footer'})).inject(message);
	
				message.inject(this.popup);
				
				this.popup.fireEvent('show');
			}
		},
		
		initDate : function (container, radical) {
			var current = ($('key-gen').get('value')).split('-');

			$$('#'+container+' input').each(function (e, i) {
				if (e.get('name') == radical+'_d') e.set('value', current[0]);
				else if (e.get('name') == radical+'_m') e.set('value', current[1]);
				else if (e.get('name') == radical+'_y') e.set('value', current[2]);
			})

		}
	});