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();
}
function OpenProductTab(_this, tab) {	
	$('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);
					    $('#drpOrganization').html(dt.OrganizationRes);
						$('#drpStatus').html(dt.StatusRes);
						$('#drpStatus').val(7);
						$('#drpAvailableFields').html(dt.AvailableRes + dt.AvailableEmployeeCustomRes);
						$('#drpAvailableFieldsO').html(dt.AvailableRes + dt.AvailableEmployeeCustomRes);
						if(dt.ReportList != '')
							$('#tblReportList').html(dt.ReportList);
						else
						    $('#tblReportList').html('<tr><td colspan="5">No Records available!</td></tr>');
						$('#drpSavedReport').html(dt.SavedReportList);
						$('#customtagchkdropdown').html(dt.customtaghklist);
						

						$("#customtagchkdropdown").multiSelect();

						$('#drpAvailableFields option').each(function (i, selected) {
						    //debugger;
						    $(this).text($(this).text().replace("|", "[").replace("||", "]"));
						    $(this).val($(this).text().replace("|", "[").replace("||", "]"));
						});
						$('#drpAvailableFieldsO option').each(function (i, selected) {
						    //debugger;
						    $(this).text($(this).text().replace("|", "[").replace("||", "]"));
						    $(this).val($(this).text().replace("|", "[").replace("||", "]"));
						});

						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 ShowHideAndBind(cobj, flag)
{
	if($(cobj).is(':checked'))
	{
		$(cobj).parent().next('div').show();
		$(cobj).parent().next('div').html('&nbsp;<img src="../../../Images/loading-ajax.gif" />' + '&nbsp; Loading....');
		BindValues(cobj, flag);
	}
	else
	{
		$(cobj).parent().next('div').hide();
		$(cobj).parent().next('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,
				    "OrgId": $('#drpOrganization').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().next('div').html(datas.Result);
							$(cobj).parent().next('div').css('border','1px solid Silver');
							$(cobj).parent().next('div').slimScroll({ height: '100px' });
						}
						else
						{
							$(cobj).parent().next('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 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){
		$('#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 SearchEmployees()
{
	$.ajax({
        type: "POST",
        url: URL + "/GetSession",
        data: '{}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (dt)
        {
            debugger;
			if(dt.d > 0)
			{
				LoadingMessage('Loading Details','<b>Please Wait ...</b>');
				var OrderByStr = '', StatusStr = '', ReligionStr = '', MaritalStr = '', GenderStr = '';
				var DesignationStr = '', EmpTypeStr = '', EmpGroupStr = '', BloodGroupStr = '', DepartmentStr = '', TagStr = '';
				$("#drpSelectedFieldsO option").each(function(index, element) {
					OrderByStr = OrderByStr + $(this).text() + ',';
				});
				$('#customtagchkdropdown option:selected').each(function (i, sel) {
				    TagStr = TagStr + $(sel).val() + ',';
				});
				if ($('#chkCustomTag').is(':checked')) {
				    $('#dvCustomTag').children('input[type=checkbox]').each(function (index, element) {
				        if ($(this).is(':checked')) {
				            TagStr = TagStr + $(this).attr('attrid') + ',';
				        }
				    });
				}
				if($('#chkStatus').is(':checked'))
				{
					$('#dvStatus').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							StatusStr = StatusStr + $(this).attr('attrid') + ',';
						}
                    });
				}
				if($('#chkReligion').is(':checked'))
				{
					$('#dvReligion').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							ReligionStr = ReligionStr + $(this).attr('attrid') + ',';
						}
                    });
				}
				if($('#chkMaritalStatus').is(':checked'))
				{
					$('#dvMaritalStatus').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							MaritalStr = MaritalStr + $(this).attr('attrid') + ',';
						}
                    });
				}
				if($('#chkGender').is(':checked'))
				{
					$('#dvGender').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							GenderStr = GenderStr + $(this).attr('attrid') + ',';
						}
                    });
				}
				if($('#chkDesignation').is(':checked'))
				{
					$('#dvDesignation').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							DesignationStr = DesignationStr + $(this).attr('attrid') + ',';
						}
                    });
				}
				if($('#chkEmployeeType').is(':checked'))
				{
					$('#dvEmployeeType').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							EmpTypeStr = EmpTypeStr + $(this).attr('attrid') + ',';
						}
                    });
				}
				if($('#chkEmployeeGroup').is(':checked'))
				{
					$('#dvEmployeeGroup').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							EmpGroupStr = EmpGroupStr + $(this).attr('attrid') + ',';
						}
                    });
				}
				if($('#chkOrganizationDepartment').is(':checked'))
				{
					$('#dvOrganizationDepartment').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							DepartmentStr = DepartmentStr + $(this).attr('attrid') + ',';
						}
                    });
				}
				if($('#chkBloodGroup').is(':checked'))
				{
					$('#dvBloodGroup').children('input[type=checkbox]').each(function(index, element) {
                        if($(this).is(':checked'))
						{
							BloodGroupStr = BloodGroupStr + $(this).attr('attrid') + ',';
						}
                    });
				}				
				var isSaveReport = $('#chkSaveReport').is(':checked') ? 1 : 0;
				var isCommon = $('#chkIsCommon').is(':checked') ? 1 : 0;
				var isCommonForOrg = $('#chkIsCommonForOrg').is(':checked') ? 1 : 0;
				var isOtherUser = $('#chkNotEmployee').is(':checked') ? 1 : 0;
				var obj = {
                    
					"StatusId": $('#drpStatus').val(),
					"IdNumber": $('#txtIdNo').val(),
                    "Number": $('#txtNo').val(),
					"FirstName": $('#txtFirstName').val(),
					"LastName": $('#txtLastName').val(),
					"Qualification": $('#txtQualification').val(),					
					"FromDateOfBirth": $('#txtFDateOfBirth').val(),
					"ToDateOfBirth": $('#txtTDateOfBirth').val(),
					"FromJoiningDate": $('#txtFJoiningDate').val(),
					"ToJoiningDate": $('#txtTJoiningDate').val(),
					"OrderByStr": OrderByStr,
					"StatusStr": StatusStr,
					"ReligionStr": ReligionStr,
					"MaritalStr": MaritalStr,
					"GenderStr": GenderStr,
					"DesignationStr": DesignationStr,
					"EmpTypeStr": EmpTypeStr,
					"EmpGroupStr": EmpGroupStr,
					"BloodGroupStr": BloodGroupStr,
					"DepartmentStr": DepartmentStr,
					"isSaveReport": isSaveReport,
					"isCommon": isCommon,
					"isCommonForOrg": isCommonForOrg,
					"ReportName": $('#txtReportName').val(),
					"PageIndex": $('#hdnPageIndex').val(),
                    "LeftFromDate": $('#txtFLeftDate').val(),
                    "LeftToDate": $('#txtTLeftDate').val(),
                    "ProbationUptoDate": $('#txtProbationUptoDate').val(),
                    "AhdocUptoDate": $('#txtAhdocUptoDate').val(),
                    "PermanentDate": $('#txtPermanentDate').val(),
                    "DateOfResignation": $('#txtDateOfResignation').val(),
                    "PageIndex": $('#hdnPageIndex').val(),
                    "TagStr": TagStr,
                    "isOtherUser": isOtherUser,
                    "OrganizationId": $('#drpOrganization').val()
				};
				debugger;
				$.ajax({
					type: "POST",
					url: URL + "/SearchEmployees",
					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.EmpList);
							var paging = datas.Paging.replace('../../Images/arrowRight.gif','../../../Images/arrowRight.gif');
							paging = paging.replace('../../Images/arrowLeft.gif','../../../Images/arrowLeft.gif');
							$('#pagging').html(paging);
							$('#lblTotalRecords').html('Total Records : ' + datas.TotalRecords + '&nbsp;&nbsp;&nbsp;&nbsp;');
						}
						else
						{
							$('#tblStudentList').html('<tr><td colspan="5">No Records Available</td></tr>');
						}
						window.setTimeout(function () { CloseHlsPopup(); }, 400);
						//$("#customPaging").show();
						//$("#drpCustomUpdatePaging").html(DropDownHtml);
					},
					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 ChangePage(pageindex)
{
    debugger;
	$('#hdnPageIndex').val(pageindex);	
	SearchEmployees();
}
function ResetControls()
{
	$('#hdnPageIndex').val(1);	
	$('#drpStatus').val(0);
	$('#txtIdNo').val('');
	$('#txtNo').val('');
	$('#txtFirstName').val('');
	$('#txtLastName').val('');	
	$('#txtFDateOfBirth').val('');
	$('#txtTDateOfBirth').val('');
	$('#txtFJoiningDate').val('');
	$('#txtTJoiningDate').val('');	
	$('#txtQualification').val('');	
	$('#txtReportName').val('');
	$('#txtProbationUptoDate').val('');
	$('#txtAhdocUptoDate').val('');
	$('#txtPermanentDate').val('');
	$('#txtDateOfResignation').val('');
	$("#customtagchkdropdown").val('');
	
	$('#chkStatus').prop('checked',false);
	$('#dvStatus').html('');
	$('#dvStatus').hide();
	$('#dvStatus').css('height','0');
	$("#dvStatus").slimScroll({destroy: true});
	
	$('#chkReligion').prop('checked',false);
	$('#dvReligion').html('');
	$('#dvReligion').hide();
	$('#dvReligion').css('height','0');
	$("#dvReligion").slimScroll({destroy: true});
	
	$('#chkMaritalStatus').prop('checked',false);
	$('#dvMaritalStatus').html('');
	$('#dvMaritalStatus').hide();
	$('#dvMaritalStatus').css('height','0');
	$("#dvMaritalStatus").slimScroll({destroy: true});
	
	$('#chkGender').prop('checked',false);
	$('#dvGender').html('');
	$('#dvGender').hide();
	$('#dvGender').css('height','0');
	$("#dvGender").slimScroll({destroy: true});
	
	$('#chkDesignation').prop('checked',false);
	$('#dvDesignation').html('');
	$('#dvDesignation').hide();
	$('#dvDesignation').css('height','0');
	$("#dvDesignation").slimScroll({destroy: true});
	
	$('#chkEmployeeType').prop('checked',false);
	$('#dvEmployeeType').html('');
	$('#dvEmployeeType').hide();
	$('#dvEmployeeType').css('height','0');
	$("#dvEmployeeType").slimScroll({destroy: true});
	
	$('#chkEmployeeGroup').prop('checked',false);
	$('#dvEmployeeGroup').html('');
	$('#dvEmployeeGroup').hide();
	$('#dvEmployeeGroup').css('height','0');
	$("#dvEmployeeGroup").slimScroll({destroy: true});
	
	$('#chkOrganizationDepartment').prop('checked',false);
	$('#dvOrganizationDepartment').html('');
	$('#dvOrganizationDepartment').hide();
	$('#dvOrganizationDepartment').css('height','0');
	$("#dvOrganizationDepartment").slimScroll({destroy: true});
	
	$('#chkBloodGroup').prop('checked',false);
	$('#dvBloodGroup').html('');
	$('#dvBloodGroup').hide();
	$('#dvBloodGroup').css('height','0');
	$("#dvBloodGroup").slimScroll({destroy: true});
	
	$('#chkSaveReport').prop('checked',false);
	$('#chkIsCommon').prop('checked', false);
	$('#chkIsCommonForOrg').prop('checked', false);
	$('#tblStudentList').html('');
	$('#pagging').html('');
	$("#customPaging").hide();
	$('#lblTotalRecords').html('');
}
function GenerateReport()
{
    if ($("#drpSelectedFields option").length > 0 || parseInt($('#drpSavedReport').val()) != 0)
    {
        if ($("#drpSelectedFields option").length > 9 && $('#drpViewMode').val() == "PDF") {
            alert('Select maximum 8 custom fields');
        }
        else {
            $.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 = '', StatusStr = '', ReligionStr = '', MaritalStr = '', GenderStr = '';
                        var DesignationStr = '', EmpTypeStr = '', EmpGroupStr = '', BloodGroupStr = '', DepartmentStr = '';
                        var CustomFields = '', TagStr = '';
                        $("#drpSelectedFieldsO option").each(function (index, element) {
                            OrderByStr = OrderByStr + $(this).text() + ',';
                        });
                        $("#drpSelectedFields option").each(function (index, element) {
                            CustomFields = CustomFields + $(this).text() + ',';
                        });
                        $('#customtagchkdropdown option:selected').each(function (i, sel) {
                            TagStr = TagStr + $(sel).val() + ',';
                        });
                        if ($('#chkStatus').is(':checked')) {
                            $('#dvStatus').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    StatusStr = StatusStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkReligion').is(':checked')) {
                            $('#dvReligion').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    ReligionStr = ReligionStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkMaritalStatus').is(':checked')) {
                            $('#dvMaritalStatus').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    MaritalStr = MaritalStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkGender').is(':checked')) {
                            $('#dvGender').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    GenderStr = GenderStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkDesignation').is(':checked')) {
                            $('#dvDesignation').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    DesignationStr = DesignationStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkEmployeeType').is(':checked')) {
                            $('#dvEmployeeType').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    EmpTypeStr = EmpTypeStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkEmployeeGroup').is(':checked')) {
                            $('#dvEmployeeGroup').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    EmpGroupStr = EmpGroupStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkOrganizationDepartment').is(':checked')) {
                            $('#dvOrganizationDepartment').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    DepartmentStr = DepartmentStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkBloodGroup').is(':checked')) {
                            $('#dvBloodGroup').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    BloodGroupStr = BloodGroupStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        if ($('#chkCustomTag').is(':checked')) {
                            $('#dvCustomTag').children('input[type=checkbox]').each(function (index, element) {
                                if ($(this).is(':checked')) {
                                    TagStr = TagStr + $(this).attr('attrid') + ',';
                                }
                            });
                        }
                        var isSaveReport = $('#chkSaveReport').is(':checked') ? 1 : 0;
                        var isCommon = $('#chkIsCommon').is(':checked') ? 1 : 0;
                        var isCommonForOrg = $('#chkIsCommonForOrg').is(':checked') ? 1 : 0;
                        var isOtherUser = $('#chkNotEmployee').is(':checked') ? 1 : 0;
                        var obj = {
                            "StatusId": $('#drpStatus').val(),
                            "IdNumber": $('#txtIdNo').val(),
                            "Number": $('#txtNo').val(),
                            "FirstName": $('#txtFirstName').val(),
                            "LastName": $('#txtLastName').val(),
                            "Qualification": $('#txtQualification').val(),
                            "FromDateOfBirth": $('#txtFDateOfBirth').val(),
                            "ToDateOfBirth": $('#txtTDateOfBirth').val(),
                            "FromJoiningDate": $('#txtFJoiningDate').val(),
                            "ToJoiningDate": $('#txtTJoiningDate').val(),
                            "OrderByStr": OrderByStr,
                            "StatusStr": StatusStr,
                            "ReligionStr": ReligionStr,
                            "MaritalStr": MaritalStr,
                            "GenderStr": GenderStr,
                            "DesignationStr": DesignationStr,
                            "EmpTypeStr": EmpTypeStr,
                            "EmpGroupStr": EmpGroupStr,
                            "BloodGroupStr": BloodGroupStr,
                            "DepartmentStr": DepartmentStr,
                            "isSaveReport": isSaveReport,
                            "isCommon": isCommon,
                            "isCommonForOrg": isCommonForOrg,
                            "ReportName": $('#txtReportName').val(),
                            "PageIndex": $('#hdnPageIndex').val(),
                            "CustomFields": CustomFields,
                            "SavedReport": $('#drpSavedReport').val(),
                            "LeftFromDate": $('#txtFLeftDate').val(),
                            "LeftToDate": $('#txtTLeftDate').val(),
                            "ProbationUptoDate": $('#txtProbationUptoDate').val(),
                            "AhdocUptoDate": $('#txtAhdocUptoDate').val(),
                            "PermanentDate": $('#txtPermanentDate').val(),
                            "DateOfResignation": $('#txtDateOfResignation').val(),
                            "TagStr": TagStr,
                            "isOtherUser": isOtherUser,
                            "OrganizationId": $('#drpOrganization').val()
                        };
                        $.ajax({
                            type: "POST",
                            url: URL + "/GenerateReport",
                            data: JSON.stringify(obj),
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            success: function (data) {
                                if ($('#drpViewMode').val() == "Excel")
                                    $('#btnGenerate').click();
                                else
                                    $('#btnView').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 CheckUncheckMessage(flag)
{
	if(flag == 1)
	{
		$('#dvSubject').hide();
		$('#txtSubject').val('');
		$('#lblMail').show();
		$('#lblMobile').show();
	}
	else if(flag == 2)
	{
		$('#dvSubject').show();
		$('#txtSubject').val('');
		$('#lblMobile').show();
		$('#lblMail').hide();
	}
	else
	{
		$('#dvSubject').show();
		$('#txtSubject').val('');
		$('#lblMail').hide();
		$('#lblMobile').hide();
	}
}
function ValidateAlert()
{
	var fields = '';
    var Title = 'Please fill the following details ___________________ \n\n';
	if($('#rdoMail').is(':checked') || $('#rdoMobile').is(':checked'))
	{
		if($('#txtSubject').val() == '')
		{
			fields = fields + 'Subject \n';
		}
	}
	if($('#txtMessage').val() == '')
	{
		fields = fields + 'Message \n';
	}
	if (fields.length > 0)
	{		
        alert(Title + fields);
		return false;
    }
    else
	{
        var x = confirm('Do you want to send alert?');
		if(x == true)
		{
			SendAlert();
		}
    }
}
function SendAlert()
{
	$.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 isRadioSMS = $('#rdoSMS').is(':checked') ? 1 : 0;
				var isRadioMail = $('#rdoMail').is(':checked') ? 1 : 0;
				var isRadioMobileApp = $('#rdoMobile').is(':checked') ? 1 : 0;
				var isChkMail = $('#chkMail').is(':checked') ? 1 : 0;
				var isChkMobileApp = $('#chkMobile').is(':checked') ? 1 : 0;
				var obj = {
					"isRadioSMS": isRadioSMS,
					"isRadioMail": isRadioMail,
					"isRadioMobileApp": isRadioMobileApp,
					"isChkMail": isChkMail,
					"isChkMobileApp": isChkMobileApp,
					"Subject": $('#txtSubject').val(),
					"Message": $('#txtMessage').val()
				};
				$.ajax({
					type: "POST",
					url: URL + "/SendAlert",
					data: JSON.stringify(obj),
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					success: function (data)
					{
						if (Number(datas.dtStatus) == 1)
						{
                            alert(datas.dtMessage);
                        }
						else
						{
                            alert(datas.dtMessage);
                        }
						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);
		}
    });
}
function SelectEmp(EmployeeId, Code)
{
	$.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 obj = {
					"EmployeeId": EmployeeId,
					"Code": Code
				};
				$.ajax({
					type: "POST",
					url: URL + "/SelectEmployee",
					data: JSON.stringify(obj),
					contentType: "application/json;charset=utf-8",
					dataType: "json",
					success: function (data)
					{
						window.location = '/Pages/Hrm/Employee/EmployeeGeneral.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 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);
        }
    });
}
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,
                        "OrganizationId": $('#drpOrganization').val()
                    };
                    $.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);
        }
    });
}