var URL = window.location.href;
function isValidDate2(inputText)  
{
	if(inputText.value != '')
	{
		var dateformat = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
		if(inputText.value.match(dateformat))  
		{		
			var opera1 = inputText.value.split('/');  
			var opera2 = inputText.value.split('-');  
			lopera1 = opera1.length;  
			lopera2 = opera2.length;
			if (lopera1>1)
			{
				var pdate = inputText.value.split('/');
			}
			else if (lopera2>1)
			{
				var pdate = inputText.value.split('-');
			}
			var dd = parseInt(pdate[0]);
			var mm  = parseInt(pdate[1]);
			var yy = parseInt(pdate[2]);
			var ListofDays = [31,28,31,30,31,30,31,31,30,31,30,31];
			if (mm==1 || mm>2)  
			{
				if (dd>ListofDays[mm-1])  
				{
					alert('Invalid date!');
					inputText.value ='';
					return false;
				}
			}
			if (mm==2)  
			{
				var lyear = false;
				if ( (!(yy % 4) && yy % 100) || !(yy % 400))
				{
					lyear = true;
				}
				if ((lyear==false) && (dd>=29))  
				{
					alert('Invalid date!');
					inputText.value ='';
					return false;
				}
				if ((lyear==true) && (dd>29))  
				{
					alert('Invalid date!');
					inputText.value ='';
					return false;
				}
			}  
		}
		else  
		{  
			alert('Invalid date!');
			inputText.value ='';
			return false;
		}
	}
}
function FormatIt(obj) {
	if (obj.value.length == 2) // Day
		obj.value = obj.value + "/";
	if (obj.value.length == 5) // month
		obj.value = obj.value + "/";
}
function LoadingMessage(msg1, msg2)
{
	$('#dvLoadingmsg').show();
	$('#spn1msg').html(msg1);
	$('#spn2msg').html(msg2);
	$('.hls-bg').show();
}
function CloseHlsPopup()
{
	$('.hls-bg').hide();
	$('.hls-wrap').hide();
	$('.hls-wrap1').hide();
	$('#dvLoadingmsg').hide();
	$('#dvUserpopup').fadeOut();
}
function OpenProductTab(_this, tab) {
    debugger;
	$('a[group=ProductTab]').each(function () {
		$(this).removeClass('active');
	});
	$(_this).addClass('active');
	$('div[group=ProudctTabDiv]').each(function () {
		$(this).css('display', 'none');
	});
	$('#div' + tab + 'Tab').css('display', '');	
}
function BindDropDowns()
{
	$.ajax({
        type: "POST",
        url: URL + "/GetSession",
        data: '{}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (dt)
		{
			if(dt.d > 0)
			{
				$.ajax({
					type: "POST",
					url: URL + "/BindDropDowns",
					data: '{}',
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					success: function (data)
					{
						var dt = $.parseJSON(data.d);
						$('#drpGroupBatch').html(dt.OrgGroupRes);
						$('#drpOrganization').html(dt.OrganizationRes);
						$('#drpReceiptBook').html(dt.ReceiptBookRes);
						$('#drpStatus').html(dt.StatusRes);
						$('#drpDivision').html(dt.DivisionRes);
						$('#drpClass').html(dt.ClassRes);
						$('#drpDepartment').html(dt.DepartmentRes);
						$('#drpBatch').html(dt.BatchRes);
						$('#drpAvailableFields').html(dt.AvailableRes);
						$('#drpAvailableFieldsO').html(dt.AvailableRes);
						$('#drpAdmissionCategory').html(dt.AdmissionCategoryRes);
						$('#drpSavedReport').html(dt.SavedReportList);

						if(dt.ReportList != '')
							$('#tblReportList').html(dt.ReportList);
						else
							$('#tblReportList').html('<tr><td colspan="5">No Records Available</td></tr>');
						window.setTimeout(function() { CloseHlsPopup(); },500);
					},
					error: function (xhr, status, error)
					{
						var err = eval("(" + xhr.responseText + ")");
						console.log(err.Message);
					}
				});
			}
			else
			{
				CloseHlsPopup();
				LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
				window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
			}
        },
		error: function (xhr, status, error)
		{
			var err = eval("(" + xhr.responseText + ")");
			console.log(err.Message);
		}
    });
}
function LoadBatchAndDepartment()
{
	if($('#drpGroupBatch').val() > 0 && $('#drpOrganization').val() > 0)
	{
		$.ajax({
			type: "POST",
			url: URL + "/GetSession",
			data: '{}',
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			success: function (dt)
			{
				if(dt.d > 0)
				{
					var obj = {
						"OrgGroupBatchId": $('#drpGroupBatch').val(),
						"OrganizationId": $('#drpOrganization').val()
					};
					$.ajax({
						type: "POST",
						url: URL + "/LoadBatchAndDepartment",
						data: JSON.stringify(obj),
						contentType: "application/json;charset=utf-8",
						dataType: "json",
						success: function (data)
						{
							var dt = $.parseJSON(data.d);
							$('#drpDepartment').html(dt.DepratmentRes);
							$('#drpBatch').html(dt.BatchRes);
						},
						error: function (xhr, status, error)
						{
							var err = eval("(" + xhr.responseText + ")");
							console.log(err.Message);
						}
					});
				}
				else
				{
					CloseHlsPopup();
					LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
					window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
				}
			},
			error: function (xhr, status, error)
			{
				var err = eval("(" + xhr.responseText + ")");
				console.log(err.Message);
			}
		});
	}
}
function LoadClass(vObj)
{
	if($(vObj).val() > 0)
	{
		$('#chkClass').removeAttr('disabled');
		$.ajax({
			type: "POST",
			url: URL + "/GetSession",
			data: '{}',
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			success: function (dt)
			{
				if(dt.d > 0)
				{
					var obj = {
						"BatchId": $(vObj).val()
					};
					$.ajax({
						type: "POST",
						url: URL + "/LoadClassDropDown",
						data: JSON.stringify(obj),
						contentType: "application/json;charset=utf-8",
						dataType: "json",
						success: function (data)
						{
							var dt = $.parseJSON(data.d);
							$('#drpClass').html(dt.ClassRes);
						},
						error: function (xhr, status, error)
						{
							var err = eval("(" + xhr.responseText + ")");
							console.log(err.Message);
						}
					});
				}
				else
				{
					CloseHlsPopup();
					LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
					window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
				}
			},
			error: function (xhr, status, error)
			{
				var err = eval("(" + xhr.responseText + ")");
				console.log(err.Message);
			}
		});
	}
	else
	{
		$('#chkClass').attr('disabled','disabled');
	}
}
function LoadDivision(vObj)
{
	if($(vObj).val() > 0)
	{		
		$.ajax({
			type: "POST",
			url: URL + "/GetSession",
			data: '{}',
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			success: function (dt)
			{
				if(dt.d > 0)
				{
					var obj = {
						"ClassId": $(vObj).val()
					};
					$.ajax({
						type: "POST",
						url: URL + "/LoadDivision",
						data: JSON.stringify(obj),
						contentType: "application/json;charset=utf-8",
						dataType: "json",
						success: function (data)
						{
							var dt = $.parseJSON(data.d);
							$('#drpDivision').html(dt.DivisionRes);
						},
						error: function (xhr, status, error)
						{
							var err = eval("(" + xhr.responseText + ")");
							console.log(err.Message);
						}
					});
				}
				else
				{
					CloseHlsPopup();
					LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
					window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
				}
			},
			error: function (xhr, status, error)
			{
				var err = eval("(" + xhr.responseText + ")");
				console.log(err.Message);
			}
		});
	}	
}
function ShowHideAndBind(cobj, flag)
{
	if($(cobj).is(':checked'))
	{
		$(cobj).parent().find('div').show();
		$(cobj).parent().find('div').html('&nbsp;<img src="../../Images/loading-ajax.gif" />' + '&nbsp; Loading....');
		BindValues(cobj, flag);
	}
	else
	{
	    $(cobj).parent().find('div').hide();
	    $(cobj).parent().find('div').html('');
	}
}
function BindValues(cobj, flag)
{
	$.ajax({
        type: "POST",
        url: URL + "/GetSession",
        data: '{}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (dt)
		{
			if(dt.d > 0)
			{
				var obj = {
					"flag": flag,
					"BatchId": $('#drpBatch').val()
				};
				$.ajax({
					type: "POST",
					url: URL + "/BindValues",
					data: JSON.stringify(obj),
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					success: function (data)
					{
						var datas = $.parseJSON(data.d);
						if(datas.Result != '')
						{
						    $(cobj).parent().find('div').html(datas.Result);
						    $(cobj).parent().find('div').css('border', '1px solid Silver');
						    $(cobj).parent().find('div').slimScroll({ height: '100px' });
						}
						else
						{
						    $(cobj).parent().find('div').html('&nbsp;No Data');
						}
					},
					error: function (xhr, status, error)
					{
						var err = eval("(" + xhr.responseText + ")");
						console.log(err.Message);
					}
				});
			}
			else
			{
				CloseHlsPopup();
				LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
				window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
			}
        },
		error: function (xhr, status, error)
		{
			var err = eval("(" + xhr.responseText + ")");
			console.log(err.Message);
		}
    });
}
function UserPopups()
{
	$('#dvUserpopup').show();
	$('.hls-bg').show();
}
function OpenUser()
{
	LoadingMessage('Loading Details','<b>Please Wait ...</b>');
	BindUsers();
}
function BindUsers()
{
	$.ajax({
        type: "POST",
        url: URL + "/GetSession",
        data: '{}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (dt)
		{
			if(dt.d > 0)
			{
				$('#tblUsersList').html('<tr><td colspan="3" style="text-align:center;"><img src="../../Images/Loading.gif" /></td></tr>');
				$("#dvScrollUsers").slimScroll({destroy: true});
				var obj = {
					"DisplayTitle": $('#txtDisplayTitle').val(),
					"LoginTitle": $('#txtLoginTitle').val(),
					"PageIndex": $('#hdnUserPageIndex').val()
				};
				$.ajax({
					type: "POST",
					url: URL + "/BindUsers",
					data: JSON.stringify(obj),
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					success: function (data)
					{
						var datas = $.parseJSON(data.d);
						window.setTimeout(function(){
							if(datas.UserResult != '')
							{
								$('#tblUsersList').html(datas.UserResult);
								$('#userpagging').html(datas.UserPaging);
								$('#lblUserTotalRecords').html('Total Records : ' + datas.UserTotal);
								$('#dvScrollUsers').slimScroll({ height: '250px' });
							}
							else
							{
								$('#tblUsersList').html('<tr><td colspan="3">No Records Available</td></tr>');
								$('#userpagging').html('');
								$('#lblUserTotalRecords').html('');
								$("#dvScrollUsers").slimScroll({destroy: true});
							}
							window.setTimeout(function(){ CloseHlsPopup(); UserPopups();},500);
						},500)
					},
					error: function (xhr, status, error)
					{
						var err = eval("(" + xhr.responseText + ")");
						console.log(err.Message);
					}
				});
			}
			else
			{
				CloseHlsPopup();
				LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
				window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
			}
        },
		error: function (xhr, status, error)
		{
			var err = eval("(" + xhr.responseText + ")");
			console.log(err.Message);
		}
    });
}
function ResetUsers()
{
	$('#hdnUserPageIndex').val(1);
	$('#txtDisplayTitle').val('');
	$('#txtLoginTitle').val('');
	$('#tblUsersList').html('<tr><td colspan="3">No Records Available</td></tr>');
	$('#userpagging').html('');
	$('#lblUserTotalRecords').html('');
	$("#dvScrollUsers").slimScroll({destroy: true});
}
function ChangeUserPage(pageindex)
{
	$('#hdnUserPageIndex').val(pageindex);
	BindUsers();
}
function SelectUsers(vObj)
{
	$('#txtUser').val($(vObj).parent().parent().attr('attrDisplayTitle'));
	$('#hdnUserId').val($(vObj).parent().parent().attr('attrDisplayTitle'))
	CloseHlsPopup();
}
function CheckUser(obj)
{
	if($(obj).val() == '')
	{
		$('#hdnUserId').val(0);
	}
}
function ShowHideSaveReport(obj)
{
	if($(obj).is(':checked'))
	{
		$('div[group=dvreportgroup]').show();
	}
	else
	{
		$('div[group=dvreportgroup]').hide();
	}
}
function AppendSelected(flag)
{
	if(flag == 1)
	{
		if ($("#drpAvailableFields option:selected").length > 0){
			if($("#drpAvailableFields option:selected").length == 1)
			{
				var option = new Option($('#drpAvailableFields').val(), "value");				
				var dup = false;			
				$('#drpSelectedFields option').each(function(i, selected){				
					if($(selected).text() == $('#drpAvailableFields').val())
					{
						dup = true;
					}				
				});
				if(dup == false)
				{
					$('#drpSelectedFields').append(option);				
				}
			}
			else
			{
				$("#drpAvailableFields option:selected").each(function(index, element) {
					var dup = false;
					var sTexts = $(this).val();			
					$('#drpSelectedFields option').each(function(i, selected){				
						if($(selected).text() == sTexts)
						{
							dup = true;
						}				
					});
					if(dup == false)
					{
						 var option = new Option(sTexts, "value");
						 $('#drpSelectedFields').append(option);
					}	
                });
			}
		}
		else
		{
			alert('Please select at least one value from list box');
		}
	}
	else
	{
		if ($("#drpSelectedFields option:selected").length > 0){			
			$("#drpSelectedFields option:selected").remove();
		}
		else
		{
			alert('Please select at least one value from list box');
		}
	}
	if ($("#drpSelectedFields option").length > 0 || parseInt($('#drpSavedReport').val()) != 0) {
		$('#btnGenerateReport').attr('onclick','GenerateReport();');
	}
	else
	{
		$('#btnGenerateReport').removeAttr('onclick');
	}
}
function genrateclickevent() {
    if ($("#drpSelectedFields option").length > 0 || parseInt($('#drpSavedReport').val()) != 0) {
        $('#btnGenerateReport').attr('onclick', 'GenerateReport();');
    }
    else {
        $('#btnGenerateReport').removeAttr('onclick');
    }
}
function UpDownSelected(flag)
{
	if ($("#drpSelectedFields option:selected").length > 0){
		var $op = $('#drpSelectedFields option:selected');
		if($op.length){
			(flag == '1') ? $op.first().prev().before($op) : $op.last().next().after($op);
		}
	}
}
function AppendSelectedO(flag)
{
	if(flag == 1)
	{
		if ($("#drpAvailableFieldsO option:selected").length > 0){
			if($("#drpAvailableFieldsO option:selected").length == 1)
			{
				var option = new Option($('#drpAvailableFieldsO').val(), "value");				
				var dup = false;			
				$('#drpSelectedFieldsO option').each(function(i, selected){				
					if($(selected).text() == $('#drpAvailableFields').val())
					{
						dup = true;
					}				
				});
				if(dup == false)
				{
					$('#drpSelectedFieldsO').append(option);				
				}
			}
			else
			{
				$("#drpAvailableFieldsO option:selected").each(function(index, element) {
					var dup = false;
					var sTexts = $(this).val();			
					$('#drpSelectedFieldsO option').each(function(i, selected){				
						if($(selected).text() == sTexts)
						{
							dup = true;
						}				
					});
					if(dup == false)
					{
						 var option = new Option(sTexts, "value");
						 $('#drpSelectedFieldsO').append(option);
					}	
                });
			}
		}
		else
		{
			alert('Please select at least one value from list box');
		}
	}
	else
	{
		if ($("#drpSelectedFieldsO option:selected").length > 0){			
			$("#drpSelectedFieldsO option:selected").remove();
		}
		else
		{
			alert('Please select at least one value from list box');
		}
	}
}
function UpDownSelectedO(flag)
{
	if ($("#drpSelectedFieldsO option:selected").length > 0){
		var $op = $('#drpSelectedFieldsO option:selected');
		if($op.length){
			(flag == '1') ? $op.first().prev().before($op) : $op.last().next().after($op);
		}
	}
}
function SearchFees()
{
	if($('#drpGroupBatch').val() > 0)
	{
		$.ajax({
			type: "POST",
			url: URL + "/GetSession",
			data: '{}',
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			success: function (dt)
			{
				if(dt.d > 0)
				{
					LoadingMessage('Loading Details','<b>Please Wait ...</b>');
					var OrderByStr = '', ClassStr = '', ReceiptBookStr = '';				
					$("#drpSelectedFieldsO option").each(function(index, element) {
						OrderByStr = OrderByStr + $(this).text() + ',';
					});
					if($('#chkClass').is(':checked'))
					{
						$('#dvClass').children('input[type=checkbox]').each(function(index, element) {
							if($(this).is(':checked'))
							{
								ClassStr = ClassStr + $(this).attr('attrid') + ',';
							}
						});
					}				
					if($('#chkReceiptBook').is(':checked'))
					{
						$('#dvReceiptBook').children('input[type=checkbox]').each(function(index, element) {
							if($(this).is(':checked'))
							{
								ReceiptBookStr = ReceiptBookStr + $(this).attr('attrid') + ',';
							}
						});
					}				
					var isCancel = $('#chkCancel').is(':checked') ? 1 : 0;				
					var isSaveReport = $('#chkSaveReport').is(':checked') ? 1 : 0;
					var isCommon = $('#chkIsCommon').is(':checked') ? 1 : 0;
					var isCommonForOrg = $('#chkIsCommonForOrg').is(':checked') ? 1 : 0;
					var obj = {
						"GroupBatchId": $('#drpGroupBatch').val(),
						"OrgId": $('#drpOrganization').val(),
						"BatchId": $('#drpBatch').val(),
						"ReceiptBookId": $('#drpReceiptBook').val(),
						"DepartmentId": $('#drpDepartment').val(),
						"ClassId": $('#drpClass').val(),
						"DivisionId": $('#drpDivision').val(),
						"StatusId": $('#drpStatus').val(),
						"AdmissionCategoryId": $('#drpAdmissionCategory').val(),
						"UserName": $('#txtUser').val(),
						"Code": $('#txtIdNumber').val(),
						"FirstName": $('#txtFirstName').val(),
						"LastName": $('#txtLastName').val(),
						"FromDate": $('#txtFReceiptDate').val(),
						"ToDate": $('#txtTReceiptDate').val(),					
						"FromNumber": $('#txtFReceiptNo').val(),
						"ToNumber": $('#txtTReceiptNo').val(),										
						"OrderByStr": OrderByStr,
						"ClassStr": ClassStr,
						"ReceiptBookStr": ReceiptBookStr,					
						"isSaveReport": isSaveReport,
						"isCancel": isCancel,					
						"isCommon": isCommon,
						"isCommonForOrg": isCommonForOrg,
						"ReportName": $('#txtReportName').val(),
						"PageIndex": $('#hdnPageIndex').val(),
						"UserId": $('#hdnUserId').val()
					};
					$.ajax({
						type: "POST",
						url: URL + "/SearchFees",
						data: JSON.stringify(obj),
						contentType: "application/json;charset=utf-8",
						dataType: "json",
						success: function (data)
						{
							var datas = $.parseJSON(data.d);
							if(datas.StudentList != '')
							{
								$('#tblStudentList').html(datas.UserResult);
								$('#pagging').html(datas.UserPaging);
								$('#lblTotalRecords').html('Total Records : ' + datas.UserTotal + '&nbsp;&nbsp;&nbsp;&nbsp;');
							}
							else
							{
								$('#tblStudentList').html('<tr><td colspan="11">No Records Available</td></tr>');
							}
							window.setTimeout(function () { CloseHlsPopup(); },400);
						},
						error: function (xhr, status, error)
						{
							var err = eval("(" + xhr.responseText + ")");
							console.log(err.Message);
						}
					});
				}
				else
				{
					CloseHlsPopup();
					LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
					window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
				}
			},
			error: function (xhr, status, error)
			{
				var err = eval("(" + xhr.responseText + ")");
				console.log(err.Message);
			}
		});
	}
	else
	{
		alert('please select group batch');
	}
}
function ResetControls()
{
	$('#hdnPageIndex').val(1);
	$('#hdnUserId').val(0);
	$('#drpGroupBatch').val(0);
	$('#drpOrganization').val(0);
	$('#drpBatch').val(0);
	$('#drpReceiptBook').val(0);
	$('#drpDepartment').val(0);
	$('#drpClass').val(0);
	$('#drpDivision').val(0);
	$('#drpStatus').val(0);
	$('#txtUser').val('');
	$('#txtIdNumber').val('');
	$('#txtFirstName').val('');
	$('#txtLastName').val('');
	$('#txtFReceiptDate').val('');
	$('#txtTReceiptDate').val('');					
	$('#txtFReceiptNo').val('');
	$('#txtTReceiptNo').val('');
	$('#txtReportName').val('');
	
	$('#chkClass').prop('checked',false);
	$('#dvClass').html('');
	$('#dvClass').hide();
	$('#dvClass').css('height','0');
	$("#dvClass").slimScroll({destroy: true});
	
	$('#chkReceiptBook').prop('checked',false);
	$('#dvReceiptBook').html('');
	$('#dvReceiptBook').hide();
	$('#dvReceiptBook').css('height','0');
	$("#dvReceiptBook").slimScroll({destroy: true});
	
	$('#chkCancel').prop('checked', false);
	$('#chkSaveReport').prop('checked', false);
	$('#chkIsCommon').prop('checked', false);
	$('#chkIsCommonForOrg').prop('checked', false);
	
	$('#tblStudentList').html('');
	$('#pagging').html('');
	$('#lblTotalRecords').html('');
}
function ChangePage(pageindex)
{
	$('#hdnPageIndex').val(pageindex);
	SearchFees();
}
function GenerateReport()
{
    if ($("#drpSelectedFields option").length > 0 || parseInt($('#drpSavedReport').val()) != 0)
	{
		$.ajax({
			type: "POST",
			url: URL + "/GetSession",
			data: '{}',
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			success: function (dt)
			{
				if(dt.d > 0)
				{
					LoadingMessage('Loading Details','<b>Please Wait ...</b>');
					var OrderByStr = '', ClassStr = '', ReceiptBookStr = '', CustomFields = '';				
					$("#drpSelectedFieldsO option").each(function(index, element) {
						OrderByStr = OrderByStr + $(this).text() + ',';
					});
					$("#drpSelectedFields option").each(function(index, element) {
						CustomFields = CustomFields + $(this).text() + ',';
					});
					if($('#chkClass').is(':checked'))
					{
						$('#dvClass').children('input[type=checkbox]').each(function(index, element) {
							if($(this).is(':checked'))
							{
								ClassStr = ClassStr + $(this).attr('attrid') + ',';
							}
						});
					}				
					if($('#chkReceiptBook').is(':checked'))
					{
						$('#dvReceiptBook').children('input[type=checkbox]').each(function(index, element) {
							if($(this).is(':checked'))
							{
								ReceiptBookStr = ReceiptBookStr + $(this).attr('attrid') + ',';
							}
						});
					}				
					var isCancel = $('#chkCancel').is(':checked') ? 1 : 0;				
					var isSaveReport = $('#chkSaveReport').is(':checked') ? 1 : 0;
					var isCommon = $('#chkIsCommon').is(':checked') ? 1 : 0;
					var isCommonForOrg = $('#chkIsCommonForOrg').is(':checked') ? 1 : 0;
					var obj = {
						"GroupBatchId": $('#drpGroupBatch').val(),
						"OrgId": $('#drpOrganization').val(),
						"BatchId": $('#drpBatch').val(),
						"ReceiptBookId": $('#drpReceiptBook').val(),
						"DepartmentId": $('#drpDepartment').val(),
						"ClassId": $('#drpClass').val(),
						"DivisionId": $('#drpDivision').val(),
						"StatusId": $('#drpStatus').val(),
						"UserName": $('#txtUser').val(),
						"Code": $('#txtIdNumber').val(),
						"FirstName": $('#txtFirstName').val(),
						"LastName": $('#txtLastName').val(),
						"FromDate": $('#txtFReceiptDate').val(),
						"ToDate": $('#txtTReceiptDate').val(),					
						"FromNumber": $('#txtFReceiptNo').val(),
						"ToNumber": $('#txtTReceiptNo').val(),										
						"OrderByStr": OrderByStr,
						"ClassStr": ClassStr,
						"ReceiptBookStr": ReceiptBookStr,					
						"isSaveReport": isSaveReport,
						"isCancel": isCancel,					
						"isCommon": isCommon,
						"isCommonForOrg": isCommonForOrg,
						"ReportName": $('#txtReportName').val(),
						"PageIndex": $('#hdnPageIndex').val(),
						"UserId": $('#hdnUserId').val(),
						"CustomFields": CustomFields,
						"SavedReport": $('#drpSavedReport').val(),
						"AdmissionCategoryId": $('#drpAdmissionCategory').val(),
					};
					$.ajax({
						type: "POST",
						url: URL + "/GenerateFeeReport",
						data: JSON.stringify(obj),
						contentType: "application/json;charset=utf-8",
						dataType: "json",
						success: function (data)
						{
							$('#btnGenerate').click();
							window.setTimeout(function () { CloseHlsPopup(); },400);
						},
						error: function (xhr, status, error)
						{
							var err = eval("(" + xhr.responseText + ")");
							console.log(err.Message);
						}
					});
				}
				else
				{
					CloseHlsPopup();
					LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
					window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
				}
			},
			error: function (xhr, status, error)
			{
				var err = eval("(" + xhr.responseText + ")");
				console.log(err.Message);
			}
		});
	}
	else
	{
		alert('select atleast one field in custom field');
	}
}
function SecectThisRecord(vObj)
{
	$.ajax({
		type: "POST",
		url: URL + "/GetSession",
		data: '{}',
		contentType: "application/json;charset=utf-8",
		dataType: "json",
		success: function (dt)
		{
			if(dt.d > 0)
			{
				var ReceiptNo = $(vObj).parent().parent().attr('attrReceiptNo');
				var BatchId = $(vObj).parent().parent().attr('attrBatchId');
				var OrgId = $(vObj).parent().parent().attr('attrOrgId');
				var OrgGroupBatch = $(vObj).parent().parent().attr('attrOrgGroupBatchId');
				LoadingMessage('Loading Details','<b>Please Wait ...</b>');				
				var obj = {
					"ReceiptNo": ReceiptNo,
					"BatchId": BatchId,
					"OrgId": OrgId,
					"OrgGroupBatch": OrgGroupBatch
				};
				$.ajax({
					type: "POST",
					url: URL + "/SecectThisRecord",
					data: JSON.stringify(obj),
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					success: function (data)
					{
						window.location = '/Pages/FeeManagement/FeeReceipt.aspx';
					},
					error: function (xhr, status, error)
					{
						var err = eval("(" + xhr.responseText + ")");
						console.log(err.Message);
					}
				});
			}
			else
			{
				CloseHlsPopup();
				LoadingMessage('Your session has expired, we are redirecting to login page','<b>Please Wait ...</b>');
				window.setTimeout(function(){ window.location = '/Pages/BaseFramework/Security/Login.aspx'; },2000);
			}
		},
		error: function (xhr, status, error)
		{
			var err = eval("(" + xhr.responseText + ")");
			console.log(err.Message);
		}
	});
}

function ViewReport(Id, Title, ColumnName) {
    $.ajax({
        type: "POST",
        url: URL + "/GetSession",
        data: '{}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (dt) {
            if (dt.d > 0) {
                var x = confirm('Do you want to Download?');
                if (x == true) {
                    LoadingMessage('Loading Details', '<b>Please Wait ...</b>');
                    var obj = {
                        "Id": Id,
                        "Title": Title,
                        "ColumnName": ColumnName
                    };
                    $.ajax({
                        type: "POST",
                        url: URL + "/ViewReport",
                        data: JSON.stringify(obj),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            $('#btnSaveReport').click();
                            CloseHlsPopup();
                        },
                        error: function (xhr, status, error) {
                            var err = eval("(" + xhr.responseText + ")");
                            console.log(err.Message);
                        }
                    });
                }
            }
            else {
                CloseHlsPopup();
                LoadingMessage('Your session has expired, we are redirecting to login page', '<b>Please Wait ...</b>');
                window.setTimeout(function () { window.location = '/Pages/BaseFramework/Security/Login.aspx'; }, 2000);
            }
        },
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}


function DeleteReport(Id) {
    $.ajax({
        type: "POST",
        url: URL + "/GetSession",
        data: '{}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (dt) {
            if (dt.d > 0) {
                var x = confirm('Do you want to delete?');
                if (x == true) {
                    LoadingMessage('Loading Details', '<b>Please Wait ...</b>');
                    var obj = {
                        "Id": Id
                    };
                    $.ajax({
                        type: "POST",
                        url: URL + "/DeleteReport",
                        data: JSON.stringify(obj),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            alert('Deleted successfully.... Please Refresh the Page');
                            CloseHlsPopup();
                        },
                        error: function (xhr, status, error) {
                            var err = eval("(" + xhr.responseText + ")");
                            console.log(err.Message);
                        }
                    });
                }
            }
            else {
                CloseHlsPopup();
                LoadingMessage('Your session has expired, we are redirecting to login page', '<b>Please Wait ...</b>');
                window.setTimeout(function () { window.location = '/Pages/BaseFramework/Security/Login.aspx'; }, 2000);
            }
        },
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}


