//BMI script

function mycalculator(form) {
   form.imc.value = form.weight.value * 10000/(form.height.value*form.height.value) ;
   form.comment.value = commente(form.imc.value) ;
}

function commente(imc) {
   if (imc<18.5) {
     return "Mangez plus car votre weight est trop faible." ;
   }
   if (imc>=18.5 && imc<25) {
     return "Votre weight est correct." ;
   }
   if (imc>=25 && imc <30) {
     return "Vous etes en surweight, revoyez votre alimentation." ;
   }
   if (imc >= 30) {
     return "Trop eleve. Prenez contact avec un nutritionniste." ;
   }
}

//To change background color onClick

function changeBg(box){
		box.style.backgroundColor = "#f4f3f3";
		box.style.color = "black";
	}
	
//Functions for Questionnaire.php start here

//This function is used to trim any string value using javascript

function validateTestForm(radio_button){

	var frm=document.DisplayQuestions;
	var errorMsg = "";
	var errorQuestion = 1;
	
	for( i=0;i<frm.elements.length;i++ )  {
	
		switch(radio_button)
		{
		case 1:
			if(frm.question1[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 1;
			}
			break;
		
		case 2:
			if(frm.question2[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 2;
			}
			break;
		case 3:
			if(frm.question3[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 3;
			}
			break;
		case 4:
			if(frm.question4[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 4;
			}
			break;
		case 5:
			if(frm.question5[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 5;
			}
			break;
		case 6:
			if(frm.question6[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 6;
			}
			break;
		case 7:
			if(frm.question7[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 7;
			}
			break;
		case 8:
			if(frm.question8[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 8;
			}
			break;
		case 9:
			if(frm.question9[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 9;
			}
			break;
		case 10:
			if(frm.question10[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 10;
			}
			break;
		case 11:
			if(frm.question11[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 11;
			}
			break;
		case 12:
			if(frm.question12[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 12;
			}
			break;
		case 13:
			if(frm.question13[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 13;
			}
			break;
		case 14:
			if(frm.question14[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 14;
			}
			break;
		case 15:
			if(frm.question15[i].checked==true){
				errorQuestion = 0;
			} else {
				errorQuestion = 15;
			}
			break;
		default:
			break;
		}
		
		if( errorQuestion == 0 ) {
			break;
		}
	}
	
	if( errorQuestion == 0 ) {
		return true;
	} else {
		errorMsg+="Merci de repondre a la question "+errorQuestion+".\n";
		alert(errorMsg);
		return false;
	}

}



//Functions for Questionnaire.php end here