jQuery(document).ready(function() {
	jQuery("#bmrCalc input.bmrCBtn").click(function() {
		jQuery ("#bmrCalc .results").removeClass ("error");
		jQuery ("#bmrCalc .results").removeClass ("result");
		jQuery ("#bmrCalc .results").html ("").css ("display","none");
		/*Formula 
		Women: BMR = 655 + ( 4.35 x weight in pounds ) + ( 4.7 x height in inches ) - ( 4.7 x age in years ) 
		Men: BMR = 66 + ( 6.23 x weight in pounds ) + ( 12.7 x height in inches ) - ( 6.8 x age in year ) 
		*/
		var age = jQuery ("#bmrCalc input.age").val();
		var height_inch = parseInt(jQuery ("#bmrCalc input.feet").val() * 12) + parseInt(jQuery ("#bmrCalc input.inch").val());
		var weight = jQuery ("#bmrCalc input.weight").val();
		var gender = jQuery ("#bmrCalc input.gender").val();
		
		var err = 0;
		
		if (age.length==0){
			err = 1;
			alert("Pleae enter your age.");
		}
		if (height_inch.length==0){
			err = 1;
			alert("Pleae enter your height.");
		}
		if (weight.length==0){
			err = 1;
			alert("Pleae enter your weight.");
		}
		if (gender.length==0){
			err = 1;
			alert("Pleae select your gender.");
		}
		
		if (gender=='female'){
			var BMR = 655 + ( 4.35 * weight ) + ( 4.7 * height_inch ) - ( 4.7 * age );
		}else if (gender=='male'){
			var BMR = 66 + ( 6.23 * weight ) + ( 12.7 * height_inch ) - ( 6.8 * age );
		}
		if (err==0){
			jQuery ("#bmrCalc .results").addClass ("result").html ("You have a BMR of <strong>" + Math.round(BMR) + "</strong>.").fadeIn ("slow");
		}
	});
	
	jQuery ("#bmrCalc input.gen").click (function (){
		jQuery ("#bmrCalc input.gender").val (jQuery (this).val ());
	});
	
	
	jQuery("#bmiCalc input.bmiCBtn").click(function() {
		jQuery ("#bmiCalc .results").removeClass ("error");
		jQuery ("#bmiCalc .results").removeClass ("result");
		jQuery ("#bmiCalc .results").html ("").css ("display","none");
		
		var height_inch = parseInt(jQuery ("#bmiCalc input.feet").val() * 12) + parseInt(jQuery ("#bmiCalc input.inch").val());
		var weight = jQuery ("#bmiCalc input.weight").val();
		
		var err = 0;
		
		if (height_inch.length==0){
			err = 1;
			alert("Pleae enter your height.");
		}
		if (weight.length==0){
			err = 1;
			alert("Pleae enter your weight.");
		}
		var HSQ = height_inch * height_inch;
		var WDH = weight/HSQ;
		var BMI = WDH * 703; //655 + ( 4.35 * weight ) + ( 4.7 * height_inch ) - ( 4.7 * age );
		
		if (err==0){
			jQuery ("#bmiCalc .results").addClass ("result").html ("You have a BMI of <strong>" + Math.round(BMI) + "</strong>.").fadeIn ("slow");
		}
	});
	
	
});
