function fnValidate() {
    var himsValidator = [
							 new hims_ctl_val('ctl00_CP_OrganizationDropDownList', "Organization", "T", "", "", "", 20),
							 new hims_ctl_val('ctl00_CP_BatchDropDownList', "Batch", "T", "", "", "", 20)
    ];
    if (fnDoValidate(himsValidator))
        return confirm('Are you sure you Want to Save?');
    else
        return false;
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function isNumberKeyForApply(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    var AssignTypeId = document.getElementById("ctl00_CP_StudentFeeTabContainer_StudentwiseFeeTabPanel_AssignTypeDropDownList").value;
    if (AssignTypeId == 2) {
        var value = $(evt).val();
        if ((value.match(/\./g) || []).length > 0) {
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
        }
        else {
            if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
                return false;
            }
        }
    }
    else {
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
    }
    return true;
}

function funcsum(lnk) {

    var table = document.getElementById('ctl00_CP_FeeAllocationGridView');
    var Amount = 0;
    var AdditionalAmount = 0;
    var DiscountAmount = 0;
    var NotApplicableAmount = 0;
    var PaidAmount = 0;
    var PendingAmount = 0;
    var Pendingi = 0;


    for (var i = 0; i < table.rows.length - 1; i++) {
        if (!isNaN(table.rows[i].cells[3].innerText)) {

            var TempDiscountAmount = parseFloat(table.rows[i].cells[5].childNodes[1].value);
            if (isNaN(TempDiscountAmount))
                TempDiscountAmount = 0;
            var TempNotApplicableAmount = parseFloat(table.rows[i].cells[6].childNodes[1].value);
            if (isNaN(TempNotApplicableAmount))
                TempNotApplicableAmount = 0;
            Amount = parseFloat(table.rows[i].cells[3].childNodes[1].value);

            AdditionalAmount = parseFloat(table.rows[i].cells[4].childNodes[1].value);

            PaidAmount = parseFloat(table.rows[i].cells[7].childNodes[1].innerText);
            if (isNaN(PaidAmount))
                PaidAmount = 0;

            DiscountAmount = parseFloat(table.rows[i].cells[5].childNodes[1].value);

            NotApplicableAmount = parseFloat(table.rows[i].cells[6].childNodes[1].value);

            PendingAmount = parseFloat(table.rows[i].cells[8].innerText);
            Pendingi = i;
            if (isNaN(Amount) && (!isNaN(AdditionalAmount) || !isNaN(DiscountAmount) || !isNaN(NotApplicableAmount))) {
                alert("Enter Amount");
                table.rows[i].cells[3].childNodes[1].value = "";
                table.rows[i].cells[4].childNodes[1].value = "";
                table.rows[i].cells[5].childNodes[1].value = "";
                table.rows[i].cells[6].childNodes[1].value = "";

            }
            else {

                if ((!isNaN(DiscountAmount) || !isNaN(NotApplicableAmount))) {
                    if (!isNaN(DiscountAmount)) {
                        DiscountAmount = parseFloat(table.rows[i].cells[5].childNodes[1].value);

                    }
                    else
                        DiscountAmount = 0;
                    if (!isNaN(NotApplicableAmount)) {
                        NotApplicableAmount = parseFloat(table.rows[i].cells[6].childNodes[1].value);
                    }
                    else
                        NotApplicableAmount = 0;
                    if (isNaN(AdditionalAmount))
                        AdditionalAmount = 0;
                    var TempAmount = Amount + AdditionalAmount - PaidAmount;
                    if (DiscountAmount + NotApplicableAmount > TempAmount) {
                        alert('Enter proper Exemption Amount + NotApplicable Amount');

                        table.rows[i].cells[5].childNodes[1].value = TempDiscountAmount.toFixed(2);
                        table.rows[i].cells[6].childNodes[1].value = TempNotApplicableAmount.toFixed(2);
                    }
                    else if (!isNaN(PendingAmount)) {
                        TempAmount = Amount + AdditionalAmount - DiscountAmount - NotApplicableAmount - PaidAmount;
                        table.rows[Pendingi].cells[8].innerText = TempAmount.toFixed(2);
                    }
                }
                else if (AdditionalAmount != 0 && !isNaN(AdditionalAmount) && !isNaN(PendingAmount) && PendingAmount != 0) {
                    TempAmount = Amount + AdditionalAmount;
                    table.rows[Pendingi].cells[8].innerText = TempAmount.toFixed(2);
                }
            }

        }

    }

    var grid = document.getElementById('ctl00_CP_FeeAllocationGridView');
    var FAmount = 0;
    var FAdditionalAmount = 0;
    var FDiscountAmount = 0;
    var FNotApplicableAmount = 0;
    var FPaidAmount = 0;
    var FPendingAmount = 0;
    var FooterRow = grid.rows.length - 1;
    for (i = 1; i < grid.rows.length - 1; i++) {
        if (grid.rows[i].cells[3].firstElementChild.value != "")
            FAmount = parseFloat(FAmount) + parseFloat(grid.rows[i].cells[3].firstElementChild.value);
        if (grid.rows[i].cells[4].firstElementChild.value != "")
            FAdditionalAmount = parseFloat(FAdditionalAmount) + parseFloat(grid.rows[i].cells[4].firstElementChild.value);
        if (grid.rows[i].cells[5].firstElementChild.value != "")
            FDiscountAmount = parseFloat(FDiscountAmount) + parseFloat(grid.rows[i].cells[5].firstElementChild.value);
        if (grid.rows[i].cells[6].firstElementChild.value != "")
            FNotApplicableAmount = parseFloat(FNotApplicableAmount) + parseFloat(grid.rows[i].cells[6].firstElementChild.value);
        if (grid.rows[i].cells[7].firstElementChild.innerText != "")
            FPaidAmount = parseFloat(FPaidAmount) + parseFloat(grid.rows[i].cells[7].firstElementChild.innerText);
        if (grid.rows[i].cells[8].innerText != "")
            FPendingAmount = parseFloat(FPendingAmount) + parseFloat(grid.rows[i].cells[8].innerText);
    }
    grid.rows[FooterRow].cells[3].firstElementChild.innerText = FAmount;
    grid.rows[FooterRow].cells[4].firstElementChild.innerText = FAdditionalAmount;
    grid.rows[FooterRow].cells[5].firstElementChild.innerText = FDiscountAmount;
    grid.rows[FooterRow].cells[6].firstElementChild.innerText = FNotApplicableAmount;
    grid.rows[FooterRow].cells[7].firstElementChild.innerText = FPaidAmount;
    grid.rows[FooterRow].cells[8].firstElementChild.innerText = FPendingAmount;
}

//changes for mantis Id:0047432
function MaskDecimal(e, t, n) {
    var r = e.charCode ? e.charCode : e.keyCode;
    if (8 > r || r > 9) {
        if (!(46 == r || r >= 48 && 57 >= r)) return !1;
        var i = e.srcElement.value.split(".");
        if (i.length > 2) return !1;
        if (46 == r) return 1 == i.length;
        if (e.srcElement.value.length >= t + n + 1) return !1;
        if (i[0].length == t && 1 == i.length) return !1
    }
}