function in_array(search, myArray) {
	
	if(myArray.length < 1)
		return false;
		
		
	for(var i = 0; i < myArray.length; i++) {
		
		if(myArray[i] == search) 
			return true;	
	}

	return false;
}

function array_diff(tab1, tab2) {
	
	var tabDiff = new Array();
		
	for(var i = 0; i < tab2.length; i++) {
		
		if(in_array(tab2[i] , tab1) == false)
			tabDiff[tabDiff.length] = tab2[i];
	} 
	
	return tabDiff;
}


function checkNumeric(element) {

	myValue = element.value;
	
	var newValue = '';
	myValue.scan(/[0-9]{1}/, function(match) { newValue += match[0];  } );

	return newValue;
}





var Radio = Class.create();

Radio.prototype = {
	
	initialize: function(idGroupe , nb) {
		
		this.idGroupe = idGroupe;
		this.nb = nb;
		
		this.precision = new Array();
		this.precisionCache = new Array();
		
		this.setObserver();
	},
	setObserver: function() {
		
		var _this = this;
		
		for(var i = 1; i <= this.nb; i++) {	
		
			var myElement = $(this.idGroupe + '_' + i);
			
			myElement.observe('click' , function(event) { 
					var myEl = Event.element(event);
					_this.check(myEl); 
 			} );
		}	
	},
	check: function(element) {

		var valueElement = element.value;
		
		for(var i = 0; i < this.precision.length; i++) {
			this.updatePreciser(this.precision[i]);
		}

		
	},
	
	setPrecision: function(numero) {
		
		var _this = this;
		
		for(var j = 0; j < this.setPrecision.arguments.length; j++) {
			
			var numero = this.setPrecision.arguments[j];
			var inputPrecision = $(this.idGroupe + '_' + numero + '_Pr');
			
			if(inputPrecision) {
				this.precision[this.precision.length] = numero;
				
				inputPrecision.observe('keyup' , function(event) { 
						var myEl = Event.element(event);
						_this.checkPrecision(myEl); 
	 			} );		
				inputPrecision.observe('change' , function(event) { 
						var myEl = Event.element(event);
						_this.checkPrecision(myEl); 
	 			} );
				inputPrecision.observe('click' , function(event) { 
						var myEl = Event.element(event);
						_this.checkPrecision(myEl); 
	 			} );				
			}	
		}
	},

	checkPrecision: function(element) {
		
		var boxPrecisionId = element.id;
		var boxId = boxPrecisionId.substring(0 , boxPrecisionId.length - 3);		

		var box = $(boxId);
		var boxPrecision = $(boxPrecisionId);
		
		if(boxPrecision.value != '') {			
			box.checked = true;
			this.check(box);			
		}  
		
	},
	updatePreciser: function(numElement) {
		
		var i = numElement;
		var box = $(this.idGroupe + '_' + i);
		var boxPrecision = $(this.idGroupe + '_' + i + '_Pr');
		
		if(boxPrecision) {
					
			if(box.checked == true && boxPrecision.value == '' && this.precisionCache[numElement] != undefined ) 
				boxPrecision.value = this.precisionCache[numElement];
				
			else if(box.checked == false && boxPrecision.value != '') {
					this.precisionCache[numElement] = boxPrecision.value;
					boxPrecision.value = '';
			}
			
			if(box.checked == true)
				Form.Element.focus(boxPrecision);
		}
	}
}



var Checkbox = Class.create();

Checkbox.prototype = {
	
	initialize: function(idGroupe , nb) {
		
		this.idGroupe = idGroupe;
		this.nb = nb;
		this.choixMax = false;
		
		
		this.precision = new Array();
		this.precisionCache = new Array();
		
		this.inverses = new Array();
		
		this.setObserver();
	},
	setObserver: function() {
		
		var _this = this;
		
		for(var i = 1; i <= this.nb; i++) {	
		
			var myElement = $(this.idGroupe + '_' + i);
			
			myElement.observe('click' , function(event) { 
					var myEl = Event.element(event);
					_this.check(myEl); 
 			} );
 			myElement.observe('change' , function(event) { 
					var myEl = Event.element(event);
					_this.check(myEl); 
 			} );
		}		
	},
	setPrecision: function(numero) {
		
		var _this = this;
		
		for(var j = 0; j < this.setPrecision.arguments.length; j++) {
			
			var numero = this.setPrecision.arguments[j];
			var inputPrecision = $(this.idGroupe + '_' + numero + '_Pr');
			
			if(inputPrecision) {
				
				this.precision[this.precision.length] = numero;
				
				inputPrecision.observe('keyup' , function(event) { 
						var myEl = Event.element(event);
						_this.checkPrecision(myEl); 
	 			} );		
				inputPrecision.observe('change' , function(event) { 
						var myEl = Event.element(event);
						_this.checkPrecision(myEl); 
	 			} );
				inputPrecision.observe('click' , function(event) { 
						var myEl = Event.element(event);
						_this.checkPrecision(myEl); 
	 			} );				
			}	
		}
	},
	setInverse: function(groupe1 , groupe2) {
		
		var myGroupe1 = new Array();
		var myGroupe2 = new Array();
		

		if(groupe2 == false) {
			
			for(var i = 1; i <= this.nb; i++) {
			
				if(in_array(i , groupe1) == false)
					myGroupe2[myGroupe2.length] = i;
			}
		
		
		} else
			myGroupe2 = groupe2;
			
		
		myGroupe1 = groupe1;
	
		var indiceCourant = this.inverses.length;
				
		this.inverses[indiceCourant] = new Array();
		this.inverses[indiceCourant]['c'] = myGroupe1;
		this.inverses[indiceCourant]['i'] = myGroupe2;
	},
	setMax: function(max) {
	
		this.choixMax = max;
	},
	check: function(element) {
		
		var numModalite = element.id.split('_');
			numModalite = numModalite[1];
	
		if(this.choixMax != false) {
			
			var nbChecked = 0;
			
			for(var j = 1; j <= this.nb; j++) {
				if($(this.idGroupe + '_' + j).checked == true) 
					nbChecked++;
			}
			
			if(nbChecked >  this.choixMax) {
				$(this.idGroupe + '_' + numModalite).checked = false;
				return;
			}
		}
						
		if(in_array(numModalite, this.precision) == true)
			this.updatePreciser(numModalite);
		
		if(	$(this.idGroupe + '_' + numModalite).checked == true) {
			
			for(var i = 0; i < this.inverses.length; i++) {
		
				if(in_array(numModalite, this.inverses[i]['c'])) 
					this.deselectGroupe(this.inverses[i]['i']);
				else if(in_array(numModalite, this.inverses[i]['i'])) 
					this.deselectGroupe(this.inverses[i]['c']);				
				
			}
		}
	},
	deselectGroupe: function(groupe) {
				
		for(var i = 0; i < groupe.length; i++) {
			$(this.idGroupe + '_' + groupe[i]).checked = false;
			this.check($(this.idGroupe + '_' + groupe[i]));
		}				
	
	},
	checkPrecision: function(element) {
		
		var boxPrecisionId = element.id;
		var boxId = boxPrecisionId.substring(0 , boxPrecisionId.length - 3);		

		var box = $(boxId);
		var boxPrecision = $(boxPrecisionId);
		
		if(boxPrecision.value != '') {			
			box.checked = true;
			this.check(box);			
		}  
		
	},
	updatePreciser: function(numElement) {
		
		var i = numElement;
		var box = $(this.idGroupe + '_' + i);
		var boxPrecision = $(this.idGroupe + '_' + i + '_Pr');
		
		if(boxPrecision) {
					
			if(box.checked == true && boxPrecision.value == '' && this.precisionCache[numElement] != undefined ) {
				boxPrecision.value = this.precisionCache[numElement];
			}
			else if(box.checked == false && boxPrecision.value != '') {
			
					this.precisionCache[numElement] = boxPrecision.value;
					boxPrecision.value = '';
			}
			
			if(box.checked == true)
				Form.Element.focus(boxPrecision);
		}
	}
}


var SelectMultiple = Class.create();

SelectMultiple.prototype = {
	
	initialize: function(idGroupe , nb) {
		
		this.idGroupe = idGroupe;
		this.nb = nb;
		this.choixMax = false;
		this.selected = new Array();
		
		this.setObserver();
	},
	setObserver: function() {
		
		var _this = this;
		
		var myElement = $(this.idGroupe);

 		myElement.observe('change' , function() { 
				_this.check(); 
 		});
	},
	setMax: function(max) {
		this.choixMax = max;
	},
	check: function() {
		
		var currentElements = new Array();
	
		for(var i = 1; i <= this.nb; i++) {
			
			if($(this.idGroupe + '_' + i).selected == true) {
			
				currentElements[currentElements.length] = i;	
			}
			else if(this.selected.indexOf(i) != -1)
					this.selected = this.selected.without(i);
				
		}
		
		var nouveaux = array_diff(this.selected, currentElements);
				
		if(this.choixMax != false && (this.selected.length + nouveaux.length) > this.choixMax) {
			
			var exces = (this.selected.length + nouveaux.length) - this.choixMax ;
			var temp_nouveaux = nouveaux;

			for(var i = 0; i < exces; i++) {
				
				$(this.idGroupe + '_' + nouveaux[i]).selected = false;
				temp_nouveaux = temp_nouveaux.without(nouveaux[i]);
			}
			nouveaux = temp_nouveaux;
		}
		
		for(var j = 0; j < nouveaux.length; j++) 
			this.selected[this.selected.length] = nouveaux[j];	
		
	}
}







 
var Classement_Saisie = Class.create();

Classement_Saisie.prototype = {
	
	initialize: function(idGroupe , nb) {
		
		this.idGroupe = idGroupe;
		this.nb = nb;
		this.max = this.nb;
		
		this.setObserver();
		
		this.valeurs = new Array();
		
		for(var i = 1; i <= this.nb; i++) 
			this.valeurs[i] = $(this.idGroupe + '_' + i).value;
		
		
	},
	setMax: function(maximum) {
	
		this.max = maximum;
	},
	setObserver: function() {
		
		var _this = this;
		
		for(var i = 1; i <= this.nb; i++) {
			
			var myElement = $(this.idGroupe + '_' + i);
			
			myElement.observe('keyup' , function(event) { 
						var myEl = Event.element(event);
						_this.checkElement(myEl);
				 } );
			myElement.observe('change' , function(event) { 
						var myEl = Event.element(event);
						_this.checkElement(myEl);
				 } );		
		}
	},
	checkElement: function(myElement) {
	
		newValue = checkNumeric(myElement);

		if(newValue != '' && (parseInt(newValue) < 1 || parseInt(newValue) > this.max) )
				newValue = '';

		if(newValue != '' && !this.checkDoublon(myElement)) {
			newValue = '';
		}
		
		myElement.value =  newValue;
	},
	checkDoublon: function(element) {
		
		for(var i = 1; i <= this.nb; i++) {
			
			var myElement = $(this.idGroupe + '_' + i);
			if(myElement.id == element.id) continue;
				
			if(myElement.value == element.value) 
				return false;
		
		}
	
		return true;	
	},
	getInputByValue: function(myValue) {
	
		for(var i = 1; i <= this.nb; i++) {
			
			var myElement = $(this.idGroupe + '_' + i);
			
			if(myElement.value == myValue) 
				return myElement;		

		}		
	
		return false;
	}
}	

var Classement_Select = Class.create();

Classement_Select.prototype = {
	
	initialize: function(idGroupe , nb) {
		
		this.idGroupe = idGroupe;
		this.nb = nb;
		this.max = this.nb;
		
		this.setObserver();
		
	},
	setMax: function(maximum) {
		this.max = maximum;
	},
	setObserver: function() {
		
		var _this = this;
	
		for(var i = 1; i <= this.nb; i++) {
			
			var myElement = $(this.idGroupe + '_' + i);
			
			myElement.observe('change' , function(event) { 
						var myEl = Event.element(event);
						_this.checkElement(myEl);
			} );		
		}
	},
	initialiseElement: function() {
	
		for(var i = 1; i <= this.nb; i++) {
			
			var currentSelect = $(this.idGroupe + '_' + i);
		
			if(currentSelect.value != '')
				this.checkElement(currentSelect);
		}
		
	},
	checkElement: function(myElement) {
	
		newValue = myElement.value;


		if(newValue != '')
			this.chooseOption(myElement , newValue);
		
		for(var i = 1; i <= this.max; i++) {
			
			if(!this.isSelected(i))
				this.restoreOption(i);		
		}
		
		return true;
	},
	chooseOption: function(select , option) {
		
		for(var i = 1; i <= this.nb; i++) {
			
			var currentSelect = $(this.idGroupe + '_' + i);
			
			if(currentSelect.id == select.id)
				continue;
				
			this.removeOption(currentSelect , option);
		}
	
		return true;
	
	},
	restoreOption: function(option) {
		
		for(var i = 1; i <= this.nb; i++) {
			
			var currentSelect = $(this.idGroupe + '_' + i);
			
			if(!this.inSelect(currentSelect , option))
				this.addOption(currentSelect , option);
		
		}
		
		return true;		
	},
	removeOption: function(select , value) {
		
		if(this.inSelect(select , value)) {
		
			var options = select.childNodes;
			
			for(var i = 0; i < 	options.length; i++) {
			
				if(options[i].value == value) {
					select.removeChild(options[i])
					break;
				}
			}				
		}	
	
		return true;
	},
	addOption: function(select , value) {
	
		var myOption = document.createElement('option');
			myOption.setAttribute('value' , value);
			
		var texte = document.createTextNode(value);
			myOption.appendChild(texte);
			
		var listeOptions = select.childNodes;
		var insert = false;
		
		for(var i = 0; i < listeOptions.length ; i++) {
		
			if(listeOptions[i].value > value) {
				select.insertBefore(myOption , listeOptions[i]);
				insert = true;
				break;
			} 
		}
		
		if(!insert) 
			select.appendChild(myOption);			
		
		return true;
	},
	isSelected: function(option) {
	
		for(var i = 1; i <= this.nb; i++) {
			
			var currentSelect = $(this.idGroupe + '_' + i);
			
			if(currentSelect.value == option) 
				return true;
		}
		
		return false;		
		
	},	
	inSelect: function(select , myOption) {
	
		var options = select.childNodes;
		
		for(var i = 0; i < options.length; i++) {
			
			if(options[i].value ==  myOption)
				return true;	
		}		
		
		return false;
	}
}	



var Matrice_Radio = Class.create();

Matrice_Radio.prototype = {
	
	initialize: function(idGroupe , nbEchelles, nbModalites, classHoover, classChecked) {
		
		this.idGroupe = idGroupe;
		this.nbEchelles = nbEchelles;
		this.nbModalites = nbModalites;
		this.classHoover = classHoover;
		this.classChecked = classChecked;
		
					
		this.setObserver();
		
	},
	
	setObserver: function() {
	
		var _this = this;
		
		for(var i = 1; i <= this.nbModalites; i++) {
			
			for(var j = 1; j <= this.nbEchelles; j++) {
				
				var myCell = $(this.idGroupe + 'M' + i + '_' + j);
				var parentCell = myCell.parentNode;
				
				if(this.classHoover) {
					Element.observe(parentCell, 'mouseover' , function(event) { 
								var myEl = Event.findElement(event , 'TD');
								_this.onMouse(myEl);
					} );
		
					Element.observe(parentCell, 'mouseout' , function(event) { 
								var myEl = Event.findElement(event , 'TD');
								_this.outMouse(myEl);
					} );
				}
				
				
				Element.observe(parentCell, 'click' , function(event) { 
							
							if(Event.element(event).tagName == 'INPUT' && Event.element(event).type && Event.element(event).type == "text")
								return false;
							
							var myEl = Event.findElement(event , 'TD');
							_this.clickMouse(myEl);
				} );											
			}
		
		}
		
		return true;	
	},
	onMouse: function(element) {
	
		Element.addClassName(element , this.classHoover);

		return true;
	},
	outMouse: function(element) {
		
		Element.removeClassName(element , this.classHoover);
		
		return true;
	},
	clickMouse: function(element) {
		
		var myRadio = element.getElementsByTagName('INPUT')[0];
		
		myRadio.checked = true;
		
		if(this.classChecked) {
			this.updateModaliteStyle(element);
			Element.addClassName(element , this.classChecked);		
		}
		Form.Element.focus(myRadio);
		return true;		
	},
	updateModaliteStyle: function(element) {
		
		
		var myInput = Element.select(element , 'input')[0];
		 
		var myId = myInput.readAttribute('id');
		var tampon = myId.substring(0, myId.lastIndexOf('_'));
		var numLigne = tampon.substring(tampon.lastIndexOf('M')+1 );
		
		
		for(var i = 1; i <= this.nbEchelles; i++) {
		
			var myCell = $(this.idGroupe + 'M' + numLigne + '_' + i);
			var parentCell = myCell.parentNode;
				
				
			if(Element.hasClassName(parentCell , this.classChecked))
				Element.removeClassName(parentCell , this.classChecked);
				
				
		}

		return true;		
	},
	setDefaut: function(valeurs) {
	
		if(this.classChecked) {
		
			for(var i = 0; i < this.setDefaut.arguments.length; i++) {
			
				var myArg = this.setDefaut.arguments[i];
				var myRadio = $(this.idGroupe + 'M' + myArg[0] + '_' + myArg[1]);
				var myCell = myRadio.parentNode;
				
				Element.addClassName(myCell , this.classChecked);
			}
		}
	}


}










var Matrice_Checkbox = Class.create();

Matrice_Checkbox.prototype = {
	
	initialize: function(idGroupe , nbEchelles, nbModalites, classHoover, classChecked) {
		
		this.idGroupe = idGroupe;
		this.nbEchelles = nbEchelles;
		this.nbModalites = nbModalites;
		this.classHoover = classHoover;
		this.classChecked = classChecked;
		
					
		this.setObserver();
		
	},
	
	setObserver: function() {
	
		var _this = this;
		
		for(var i = 1; i <= this.nbModalites; i++) {
			
			for(var j = 1; j <= this.nbEchelles; j++) {
				
				var myCell = $(this.idGroupe + 'M' + i + '_' + j);
				var parentCell = myCell.parentNode;
				
				if(this.classHoover) {
					Element.observe(parentCell, 'mouseover' , function(event) { 
								var myEl = Event.findElement(event , 'TD');
								_this.onMouse(myEl);
					} );
		
					Element.observe(parentCell, 'mouseout' , function(event) { 
								var myEl = Event.findElement(event , 'TD');
								_this.outMouse(myEl);
					} );
				}
				
				
				Element.observe(parentCell, 'click' , function(event) { 
							_this.clickMouse(event);
							
				} );											
			}
		
		}
		
		return true;	
	},
	onMouse: function(element) {
	
		Element.addClassName(element , this.classHoover);

		return true;
	},
	outMouse: function(element) {
		
		Element.removeClassName(element , this.classHoover);
		
		return true;
	},
	clickMouse: function(event) {
		
		var element = Event.findElement(event , 'TD');
		var tagElement = Event.element(event).tagName;
		
		var myCheckbox= element.getElementsByTagName('INPUT')[0];
							
		if(tagElement == 'TD') {

			if(!myCheckbox.checked) {
				myCheckbox.checked = true;
				Element.addClassName(element , this.classChecked);
			}
			else {
				myCheckbox.checked = false;
				Element.removeClassName(element , this.classChecked);
			}		
		
		
		} else {
		
			var myCheckbox= element.getElementsByTagName('INPUT')[0];
			
			if(myCheckbox.checked) {
				myCheckbox.checked = true;
				Element.addClassName(element , this.classChecked);
			}
			else {
				myCheckbox.checked = false;
				Element.removeClassName(element , this.classChecked);
			}		
		}
		
		return true;		
	},
	updateModaliteStyle: function(element) {
		
		var myTr = element.parentNode;
		var listeTd = Element.immediateDescendants(myTr);
		
		for(var i = 0; i < listeTd.length; i++) {
		
			if(Element.hasClassName(listeTd[i] , this.classChecked) && element.checked == false)
				Element.removeClassName(listeTd[i] , this.classChecked);
		}
		
		return true;		
	},
	setDefaut: function(valeurs) {
	
		if(this.classChecked) {
		
			for(var i = 0; i < this.setDefaut.arguments.length; i++) {
			
				var myArg = this.setDefaut.arguments[i];
				
				for(var z = 0; z < myArg[1].length; z++) {
				
					var myCheckbox = $(this.idGroupe + 'M' + myArg[0] + '_' + myArg[1][z]);
					var myCell = myCheckbox.parentNode;
					Element.addClassName(myCell , this.classChecked);
				}

				
			}
		}
		
	}


}




var Numerique = Class.create();

Numerique.prototype = {
	
	initialize: function(idInput) {
		
		this.input = $(idInput);

		this.setObserver();
	},
	setObserver: function() {
		
		var _this = this;
		
		Element.observe(this.input , 'keyup', function() {
			_this.input.value = checkNumeric(_this.input);
		});
		
		Element.observe(this.input , 'keypress', function() {
			_this.input.value = checkNumeric(_this.input);
		});
		
		Element.observe(this.input , 'change', function() {
			_this.input.value = checkNumeric(_this.input);
		});
		
		
		
	},
	setMin: function(value) {

		
	},
	
	setMax: function(value) {

		
	}
}








var Repartition = Class.create();

Repartition.prototype = {
	
	initialize: function(idGroupe , nb, total) {
	
		this.idGroupe = idGroupe;
		this.nb = nb;
		this.min = false;
		this.max = false;	
		this.showTotal = total;
	
		this.setObserver();
		
		if(this.showTotal)
			this.calculerTotal();
	},
	setObserver: function() {
	
	
		var _this = this;
		
		for(var i= 1; i <= this.nb; i++) {
		
			var idModalite = this.idGroupe + '_' + i;
			
			
			new Element.observe($(idModalite) , 'keyup', function(event) {

				var myEl = Event.findElement(event , 'INPUT');
				_this.checkSaisie(myEl);
				
			});
			
			new Element.observe($(idModalite) , 'keypress', function(event) {

				var myEl = Event.findElement(event , 'INPUT');
				_this.checkSaisie(myEl);
				
			});
			
			new Element.observe($(idModalite) , 'change', function(event) {
				
				var myEl = Event.findElement(event , 'INPUT');
				_this.checkSaisie(myEl);
				
				
			});			
							
		}
	
		
	},
	checkSaisie: function(myEl) {
		
		if(myEl.value == "0") return;
		
		myEl.value = checkNumeric(myEl);
		
		if(this.showTotal)
			this.calculerTotal();
	
		return;
	},
	calculerTotal: function() {
	
		var total = 0;
		
		for(var i= 1; i <= this.nb; i++) {
		
			if($(this.idGroupe + '_' + i).value != '')
				total += parseInt($(this.idGroupe + '_' + i).value);
						
		}	
			
		$(this.idGroupe + '_total').innerHTML = total + '%';
		
		if(this.min && total < this.min) 
			$(this.idGroupe + '_total').addClassName('erreur');
		else if(this.max && total > this.max)
				$(this.idGroupe + '_total').addClassName('erreur');
		     else
		     	$(this.idGroupe + '_total').removeClassName('erreur');
		     	
		  return true;
	},
	setMin: function(valeur) {
	
		this.min = valeur;
	
		return true;
	},
	setMax: function(valeur) {
	
		this.max = valeur;

		return true;	
	}
	
}

















var Matrice_UniqueMultiple = Class.create();

Matrice_UniqueMultiple.prototype = {
	
	initialize: function(idGroupe , nbModalites, classHoover, classChecked) {
		
		this.idGroupe = idGroupe;
		this.nbModalites = nbModalites;
		this.classHoover = classHoover;
		this.classChecked = classChecked;
		
					
		this.setObserver();
		
	},
	
	setObserver: function() {
	
		this.unique =  new Matrice_Radio(this.idGroupe + '_1' , this.nbModalites, 1, this.classHoover, this.classChecked);
		this.multiple =  new Matrice_Checkbox(this.idGroupe + '_2' ,this.nbModalites, 1,  this.classHoover, this.classChecked);
		this.multiple =  new Matrice_Checkbox(this.idGroupe + '_3' ,this.nbModalites, 1,  this.classHoover, this.classChecked);
	
		
		/*
		for(var i = 1; i <= this.nbModalites; i++) {
			
			idModalite = this.idGroupe + '_1M1_'+ i;
			
			
			new Element.observe($(idModalite) , 'change', function(event) {
				
				var myEl = Event.findElement(event , 'INPUT');
				_this.checkSaisie(myEl);
				
				
			});			
		
		}
		*/
		
		return true;	
	},
	/*
	checkerSpecifique: function() {
		
		
		for(var i = 1; var i <= this.nbModalites; i++) {
		
			if(
		
		
		
		
		
		
		}
		
		
		
		var element = this.idGroupe + '_1M1_'+numModalite;
		
		
		if($(element).checked == true) {
			
			$(this.idGroupe + '_1M2_'+numModalite).checked = false;
			$(this.idGroupe + '_1M3_'+numModalite).checked = false;
			
		}
		
		return true;
	},
	
	*/
	
	setUniqueDefaut: function(valeur) {
	
		this.unique.setDefaut(valeur);
	
	},
	
	setMultipleDefaut: function(valeur) {
	
		this.multiple.setDefaut(valeur);
	
	}

}





var Matrice_Radio_Echelle = Class.create();

Matrice_Radio_Echelle.prototype = {
	
	initialize: function(idGroupe , nbEchelles, nbModalites, classHoover, classChecked) {
		
		this.idGroupe = idGroupe;
		this.nbEchelles = nbEchelles;
		this.nbModalites = nbModalites;
		this.classHoover = classHoover;
		this.classChecked = classChecked;
		
					
		this.setObserver();
		
	},
	
	setObserver: function() {
	
		var _this = this;
		
		for(var i = 1; i <= this.nbModalites; i++) {
			
			for(var j = 1; j <= this.nbEchelles; j++) {
				
				var myCell = $(this.idGroupe + 'M' + i + '_' + j);
				var parentCell = myCell.parentNode;
				
				if(this.classHoover) {
					Element.observe(parentCell, 'mouseover' , function(event) { 
								var myEl = Event.findElement(event , 'TD');
								_this.onMouse(myEl);
					} );
		
					Element.observe(parentCell, 'mouseout' , function(event) { 
								var myEl = Event.findElement(event , 'TD');
								_this.outMouse(myEl);
					} );
				}
				
				
				Element.observe(parentCell, 'click' , function(event) { 
							var myEl = Event.findElement(event , 'TD');
							_this.clickMouse(myEl);
				} );											
			}
		
		}
		
		return true;	
	},
	onMouse: function(element) {
	
		Element.addClassName(element , this.classHoover);

		return true;
	},
	outMouse: function(element) {
		
		Element.removeClassName(element , this.classHoover);
		
		return true;
	},
	clickMouse: function(element) {

		var myRadio = element.getElementsByTagName('INPUT')[0];
		
		myRadio.checked = true;
		
		if(this.classChecked) {
			this.updateModaliteStyle(element);
			Element.addClassName(element , this.classChecked);		
		}
		Form.Element.focus(myRadio);
		return true;		
	},
	updateModaliteStyle: function(element) {
		
		var myTr = element.parentNode;
		var listeTd = Element.immediateDescendants(myTr);
		
		for(var i = 0; i < listeTd.length; i++) {
		
			if(Element.hasClassName(listeTd[i] , this.classChecked))
				Element.removeClassName(listeTd[i] , this.classChecked);
		}
		
		return true;		
	},
	setDefaut: function(valeurs) {
	
		if(this.classChecked) {
		
			for(var i = 0; i < this.setDefaut.arguments.length; i++) {
			
				var myArg = this.setDefaut.arguments[i];
				var myRadio = $(this.idGroupe + 'M' + myArg[0] + '_' + myArg[1]);
				var myCell = myRadio.parentNode;
				
				Element.addClassName(myCell , this.classChecked);
			}
		}
	}


}
