﻿function checkNull(src){
	var result = document.getElementById("txtresult");
	if (!src) {
		/*result.value = "Please enter your height in inches and your weight in pounds first before clicking the calculate button."*/
		return false;
	}
    return true;
}
	
		
function calcBMI(height, weight) {	
	return (weight/(Math.pow(height, 2)));
}
		
function converttocm(height) {	
	return (height * 0.025397);
}
		
function converttokg(weight) {
	return (weight * 0.4545);
}
		
function btncalcBMI() {
        
            var height = 0;
            var weight;
            var bmi;
            var feetElement = document.getElementById("feet");
            var inchesElement = document.getElementById("inches");
            var weightElement = document.getElementById("weight");
            $("#BMI_info").hide();
            $("#bmi18").hide();
            $("#bmi18-24").hide();
            $("#bmi25-30").hide();
            $("#bmi30").hide();
            
            if (($("#feet").val() == "") || ($("#inches").val() == "") ||($("#weight").val() == "")){
                alert("Please enter a value in all three boxes");
                return false;
            }
            if (($("#feet").val() < 3) || ($("#feet").val() > 7)){
                return false;
            }
            
            if (($("#inches").val() < 0) || ($("#inches").val() > 11.5)){
                return false;
            }
            
            if (($("#weight").val() <= 0) || ($("#weight").val() > 999)) {
                alert("Please enter a weight less than 1000.");
                return false;
            }
            
            height = Number(12*$("#feet").val());
            height += Number($("#inches").val());
            height = converttocm(height);
            weight = converttokg($("#weight").val());
            
            
            bmi = calcBMI(height, weight);
            $("#BMI_info").show();
            $("#your_bmi").html('');
            $("#your_bmi").append('<strong>Your BMI: ' + parseInt(bmi) + "</strong>");
            $("#your_bmi").show();
            _gaq.push(['_trackPageview', '/calculate_bmi']);
            if (bmi < 18.5) {
                $("#bmi18").show();
            } else if ((bmi >= 18.5) && (bmi <= 24.9)) {
                $("#bmi18-24").show();
            } else if ((bmi >= 25) && (bmi <= 30)) {
                $("#bmi25-30").show();
            } else {
                $("#bmi30").show();
               
            }
            
            return false;
}
		
		
		function btncalcReadiness() {
		
		var rsurveyResults = document.getElementById("rsurveyResults");
		
		dcsMultiTrack('DCS.dcsuri','/submit_readiness_survey.do','WT.ti','Submit Survey','WT.si_n','BMI Calculator Funnel','WT.si_x','3');
		
		var readiness = 0;
		var a1 = document.getElementById("a1");
		var a2 = document.getElementById("a2");
		var a3 = document.getElementById("a3");
		var a4 = document.getElementById("a4");
		var a5 = document.getElementById("a5");
		var a6 = document.getElementById("a6");
		var a7 = document.getElementById("a7");
		var a8 = document.getElementById("a8");
		var a9 = document.getElementById("a9");
		var a10 = document.getElementById("a10");
		var a11 = document.getElementById("a11");
		var a12 = document.getElementById("a12");
		var a13 = document.getElementById("a13");
		var a14 = document.getElementById("a14");
		var a15 = document.getElementById("a15");
		var a16 = document.getElementById("a16");
		var a17 = document.getElementById("a17");
		var a18 = document.getElementById("a18");
		var a19 = document.getElementById("a19");
		var a20 = document.getElementById("a20");
		
		var readinessresult = document.getElementById("readinessresult").firstChild;
		
		
		
		if (a1.checked) readiness++;
		if (a2.checked) readiness++;
		if (!a3.checked) readiness++;
		if (!a4.checked) readiness++;
		if (a5.checked) readiness++;
		if (a6.checked) readiness++;
		if (a7.checked) readiness++;
		if (a8.checked) readiness++;
		if (a9.checked) readiness++;
		if (!a10.checked) readiness++;
		if (!a11.checked) readiness++;
		readiness++;
		if (!a13.checked) readiness++;
		if (!a14.checked) readiness++;
		if (a15.checked) readiness++;
		if (a16.checked) readiness++;
		if (a17.checked) readiness++;
		if (!a18.checked) readiness++;
		if (!a19.checked) readiness++;
		if (!a20.checked) readiness++;
		
		if (readiness>11) {
			readinessresult.nodeValue="Your BMI indicate that you may be an appropriate candidate for the OPTIFAST program. To continue your journey to weight loss and improved health, contact an OPTIFAST clinic near you to schedule a free, no-obligation consultation.";
		} else {
		
			readinessresult.nodeValue="OPTIFAST is a serious solution for weight loss, and success requires a serious commitment. It is not clear that you are ready to make that commitment. An OPTIFAST professional can discuss the best approach to treatment based on your medical condition and motivation level.";
		}
		
		
		
		rsurveyResults.style.display="block";
		return false;

		}
