// Validate fields on the Ask the Trainer form 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

function getSelectedButton(buttonGroup){
	for (var i = 0; i < buttonGroup.length; i++) {
	 
		if (buttonGroup[i].checked) {
			return i
		}
	}
	return 99
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

function CheckFrm() {
   var badCount = 0;
   var f = document.askfrm;
   var msg = "";
   var tmp = "";
 
   if (f.question.value == "") {
      badCount = badCount + 1;
	  msg = msg + "Enter your question.\n";
   }
   if (f.email.value == "") {
      badCount = badCount + 1;
	    msg = msg + "Enter your email.\n";
   }
   if (f.age.value == "") {
   		badCount = badCount + 1;
	    msg = msg + "Enter your age.\n";
   }
      // check that one of the genders has been selected
   var i = getSelectedButton(f.gender)
   if (i == 99) {
		badCount = badCount + 1;
		msg = msg + "Select a gender.\n";
	}
   var i = getSelectedButton(f.exercises_now)
   if (i == 99) {
		badCount = badCount + 1;
		msg = msg + "Inidcate whether you are exercising now.\n";
	} 
	tmp = f.current_exercise.value;
	if ((i ==0) && (tmp.length == 0)) {
		badCount = badCount + 1;
		msg = msg + "Describe the exercising you currently do.\n";
	}
	if (tmp.length > 255) {
		badCount = badCount + 1;
		msg = msg + "Current exercise description too long.\n";
	}
	tmp = f.question.value;
    if (tmp.length >255) {
		badCount = badCount + 1;
		msg = msg + "Question too long.\n";
	}
	tmp = f.personal_info.value;
    if (tmp.length >255) {
		badCount = badCount + 1;
		msg = msg + "Personal Information too long.\n";
	}
   
   if (badCount == 0) {
      return true;
    } else {
      alert (msg);
      return false;
     }
   
  }