﻿

function Calculator_Init() {
    ReCalculate();
    $('INPUT.txtBox').each(function(i) {
        $(this).blur(function(e) {
            ReCalculate();
        });
    });
}

function ReCalculate() {
    if (Page_IsValid) {
        var totalA =    GetTextboxValue(txtFuneral) +
                        GetTextboxValue(txtCreditStoreCards) +
                        GetTextboxValue(txtPersonalLoans) +
                        GetTextboxValue(txtMortgage) +
                        GetTextboxValue(txtInvestmentLoans) +
                        GetTextboxValue(txtEmergencyFund) +
                        GetTextboxValue(txtChildrensEducation) +
                        GetTextboxValue(txtAnnualLivingExpenses) +
                        GetTextboxValue(txtLegacies)

        var totalB =    GetTextboxValue(txtSoldImmediately) +
                        GetTextboxValue(txtSuperAccountBalance) +
                        GetTextboxValue(txtSuperInsuranceCover) +
                        GetTextboxValue(txtPoliciesNotAttached)

        txtTotalA.value = totalA.toFixed(0);
        txtTotalB.value = totalB.toFixed(0);
        txtGrandTotal.value = (totalB - totalA).toFixed(0);
    }
    else {
        txtTotalA.value = "0";
        txtTotalB.value = "0";
        txtGrandTotal.value = "0";
    }
}

function GetTextboxValue(txtBox) {
    if (txtBox.value.trim() == "") {
        return 0;
    }
    else {
        return (Number.parseInvariant(txtBox.value));
    }
}

