function radio_selected(radiobutton) {
 for (i = 0; i < radiobutton.length; i++) {
  if (radiobutton[i].checked) {
   return true;
  }
 }
 return false;
}
function radio_selected_extra(radiobutton, extrafield)
{
 for (i = 0; i < radiobutton.length - 1; i++) {
  if (radiobutton[i].checked) {
   return true;
  }
 }
 if (radiobutton[i].checked && extrafield.value) {
  return true;
 }
 return false;
}
function checkbox_selected(checkbox, tr, rl, rh, ve, extrafield) {

 var tc = 0;

 for (i = 0; i < checkbox.length - 1; i++) {
  if (checkbox[i].checked) {
   tc++;
  }
 }
 
 if (checkbox[i].checked) {
  tc++;
  if (ve == 1 && !extrafield.value) {
   return false;
  }
 }

 if (tr == 1 && tc >= rl) {
  return true;
 } else if (tr == 2 && tc <= rh) {
  return true;
 } else if (tr == 3 && tc >= rl && tc <= rh) {
  return true;
 } else {
  return false;
 }

}
function checkbox_selected(checkbox, tr, rl, rh, ve, extrafield) {

 var tc = 0;

 for (i = 0; i < checkbox.length - 1; i++) {
  if (checkbox[i].checked) {
   tc++;
  }
 }
 
 if (checkbox[i].checked) {
  tc++;
  if (ve == 1 && !extrafield.value) {
   return false;
  }
 }

 if (tr == 1 && tc >= rl) {
  return true;
 } else if (tr == 2 && tc <= rh) {
  return true;
 } else if (tr == 3 && tc >= rl && tc <= rh) {
  return true;
 } else {
  return false;
 }

}
function check_form(page) {
if ( (page == 1) && (!radio_selected_extra(document.prontosurvey.q1, document.prontosurvey.q1_extra)) ) {
 alert('Choix obligatoire');
 return false;
}
if ( (page == 1) && (!document.prontosurvey.q2.value) ) {
 alert('Champ obligatoire');
 return false;
}
if ( (page == 1) && (!checkbox_selected(document.prontosurvey.q8, 1, 1, 0, 1, document.prontosurvey.q8_extra)) ) {
 alert('Champs obligatoires');
 return false;
}
if ( (page == 1) && (!checkbox_selected(document.prontosurvey.q9, 1, 1, 0, 0, 0)) ) {
 alert('Champ obligatoire');
 return false;
}
if ( (page == 1) && (!radio_selected(document.prontosurvey.q20)) ) {
 alert('One or more mandatory fields are empty');
 return false;
}

}
