// EAN


/*----------------------	LEXICO	------------------------	

-subsection: "ul_hors_oeuvres_VQ"
------------
(ul_) 			---	defines a subsection
(hors_oeuvres_)	---	subsection's name
(VQ)			---	defines the subsection validation type
					(VQ)			Questions only : yes or no
					(V1)			only one radio button has to be selected
					(V2, ..., Vn)	selection of one up to "n" radio buttons

	----------------------	LEXICO	------------------------	*/
var all_checked = false;






//this function receives an object (a subsection)
// and counts the number of radio buttons contained
//in this object
function check_radioButton(subSection){
	
	var radioButton_list = subSection.getElementsByTagName("input");		//number of radio buttons in the section
	var radioButton_list_toCheck =  user_assignment(subSection);			//number of radio buttons to select from
	var nb_radioBtn = radioButton_list.length;
	var counter = 0;														//-------
	
	
	
	if(radioButton_list_toCheck > 1){										//if there is something to check
		//alert("Only "+ radioButton_list_toCheck +" has to be checked");
		
			for(var i = 0 ; i < nb_radioBtn ; i++ ){
				var radioButton = radioButton_list[i];
				var radioButton_value = radioButton.value;
					
				//we make sure the function checks only the right buttons
				if( radioButton_value.indexOf("Yes") < 0 && radioButton_value.indexOf("No") < 0 ){
					//if( radioButton.checked == true )			//if the radio button is checked
					//	counter ++;
						
						
					//when somebody click on a radio button	
					radioButton_list[i].onclick= function(){
						if( (howManyAreChecked(radioButton_list,radioButton_list.length) == (radioButton_list_toCheck+1)) ){
							this.checked = false;	
							all_checked = true;
							alert("You have to make only "+ radioButton_list_toCheck +" selections , please click on one to deselect it!");
						}
						if( this.checked == true && all_checked == true  ){
							this.checked = false;
							all_checked = false;
						}
					}//----------  end onclick	
						
						
				}//------ end if(we make sure the function checks only the right buttons)
					
			}//--- end for
	
			//alert(counter +" has already been selected");
	}

}



//this function determine whith exactitude what the user has to do
//based on the subsection's ID where he is located
function user_assignment(subSection){
	var subSection_ID = subSection.id;							//subsection's ID
	
	var start = subSection_ID.indexOf("_V");
	var encrypt = subSection_ID.substring(start+2);				//all we want is the last character of the "_V ..." string
	
	return encrypt == "Q" ? 0 : parseInt(encrypt);
}






//count the number of radio btn that are checked
function howManyAreChecked(tab,l){
	var counter = 0;
	
	for(var i = 0 ; i < l ; i++ ){
		var radioButton = tab[i];
		var radioButton_value = radioButton.value;
			
		//we make sure the function checks only the right buttons
		if( radioButton_value.indexOf("Yes") < 0 && radioButton_value.indexOf("No") < 0 ){
			if( radioButton.checked == true )			//if the radio button is checked
				counter ++;
		}
			
	}//--- end for

	return counter;
}

	
	
	
















