$(document).ready(function () {
$(function () {
$('.allow_only_decimal').on('keypress', function (e) {
return isNumber(e, this);
});
});
$.fn.SetDecimalOnly = function () {
return this.each(function () {
$(this).keydown(function (e) {
var key = e.charCode || e.keyCode || 0;
return (
key == 8 ||
key == 9 ||
key == 13 ||
key == 46 ||
key == 110 ||
key == 190 ||
(key >= 35 && key <= 40) ||
(key >= 48 && key <= 57) ||
(key >= 96 && key <= 105));
});
});
};
$('#btnSave').on('click', function (e) {
e.preventDefault();
var flag = true;
$('#tbodyAddGrant tr input:text').each(function () {
if ($(this).val() == '' || $(this).val() == '.' || $(this).val() == '-' || $(this).val() == '.-' || $(this).val() == '-.') {
if ($(this).attr('id').indexOf('Total') < 0) {
$(this).focus();
$(this).addClass('error_input');
flag = false;
}
} else {
$(this).removeClass('error_input');
}
});
if (flag) {
$('#btnSavePostback').trigger('click');
}
});
$('#tbodyAddGrant').each(function () {
var tbody = $(this);
tbody.find('input:text').each(function () {
//$(this).SetDecimalOnly();
$(this).addClass('allow_only_decimal');
$(this).attr('maxlength', '7');
if ($(this).attr('id').indexOf('Total') >= 0) {
$(this).attr('readonly', true);
}
else {
$(this).attr('onblur', 'Calculate_Total($(this))');
}
});
});
});
function isNumber(evt, element) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (
(charCode != 45 || $(element).val().indexOf('-') != -1) && // “-” CHECK MINUS, AND ONLY ONE.
(charCode != 46 || $(element).val().indexOf('.') != -1) && // “.” CHECK DOT, AND ONLY ONE.
((charCode < 48 || charCode > 57) && charCode != 8))
return false;
return true;
}
function Calculate_Total(txt) {
var id = txt.attr('id');
var IDs = id.split('_');
var Value_2012_13 = 0;
var Value_2013_14 = 0;
var Value_2014_15 = 0;
var Value_2015_16 = 0;
var Value_2016_17 = 0;
var TotalEXp = 0;
var Unspent = 0;
if ($('#txt_2012_13_' + IDs[3] + '').val() != '') {
Value_2012_13 = parseFloat($('#txt_2012_13_' + IDs[3] + '').val());
}
if ($('#txt_2013_14_' + IDs[3] + '').val() != '') {
Value_2013_14 = parseFloat($('#txt_2013_14_' + IDs[3] + '').val());
}
if ($('#txt_2014_15_' + IDs[3] + '').val() != '') {
Value_2014_15 = parseFloat($('#txt_2014_15_' + IDs[3] + '').val());
}
if ($('#txt_2015_16_' + IDs[3] + '').val() != '') {
Value_2015_16 = parseFloat($('#txt_2015_16_' + IDs[3] + '').val());
}
if ($('#txt_2016_17_' + IDs[3] + '').val() != '') {
Value_2016_17 = parseFloat($('#txt_2016_17_' + IDs[3] + '').val());
}
var TOTAL = Value_2012_13 + Value_2013_14 + Value_2014_15 + Value_2015_16 + Value_2016_17;
$('#txt_Total_' + IDs[3] + '').val(TOTAL.toFixed(2));
var ALL_31 = 0;
var ALL_35 = 0;
var ALL_36 = 0;
if ($('#txt_' + IDs[1] + '_' + IDs[2] + '_31').val() != '') {
ALL_31 = parseFloat($('#txt_' + IDs[1] + '_' + IDs[2] + '_31').val());
}
if ($('#txt_' + IDs[1] + '_' + IDs[2] + '_35').val() != '') {
ALL_35 = parseFloat($('#txt_' + IDs[1] + '_' + IDs[2] + '_35').val());
}
if ($('#txt_' + IDs[1] + '_' + IDs[2] + '_36').val() != '') {
ALL_36 = parseFloat($('#txt_' + IDs[1] + '_' + IDs[2] + '_36').val());
}
$('#txt_' + IDs[1] + '_' + IDs[2] + '_Total').val(ALL_31 + ALL_35 + ALL_36);
var Total_2012_13 = 0;
var Total_2013_14 = 0;
var Total_2014_15 = 0;
var Total_2015_16 = 0;
var Total_2016_17 = 0;
var Total_Total = 0;
if ($('#txt_2012_13_Total').val() != '') {
Total_2012_13 = parseFloat($('#txt_2012_13_Total').val());
}
if ($('#txt_2013_14_Total').val() != '') {
Total_2013_14 = parseFloat($('#txt_2013_14_Total').val());
}
if ($('#txt_2014_15_Total').val() != '') {
Total_2014_15 = parseFloat($('#txt_2014_15_Total').val());
}
if ($('#txt_2015_16_Total').val() != '') {
Total_2015_16 = parseFloat($('#txt_2015_16_Total').val());
}
if ($('#txt_2016_17_Total').val() != '') {
Total_2016_17 = parseFloat($('#txt_2016_17_Total').val());
}
var Total_Total = Total_2012_13 + Total_2013_14 + Total_2014_15 + Total_2015_16 + Total_2016_17;
$('#txt_Total_Total').val(Total_Total.toFixed(2));
}