 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 funcsum(lnk) {
	var row = lnk.parentNode.parentNode;
	var Amount = 0;
	var AdditionalAmount = 0;
	var DiscountAmount = 0;
	var NotApplicableAmount = 0;
	var PaidAmount = 0;
	var PendingAmount = 0;
	var Discounti = 0;
	var NotApplicablei = 0;
	var Pendingi = 0;
	var Additionali = 0;
	for (var i = 0; i < row.all.length; i++) {
		if (row.all[i].id == "AmountTextBox") {
			if (row.all[i].value != "")
				Amount = row.all[i].value;
		}
		if (row.all[i].id == "AdditionalAmountTextBox") {
			if (row.all[i].value != "") {
				AdditionalAmount = row.all[i].value;
				Additionali = i;
			}
		}
		if (row.all[i].id == "DiscountAmountTextBox") {
			if (row.all[i].value != "") {
				DiscountAmount = row.all[i].value;
				Discounti = i;
			}
		}
		if (row.all[i].id == "NotApplicableAmountTextBox") {
			if (row.all[i].value != "") {
				NotApplicableAmount = row.all[i].value;
				NotApplicablei = i;
			}
		}
		if (row.all[i].id == "PaidAmountLabel") {
			if (row.all[i].innerText != "")
				PaidAmount = row.all[i].innerText;
		}
		if (row.all[i].id == "PendingAmountLabel")
			Pendingi = i;

	}
	if (parseFloat(Amount) == 0) {
		alert("Enter Amount");
	}
	else if (parseFloat(DiscountAmount) + parseFloat(NotApplicableAmount) > parseFloat(Amount) + parseFloat(AdditionalAmount)) {
		alert("Exemption Amount should be less than Amount+Additional Amount");
		row.all[Discounti].innerText = "";
		row.all[NotApplicablei].innerText = "";
		DiscountAmount = 0;
		NotApplicableAmount = 0;
		PendingAmount = parseFloat(Amount) + parseFloat(AdditionalAmount) - parseFloat(DiscountAmount) - parseFloat(NotApplicableAmount) - parseFloat(PaidAmount);
		if (PendingAmount == 0) {
			row.all[Pendingi].innerText = "";
			PendingAmount = 0;
		}
		else
			row.all[Pendingi].innerText = PendingAmount;
	}
	else {
		PendingAmount = parseFloat(Amount) + parseFloat(AdditionalAmount) - parseFloat(DiscountAmount) - parseFloat(NotApplicableAmount) - parseFloat(PaidAmount);
		if (PendingAmount < 0) {
			row.all[Pendingi].innerText = PendingAmount;
			alert("Exemption+NotApplicable Amount should be less than Amount+Additional Amount-Paid Amount");
			row.all[Discounti].innerText = "";
			NotApplicableAmount = 0;
			DiscountAmount = 0;
		}
		PendingAmount = parseFloat(Amount) + parseFloat(AdditionalAmount) - parseFloat(DiscountAmount) - parseFloat(NotApplicableAmount) - parseFloat(PaidAmount);
		if (PendingAmount == 0) {
			row.all[Pendingi].innerText = "";
			PendingAmount = 0;
		}
		else
			row.all[Pendingi].innerText = PendingAmount;
	}
	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].firstChild.value != "")
			FAmount = parseFloat(FAmount) + parseFloat(grid.rows[i].cells[3].firstChild.value);
		if (grid.rows[i].cells[4].firstChild.value != "")
			FAdditionalAmount = parseFloat(FAdditionalAmount) + parseFloat(grid.rows[i].cells[4].firstChild.value);
		if (grid.rows[i].cells[5].firstChild.value != "")
			FDiscountAmount = parseFloat(FDiscountAmount) + parseFloat(grid.rows[i].cells[5].firstChild.value);
		if (grid.rows[i].cells[6].firstChild.value != "")
			FNotApplicableAmount = parseFloat(FNotApplicableAmount) + parseFloat(grid.rows[i].cells[6].firstChild.value);
		if (grid.rows[i].cells[7].firstChild.innerHTML != "")
			FPaidAmount = parseFloat(FPaidAmount) + parseFloat(grid.rows[i].cells[7].firstChild.innerHTML);
		if (grid.rows[i].cells[8].firstChild.innerHTML != "")
			FPendingAmount = parseFloat(FPendingAmount) + parseFloat(grid.rows[i].cells[8].firstChild.innerHTML);
	}
	grid.rows[FooterRow].cells[3].firstChild.innerHTML = FAmount;
	grid.rows[FooterRow].cells[4].firstChild.innerHTML = FAdditionalAmount;
	grid.rows[FooterRow].cells[5].firstChild.innerHTML = FDiscountAmount;
	grid.rows[FooterRow].cells[6].firstChild.innerHTML = FNotApplicableAmount;
	grid.rows[FooterRow].cells[7].firstChild.innerHTML = FPaidAmount;
	grid.rows[FooterRow].cells[8].firstChild.innerHTML = FPendingAmount;
}
