﻿    function PoidIdeal(){
        var Poids = ""
        var Taille = ""
        //Poids = EntrerNombre("Calcul de votre indice de masse corporelle, Entrez votre poids (en kilogramme)")
        Poids = EntrerNombre(document.getElementById("Poids").value)
        if (Poids != null)
        {
            //Taille = EntrerNombre("Calcul de votre indice de masse corporelle, Entrez votre taille (en mètre)")
            Taille = EntrerNombre(document.getElementById("Taille").value)
            if (Taille != null)
            {
                var Rapport = Math.round((Poids/(Taille*Taille))*100) / 100
                var m = "Votre indice de masse corporelle est de " + Rapport
                var r = ""
                var SelectBackColor = "#000000"
                var SelectFontColor = "#FFFFFF"
             //   Rapport=19
                if (Rapport < 20) {
                    r = "maigre"
                    document.getElementById("th_1").style.color=SelectFontColor
                    document.getElementById("th_1").style.backgroundColor=SelectBackColor
                    document.getElementById("td_1").style.color=SelectFontColor
                    document.getElementById("td_1").style.backgroundColor=SelectBackColor
                }
                else {
                    document.getElementById("th_1").style.color = "#006A99"
                    document.getElementById("th_1").style.backgroundColor = "#D5F2FF"
                    document.getElementById("td_1").style.color = "#006A99"
                    document.getElementById("td_1").style.backgroundColor = "#D5F2FF"
                }
                if (Rapport >= 20 && Rapport < 25) {
                    r = "normal"
                    document.getElementById("th_2").style.color=SelectFontColor
                    document.getElementById("th_2").style.backgroundColor=SelectBackColor
                    document.getElementById("td_2").style.color=SelectFontColor
                    document.getElementById("td_2").style.backgroundColor=SelectBackColor
                }
                else {
                    document.getElementById("th_2").style.color = "#006A99"
                    document.getElementById("th_2").style.backgroundColor = "#F8E0B8"
                    document.getElementById("td_2").style.color = "#006A99"
                    document.getElementById("td_2").style.backgroundColor = "#F8E0B8"
                }
                
                if (Rapport >= 25 && Rapport < 30) {
                    r = "surpoids"
                    document.getElementById("th_3").style.color=SelectFontColor
                    document.getElementById("th_3").style.backgroundColor=SelectBackColor
                    document.getElementById("td_3").style.color=SelectFontColor
                    document.getElementById("td_3").style.backgroundColor=SelectBackColor
                }
                else {
                    document.getElementById("th_3").style.color = "#006A99"
                    document.getElementById("th_3").style.backgroundColor = "#D5F2FF"
                    document.getElementById("td_3").style.color = "#006A99"
                    document.getElementById("td_3").style.backgroundColor = "#D5F2FF"
                }
                if (Rapport >= 30 && Rapport < 35) {
                    r = "obésité type 1 ou modérée"
                    document.getElementById("th_4").style.color=SelectFontColor
                    document.getElementById("th_4").style.backgroundColor=SelectBackColor
                    document.getElementById("td_4").style.color=SelectFontColor
                    document.getElementById("td_4").style.backgroundColor=SelectBackColor
                }
                else {
                    document.getElementById("th_4").style.color = "#006A99"
                    document.getElementById("th_4").style.backgroundColor = "#F8E0B8"
                    document.getElementById("td_4").style.color = "#006A99"
                    document.getElementById("td_4").style.backgroundColor = "#F8E0B8"
                }
                if (Rapport >= 35 && Rapport < 40) {
                    r = "obésité type 2 ou sévère"
                    document.getElementById("th_5").style.color=SelectFontColor
                    document.getElementById("th_5").style.backgroundColor=SelectBackColor
                    document.getElementById("td_5").style.color=SelectFontColor
                    document.getElementById("td_5").style.backgroundColor=SelectBackColor
                }
                else {
                    document.getElementById("th_5").style.color = "#006A99"
                    document.getElementById("th_5").style.backgroundColor = "#D5F2FF"
                    document.getElementById("td_5").style.color = "#006A99"
                    document.getElementById("td_5").style.backgroundColor = "#D5F2FF"
                }
                if (Rapport >= 40) {
                    r = "obésité type 3 ou morbide"
                    document.getElementById("th_6").style.color=SelectFontColor
                    document.getElementById("th_6").style.backgroundColor=SelectBackColor
                    document.getElementById("td_6").style.color=SelectFontColor
                    document.getElementById("td_6").style.backgroundColor=SelectBackColor
                }
                else {
                    document.getElementById("th_6").style.color = "#006A99"
                    document.getElementById("th_6").style.backgroundColor = "#F8E0B8"
                    document.getElementById("td_6").style.color = "#006A99"
                    document.getElementById("td_6").style.backgroundColor = "#F8E0B8"
                }
                m += " (" + r + ")"
                alert(m)
            }
        }
    }
    function EntrerNombre(Valeur)
    {
        if (Valeur == null)
        {return null}
        else
        {
            Valeur = Valeur.replace(",", ".")
            if (isNaN(Valeur))
            {
                alert("'" + Valeur + "' n'est pas un nombre valide")
                Valeur = null
            }
            else 
            {return 1*Valeur}
        }
    }    


