$(document).ready(function () {
    SubmitClick();
    ReturnClick();
    PopUpClick();
});

function PopUpClick() {
    $('.docBtn').click(function () {
        $('.popup').fadeIn(500);
    });
    $('.popClose').click(function() {
        $('.popup').fadeOut(500);
    });
}

function SubmitClick() {
    $('#btSubmit').click(function () {
        var ft = $('#txtFeet').val();
        var inch = $('#txtInches').val();
        var lbs = $('#txtLbs').val();

        //ft = ft * 1;inch = inch * 1;lbs = lbs * 1;

        if ((ft.length > 0) && (inch.length > 0) && (lbs.length > 0) && (IsNumeric(ft)) && (IsNumeric(inch)) && (IsNumeric(lbs))) {
            $('#msg').hide();
            $('.leftContent, .rightContent').fadeOut(500);
            $('.fullContent, #sideImg').fadeIn(500);

            $('#sBMI').html(CalculateBMI(lbs, ((ft * 12) + (inch * 1))));
            $('#sState').html(GetBMICategory(CalculateBMI(lbs, ((ft * 12) + (inch * 1)))));
        } else {
            $('#msg').show();
        }
    });
}

function ReturnClick() {
    $('#btReturn').click(function () {
        $('.leftContent, .rightContent').fadeIn(500);
        $('.fullContent, #sideImg').fadeOut(500);
    });
}

function CalculateBMI(lbs, inches) { return RoundNumber(((lbs / (inches * inches)) * 703), 2); }
function GetBMICategory(bmi) {
    if (bmi <= 18.5) { return "underweight"; }
    else if ((bmi > 18.5) && (bmi <= 24.99)) { return "normal weight"; }
    else if ((bmi >= 25) && (bmi <= 29.99)) { return "overweight"; }
    else if ((bmi >= 30) && (bmi <= 39.99)) { return "obese"; }
    else if (bmi >= 40) { return "morbidly obese"; }
}
function IsNumeric(input) { return (input - 0) == input && input.length > 0; }
function RoundNumber(num, dec) { var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);return result; }
