function calculate_bodyfat(f){
    var objRegExp  = /^\d\d*$/;
    if (f.weight.value == '') {
        alert ('Please enter your weight');
        f.weight.focus();
        return false;
    }
    if (!objRegExp.test(f.weight.value)) {
        alert ('Please enter only numbers for your weight');
        f.weight.focus();
        return false;
    }
    if (f.waist.value == '') {
        alert ('Please enter your waist measurement');
        f.waist.focus();
        return false;
    }
    if (!objRegExp.test(f.waist.value)) {
        alert ('Please enter only numbers for your waist measurement');
        f.waist.focus();
        return false;
    }
    if (f.sex.value == 'female') {
        if (f.wrist.value == '') {
            alert ('Please enter your wrist measurement');
            f.wrist.focus();
            return false;
        }
        if (!objRegExp.test(f.wrist.value)) {
            alert ('Please enter only numbers for your wrist measurement');
            f.wrist.focus();
            return false;
        }
        if (f.hips.value == '') {
            alert ('Please enter your hips measurement');
            f.hips.focus();
            return false;
        }
        if (!objRegExp.test(f.hips.value)) {
            alert ('Please enter only numbers for your hips measurement');
            f.hips.focus();
            return false;
        }
        if (f.forearm.value == '') {
            alert ('Please enter your forearm measurement');
            f.forearm.focus();
            return false;
        }
        if (!objRegExp.test(f.forearm.value)) {
            alert ('Please enter only numbers for your forearm measurement');
            f.forearm.focus();
            return false;
        }
        /*
            Factor 1	(Total body weight x 0.732) + 8.987
            Factor 2	Wrist measurement (at fullest point) / 3.140
            Factor 3	Waist measurement (at naval) x 0.157
            Factor 4	Hip measurement (at fullest point) x 0.249
            Factor 5	Forearm measurement (at fullest point) x 0.434
            Lean Body Mass	Factor 1 + Factor 2 - Factor 3 - Factor 4 + Factor 5
            Body Fat Weight	Total bodyweight - Lean Body Mass
            Body Fat Percentage	(Body Fat Weight x 100) / total bodyweight
        */
        var weight = parseInt(f.weight.value) * 2.20462262;
        var waist = parseInt(f.waist.value) * 0.393700787;
        var wrist = parseInt(f.wrist.value) * 0.393700787;
        var hips = parseInt(f.hips.value) * 0.393700787;
        var forearm = parseInt(f.forearm.value) * 0.393700787;

        var f1 = (weight * 0.732) + 8.987;
        var f2 = wrist / 3.140;
        var f3 = waist * 0.157;
        var f4 = hips * 0.249;
        var f5 = forearm * 0.434;
        var lbm = f1 + f2 - f3 - f4 + f5;
        var bfw = weight - lbm;
        var bfp = bfw * 100 / weight;
    } else {
        /*
            Factor 1	(Total body weight x 1.082) + 94.42
            Factor 2	Waist measurement x 4.15
            Lean Body Mass	Factor 1 - Factor 2
            Body Fat Weight	Total bodyweight - Lean Body Mass
            Body Fat Percentage	(Body Fat Weight x 100) / total bodyweight
        */
        var weight = parseInt(f.weight.value) * 2.20462262;
        var waist = parseInt(f.waist.value) * 0.393700787;

        var f1 = (weight * 1.082) + 94.42;
        var f2 = waist * 4.15;
        var lbm = f1 - f2;
        var bfw = weight - lbm;
        var bfp = bfw * 100 / weight;
    }
    document.getElementById('bmr_result_span_1').innerHTML = Math.round(bfp*100)/100;
    document.getElementById('bmr-result-div').style.display = 'block';
    return false;
}
