﻿function calFat() {

    var Fatheight = document.getElementById("txtFatheight").value;
    var FatResult = document.getElementById("FatResult");
    var FatWeight = document.getElementById("txtFatWeight").value;
    var FatError = document.getElementById("FatError");
    var result = true;


    if (isNaN(Fatheight) || (Fatheight.length == 0) ) {
        document.getElementById("txtFatheight").style.backgroundColor = "Red";
        FatError.innerHTML = "أكتب طول صحيح";
        result = false;
        return;
    }
    else
    {
        document.getElementById("txtFatheight").style.backgroundColor = "silver";
        FatError.innerHTML = "";
        result = true;
    }

    if (isNaN(FatWeight) || (FatWeight.length == 0)) {
        document.getElementById("txtFatWeight").style.backgroundColor = "Red";
        FatError.innerHTML = "أكتر وزن صحيح";
        result = false;
        return;
    }
    else {
        document.getElementById("txtFatheight").style.backgroundColor = "silver";
        FatError.innerHTML = "";
        result = true;
    }
    if (result) {
        var Fatheight = Fatheight / 100;
        var result = FatWeight / (Fatheight * Fatheight);
        result = Math.round(result);
        FatResult.innerHTML = " نسبة الدهون " + result + " % ";
    }
    
}

