



//pulmonary Common javascript function

        function calculatePridicted(ObservedTextBoxId, PredictedTextBoxId, PerOfPredictedTextBox) {


            var Observedvalue = ObservedTextBoxId.value;
            var predictedValue = PredictedTextBoxId.value;

            var perOfFEV1FVC = document.getElementById('PerOfFEV1FVCTextBox');

            if ((Observedvalue != 0) && (predictedValue != 0)) {

                PerOfPredictedTextBox.value = 0;
                PerOfPredictedTextBox.value = parseFloat((Observedvalue * 100) / predictedValue).toFixed(2);

            }
            else if ((Observedvalue == "") && (predictedValue == ""))
                PerOfPredictedTextBox.value = "";

            else if ((Observedvalue == 0) || (predictedValue == 0))
                PerOfPredictedTextBox.value = 0.00;

        }


        function CalculateBronchotest(BronchoTextBox, observerdTextBox, PerOfBronchotest) {

            var Broncho = BronchoTextBox.value;
            var Observed = observerdTextBox.value;

            if ((Broncho != 0) && (Observed != 0)) {
                PerOfBronchotest.value = 0;
                PerOfBronchotest.value = (((Broncho - Observed) * 100) / Observed).toFixed(2);
            }
            else if ((Broncho == "") && (Observed == ""))
                PerOfBronchotest.value = "";
            else if ((Broncho == 0) || (Observed == 0))
                PerOfBronchotest.value = 0;
        }


        function CalculateFEV1FVC(Fev1ObservedTextBox, FvcObservedTextBox, FvcPredictTextBox, PrdFEV1TextBox, perOfFEV1FVCtextBox) {

            if ((PrdFEV1TextBox.value != 0) && (FvcPredictTextBox.value != 0) && (Fev1ObservedTextBox.value != 0) && (FvcObservedTextBox.value != 0)) {
                var a = ((PrdFEV1TextBox.value * 100) / FvcPredictTextBox.value);
                var b = ((Fev1ObservedTextBox.value * 100) / FvcObservedTextBox.value);
                if (a != 0 && b != 0) {
                    perOfFEV1FVCtextBox.value = parseFloat(b * 100 / a).toFixed(2);
                }
            }
            else if ((PrdFEV1TextBox.value == "") && (FvcPredictTextBox.value == "") && (Fev1ObservedTextBox.value == "") && (FvcObservedTextBox.value == ""))
                perOfFEV1FVCtextBox.value = "";
            else if ((PrdFEV1TextBox.value == 0) && (FvcPredictTextBox.value == 0) && (Fev1ObservedTextBox.value == 0) && (FvcObservedTextBox.value == 0))
                perOfFEV1FVCtextBox.value = 0.00;
        }





        function CalculateFev5(Fev1observerdTextBox, Fev5PredictedTextBox, MvvPredictedTextBox) {

            var fev1Observed = Fev1observerdTextBox.value;

            if (fev1Observed != 0) {

                Fev5PredictedTextBox.value = (fev1Observed / 1.8).toFixed(2);
                MvvPredictedTextBox.value = (fev1Observed * 35).toFixed(2);
            }
            else if (fev1Observed == "") {
                Fev5PredictedTextBox.value = "";
                MvvPredictedTextBox.value = "";
            }
            else if (fev1Observed == 0) {
                Fev5PredictedTextBox.value = 0;
                MvvPredictedTextBox.value = 0;
            }

        }

        function CalculateFEV1FEV5(Fev1ObserverdTextbox, Fev5ObserverdTextbox, PerOfFev1Fev5) {

            if ((Fev1ObserverdTextbox.value != 0) && (Fev5ObserverdTextbox.value != 0)) {

                PerOfFev1Fev5.value = 0;
                PerOfFev1Fev5.value = parseFloat((Fev1ObserverdTextbox.value * 100) / Fev5ObserverdTextbox.value).toFixed(2);

            }
            else if ((Fev1ObserverdTextbox.value == '') || (Fev5ObserverdTextbox.value == ''))
                PerOfFev1Fev5.value = "";

            else if ((Fev1ObserverdTextbox.value == 0) || (Fev5ObserverdTextbox.value == 0))
                PerOfFev1Fev5.value = 0.00;

        }
        function CalculateResult(PerOfPredictedFVCTextBox, PerOfFEV1FVCTextBox, ResultTextBox) {

            if ((PerOfPredictedFVCTextBox.value != '') && (PerOfFEV1FVCTextBox.value != '') &&  (PerOfPredictedFVCTextBox.value < 80) && (PerOfFEV1FVCTextBox.value < 80)) {
                ResultTextBox.value = "Mix Lung Disease";

            }
            else if ((PerOfPredictedFVCTextBox.value != '') && (PerOfPredictedFVCTextBox.value < 80)) {
                ResultTextBox.value = "Restrictive Lung Disease";

            }
            else if ((PerOfFEV1FVCTextBox.value != '') && (PerOfFEV1FVCTextBox.value < 80)) {
                ResultTextBox.value = "Obstructive Lung Disease";

            }
            else if ((PerOfFEV1FVCTextBox.value != '') || (PerOfPredictedFVCTextBox.value != ''))
            { 
                ResultTextBox.value = "Normal";
            }

        }

        //End Pulmonary Function


        //BMI Calculation

        function CalculateBMI(HightTextBox, WeightTextBox, BMITextBox, BMICategoryLable) {


            if (HightTextBox.value != "" && WeightTextBox.value != "") {
                //                BMITextBox.value = "";
                //                BMICategoryLable.innerHTML = '';

                if (HightTextBox.value == 0 || WeightTextBox.value == 0)
                    BMITextBox.value = 0.00;
                else if (HightTextBox.value != 0 && WeightTextBox.value != 0) {
                    var Hieght = HightTextBox.value / 100;
                    var Weight = WeightTextBox.value;
                    BMITextBox.value = 0;
                    BMITextBox.value = (Weight / ((Hieght) * (Hieght))).toFixed(2);
                    //               BMITextBox.value = Math.round(BMITextBox.value, 2);

                    BMI = BMITextBox.value;

                    if (BMI < 18.5)
                        BMICategoryLable.innerHTML = "Underweight";
                    else if ((BMI >= 18.5) && (BMI <= 24.9))
                        BMICategoryLabel.innerHTML = "Normal";
                    else if ((BMI >= 25) && (BMI <= 29.9))
                        BMICategoryLabel.innerHTML = "Overweight";
                    else if ((BMI >= 30) && (BMI <= 34.9))
                        BMICategoryLabel.innerHTML = "Obese";
                    else if (BMI >= 35)
                        BMICategoryLabel.innerHTML = "Morbidly Obese";

                }
            }
            else {

                BMITextBox.value = "";
                BMICategoryLabel.innerHTML = "";
            }
        }


        function CalculateAcBcResult(AcBcValue, ResultDropDown) {

            var ResultDropDown = document.getElementById('ResultDropDown');
           
            if (AcBcValue != null) {

                if (AcBcValue / 3 == 0)
                    ResultDropDown.value = 0;

                else if ((AcBcValue / 3) > 0 && (AcBcValue / 3) <= 15)
                    ResultDropDown.value = 1;

                else if (AcBcValue / 3 > 15 && AcBcValue / 3 <= 25)
                    ResultDropDown.value = 2;

                else if (AcBcValue / 3 > 25 && AcBcValue / 3 <= 40)
                    ResultDropDown.value = 3;

                else if (AcBcValue / 3 > 40 && AcBcValue / 3 <= 55)
                    ResultDropDown.value = 4;

                else if (AcBcValue / 3 > 55 && AcBcValue / 3 <= 70)
                    ResultDropDown.value = 5;

                else if (AcBcValue / 3 > 70 && AcBcValue / 3 <= 90)
                    ResultDropDown.value = 6;
                else
                    ResultDropDown.value = 7;
            }


        }


        function CheckAll(Checkbox) {  
        var GridView = Checkbox.parentNode.parentNode.parentNode.parentNode;
            for (i = 1; i < GridView.rows.length; i++) {
                GridView.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = Checkbox.checked;
              }
        }



        function calendarShown(sender, e) {
            sender._switchMode("months", true);
        }