//======================
// 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()
{
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 actuel weight seems incorrect (between 35 Kg and 200 Kg).");
return false;
}
}

else
{
alert("Your actuel 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);

if (weight_lbs<=14)
{

if (weight_st>=5)
{

if (weight_st<=30)
{

if (goal_st.match(reg_sans_point) && goal_lbs.match(reg_sans_point_0))
{
goal_st=parseInt(goal_st);
goal_lbs=parseInt(goal_lbs);

if (goal_lbs<=14)
{

if (goal_st>=5)
{

if (goal_st<=30)
{

if (height_ft.match(reg_sans_point) && height_ins.match(reg_inch))
{
height_ft=parseInt(height_ft);
height_ins=parseInt(height_ins);

if (height_ins<=12)
{

if (height_ft>=4)
{

if (height_ft<=6)
{

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 4ft and 7ft).");
return false;
}
}

else
{
alert("Your height seems incorrect (between 4ft and 7ft).");
return false;
}
}

else
{
alert("Your height seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your height seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
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;
}
}

else
{
alert("Your weight goal seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your weight goal seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
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;
}
}

else
{
alert("Your actuel weight seems incorrect.\nPlease check your form.");
return false;
}
}

else
{
alert("Your actuel weight seems incorrect.\nPlease check your form.");
return false;
}
}

}
//=======================================
// Fin fonction de validation des données
//=======================================
