//======================
// Début Système utilisé
//======================
// Fonction mise à zéro du système Impérial
function disableImperial()
{
document.name_form.metric[0].checked=false;
document.name_form.metric[1].checked=false;
document.name_form.metric[1].checked=true;

document.name_form.weight_kg.disabled=false;
document.name_form.height_cm.disabled=false;
document.name_form.goal_kg.disabled=false;
document.name_form.weight_kg.style.background="#FFFFFF";
document.name_form.height_cm.style.background="#FFFFFF";
document.name_form.goal_kg.style.background="#FFFFFF";
document.name_form.weight_st.disabled=true;
document.name_form.weight_lbs.disabled=true;
document.name_form.height_ft.disabled=true;
document.name_form.height_ins.disabled=true;
document.name_form.goal_st.disabled=true;
document.name_form.goal_lbs.disabled=true;
document.name_form.weight_st.value="";
document.name_form.weight_lbs.value="";
document.name_form.height_ft.value="";
document.name_form.height_ins.value="";
document.name_form.goal_st.value="";
document.name_form.goal_lbs.value="";
document.name_form.weight_st.style.background="#CCCCCC";
document.name_form.weight_lbs.style.background="#CCCCCC";
document.name_form.height_ft.style.background="#CCCCCC";
document.name_form.height_ins.style.background="#CCCCCC";
document.name_form.goal_st.style.background="#CCCCCC";
document.name_form.goal_lbs.style.background="#CCCCCC";
}

// Fonction mise à zéro du système métrique
function disableMetric()
{
document.name_form.metric[0].checked=false;
document.name_form.metric[1].checked=false;
document.name_form.metric[0].checked=true;

document.name_form.weight_kg.disabled=true;
document.name_form.height_cm.disabled=true;
document.name_form.goal_kg.disabled=true;
document.name_form.weight_kg.value="";
document.name_form.height_cm.value="";
document.name_form.goal_kg.value="";
document.name_form.weight_kg.style.background="#CCCCCC";
document.name_form.height_cm.style.background="#CCCCCC";
document.name_form.goal_kg.style.background="#CCCCCC";
document.name_form.weight_st.disabled=false;
document.name_form.weight_lbs.disabled=false;
document.name_form.height_ft.disabled=false;
document.name_form.height_ins.disabled=false;
document.name_form.goal_st.disabled=false;
document.name_form.goal_lbs.disabled=false;
document.name_form.weight_st.style.background="#FFFFFF";
document.name_form.weight_lbs.style.background="#FFFFFF";
document.name_form.height_ft.style.background="#FFFFFF";
document.name_form.height_ins.style.background="#FFFFFF";
document.name_form.goal_st.style.background="#FFFFFF";
document.name_form.goal_lbs.style.background="#FFFFFF";
}
//====================
// Fin Système utilisé
//====================


//=========================================
// Début fonction de validation des données
// function valider()
//=========================================
function valider()
{
var reg_point=new RegExp("^[1-9]{1}[0-9]*[/.,][0-9]+$","g");
var reg_sans_point=new RegExp("^[1-9]{1}[0-9]*$","g");
var reg_sans_point_0=new RegExp("^[0-9]{1}[0-9]*$","g");
var reg_inch=new RegExp("^[0-9]*$","g");
var metric=true;

if (document.name_form.metric[0].checked==true)
{
metric=false;
}

// Vérification du mode metric
if (metric)
{
var weight=document.name_form.weight_kg.value;
var goal=document.name_form.goal_kg.value;
var height=document.name_form.height_cm.value;
var age=document.name_form.age.value;

if (weight.match(reg_sans_point) || weight.match(reg_point))
{
weight=parseInt(weight);

if (weight>=35 && weight<=200)
{

if (goal.match(reg_sans_point) || goal.match(reg_point))
{
goal=parseInt(goal);

if (goal>=35 && goal<=200)
{

if (height.match(reg_sans_point))
{
height=parseInt(height);

if (height>=130 && height<=220)
{

if (age.match(reg_sans_point))
{
age=parseInt(age);

if(age>=18)
{

if(age<=95)
{

if ((document.name_form.sexe[0].checked==true) || (document.name_form.sexe[1].checked==true))
{
return true;
}

else
{
alert("Your sex seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}
}

else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}
}

else
{
alert("Your age seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your height seems incorrect (between 130 and 220 cm).");
return false;
}
}

else
{
alert("Your height seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your weight goal seems incorrect (between 35 Kg and 200 Kg).");
return false;
}
}

else
{
alert("Your weight goal seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your actual weight seems incorrect (between 35 Kg and 200 Kg).");
return false;
}
}

else
{
alert("Your actual weight seems incorrect.\nPlease check your form.");
return false;
}
}

// Vérification du mode imperial
else
{
var weight_st=document.name_form.weight_st.value;
var weight_lbs=document.name_form.weight_lbs.value;
var goal_st=document.name_form.goal_st.value;
var goal_lbs=document.name_form.goal_lbs.value;
var height_ft=document.name_form.height_ft.value;
var height_ins=document.name_form.height_ins.value;
var age=document.name_form.age.value;

if (weight_st.match(reg_sans_point) && weight_lbs.match(reg_sans_point_0))
{
weight_st=parseInt(weight_st);
weight_lbs=parseInt(weight_lbs);
}
else
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}

if (weight_lbs<=14)
{
if (weight_st<5)
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}
if (weight_st>30)
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}
}
else
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}

if (goal_st.match(reg_sans_point) && goal_lbs.match(reg_sans_point_0))
{
goal_st=parseInt(goal_st);
goal_lbs=parseInt(goal_lbs);
}
else
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}

if (goal_lbs<=14)
{
if (goal_st<5)
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}
if (goal_st>30)
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}
}
else
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}

if (height_ft.match(reg_sans_point) && height_ins.match(reg_sans_point_0))
{
height_ft=parseInt(height_ft);
height_ins=parseInt(height_ins);
}
else
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft<4)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft==4 && height_ins<3)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft>7)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft==7 && height_ins>3)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ins>12)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (age.match(reg_sans_point))
{
age=parseInt(age);
}
else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if(age<18)
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if(age>95)
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if ((document.name_form.sexe[0].checked==false) && (document.name_form.sexe[1].checked==false))
{
alert("Your sex seems incorrect.\nPlease check your form.");
return false;
}
}

}
//=======================================
// Fin fonction de validation des données
// function valider()
//=======================================



//=========================================
// Début fonction de validation des données
// function valider_2()
//=========================================
function valider_2()
{
var reg_point=new RegExp("^[1-9]{1}[0-9]*[/.,][0-9]+$","g");
var reg_sans_point=new RegExp("^[1-9]{1}[0-9]*$","g");
var reg_sans_point_0=new RegExp("^[0-9]{1}[0-9]*$","g");
var reg_inch=new RegExp("^[0-9]*$","g");
var metric=true;

if (document.name_form_2.metric_2[0].checked==true)
{
metric=false;
}

// Vérification du mode metric
if (metric)
{
var weight=document.name_form_2.weight_kg_2.value;
var goal=document.name_form_2.goal_kg_2.value;
var height=document.name_form_2.height_cm_2.value;
var age=document.name_form_2.age_2.value;

if (weight.match(reg_sans_point) || weight.match(reg_point))
{
weight=parseInt(weight);

if (weight>=35 && weight<=200)
{

if (goal.match(reg_sans_point) || goal.match(reg_point))
{
goal=parseInt(goal);

if (goal>=35 && goal<=200)
{

if (height.match(reg_sans_point))
{
height=parseInt(height);

if (height>=130 && height<=220)
{

if (age.match(reg_sans_point))
{
age=parseInt(age);

if(age>=18)
{

if(age<=95)
{

if ((document.name_form_2.sexe_2_2[0].checked==true) || (document.name_form_2.sexe_2_2[1].checked==true))
{
return true;
}

else
{
alert("Your sex seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}
}

else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}
}

else
{
alert("Your age seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your height seems incorrect (between 130 and 220 cm).");
return false;
}
}

else
{
alert("Your height seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your weight goal seems incorrect (between 35 Kg and 200 Kg).");
return false;
}
}

else
{
alert("Your weight goal seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your actual weight seems incorrect (between 35 Kg and 200 Kg).");
return false;
}
}

else
{
alert("Your actual weight seems incorrect.\nPlease check your form.");
return false;
}
}

// Vérification du mode imperial
else
{
var weight_st=document.name_form_2.weight_st_2.value;
var weight_lbs=document.name_form_2.weight_lbs_2.value;
var goal_st=document.name_form_2.goal_st_2.value;
var goal_lbs=document.name_form_2.goal_lbs_2.value;
var height_ft=document.name_form_2.height_ft_2.value;
var height_ins=document.name_form_2.height_ins_2.value;
var age=document.name_form_2.age_2_2.value;

if (weight_st.match(reg_sans_point) && weight_lbs.match(reg_sans_point_0))
{
weight_st=parseInt(weight_st);
weight_lbs=parseInt(weight_lbs);
}
else
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}

if (weight_lbs<=14)
{
if (weight_st<5)
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}
if (weight_st>30)
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}
}
else
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}

if (goal_st.match(reg_sans_point) && goal_lbs.match(reg_sans_point_0))
{
goal_st=parseInt(goal_st);
goal_lbs=parseInt(goal_lbs);
}
else
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}

if (goal_lbs<=14)
{
if (goal_st<5)
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}
if (goal_st>30)
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}
}
else
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}

if (height_ft.match(reg_sans_point) && height_ins.match(reg_sans_point_0))
{
height_ft=parseInt(height_ft);
height_ins=parseInt(height_ins);
}
else
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft<4)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft==4 && height_ins<3)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft>7)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft==7 && height_ins>3)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ins>12)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (age.match(reg_sans_point))
{
age=parseInt(age);
}
else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if(age<18)
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if(age>95)
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if ((document.name_form_2.sexe_2_2[2].checked==false) && (document.name_form_2.sexe_2_2[3].checked==false))
{
alert("Your sex seems incorrect.\nPlease check your formdd.");
return false;
}
}

}
//=======================================
// Fin fonction de validation des données
// function valider_2()
//=======================================

//=========================================
// Début fonction de validation des données
// function valider_form_2()
//=========================================
function valider_form_2()
{
var reg_point=new RegExp("^[1-9]{1}[0-9]*[/.,][0-9]+$","g");
var reg_sans_point=new RegExp("^[1-9]{1}[0-9]*$","g");
var reg_sans_point_0=new RegExp("^[0-9]{1}[0-9]*$","g");
var reg_inch=new RegExp("^[0-9]*$","g");
var metric=true;

if (document.direct_form_2.metric_2[0].checked==true)
{
metric=false;
}

// Vérification du mode metric
if (metric)
{
var weight=document.direct_form_2.weight_kg_2.value;
var goal=document.direct_form_2.goal_kg_2.value;
var height=document.direct_form_2.height_cm_2.value;
var age=document.direct_form_2.age_2_2.value;

if (weight.match(reg_sans_point) || weight.match(reg_point))
{
weight=parseInt(weight);

if (weight>=35 && weight<=200)
{

if (goal.match(reg_sans_point) || goal.match(reg_point))
{
goal=parseInt(goal);

if (goal>=35 && goal<=200)
{

if (height.match(reg_sans_point))
{
height=parseInt(height);

if (height>=130 && height<=220)
{

if (age.match(reg_sans_point))
{
age=parseInt(age);

if(age>=18)
{

if(age<=95)
{

if ((document.direct_form_2.sexe_2_2[0].checked==true) || (document.direct_form_2.sexe_2_2[1].checked==true))
{
return true;
}

else
{
alert("Your sex seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}
}

else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}
}

else
{
alert("Your age seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your height seems incorrect (between 130 and 220 cm).");
return false;
}
}

else
{
alert("Your height seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your weight goal seems incorrect (between 35 Kg and 200 Kg).");
return false;
}
}

else
{
alert("Your weight goal seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your actual weight seems incorrect (between 35 Kg and 200 Kg).");
return false;
}
}

else
{
alert("Your actual weight seems incorrect.\nPlease check your form.");
return false;
}
}

// Vérification du mode imperial
else
{
var weight_st=document.direct_form_2.weight_st_2.value;
var weight_lbs=document.direct_form_2.weight_lbs_2.value;
var goal_st=document.direct_form_2.goal_st_2.value;
var goal_lbs=document.direct_form_2.goal_lbs_2.value;
var height_ft=document.direct_form_2.height_ft_2.value;
var height_ins=document.direct_form_2.height_ins_2.value;
var age=document.direct_form_2.age_2_2.value;

if (weight_st.match(reg_sans_point) && weight_lbs.match(reg_sans_point_0))
{
weight_st=parseInt(weight_st);
weight_lbs=parseInt(weight_lbs);
}
else
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}

if (weight_lbs<=14)
{
if (weight_st<5)
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}
if (weight_st>30)
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}
}
else
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}

if (goal_st.match(reg_sans_point) && goal_lbs.match(reg_sans_point_0))
{
goal_st=parseInt(goal_st);
goal_lbs=parseInt(goal_lbs);
}
else
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}

if (goal_lbs<=14)
{
if (goal_st<5)
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}
if (goal_st>30)
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}
}
else
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}

if (height_ft.match(reg_sans_point) && height_ins.match(reg_sans_point_0))
{
height_ft=parseInt(height_ft);
height_ins=parseInt(height_ins);
}
else
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft<4)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft==4 && height_ins<3)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft>7)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft==7 && height_ins>3)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ins>12)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (age.match(reg_sans_point))
{
age=parseInt(age);
}
else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if(age<18)
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if(age>95)
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if ((document.direct_form_2.sexe_2_2[0].checked==false) && (document.direct_form_2.sexe_2_2[1].checked==false))
{
alert("Your sex seems incorrect.\nPlease check your form.");
return false;
}
}

}
//=======================================
// Fin fonction de validation des données
// function valider_form_2()
//=======================================



//=============================================================
// Vérification données insérées dans formulaire quest pour IMC
// Contrôle sur poids, taille et sexe
//=============================================================
function check_imc(nom_form)
{
  
  var reg_point=new RegExp("^[1-9]{1}[0-9]*[/.,][0-9]+$","g");
  var reg_sans_point=new RegExp("^[1-9]{1}[0-9]*$","g");
  
  var reg_sans_point_0=new RegExp("^[0-9]{1}[0-9]*$","g");
  var reg_inch=new RegExp("^[0-9]*$","g");
  var metric=true;

  if (nom_form=="")
    nom_form="direct_form";
  
  var form_object=eval('document.'+nom_form);
  
  if (document.imc_form.unite[0].checked==true)
    {
      metric=false;
    }
  
  // Vérification du mode metric
  if (metric)
    {
      
      // Récupération de la saisie
      var weight_kg=form_object.weight_kg.value;
      var height_cm=form_object.height_cm.value;
      var sexe=form_object.sexe.value;
      var num=0;
      
      if (weight_kg.match(reg_sans_point) || weight_kg.match(reg_point))
	{
	  weight_kg=parseInt(weight_kg);
	}
      else
	{
	  alert("Your weight seems incorrect (between 35 Kg and 200 Kg).");
	  return false;
	}
      
      if (weight_kg<35 || weight_kg>200)
	{
	  alert("Your weight seems incorrect (between 35 Kg and 200 Kg).");
	  return false;
	}
      
      if (height_cm.match(reg_sans_point))
	{
	  height_cm=parseInt(height_cm);
	}
      else
	{
	  alert("Your height seems incorrect (between 130 and 220 cm).");
	  return false;
	}
      
      if (height_cm<130 || height_cm>220)
	{
	  alert("Your height seems incorrect (between 130 and 220 cm).");
	  return false;
	}
      
      if ((form_object.sexe[0].checked==false) && (form_object.sexe[1].checked==false))
	{
	  alert("Your sex seems incorrect.\nPlease check your form.");
	  return false;
	}
      else
	{
	  return true;
	}
    }

// Vérification du mode imperial
else
{
var weight_st=form_object.weight_st.value;
var weight_lbs=form_object.weight_lbs.value;
var goal_st=form_object.goal_st.value;
var goal_lbs=form_object.goal_lbs.value;
var height_ft=form_object.height_ft.value;
var height_ins=form_object.height_ins.value;
var age=form_object.age.value;

if (weight_st.match(reg_sans_point) && weight_lbs.match(reg_sans_point_0))
{
weight_st=parseInt(weight_st);
weight_lbs=parseInt(weight_lbs);
}
else
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}

if (weight_lbs<=14)
{
if (weight_st<5)
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}
if (weight_st>30)
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}
}
else
{
alert("Your actuel weight seems incorrect (between 5st and 30st).");
return false;
}

if (goal_st.match(reg_sans_point) && goal_lbs.match(reg_sans_point_0))
{
goal_st=parseInt(goal_st);
goal_lbs=parseInt(goal_lbs);
}
else
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}

if (goal_lbs<=14)
{
if (goal_st<5)
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}
if (goal_st>30)
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}
}
else
{
alert("Your weight goal seems incorrect (between 5st and 30st).");
return false;
}

if (height_ft.match(reg_sans_point) && height_ins.match(reg_sans_point_0))
{
height_ft=parseInt(height_ft);
height_ins=parseInt(height_ins);
}
else
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft<4)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft==4 && height_ins<3)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft>7)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ft==7 && height_ins>3)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (height_ins>12)
{
alert("Your height seems incorrect (between 4ft 3in and 7ft 3in).");
return false;
}

if (age.match(reg_sans_point))
{
age=parseInt(age);
}
else
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if(age<18)
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if(age>95)
{
alert("Your age seems incorrect (between 18 and 95).");
return false;
}

if ((form_object.sexe[0].checked==false) && (form_object.sexe[1].checked==false))
{
alert("Your sex seems incorrect.\nPlease check your form.");
return false;
}
}

}


//==================================================
// Validation du formulaire quest après vérification
//==================================================
function valid_form_imc(nom_form)
{
  if (check_imc(nom_form))
    {
      return true;
    }
  return false;
}


