/**********************
 Modules declarations
**********************/
/* blocksResize : alignement des blocs en hauteur */
FW.BlocksResize = {};
FW.BlocksResize.resize = function(parentBlock, smoothResize) { //smoothResize is a boolean for only resizing blocks that are alone in a unit beceause while loading if resize is made on a lot of blocks it's not good
	smoothResize = smoothResize===true ? smoothResize : false; //forcer cet variable a etre clairement un booleen (pour gerer les pb via les addEvent)
	function last(array) {return array[array.length-1];};
	function size(block, size){
		if (size<=0) return;
		if (block){
			var body = block.className.match(/\bblock\b/) ? $n.node(block, {nodeName: "div", className: "body"}) : block; //si on a une line ou bien un block
			if (body) body.style[FW.heightStyle] = body.offsetHeight + size - FW.$(body).getVStyle() + "px";
		}
	};
	var arrayLines = FW.BlocksResize.lines;
	if (parentBlock && parentBlock.nodeType && parentBlock.nodeType==1) {
		arrayLines = $n.nodes(parentBlock, {nodeName: 'ul', className: "line"});
		$n.nodes(parentBlock, {nodeName: 'div', className: "line"}).each(function(n) {arrayLines.push(n)});
	}
	for (var i=arrayLines.length-1; i>=0; i--) {
		var line = arrayLines[i];
		var units = $n.childs(line, {className: /\b(last)?unit\b/}, {className: "noresize"});
		//remove the Bspace classe on last block of each unit
		units.each(function(unit) {
			var last = $n.lastChild(unit, {className: "(block|line)"});
			if (last) last.className = last.className.replace(/Bspace/g, '');
		});
		units.each(function(unit) {
			var blocks = $n.childs(unit, {className: "(block|line)"}, {className: "noresize"});
			unit.blocks = blocks;
			var sizeToApply = line.clientHeight-unit.clientHeight;
			var sizePerBlock = parseInt(sizeToApply/blocks.length);
			if (blocks.length > 1 &&  smoothResize) return;
			blocks.each(function(block) {
				size(block, sizePerBlock);
			});
			//sur une division on tombe parfois sur un calcul pas precis, on resize le dernier element d'un unit, afin que le calcul soit correct
			if (blocks.length > 1) size(last(blocks), line.clientHeight-unit.clientHeight);
		});
	}
}
FW.BlocksResize.lines = [];
FW.Module('blocksResize',{nodeName:'div', className:'line'},{initialize : function(line) {FW.BlocksResize.lines.push(line);}});
FW.$(window).addEvent('load', FW.BlocksResize.resize);
	

	
/* searchScroll : scrolling sur le tableau de recherche */
FW.Module("searchScroll", 
	{nodeName:"div", className:"resultatRecherche"}, 
	{
		initialize: function(elm){
			// props
			this.elm = elm;
			this.viewable = elm.className.match(/resultsBy_[0-9]/)[0].split("_")[1];
			this.btnUp = FW(elm).getElement({nodeName:"a", className:"btnUp"}).el;
			this.btnDw = FW(elm).getElement({nodeName:"a", className:"btnDown"}).el;
			this.table = FW(elm).getElement({nodeName:"table", className:"searchResults"}).el;
			this.ctn = FW(elm).getElement({nodeName:"div", className:"scrollCtn"}).el;
			
			// this.table could be null if there is no result returned 
			if(this.table!=null) {
				this.trs = this.table.rows;
			}
			
			this.size2apply = 0;
			// resize
			// need to test if this.trs was null
			if(this.trs!=null) {
				for(var i=0, l=this.trs.length;i<l;i++){
					if(this.trs[i].offsetHeight > this.size2apply) this.size2apply = this.trs[i].offsetHeight;
				}
				for(var i=0, l=this.trs.length;i<l;i++){
					var first = this.trs[i].firstChild;
					if(first.nodeType == 3) {
						first = this.trs[i].childNodes[1];
					}
					first.style.height = this.size2apply + "px";
				}
			}
			this._height = this.viewable*this.size2apply;
			
			// this.ctn could be null if there is no result returned 
			if(this.ctn!=null) {
				this.ctn.style.height = this._height + "px";
				this.ctn.style.overflow = "hidden";
				this.maxScroll = this.ctn.scrollHeight - this._height;
			}
			// events
			this.btnUp.onclick = function (scope){
				return function (){
					if(!this.className.match(/inactive/)) scope.scroll(-1);
					return false;
				}
			}(this);
			this.btnDw.onclick = function (scope){
				return function (){
					if(!this.className.match(/inactive/)) scope.scroll(1);
					return false;
				}
			}(this);
			this.check(true);
		},
		
		scroll: function (sens){
			var step = FW('moveBy').el.value || 4;
			if(!this.TO){
				this.conf = {};
				this.conf.endVal = this.ctn.scrollTop + (this.size2apply * sens * step);
			}
			else {
				clearInterval(this.TO);
				this.conf.endVal += (this.size2apply * sens);
			}
			this.conf.startTime = new Date().getTime();
			this.conf.startVal = this.ctn.scrollTop;
			this.conf.step = (this.conf.endVal - this.conf.startVal) / 500;
			this.engine();
		},
		
		engine : function (){
			this.TO = setInterval(
				function(obj){
					return function (){
						var currentTime = new Date().getTime();
						obj.ctn.scrollTop = obj.conf.startVal + (currentTime-obj.conf.startTime) * obj.conf.step;
						if( currentTime >= obj.conf.startTime + 500 ) {
							clearInterval(obj.TO);
							obj.TO = null;
							obj.ctn.scrollTop = obj.conf.endVal;
							obj.check();
						}
					}
				}(this)
			,40);			
		},
		
		check: function (firstRun){
			switch(firstRun){
				case true:
					this.elm.scrollTop = 0;
					if(!FW.hasPrevious)  this.btnUp.className += " inactive";
					
					if(this.trs!=null) {
						if(this.viewable >= this.trs.length){
							this.btnDw.className += " inactive";
						}
					}
					break;
				default:
					if(this.trs!=null) {
						if(this.viewable >= this.trs.length){
							if(!FW.hasPrevious) this.btnUp.className += " inactive";
							else if(typeof paginateResults == "function") paginateResults(-1);
							this.btnDw.className += " inactive";
						}
						else if(this.ctn.scrollTop < this.size2apply){
							this.elm.scrollTop = 0;
							this.btnUp.className += " inactive";
							this.btnDw.className = this.btnDw.className.replace(/inactive/g, "");
							if(typeof paginateResults == "function") paginateResults(-1);
						}
						else if(this.maxScroll - this.ctn.scrollTop < this.size2apply) {
							this.elm.scrollTop = this.elm.scrollHeight;
							this.btnDw.className += " inactive";
							this.btnUp.className = this.btnUp.className.replace(/inactive/g, "");
							if(typeof paginateResults == "function") paginateResults(1);
							
						}
						else {
							this.btnDw.className = this.btnDw.className.replace(/inactive/g, "");
							this.btnUp.className = this.btnUp.className.replace(/inactive/g, "");
						}
					}
					break;
			}
		}
	}
);

/* ebookingScroll : scrolling sur la sélection de l'heure dans la page ebooking */
FW.Module("ebookingScroll", 
	{nodeName:"div", className:"daySelectedEbooking"}, 
	{
		initialize: function(elm){
			// props
			this.elm = elm;
			this.viewable = elm.className.match(/resultsBy_12/)[0].split("_")[1];
			this.btnUp = FW(elm).getElement({nodeName:"a", className:"btnUp"}).el;
			this.btnDw = FW(elm).getElement({nodeName:"a", className:"btnDown"}).el;
			this.table = FW(elm).getElement({nodeName:"table", className:"hourResults"}).el;
			this.ctn = FW(elm).getElement({nodeName:"div", className:"scrollCtn"}).el;
			this.scrollStep = FW(elm).getElement({nodeName:"input", className:"scrollStep"}).el;
			
			// this.table could be null if there is no result returned 
			if(this.table!=null) {
				this.trs = this.table.rows;
			}
			
			this.size2apply = 0;
			// resize
			// need to test if this.trs was null
			if(this.trs!=null) {
				for(var i=0, l=this.trs.length;i<l;i++){
					if(this.trs[i].offsetHeight > this.size2apply) this.size2apply = this.trs[i].offsetHeight;
				}
				for(var i=0, l=this.trs.length;i<l;i++){
					var first = this.trs[i].firstChild;
					if(first.nodeType == 3) {
						first = this.trs[i].childNodes[1];
					}
					if (navigator.appName=="Microsoft Internet Explorer") {
						first.style.height = this.size2apply - 2 + "px";
					} else {
						first.style.height = this.size2apply + "px";
					}
				}
			}
			this._height = this.viewable*this.size2apply;
			
			// this.ctn could be null if there is no result returned 
			if(this.ctn!=null) {
				this.ctn.style.height = this._height + "px";
				this.ctn.style.overflow = "hidden";
				this.maxScroll = this.ctn.scrollHeight - this._height;
			}
			// events
			this.btnUp.onclick = function (scope){
				return function (){
					if(!this.className.match(/inactive/)) scope.scroll(-1);
					return false;
				}
			}(this);
			this.btnDw.onclick = function (scope){
				return function (){
					if(!this.className.match(/inactive/)) scope.scroll(1);
					return false;
				}
			}(this);
			this.check(true);
		},
		
		scroll: function (sens){
			var step = this.scrollStep.value;
			if(!this.TO){
				this.conf = {};
				this.conf.endVal = this.ctn.scrollTop + (this.size2apply * sens * step);
			}
			else {
				clearInterval(this.TO);
				this.conf.endVal += (this.size2apply * sens);
			}
			this.conf.startTime = new Date().getTime();
			this.conf.startVal = this.ctn.scrollTop;
			this.conf.step = (this.conf.endVal - this.conf.startVal) / 500;
			this.engine();
		},
		
		engine : function (){
			this.TO = setInterval(
				function(obj){
					return function (){
						var currentTime = new Date().getTime();
						obj.ctn.scrollTop = obj.conf.startVal + (currentTime-obj.conf.startTime) * obj.conf.step;
						if( currentTime >= obj.conf.startTime + 500 ) {
							clearInterval(obj.TO);
							obj.TO = null;
							obj.ctn.scrollTop = obj.conf.endVal;
							obj.check();
						}
					}
				}(this)
			,40);			
		},
		
		check: function (firstRun){
			switch(firstRun){
				case true:
					this.elm.scrollTop = 0;
					if(!FW.hasPrevious)  this.btnUp.className += " inactive";
					
					if(this.trs!=null) {
						if(this.viewable >= this.trs.length){
							this.btnDw.className += " inactive";
						}
					}
					break;
				default:
					if(this.trs!=null) {
						if(this.viewable >= this.trs.length){
							if(!FW.hasPrevious) this.btnUp.className += " inactive";
							else if(typeof paginateResults == "function") paginateResults(-1);
							this.btnDw.className += " inactive";
						}
						else if(this.ctn.scrollTop < this.size2apply){
							this.elm.scrollTop = 0;
							this.btnUp.className += " inactive";
							this.btnDw.className = this.btnDw.className.replace(/inactive/g, "");
							if(typeof paginateResults == "function") paginateResults(-1);
						}
						else if(this.maxScroll - this.ctn.scrollTop < this.size2apply) {
							this.elm.scrollTop = this.elm.scrollHeight;
							this.btnDw.className += " inactive";
							this.btnUp.className = this.btnUp.className.replace(/inactive/g, "");
							if(typeof paginateResults == "function") paginateResults(1);
							
						}
						else {
							this.btnDw.className = this.btnDw.className.replace(/inactive/g, "");
							this.btnUp.className = this.btnUp.className.replace(/inactive/g, "");
						}
					}
					break;
			}
		}
	}
);

/****************
 Modules de blocks
****************/
/* blockTabs : module bloc a onglets */
FW.tabs = []; // tableau stockant les blocs tabs
FW.Module(
	'blockTabs', 
	{nodeName:'div', className:'blockTabs,blockTabSub' },  
	{
		initialize : function(block) {
			//FW.tabs.push(block);
			var self = this;
			this.tabs = FW(block).getElement({nodeName:'ul', className:'tabs'}).getElements('li');
			this.tabsContent = FW(block).getElement({nodeName:'div', className:'body'})
										.getChildsNodes({nodeName:'div', className:'tabCtn'});
			this.tabs.each(function(tab, index) {
				var a = FW(tab).getElement('a', {className:'nochange'});
				if (tab.className.match('current')) self.currentTab = index;
				var oldChange = typeof tab.onclick == 'function' ? tab.onclick : null;
				if (a.el && !FW(tab).hasClass('nochange')) {
					tab.onclick = function() { //li
						self.changeTab(index);
						if(oldChange) oldChange();
					};
					/*a.el.onclick = function() {
						tab.onclick();
						return false;
					};*/
				}
			});
			this.changeTab(self.currentTab);
		},
			
		changeTab : function(choosenIndex) {
			this.tabs.each(function(tab, index) {FW(tab).removeClass('current');});
			this.tabsContent.each(function(tab, index) {FW(tab).removeClass('tabCurrent');});
			FW(this.tabs[choosenIndex]).addClass('current');
			FW(this.tabsContent[choosenIndex]).addClass('tabCurrent');
			//log(this.tabsContent[choosenIndex])
		}
	}
);



/* FW.colResize */
FW.colResize = {
	colsId : ['main', 'rightCol'],
	colsIdInside : [], // tableau contenant les id des elements a l'interieur des colonnes si ceux-ci existent
	colsClassInside : ['', 'rightColInside'],
	colsInsidesByClass:[],
	timer : 40, // temps entre deux verifications de hauteur
	colsContainer : 'content',
	elementNeededToRun : '', //'rightColInside',
	cols : [], //colonnes existantes dans la page
	colsInside : [], //elements a l'interieur des colonnes
	lastHeights : [], //derniere hauteur du conteneur central qui a ï¿½tï¿½ enregistree, cela permet de gagner du temps dans la verification de la modification de la hauteur
	init : function() {
		var self = this;
//		if (this.elementNeededToRun!=null && this.elementNeededToRun!='' && FW(this.elementNeededToRun).el!=null) {
			this.colsContainer = document.getElementById(this.colsContainer); 
			if (!this.colsContainer) return;
			this.colsId.each(function(colId, i) {
				var col = colId!=null ? document.getElementById(colId) : null;
				self.cols.push(col);
				//self.colsInside.push(self.colsIdInside[i] ? document.getElementById(self.colsIdInside[i]) : null);
				self.colsInsidesByClass.push(self.colsClassInside[i]=='' ? null : FW(col).getElements({nodeName:'div', className:self.colsClassInside[i]}));
			});
			this.checker();		
			var timer = setInterval(function() {self.checker()},this.timer); 
//		}
	},
	checker : function() {

		if(this.resizing) return;
		if(this.cssIsDisabled())  return;
		var colsHeight = this.cols.map(function(col) {
			return col ? col.offsetHeight : 0;
		});
		if (this.lastHeights.join('')!=colsHeight.join('')) {
			this.resize();
			this.lastHeights=this.cols.map(function(col) {
				return col ? col.offsetHeight : 0;
			});
		}
	},
	resize : function() {	
		this.resizing = true;
		var self = this;
		this.cols.each(function(col, idx) {
			if (col) {
				var elm = self.colsInside[idx] || self.colsInsidesByClass[idx] || col;
				elm = elm instanceof Array ? elm : [elm];
				elm.each(function(elm) {
					elm.style[FW.heightStyle] = 0;
				});
			}
		});
		
		var containerHeight = self.colsContainer.scrollHeight;
		this.cols.each(function(col, idx) {
			if (col) {
				if (col.offsetHeight!=containerHeight) {
					self.resizeBlocks(self.colsInside[idx] || self.colsInsidesByClass[idx] || col, containerHeight-col.offsetHeight);
				}
			}
		});
		this.resizing = false;
	},
	resizeBlocks : function(blocks, sizeToAdd) {
		if (blocks.length==0) return;
		if (!(blocks instanceof Array)) blocks = [blocks];
		var size = parseInt(sizeToAdd/blocks.length,10);
		blocks.each(function(elm) {
			elm.style[FW.heightStyle] = elm.offsetHeight + size - (FW.ieQuirks ? 0 : FW(elm).getIntStyle('padding-bottom') + FW(elm).getIntStyle('padding-top'))  + 'px';
		});
		blocks[blocks.length-1].style[FW.heightStyle] = parseInt(blocks[blocks.length-1].style[FW.heightStyle] ,10) + (sizeToAdd%blocks.length) + 'px';
		if (FW.browser.ie6)
			blocks[blocks.length-1].style.zoom = 1;
	},
	cssIsDisabled : function() {
		if(!this.cssCheckElement) {
			this.cssCheckElement = document.createElement('span');
			document.body.appendChild(this.cssCheckElement);
			this.cssCheckElement.id = 'cssChecker'; 
			var s = this.cssCheckElement.style;
			s.backgroundColor  = 'red';
			s.height = 0;
			s.overflow = 'hidden';
		};
		return this.cssCheckElement.style.backgroundColor != 'red'
	}
};
FW(window).addEvent('load', function() {FW.colResize.init();})
/* tooltips */
FW.Module("toolTipsFeeder", 
	{nodeName:"a", className:"tips"}, 
	{
		initialize: function(elm){
			this.btn = elm;
			this.tips = document.getElementById("tips");
			if(!this.tips) return;
			this.tipsCtn = document.getElementById("tipsContainer");
			this.content = document.getElementById(this.btn.href.split("#")[1]).innerHTML; //  oneLiner propre et efficace...
			this.isOver = false;
			//if(FW('tips').el == null) this.generateTips();
			
			// If the Help system is disabled, we change the class to doubleDotted2 to remove the underlining
			if(!gbHelpSystemFlag && !this.btn.className.match(/tipsFixed/)) {
				this.btn.className = this.btn.className.replace(/doubleDotted/,'doubleDotted2');
				
				if(!this.btn.className.match(/second/)) {
					var loParent = this.btn.parentNode;
					// We put the same color as the parent element
					if(loParent.currentStyle) {
						// Solution for IE
						this.btn.style.color = loParent.currentStyle.color;
					} else if(document.defaultView) {
						// Solution for Firefox
						this.btn.style.color = document.defaultView.getComputedStyle(loParent, '').getPropertyValue("color");
					}
				}
			}
			
			if(!FW.tipsFX){
				//FW.tipsFX =  new simpleFX({target:this.tips, duration:500, fps:50, onComplete:function(){}});
			}
			
			FW(this.btn).addEvent('mouseover', function(obj) {
				return function (e){
					// mouseenter
					
					var lsClassName = obj.btn.className;
					// We show the help only if the help system is enabled
					// or if it is something which cannot be disabled (class=tipsFixed)
					if(gbHelpSystemFlag || (lsClassName.match(/tipsFixed/))) {
					
						if(!e) 
							e = window.event;
						
						if(obj.isOver) 
							return;
						
						obj.TO = setTimeout(function(obj){
								return function (){
									obj.getTips(e);
									obj.isOver =  true;
								}
							}(obj), 500);
					
					}
				}
			}(this))
			
			FW(this.btn).addEvent('mouseout', function(obj) {
				return function (e){
					if(obj.TO) {
						clearTimeout(obj.TO);
						obj.TO = null;
					}
					setTimeout(function(obj){
						return function (){
							obj.isOver = false;
							obj.letTips();
						}
					}(obj), 10);
				}
			}(this))
			FW(this.btn).addEvent('mousemove', function(obj) {
				return function (e){
					if(!e) e=window.event;
					obj.positionate(e);
					}
			}(this))
		},
		
		getTips : function (){
			this.tipsCtn.innerHTML = this.content;
			this.tips.style.visibility = "visible";
		},
		
		letTips : function (){
			this.tipsCtn.innerHTML = "";
			this.tips.style.visibility = "hidden";
		},
		
		positionate : function (evt){
			//for(a in evt) log(a+" = "+evt[a]);
			if(evt.pageX) this.cardinals = [evt.pageX, evt.pageY]; // w3c
			else this.cardinals = [evt.clientX + document.documentElement.scrollLeft, evt.clientY + document.documentElement.scrollTop]; //ie
			//log(this.cardinals)
			this.tips.style.left = this.cardinals[0] + (this.btn.offsetWidth+20) +  "px";
			this.tips.style.top = this.cardinals[1] - (this.btn.offsetHeight) -  0 + "px" //this.Y2set;
		},
		
		generateTips: function (){
			var html = "";
			html += '<div id="tips">';
			html += '<div class="header">&nbsp;</div>';
			html += '<div id="tipsContainer"></div>';
			html += '<div class="footer">&nbsp;</div>';
			document.body.innerHTML += html;
		},
		
		toggle : function (open){
			//if(FW.tipsFX.running) fx.stop();
			if(open){
				FW.tipsFX.start({height:100})
			}
			else {
				FW.tipsFX.start({height:20})
				this.tips.style.top = "-5000px";
				this.tips.style.left = "0";
			}	
		}
	});
// TODO prevoir checkbox multiple

var skeenForm = [];



FW.Module('skeenableForm',
	{nodeName:'form', className:'skeenable'},
	{
	initialize : function(form) {
			//return;
			skeenForm.push([form, this])
			
			this.form = form;
			this.radios = [];
			this.checkBox = [];
			this.sels = [];
			this.childs = this.form.getElementsByTagName('*');
			FW(form).addEvent('reset', function(obj) {return function (){
				obj.checkBox.each(function (elm){elm.reset();});
				obj.radios.each(function (elm){elm.reset();});
				
			}}(this))
			
			for(var i=0,elms=this.form.elements,l=elms.length;i<l;i++){
				if(!elms[i].className.match(/skeenable/) || elms[i].nodeName == "FIELDSET") continue;
				switch(elms[i].type){
					case "radio":
						// on execute un seul objet par groupe de radio
						if(this[elms[i].name]) break;
						this[elms[i].name] = true;
						//
						this.radios.push(new skeenableRadios(form[elms[i].name], this));
						break;
					case "checkbox":
						if(this[elms[i].name]) break;
						this[elms[i].name] = true;
						this.checkBox.push(new skeenableCheckboxes(form[elms[i].name], this));
						break;
					case "text":
						if(elms[i].className.match(/incrementialInput/)) new incrementialInput(elms[i], form);
						new skeenableInput(elms[i], this, false);
						break;
					case "submit":
					case "reset":
						new skeenableInput(elms[i], this, true); // idem case "text" avec resize en moins
						break;
					case "select":
					case "select-one":
					case "select-multiple":
						var group = elms[i].getAttribute('groupName');
						var obj;
						if(group && this[group]) {
							obj = new skeenableSelect(elms[i], this, i, this[group].length-1);
							this[group].push(obj)
						} 
						else if (group && !this[group]) {
							obj = new skeenableSelect(elms[i], this, i, 0);
							this[group] = [obj]
						
						} 
						else obj = new skeenableSelect(elms[i], this, i, null);
						this.sels.push(obj);
						break;
					case "textarea": 
						// a coder
						break;
				}
			}
			//this.closeAllSelect(document.body);
		},
	
	getLabel : function (input){ //gatsu powered
		var labs = this.form.getElementsByTagName('label');
		for(var i = 0 ; i < labs.length; i++){
			var theFor = labs[i].getAttribute('for') || labs[i].getAttribute('htmlFor');
			if(theFor == input.id) {
				return labs[i];
			}
		}
	},
	
	closeAllSelect : function (elm){
		for(var i = 0 ; i < this.sels.length; i++){
			if(this.sels[i].elm =! elm) this.sels[i].display(false);
		}
	},
	
	getFocusable: function (elm){ // spicy but good
		this.prev = "";
		this.aLastOne = false;
		for(var i=0,l=this.childs.length;i<l;i++){
			if(this.childs[i].nodeName.match(/\b(A|INPUT|TEXTAREA|SELECT)\b/)) {
				if(this.childs[i].nodeName == "A") continue;
				if(this.aLastOne) return [this.prev, this.childs[i]];
				if(this.childs[i] == elm) this.aLastOne = true;
				if(this.childs[i] != elm) this.prev = this.childs[i];
				
			}
		}
	},
	
	manageTabKey: function (give, obj){
		switch(give){
			case true:
				document.onkeydown = function (obj){
						return function (e){
							if (!e) e = window.event;
							if(e.keyCode == 9 && !e.shiftKey){ //tab
								obj.autoFocus = true;
								if(obj.focusableElms) obj.focusableElms[1].focus();
								return false;
							}
							if(e.keyCode == 9 && e.shiftKey){ //ctrl+tab
								obj.autoFocus = true;
								if(obj.focusableElms) obj.focusableElms[0].focus();
								return false;
							}
						}
					}(this);
				break;
			case false:
				document.onkeydown = null;
				break;
		}
	},
	
	reinitSelects : function (){
		for(var i=0; i<this.sels.length;i++){
			this.sels[i].reinit();
		}
	},
	
	reinitSelectGroup : function(groupName, index){
		for(var i=index+1,l=this[groupName].length;i<l;i++){
			this[groupName][i].select.setAttribute('disabled', 'disabled');
			this[groupName][i].select.selectedIndex = 0;
			this[groupName][i].display(false);
		}
	}
});

FW.Module('historyBack',
	{nodeName:'a', id:'back'},
	{
		initialize : function(elm) {
			//elm.onclick = function(){history.back();return false;};
		}
	}
);

//
FW.Module('cartManagerLaunch',
	{nodeName:'a', className:'buyPrd'},
	{
		initialize : function(elm) {
			FW(elm).addEvent('click', function (){
				layerMod2.openLayer('panier');
				
				return false;
				
			})
		}
	}
);
FW.capabilities = {};
FW.Module('capabilities',
	{nodeName:'div', id:'page'}, // body ...
	{
		initialize : function(elm) {
			// IMG
			var img = new Image();
			img.src = 'js/px.gif';
			var tmp = new Date();
			var suffix = tmp.getTime();
			FW.capabilities.gotIMG = false;
			img.onload = function (){FW.capabilities.gotIMG=true;}
			// CSS
			var div = document.createElement("div");
			div.style.width = "1000px";
			document.body.appendChild(div);
			FW.capabilities.gotCSS = div.offsetWidth == 1000 ? true : false;
			document.body.removeChild(div);
			// FLASH 
			FW.capabilities.gotSWF = true;
		}
	}
);
FW.Module('zoomer',
	{nodeName:'a', className:'zoomIt'},
	{
		initialize : function(elm) {
			var _self= this;
			//if(FW("layerPneu").el == null) document.body.innerHTML += '<div class="txtC VpaddingLg"><img src="" alt="..." id="layerPneu"/></div>';
			FW(elm).addEvent('click', function (){
				var me = FW(elm).el;
				layerMod.openLayer({template:'zoomLayer',content:'zoomContent',width:'700px',over:'mainStruct'});
				_self.TO = setInterval(function(){
							if(FW('layerPneu').el != null){
								FW('layerPneu').el.src = me.getAttribute('rel');
								clearInterval(_self.TO);
							}
					},25)
				
				
				return false;
				
			})
		}
	}
);

FW.Module('zoomer2',
	{nodeName:'a', className:'zoomIt2'},
	{
		initialize : function(elm) {
			var _self= this;
			this.a = elm;
			FW(this.a).addEvent('mouseover', function (){
				_self.TO = setInterval(function(){
							//document.body.innerHTML = "";
							if(document.getElementById('mediaImg').src != _self.a.getAttribute('rel')){
								document.getElementById('mediaImg').src = _self.a.getAttribute('rel');
							}
							else {
								clearInterval(_self.TO);							
							}
					},25)
			})
		}
	}
);
datePicker = null;
FW.Module('datePickin',
	{nodeName:'table', id:'calendar'},
	{
		initialize : function(elm) {
			datePicker = this;
			// gestion de la partie calendrier
			this.table = FW(elm);
			this.btns = this.table.getElements({nodeName:"a"});
			this.tds = this.table.getElements({nodeName:"td"});
			this.tds.each(function(obj){
				return function(el,i){
					if(el.className.match(/\bselected\b/g)) obj.current = el;
				}
			}(this))
			this.btns.each(function(obj){
				return function(el){
					el.onclick = function(){
						obj.selectDate(this);
						return false;
					}
				}
			}(this))
			// lecture de la date et settage des inputs
//			var txt = FW("calendarMonth").el.innerHTML;
//			var month = txt.replace(/[0-9 ]/g, "").toLowerCase();
//			FW("pickedMonth").el.value = month;
//			this.month = monthName.indexOf(month);
//			FW("pickedMonthInt").el.value = this.month;
//			this.year = txt.replace(/[a-zA-Z ]/g, "")
//			FW("pickedYear").el.value = this.year;
//			FW('pickedHour').el.value = "";
//			FW('pickedDayInt').el.value = this.current.innerText || this.current.textContent;
//			// gestion de la partie droite
			this.hourPick = FW("hourPicker");
			this.trs = this.hourPick.getElements({nodeName:"tr"});
			
			this.trs.each(function(obj){
				return function(el,i){
					if(el.className.match(/\lineGreen\b/g)) obj.currentHour = el;
					el.getElementsByTagName('td')[1].innerHTML += "<p>"+FW("customerName").el.value+"</p>";
				}
			}(this))
			this.as = this.hourPick.getElements({nodeName:"a"});
			this.as.each(function(obj){
				return function(el){
					el.onclick = function(){
						obj.selectHour(this);
						return false;
					}
				}
			}(this));
			this.enableBtn(false);
		},
		
		selectDate: function (elm){
			FW('pickedHour').el.value = "";
			if(this.current) FW(this.current).removeClass('selected');
			var td = elm.parentNode && elm.parentNode.nodeName == "TD" ? elm.parentNode : elm.parentNode.parentNode ;
			FW(td).addClass('selected');
			this.current = td;
			this.day = elm.childNodes[0].innerHTML;
			
			FW('pickedDayInt').el.value = this.day;
			var dateDay = new Date(this.year, this.month, this.day)
			FW('pickedDayName').el.value = dayName[dateDay.getDay()];
			this.refreshDate();
			/*
			code permettant de rafraichir la partier droite	
			*/
			if(!FW("hourPicker").el) return;
			var div = FW("hourPicker").el.parentNode;
			this.enableBtn(false);
			div.innerHTML = "<div class='loading'></div>";
			new Ajax({
				url : 'refreshCalendar.jsp?date='+this.year+'/'+this.month+'/'+this.day,
				onSuccess : function(xhr) {
					resizeCalendar(false);
					var txt = [
						'<p class="day"><span id="choosenDayName">',
						FW("pickedDayName").el.value,
						'</span>&nbsp;<span id="choosenDayDate">',
						FW("pickedDayInt").el.value,
						'</span></p>'						
					].join("");
					div.innerHTML = txt;
					div.innerHTML += xhr.responseText;
					resizeCalendar(true);
					setTimeout(function(){datePicker.initialize(datePicker.table.el)},25);
				},
				
				onError : function(xhr){
					// a anlever avant mis en prod
					this.onSuccess(xhr);
				}
			}).send();
			/* */
		},
		
		selectHour: function (elm){
			var tr = this.getTR(elm);
			var td = this.getTD(elm);
			FW(tr).addClass('lineGreen');
			if(FW(this.currentHour)) FW(this.currentHour).removeClass('lineGreen');
			this.currentHour = tr;
			//FW('pickedHour').el.value = tr.getElementsByTagName('td')[0].innerHTML;
			this.enableBtn(true);
			this.refreshDate();
		},
		
		refreshDate: function (){
			FW(this.getTD(FW('choosenDate').el)).removeClass(/invisible/);
			if( FW('choosenDate').el && FW("pickedDayName").el) {
				FW('choosenDate').el.innerHTML = FW("pickedDayName").el.value + " " +FW("pickedDayInt").el.value+ " " +FW("pickedMonth").el.value;
				if(FW('pickedHour').el.value != "") 
					FW('choosenHour').el.innerHTML = " " + FW("articleTrad").el.value + " " +FW("pickedHour").el.value
				else FW('choosenHour').el.innerHTML = "";
			}
		},
		
		enableBtn : function (bool){
			bool ? FW('choosePayment').removeClass('invisible') : FW('choosePayment').addClass('invisible');
		},
		
		getTR: function (elm){
			if(elm.nodeName == "TR") return elm
			else return this.getTR(elm.parentNode);
		},
		
		getTD: function (elm){
			if(elm.nodeName == "TD") return elm
			else return this.getTD(elm.parentNode);
		}
	}
);



FW.Module('diapo',
	{nodeName:'div', className:'diaporama'},
	{
		initialize : function(elm) {
			var _self = this;
			this.viewable = elm.className.match(/viewable_[0-9]*/);
			if(this.viewable != null) this.viewable = this.viewable[0].split("_")[1];
			else {this.viewable = 3}
			this.ul = FW(elm).getElements('ul')[0];
			this.lis = FW(elm).getElements('li');
			
			this.lis.each(function(el, i){
				var txt = el.lastChild.nodeType == 3 ? el.lastChild.previousSibling : el.lastChild;
				if(txt.className.match(/promoCtn/)){
					el.style.cursor = "pointer";
				} 
				var oldClick = el.onclick;
				el.onclick = function (){
					_self.displayPromoTxt(this, txt);
					if(typeof oldClick == "function") oldClick();
				}
			});
			
			this.size2apply = this.lis[0].offsetWidth+FW(this.lis[0]).getIntStyle('margin-right')+FW(this.lis[0]).getIntStyle('margin-left');
			this.ul.style.width = this.size2apply * (this.lis.length)  + "px";
			this.ctn = FW(elm).getElements('div')[0];
			this.promoCtn = FW("promoCtn").el;
			if(this.ctn)
				this.ctn.style.width = this.size2apply * this.viewable  + "px";
			if (this.promoCtn)
				this.promoCtn.style.width = (this.lis[0].offsetWidth + 10) * 3  + "px";
			this.as = FW(elm).getElements('a');
			this.as.each(function(el){
				if(el.className.match(/btnLeft/)) _self.btnLeft = el;
				if(el.className.match(/btnRight/)) _self.btnRight = el;
			})
			this.current = 1;
			if(this.ctn)
				this.ctn.scrollLeft = 0;
			this.maxScroll = this.ctn.scrollWidth - this.ctn.offsetWidth;
			FW(this.btnLeft).addEvent("click", function(obj){
				return function (){
					obj.scroll(-1);
					return false;
				}
			}(this))
			FW(this.btnRight).addEvent("click", function(obj){
				return function (){
					obj.scroll(1);
					return false;
				}
			}(this))
			
		},
		
		displayPromoTxt: function (elm, ctn){
			if(ctn && !ctn.className.match(/promoCtn/)) return;
			if(!elm) return;
			//ctn.style.display = "block";
			elm.className += " hilighted";
			if(this.oldElm){
				this.oldElm.className = this.oldElm.className.replace(/hilighted/, ""); 
				this.oldCtn.style.display = "";
			
			}
			var txt = elm.lastChild.nodeType == 3 ? elm.lastChild.previousSibling : elm.lastChild;
			this.currentPromo = txt;
			this.oldElm = elm;
			this.oldCtn = ctn;
			if(!txt.className.match(/promoCtn/)){
				this.promoCtn.innerHTML = "";
			}else {
				txt.display = 'none';
				this.promoCtn.innerHTML = txt.innerHTML;
			}
		},
		
		setCurrent : function (sens){
			this.current += sens;
			if(this.current < 0) this.current = 0;
			if(this.current > this.lis.length-1) this.current =  this.lis.length-1;
		},
		
		scroll: function (sens){
			this.displayPromoTxt();
			this.setCurrent(sens);
			if(!this.TO){
				this.conf = {};
				this.conf.endVal = this.ctn.scrollLeft + (this.size2apply * sens);
			}
			else {
				clearInterval(this.TO);
				this.conf.endVal += (this.size2apply * sens);
			}
			this.conf.startTime = new Date().getTime();
			this.conf.startVal = this.ctn.scrollLeft;
			this.conf.step = (this.conf.endVal - this.conf.startVal) / 500;
			this.engine();
			
				//suppression au clic de la classe permettant de mettre en retrait certaines promotions
			if (this.ul.className.match(/\bdownlighted\b/)) this.ul.className = '';
		},
		
		engine : function (){
			this.TO = setInterval(
				function(obj){
					return function (){
						var currentTime = new Date().getTime();
						obj.ctn.scrollLeft = obj.conf.startVal + (currentTime-obj.conf.startTime) * obj.conf.step;
						if( currentTime >= obj.conf.startTime + 500 ) {
							clearInterval(obj.TO);
							obj.TO = null;
							obj.ctn.scrollLeft = obj.conf.endVal;
							obj.check();
						}
					}
				}(this)
			,40);			
		},
		
		check: function (){
			if(this.ctn.scrollLeft < this.size2apply){
				this.ctn.scrollLeft = 0;
				this.btnLeft.className += " inactive";
				this.btnRight.className = this.btnRight.className.replace(/inactive/g, "");
			}
			else if(this.maxScroll - this.ctn.scrollLeft < this.size2apply) {
				this.ctn.scrollLeft = this.ctn.scrollWidth;
				this.btnRight.className += " inactive";
				this.btnLeft.className = this.btnLeft.className.replace(/inactive/g, "");
			}
			else {
				this.btnLeft.className = this.btnLeft.className.replace(/inactive/g, "");
				this.btnRight.className = this.btnRight.className.replace(/inactive/g, "");
			}
			
			
		}
	}
);
FW.Module("toolTipsFeederLight", 
		{nodeName:"a", className:"tipsLight"}, 
		{
			initialize: function(elm){
				this.btn = elm;
				this.tips = document.getElementById("tips");
				if(!this.tips) return;
				//console.log(this.btn);
				this.tipsCtn = document.getElementById("tipsContainer");
				this.content = [
					'<div id="tipsContainer">',
					'<div class="block blockSimple gradientToolTip">',
					'<div class="blockInside">',
					'<div class="body padding"><h4>'+this.btn.title+'</h4></div>',
					'</div></div></div>'
					].join("");
				this.btn.title = null;
				this.isOver = false;
				//if(FW('tips').el == null) this.generateTips();
				
				if(!FW.tipsFX){
					//FW.tipsFX =  new simpleFX({target:this.tips, duration:500, fps:50, onComplete:function(){}});
				}
				FW(this.btn).addEvent('mouseover', function(obj) {
					return function (e){
						// mouseenter
						if(!e) e = window.event;
						if(obj.isOver) return;
						obj.TO = setTimeout(function(obj){
							return function (){
								obj.getTips(e);
								obj.isOver =  true;
								return false;
							}
						}(obj), 100);
						
					}
				}(this))
				
				FW(this.btn).addEvent('mouseout', function(obj) {
					return function (e){
						if(obj.TO) {
							clearTimeout(obj.TO);
							obj.TO = null;
						}
						setTimeout(function(obj){
							return function (){
								obj.isOver = false;
								obj.letTips();
							}
						}(obj), 10);
					}
				}(this))
				FW(this.btn).addEvent('mousemove', function(obj) {
					return function (e){
						if(!e) e=window.event;
						obj.positionate(e);
						}
				}(this))
			},
			
			getTips : function (){
				this.tipsCtn.innerHTML = this.content;
				this.tips.style.visibility = "visible";
			},
			
			letTips : function (){
				this.tipsCtn.innerHTML = "";
				this.tips.style.visibility = "hidden";
			},
			
			positionate : function (evt){
				//for(a in evt) log(a+" = "+evt[a]);
				if(evt.pageX) this.cardinals = [evt.pageX, evt.pageY]; // w3c
				else this.cardinals = [evt.clientX + document.documentElement.scrollLeft, evt.clientY + document.documentElement.scrollTop]; //ie
				//log(this.cardinals)
				this.tips.style.left = this.cardinals[0] + (this.btn.offsetWidth+20) +  "px";
				this.tips.style.top = this.cardinals[1] - (this.btn.offsetHeight) -  0 + "px" //this.Y2set;
			},
			
			generateTips: function (){
				var html = "";
				html += '<div id="tips">';
				html += '<div class="header">&nbsp;</div>';
				html += '<div id="tipsContainer"></div>';
				html += '<div class="footer">&nbsp;</div>';
				document.body.innerHTML += html;
			},
			
			toggle : function (open){
				//if(FW.tipsFX.running) fx.stop();
				if(open){
					FW.tipsFX.start({height:100})
				}
				else {
					FW.tipsFX.start({height:20})
					this.tips.style.top = "-5000px";
					this.tips.style.left = "0";
				}	
			}
		});
FW.Module('move2main',
		{nodeName:'p', className:'move2main'},
		{
			initialize : function(elm) {
				var frag = document.createDocumentFragment();
				frag.appendChild(elm);
				FW('main').el.appendChild(frag)
			}
		}
	);

/*
mettre une classe "globalClick" sur un "a" enfant d'un "unit"
permettra que tous le "unit" soit cliquable,
si le "a" a un attribut "target='_blank'" alors on utilise window.open

sur firefox, le code ouvrira un onglet,
sur ie le code ouvrira une popup

si on precise une taille à la popup, firefox ouvre une popup et non un onglet  

*/


FW.Module('unitClickable',
	{nodeName:'a', className:'globalClick'},
	{
		initialize: function (elm){
		
			this.a = elm;
	        var unit = this.getUNIT(elm);
	        
	        
	        if(!unit) return;
				this.unit = FW(unit);
	        this.unit.el.style.cursor = "pointer";

	        this.unit.addEvent("click", function (oSelf){
				return function () {
		             oSelf.action(oSelf.a.href);
		             return false;
				}
			}(this))
		},
     
     action : function(url){
         if(this.a.target == "_blank"){
             window.open(url, "")
         }
         else {
             document.location.href = url;
             }
     },
		
		getUNIT : function (elm){
			if(elm.className.match(/unitGB/)) return elm
			else return this.getUNIT(elm.parentNode);
		}
	});