var serviceURLHR 	=localStorage['serviceURLHR'];
var HRPATH 			=localStorage['basicPATH'];
var hosturl    		=localStorage['basicURL'];
var HRPATH 			=localStorage['serviceURL'];
//var HRPATH 			=HRPATH+'HRMS/MM/Mccolins/';
//var HRPATH	= HRPATH+'HRMS/MM/Mint/';

var editIcon = "images/edit.png";
var editIconpen = "images/pen.png";
var removeIcon = "images/delete.png";

$('.edit_form_date').live('click',function(){
		 $(this).datepicker({
							dateFormat:"dd-mm-yy",
							yearRange: "1950:2020",
							changeMonth: true, 
							changeYear: true
							})
		 		.focus();	
});

//getExitInterviewList();
//setTimeout(function(){ getExitInterviewList() },200);

jQuery('.get_exit_interview_list').live('click',function(){ getExitInterviewList(); });
jQuery('.addNewExitInterview').live('click',addNewExitInterview);
jQuery('.saveExitInterview').live('click',saveExitInterview);
jQuery('.editExitInterview').live('click',editExitInterview);
jQuery('.updateExitInterview').live('click',updateExitInterview);
jQuery('.removeExitInterview').live('click',removeExitInterview);
/*jQuery('.branch_List').live('click',branchList);
jQuery('.BranchList').live('click',BranchManagement);
jQuery('.addNewBranch').live('click',addNewBranch);
jQuery('.saveBranch').live('click',saveBranch);
jQuery('.removeBranch').live('click',removeBranch);
jQuery('.editBranch').live('click',editBranch);*/

jQuery('.manageCompany').live('click',function(){ companyManagement(); });
jQuery('.company_management').live('click',function(){ companyManagement(); });
jQuery('.branch_List').live('click',branchList);
jQuery('.BranchList').live('click',BranchManagement);
jQuery('.addNewBranch').live('click',addNewBranch);
jQuery('.saveBranch').live('click',saveBranch);
jQuery('.removeBranch').live('click',removeBranch);
jQuery('.editBranch').live('click',editBranch);
//jQuery('.editBranch').live('click',editBranch);

jQuery('.hrLists').live('change',changePages);

jQuery('.department_List').live('click',departmentList);
jQuery('.addNewDepartment').live('click',addNewDepartment);
jQuery('.saveDepartment').live('click',saveDepartment);
jQuery('.updateBranch').live('click',updateBranch);
jQuery('.editDepartment').live('click',editDepartment);
jQuery('.updateDepartment').live('click',updateDepartment);
jQuery('.removeDepartment').live('click',removeDepartment);

///////////////////rights checking/////////////////////
jQuery('.removeDepartment_right').live('click',removeDepartment_right);
jQuery('.editDepartment_right').live('click',editDepartment_right);
jQuery('.addNewDepartment_right').live('click',addNewDepartment_right);

jQuery('.editBranch_right').live('click',editBranch_right);
jQuery('.removeBranch_right').live('click',removeBranch_right);
jQuery('.addNewBranch_right').live('click',addNewBranch_right);

jQuery('.editDesignation_right').live('click',editDesignation_right);
jQuery('.removeDesignation_right').live('click',removeDesignation_right);
jQuery('.addNewDesignation_right').live('click',addNewDesignation_right);

jQuery('.editreporttime_right').live('click',editreporttime_right);
jQuery('.removereporttime_right').live('click',removereporttime_right);
jQuery('.addNewreporttime_right').live('click',addNewreporttime_right);

jQuery('.editdevice_right').live('click',editdevice_right);
jQuery('.removedevice_right').live('click',removedevice_right);
jQuery('.addNewdevice_right').live('click',addNewdevice_right);

//////////////////rights checking///////////

jQuery('.designation_List').live('click',designationList);
jQuery('.addNewDesignation').live('click',addNewDesignation);
jQuery('.saveDesignation').live('click',saveDesignation);
jQuery('.removeDesignation').live('click',removeDesignation);
jQuery('.editDesignation').live('click',editDesignation);
jQuery('.UpdateDesignation').live('click',UpdateDesignation);




jQuery('.company_rankList').live('click',companyList);
jQuery('.addNewCompany').live('click',addNewCompany);
jQuery('.savecompany').live('click',savecompany);
jQuery('.removecompany').live('click',removecompany);
jQuery('.editCompany').live('click',editCompany);
jQuery('.updatecompany').live('click',updatecompany);

/*jQuery('.report_time').live('click',reportTime);
jQuery('.addNewreporttime').live('click',addNewreporttime);
jQuery('.savereporttime').live('click',savereporttime);
jQuery('.editreporttime').live('click',editreporttime);
jQuery('.removereporttime').live('click',removereporttime);
jQuery('.Updatereporttime').live('click',Updatereporttime);*/

jQuery('.report_time').live('click',reportTime);
jQuery('.addNewreporttime').live('click',addNewreporttime);
jQuery('.savereporttime').live('click',savereporttime);
jQuery('.editReportTime').live('click',editReportTime);
jQuery('.removeReportTime').live('click',removereporttime);
jQuery('.updatereporttime').live('click',Updatereporttime);

jQuery('.shifting_periods').live('click',shifting_periods);
jQuery('.saveshifttime').live('click',SaveShiftingPeriods);
//jQuery('.editShift').live('click',EditShiftingPeriods);


jQuery('.employee_grouping').live('click',employee_grouping);
jQuery('.addNewEmployeeGroup').live('click',add_employee_grouping);
jQuery('.cancelNewDeductionGroup').live('click',function(){  $('.newEmployeeDetails').hide('clip',300,function(){ $(this).remove(); })  });
jQuery('.cancelNewEarningGroup').live('click',function(){  $('.newEmployeeDetails').hide('clip',300,function(){ $(this).remove(); })  });
jQuery('.cancelempgroup').live('click',function(){  $('.newEmpGroupform').hide('clip',300,function(){ $(this).remove(); })  });
jQuery('.saveempgroup').live('click',SaveEmpGroup);
jQuery('.editEmpGroup').live('click',EditEmpGroup);
jQuery('.updateempgroup').live('click',updateempgroup);
jQuery('.removeEmpGroup').live('click',DeleteEmpGroup);

jQuery('.BrhLists').live('change',changeBranch);
jQuery('.chgdept').live('change',dyndepart)
jQuery('.emp_list').live('change',changeBranch);

jQuery('.status_active').live('click',status_active);

jQuery('.device_List').live('click',deviceList);
jQuery('.addNewdevice').live('click',addNewdevice);
jQuery('.savedevice').live('click',savedevice);
jQuery('.editdevice').live('click',editdevice);
jQuery('.Updatedevice').live('click',updatedevice);
jQuery('.removedevice').live('click',removedevice);

function ValidateEmailEmp(email) {
        var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        return expr.test(email);
    };


function status_active(){
	var $this = $(this);
	var statusval	= $this.attr('data-img');
	var userid 	= $this.attr('data-id');
	$.getJSON(serviceURLHR + "empStatUpdate.php?act=update&user_id="+userid+"&status="+statusval,function(data){
																										  var newStatus = data.status;
		if(newStatus == 1){
					$this.attr({'src':'images/bullet_green.png','data-img':'1'});
				}else{
					$this.attr({'src':'images/bullet_orange.png','data-img':'0'});
				}
		});
	//$('.newBranchform').hide('blind',500,function(){ $(this).remove(); });
}


jQuery('.cancelNewCompany').live('click',function(){ $('.company_details_form').hide('blind',500,function(){ $(this).remove(); }) });
jQuery('.cancelNewExitinterview').live('click',function(){ $('.ExitInterview_details_form').hide('blind',500,function(){ $(this).remove(); }) });
jQuery('.cancelNewLeave').live('click',function(){ $('.newBranchform').hide('blind',500,function(){ $(this).remove(); }) });
jQuery('.cancelNewDepartment').live('click',function(){ $('.newDepartmentform').hide('blind',500,function(){ $(this).remove(); }) });
jQuery('.cancelDesignation').live('click',function(){ $('.newDesignationform').hide('blind',500,function(){ $(this).remove(); }) });
jQuery('.cancelcompany').live('click',function(){ $('.newcompanyform').hide('blind',500,function(){ $(this).remove(); }) });
jQuery('.cancelreporttime').live('click',function(){ $('.newReportimrform').hide('blind',500,function(){ $(this).remove(); }) });
jQuery('.canceldevice').live('click',function(){ $('.newdeviceform').hide('blind',500,function(){ $(this).remove(); }) });



$(document).ready(function() {
			var depart_id=$('.depart_id').val(); 
			if(depart_id == 3){
							   //changeBranch();
			}
		setTimeout(function(){ employeelist(1) },200);				   
});

$(window).load(function(){
	hash = window.location.href.split('#')[1]	;
	$('*[data-page="'+hash+'"]').addClass('btn-tab-active');
	switch(hash){
		case "ExitInterview"	:getExitInterviewList();break;
		case "ReportTime"	:reportTime();break;
		case "ListCompany"	:getExitInterviewList();break;
		case "Company"	:companyList();break;
		case "Designation" : designationList();break;
		case "Department" : departmentList();break;
		case "Branch" : branchList();break;
		case "Device" : deviceList();break;
		case "Leave" : leaveManage();break;
		case "manageCompany":companyManagement();break;
		case "EmployeeStatus":statusemp();break;
		case "EmployeeGrouping":employee_grouping();break;
		case "Shift":shifting_periods();break;
	
	}
});



$('.btn-tab-01').live('click',function(){
	window.location.hash = hash = $(this).attr('data-page');
	$('.btn-tab-active').removeClass('btn-tab-active');
	$('*[data-page="'+hash+'"]').addClass('btn-tab-active');
	//$(this).addClass('btn-tab-active');
});


/*locationHashChanged();					
													
window.onhashchange = locationHashChanged;			

function locationHashChanged() {	
	hash=window.location.href.split('#')[1]						
	if(hash){													
		$('.menu-selected').removeClass('menu-selected');			
		//var menuList = $('.payroll-menu');	
		
		$('li[data-page="'+hash+'"]').addClass('menu-selected');		
		setTimeout(window[hash],100); // call current function					
	}														
}*/

var companyManagement1 = function(){

	$('#masterlist').html('<form class="company-details field-style">'+
						'<table width="100%" border="0" cellspacing="0" cellpadding="0" class=" company-management" style="display:none;">'+
						  '<tr>'+
							'<td width="26%">&nbsp;</td>'+
							'<td width="74%"><div class="div-result"></div></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Name</td>'+
							'<td><input type="text" name="company_name" class="company_name" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Address</td>'+
							'<td><input type="text" name="company_address" class="company_address" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Phone No </td>'+
							'<td><input type="text" name="company_phone" class="company_phone" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Mobile No </td>'+
							'<td><input type="text" name="company_mobile" class="company_mobile" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">E-mail </td>'+
							'<td><input type="text" name="company_email" class="company_email" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Logo</td>'+
							'<td><input type="file" name="company_logo" class="company_logo" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td>&nbsp;</td>'+
							'<td><input type="button" value="update" class="color-button updateCompany" style="visibility:visible"></td>'+
						  '</tr>'+
						  '</table>'+
						  '</form>');
	
		$('.company-management').show('blind',500);
	
		$.getJSON(serviceURLHR + "company-details.php?action=list",function(data){ 
																			
				console.log(data);
				//alert(data.length);	
														
				permissions_user = data[0].permissions[0].user_id;	
				if(permissions_user!=1)
				{ 
					 if(data[0].permissions[0].edit_right==1)
					 {
						 $('.updateCompany').css( 'visibility','visible' );
					 }
					 else
					 {
						 $('.updateCompany').css( 'visibility','hidden' );
					 }
				}
				

				$('.company_name').val(data.company_name);
				$('.company_address').val(data.company_address);
				$('.company_phone').val(data.company_phone);
				$('.company_mobile').val(data.company_mobile);
				$('.company_email').val(data.company_email);
				
				if( data.company_logo != ""){
					$('.company_logo').css('display','none')
									  .after('<a class="removeLogo" style="cursor:pointer"> Remove Logo</a>')
									  .after('<img src="upload/thumb/'+data.company_logo+'" width="50">');
				}
				
				
			//	$('.company_logo').val(data.company_logo);
		});
	
	
}

$('.removeLogo').live('click',function(){
	$(this).parent().find('img').remove();
	$('.company_logo').css('display','block');
	$(this).remove();
					
});

$('.updateCompany').live('click',function(){
		var dataString = $('.company-details').serialize();
		
		var $form = $('.company-details');
		var dataString = new FormData($form[0]);

		$.ajax({
			type:'POST',
			url: serviceURLHR + "company-details.php?action=insert",
			data: dataString,
			processData: false,
			contentType: false ,  // tell jQuery not to set contentType
			beforeSend: function(xhr) {
		   //not important
		   		$('.div-result').html('Saving changes....');
			},
			success: function(data) {
				$('.div-result').html('Successfully updated.');
				alert("Company details successfully updated.");
				setTimeout(function(){ $('.div-result').html(''); },3000);
				companyManagement();
			}
		});

});



function dyndepart(){
	
	$this = $(this);
	//var dpartid = $this.attr('data-id');
	var dpartid = $this.val();//alert(dpartid);
	//alert(dpartid);
	//var  branchid= $('.BrhLists').val();
	
	var userid=$('.userid').val();
	if(userid == 1)
	{
		var  branchid= $('.BrhLists').val();
	}
	else
	{
		var branchid=$('.sessionbranch_id').val();
	}
		
	$.getJSON(serviceURLHR + "getdepartemployee.php?action=load&branch_id="+branchid+"&depart_id="+dpartid,
			 function(data) { 
		$('#busy').hide();
  	$('#tablelist').html('');
	
		employeeslist = data.name;
		//alert(employeeslist);
		 $('#headername').html('Cutlery List');
	//$('#tablelist').append('<div></div>');
var num=1;
var i=1;var cnt=0;var name='';
		$.each(employeeslist, function(index, employeeslist) {
				f_name=employeeslist.e_fname;	
				m_name=employeeslist.e_mname;	
				l_name=employeeslist.e_lname;	
				e_mail=employeeslist.e_mail;
				e_mailtitle=employeeslist.e_mail;
				e_mail = e_mail.substr(0,28);
				e_mob=employeeslist.e_mob;
				e_post=employeeslist.depart_name;
				e_designation=employeeslist.desig_name;
				if(employeeslist.photo=='')
				{
					 photo='noimg.jpg';
				}else{
			     if(employeeslist.e_gender=='Male' && employeeslist.photo=='noimg.jpg')
				        {
					     photo='noimg.jpg'; 
						  
				        }
				        else if(employeeslist.e_gender=='Female' && employeeslist.photo=='noimg.jpg')
				        { 
					     photo='Female.PNG'; 
				         }
						 else
						 {
			             photo=employeeslist.photo;	}
						 
						 }
			
			   e_in=employeeslist.time_in;	
			   
			  e_out=employeeslist.time_out;	
			  e_inloc=employeeslist.time_inloc;	
			  e_outloc=employeeslist.time_outloc;	
			  
			  e_empid=employeeslist.employee_id;
			  
			  
			  
			  employeename = f_name+' '+l_name;
			  employeename = employeename.substr(0,20);
			  
			  
			   if(employeeslist.clock_status==1)
                  {
			     var btnval = 'Clocked-In';
                 var bt_id=   'clockedout';
				 var btncolor ='button-color-login';
				 var emp_in=e_in;
				 var empin_loc=e_inloc;
           		  }else
				   {
            	 var btnval = 'Clocked-Out';
				 var bt_id=   'clockedin';
				 var btncolor ='button-color-logout';
				  var emp_in=e_out;
		 var empin_loc=e_outloc;
				   }
				   
				if(employeeslist.status==1)
                   {
				       var imgsts= 'images/bullet_green.png';
					   var imgval= 1;
				   }
				   else
				   {
					   var imgsts= 'images/bullet_orange.png';
					   var imgval= 0;
				   }
			  
				     $('#tablelist').append('<div class="employee-cell"><div class="clocked-in"><span class="clocked-status" style="width:1px"> <input type="button" name="btn" class="btn_'+employeeslist.e_id+' '+btncolor+'" id="'+bt_id+'" nums="'+num+'" value="'+btnval+'" style="width:80px" /><input type="hidden" name="txt"  class="txt_'+employeeslist.e_id+'" id="txt_id" value="'+employeeslist.clock_status+'"/></span><a href="timesheet-individual.html?employees='+employeeslist.e_id+'"></a></div> <div class="employee-foto"><a href="profile-view.php?employ_id='+employeeslist.e_id+'"><img src="'+HRPATH+'upload/image/'+photo+'" alt="" border="0" width="170" height="172" /></a></div><div class="employee-designation">'+e_designation+'</div><a class="findurl" href="profile-view.php?employ_id='+employeeslist.e_id+'" data-link="'+ employeeslist.e_id + '" id="emps_id'+num+'"><h2 style="font-size:15px; font-weight:bold;"><translate>'+employeename+'</translate></h2></a><h3 title="'+e_mailtitle+'">'+e_mail+'</h3><div style="float:left"><h4>'+e_empid+'</h4></div><div class="timesheet-nav"><a href="timesheet-individual.php?employees='+employeeslist.e_id+'">Timesheet</a></div></div>');
				num++;
				i++;
				
		});
		
		$.getJSON(serviceURLHR+"listing.php?loadtime=1",function(responce){

						var timeDetails = responce.timeDetails											   
                        
						$.each(timeDetails, function(index, timeDetails) {

							var empid = timeDetails.e_id;
                           
							

							$('.btn_'+empid).attr('id','clockin');

							$('.btn_'+empid).value('clockout');
							
							

						});	

						

				});
		$('#submitid').css("display","none");
	
		  $('#num').val(i);
		   pagination(pagenum,0,'pagenum');
		  
	});
	
	
	 
}

function load_emp_under_brnch_modified(branch_val)
{
	loadEmpBrnch_modified(branch_val);	
}
function load_emp_under_brnch(branch_val){
	if(branch_val!='' && branch_val > 0){
		loadEmpBrnch(branch_val);
	}
}

function loadEmpBrnch(branch_val){
	$.getJSON(serviceURLHR + 'employeename_list.php?action=loademp_branch&branch='+branch_val+'',function(data){
		empnamelist = data.empnamelist;	
		$.each(empnamelist, function(index, empnamelist) {									 
			$('.emp_list').append('<option value="'+empnamelist.e_id+'">'+empnamelist.e_fname+'</option>');
		});	
	});			
}


function loadEmpBrnch_modified(branch_val){
	if($('#filter_dept').val())
	{
		var dept_id=$('#filter_dept').val();	
	}
	else
	{
		var dept_id='';	
	}
	$.getJSON(serviceURLHR + 'employeename_list.php?action=loademp_branch_modified&branch='+branch_val+'&dept_id='+dept_id,function(data){
		empnamelist = data.empnamelist;	
		$('.Searchemp_list').html('<option value="">Employee name</option>');
		$.each(empnamelist, function(index, empnamelist) {									 
			$('.Searchemp_list').append('<option value="'+empnamelist.e_id+'">'+empnamelist.e_fname+'</option>');
		});	
	});			
}

function load_emp_under_dept_modified(dept_val){
	if($('#filter_branch').val())
	{
		var branch_id=$('#filter_branch').val();	
	}
	else
	{
		var branch_id='';	
	}
	$.getJSON(serviceURLHR + 'employeename_list.php?action=loademp_dept_modified&branch='+branch_id+'&dept_id='+dept_val,function(data){
		empnamelist = data.empnamelist;	
		$('.Searchemp_list').html('<option value="">Employee name</option>');
		$.each(empnamelist, function(index, empnamelist) {									 
			$('.Searchemp_list').append('<option value="'+empnamelist.e_id+'">'+empnamelist.e_fname+'</option>');
		});	
	});			
}

loademployeelist();
function loademployeelist(){ 
	$.getJSON(serviceURLHR + 'employeename_list.php?action=load',function(data){
		empnamelist = data.empnamelist;	
		$.each(empnamelist, function(index, empnamelist) {									 
							$('.emp_list').append('<option value="'+empnamelist.e_id+'">'+empnamelist.e_fname+'</option>');
							$('.Searchemp_list').append('<option value="'+empnamelist.e_id+'">'+empnamelist.e_fname+'</option>');
							
		});	
	});
}

loademployeeStatus();
function loademployeeStatus(){ 
	$.getJSON(serviceURLHR + 'employeename_list.php?action=load_emp_status',function(data){
		empnamelist = data.empnamelist;	
		$.each(empnamelist, function(index, empnamelist) {									 
			$('#filter_emp_status').append('<option value="'+empnamelist.id+'">'+empnamelist.emply_stat+'</option>');
		});	
	});
}

loadBrchName();
function loadBrchName(){
	$.getJSON(serviceURLHR + 'branch.php?action=load',function(data){
		branch = data.branch;	
		$.each(branch, function(index, branch) {									 
							$('.BrhLists').append('<option value="'+branch.branch_id+'">'+branch.branch_name+'</option>');
							
		});	
	});
}

loadBrchNameModified();
function loadBrchNameModified(){
	$.getJSON(serviceURLHR + 'branch.php?action=load',function(data){
		branch = data.branch;	
		$.each(branch, function(index, branch) {									 
							$('.SearchBrhLists').append('<option value="'+branch.branch_id+'">'+branch.branch_name+'</option>');
							
		});	
	});
}

loadDeptName();
function loadDeptName() {
	//alert(serviceURLHR);
	$.getJSON(serviceURLHR + "getdepartment.php?action=load",function(departdata) { 
		$('#busy').hide();
		$('#tabletabheadlist').html('');
		
		departnameList = departdata.department;
		//alert(departnameList);
		$.each(departnameList,function(index,departnameList){
			/*$('#tabletabheadlist').append('<input type="button" data-id="'+departnameList.depart_id+'" value="'+departnameList.depart_name+'" class="btn-tab-01 chgdept" title="'+departnameList.depart_name+'" />');*/							   $('#seldpt').append('<option value="'+departnameList.depart_id+'">'+departnameList.depart_name+'</option>');
			$('#filter_dept').append('<option value="'+departnameList.depart_id+'">'+departnameList.depart_name+'</option>');
		})	
		 
	});
}

function modified_search_employee_list()
{
	var userid=$('.userid').val();
	if(userid == 1)
	{
		var branchid = $('#filter_branch').val();	
	}
	else
	{
		var branchid=$('.sessionbranch_id').val();
	}	
	var emp_id = $('#filter_emp_id').val();	
	var dept_id=$('#filter_dept').val();
	var emp_status=$('#filter_emp_status').val();
	console.log('hai');
	$.getJSON(serviceURLHR + "employeesearchlist.php?branch_id="+branchid+"&emp_id="+emp_id+"&dept_id="+dept_id+"&emp_status="+emp_status,
		function(data) { 
			$('#busy').hide();
  			$('#tablelist').html('');
			employeeslist = data.name;
		 	$('#headername').html('Cutlery List');
			var num=1;
			var i=1;var cnt=0;var name='';
			$.each(employeeslist, function(index, employeeslist) {
				f_name=employeeslist.e_fname;	
				m_name=employeeslist.e_mname;	
				l_name=employeeslist.e_lname;	
				e_mail=employeeslist.e_mail;	
				e_mailtitle=employeeslist.e_mail;
				e_mail = e_mail.substr(0,28);
				e_mob=employeeslist.e_mob;
				e_post=employeeslist.e_post;
				e_empid=employeeslist.employee_id;
				
				if(employeeslist.photo=='')
				{ 
					photo='noimg.jpg';
				}
				else
				{
					if(employeeslist.e_gender=='Male' && employeeslist.photo=='noimg.jpg')
				    {
						photo='noimg.jpg'; 
					}
				    else if(employeeslist.e_gender=='Female' && employeeslist.photo=='noimg.jpg')
				    { 
						photo='Female.PNG'; 
					}
					else
					{
			        	photo=employeeslist.photo;	
					}
			   	}
			
			   	e_in=employeeslist.time_in;	
			  	e_out=employeeslist.time_out;	
			 	e_inloc=employeeslist.time_inloc;	
			  	e_outloc=employeeslist.time_outloc;	
			  	employeename = f_name+' '+l_name;
			  	employeename = employeename.substr(0,20);
			  
			   	if(employeeslist.clock_status==1)
                {
			    	var btnval = 'Clocked-In';
                 	var bt_id=   'clockedout';
				 	var btncolor ='button-color-login';
				 	var emp_in=e_in;
				 	var empin_loc=e_inloc;
           		}
				else
				{
            		var btnval = 'Clocked-Out';
				 	var bt_id=   'clockedin';
				 	var btncolor ='button-color-logout';
				  	var emp_in=e_out;
		 			var empin_loc=e_outloc;
				}
				   
				if(employeeslist.status==1)
                {
				    var imgsts= 'images/bullet_green.png';
					var imgval= 1;
				}
				else
				{
					var imgsts= 'images/bullet_orange.png';
					var imgval= 0;
				}

			  
				$('#tablelist').append('<div class="employee-cell"><div class="clocked-in"><span class="clocked-status" style="width:1px"> <input type="button" name="btn" class="btn_'+employeeslist.e_id+' '+btncolor+'" id="'+bt_id+'" nums="'+num+'" value="'+btnval+'" style="width:80px" /><input type="hidden" name="txt"  class="txt_'+employeeslist.e_id+'" id="txt_id" value="'+employeeslist.clock_status+'"/></span><a href="timesheet-individual.html?employees='+employeeslist.e_id+'"><span class="clocked-time" data-times="'+emp_in+'" id="e_time'+num+'" >'+emp_in+" "+empin_loc+'</span></a></div> <div class="employee-foto"><a href="profile-view.php?employ_id='+employeeslist.e_id+'"><img src="'+HRPATH+'upload/image/'+photo+'" alt="" border="0" width="170" height="172" /></a></div><div class="employee-designation">'+e_post+'</div><a class="findurl" href="profile-view.php?employ_id='+employeeslist.e_id+'" data-link="'+ employeeslist.e_id + '" id="emps_id'+num+'"><h2 style="font-size:15px; font-weight:bold;"><translate>'+employeename+'</translate></h2></a><h3 title="'+e_mailtitle+'">'+e_mail+'</h3><div style="float:left"><h4>Emp Code:'+e_empid+'</h4></div><div class="timesheet-nav"><a href="timesheet-individual.php?employees='+employeeslist.e_id+'"><translate>Timesheet</translate></a></div></div>');
				num++;
				i++;
			});
		
			$.getJSON(serviceURLHR+"listing.php?loadtime=1",function(responce){
				var timeDetails = responce.timeDetails											   
				$.each(timeDetails, function(index, timeDetails) {
					var empid = timeDetails.e_id;
					$('.btn_'+empid).attr('id','clockin');
					$('.btn_'+empid).value('clockout');
				});	
			});
			
			$('#submitid').css("display","none");
		  	$('#num').val(i);
		   	pagination(pagenum,0,'pagenum');
		});
}

function changeBranch(){
	var userid=$('.userid').val();
	if(userid == 1)
	{
		var branchid = '';
		$this = $(this);	
		//branchid = $this.val();	
		branchid = $('.BrhLists').val();	
		emplist = $('.emp_list').val();	
	}
	else
	{
		var branchid=$('.sessionbranch_id').val();
	}
	/* $.getJSON(serviceURLHR + "getdepartment.php?action=load&branch_id="+branchid,function(departdata) {
		$('#busy').hide();
		$('#tabletabheadlist').html('');
		
		departnameList = departdata.department;
		$.each(departnameList,function(index,departnameList){
			/*$('#tabletabheadlist').append('<input type="button" data-id="'+departnameList.depart_id+'" value="'+departnameList.depart_name+'" class="btn-tab-01 chgdept" title="'+departnameList.depart_name+'" />');	*/						     /* $('#seldpt').append('<option value="'+departnameList.depart_id+'">'+departnameList.depart_name+'</option>');
		})	
		 
	});*/
	
	$.getJSON(serviceURLHR + "getdepartment.php?action=emplist&branch_id="+branchid,function(employees) { 
		employees = employees.name;
	 	$('.emp_list').html('<option value="">Emp name</option>');
		$.each(employees,function(index,employees){
			  $('.emp_list').append('<option value="'+employees.e_id+'">'+employees.e_fname+'</option>');						   
		})	
 
	});
	
	
	
	
	$.getJSON(serviceURLHR + "employeelist.php?branch_id="+branchid+"&emp_id="+emplist,
		function(data) { 
			$('#busy').hide();
  			$('#tablelist').html('');
			employeeslist = data.name;
		 	$('#headername').html('Cutlery List');
			//$('#tablelist').append('<div></div>');
			var num=1;
			var i=1;var cnt=0;var name='';
			//alert(HRPATH);
			$.each(employeeslist, function(index, employeeslist) {
				f_name=employeeslist.e_fname;	//alert(employeeslist.e_gender);//subha
				m_name=employeeslist.e_mname;	
				l_name=employeeslist.e_lname;	
				e_mail=employeeslist.e_mail;	
				e_mailtitle=employeeslist.e_mail;
				e_mail = e_mail.substr(0,28);
				e_mob=employeeslist.e_mob;
				e_post=employeeslist.e_post;
				e_empid=employeeslist.employee_id;
				
				if(employeeslist.photo=='')
				{ 
					    photo='noimg.jpg';
				  
				   
				}else{
			   		   if(employeeslist.e_gender=='Male' && employeeslist.photo=='noimg.jpg')
				        {
					     photo='noimg.jpg'; 
						  
				        }
				        else if(employeeslist.e_gender=='Female' && employeeslist.photo=='noimg.jpg')
				        { 
					     photo='Female.PNG'; 
				         }
						 else
						 {
			             photo=employeeslist.photo;	}
			   	}
			
			   	e_in=employeeslist.time_in;	
			   
			  	e_out=employeeslist.time_out;	
			 	e_inloc=employeeslist.time_inloc;	
			  	e_outloc=employeeslist.time_outloc;	
			  	employeename = f_name+' '+l_name;
			  	employeename = employeename.substr(0,20);
			  
			   	if(employeeslist.clock_status==1)
                {
			    	var btnval = 'Clocked-In';
                 	var bt_id=   'clockedout';
				 	var btncolor ='button-color-login';
				 	var emp_in=e_in;
				 	var empin_loc=e_inloc;
           		}
				else
				{
            		var btnval = 'Clocked-Out';
				 	var bt_id=   'clockedin';
				 	var btncolor ='button-color-logout';
				  	var emp_in=e_out;
		 			var empin_loc=e_outloc;
				}
				   
				if(employeeslist.status==1)
                {
				    var imgsts= 'images/bullet_green.png';
					var imgval= 1;
				}
				   else
				   {
					   var imgsts= 'images/bullet_orange.png';
					   var imgval= 0;
				   }

			  
				     $('#tablelist').append('<div class="employee-cell"><div class="clocked-in"><span class="clocked-status" style="width:1px"> <input type="button" name="btn" class="btn_'+employeeslist.e_id+' '+btncolor+'" id="'+bt_id+'" nums="'+num+'" value="'+btnval+'" style="width:80px" /><input type="hidden" name="txt"  class="txt_'+employeeslist.e_id+'" id="txt_id" value="'+employeeslist.clock_status+'"/></span><a href="timesheet-individual.html?employees='+employeeslist.e_id+'"><span class="clocked-time" data-times="'+emp_in+'" id="e_time'+num+'" >'+emp_in+" "+empin_loc+'</span></a></div> <div class="employee-foto"><a href="profile-view.php?employ_id='+employeeslist.e_id+'"><img src="'+HRPATH+'upload/image/'+photo+'" alt="" border="0" width="170" height="172" /></a></div><div class="employee-designation">'+e_post+'</div><a class="findurl" href="profile-view.php?employ_id='+employeeslist.e_id+'" data-link="'+ employeeslist.e_id + '" id="emps_id'+num+'"><h2 style="font-size:15px; font-weight:bold;"><translate>'+employeename+'</translate></h2></a><h3 title="'+e_mailtitle+'">'+e_mail+'</h3><div style="float:left"><h4>Emp Code:'+e_empid+'</h4></div><div class="timesheet-nav"><a href="timesheet-individual.php?employees='+employeeslist.e_id+'"><translate>Timesheet</translate></a></div></div>');
				num++;
				i++;
				
		});
		$.getJSON(serviceURLHR+"listing.php?loadtime=1",function(responce){

						var timeDetails = responce.timeDetails											   
                        
						$.each(timeDetails, function(index, timeDetails) {

							var empid = timeDetails.e_id;
                           
							

							$('.btn_'+empid).attr('id','clockin');

							$('.btn_'+empid).value('clockout');
							
							

						});	

						

				});
		$('#submitid').css("display","none");
	
		  $('#num').val(i);
		   pagination(pagenum,0,'pagenum');
		  
	});
}


function changePages(){
	page=$(this).val();		
	if(page){													
		window[page](); // call current function					
	}
}


function updateBranch()
{
	var branch_name = $('#branch_name').val();
	var branch_code = $('#branch_code').val();
	var branch_address = $('#branch_address').val();
	var phnum = $('#phnum').val();
	var contact_details = $('#contact_details').val();
	var tin_num = $('#tin_num').val();
	var shop_estb_licencenum = $('#shop_estb_licencenum').val();
	
	if(branch_name == ''){
		alert('Branch Name is required');$('#branch_name').focus();
	}else if(branch_code == ''){
		alert('Branch Code is required');$('#branch_code').focus();
	}else if(branch_address == ''){
		alert('Branch Address is required');$('#branch_address').focus();
	}else if(phnum == ''){
		alert('Phone is required');$('#phnum').focus();
	}else if(contact_details == ''){
		alert('Email required');$('#contact_details').focus();
	}else if(contact_details != '' && !ValidateEmailEmp(contact_details)){
		alert('Email is Invalid. Please try another');$('#contact_details').focus();
	}else if(tin_num == ''){
		alert('Trader Identification Number is required');$('#tin_num').focus();
	}else if(shop_estb_licencenum == ''){
		alert('Shops And Establishments license Number is required');$('#shop_estb_licencenum').focus();
	}else{
		var branchDetails = $('.newBranchform').serialize();
		var companynameid 	= $('#company_nameid option:selected').text();
		var companyid 	= $('#company_nameid option:selected').val();
		var userid	= $('#userid').val();
		$.post(serviceURLHR + "BrnchUpdate.php?act=update",branchDetails,function(data){
			var currentUser = $('.branch_'+userid);
			currentUser.find('.brnName').text(data.branch_name);
			currentUser.find('.brnCode').text(data.brch_code);			
			currentUser.find('.compName').text(companynameid);
			currentUser.find('.compName').attr('data-id',companyid);
			currentUser.find('.brnAdd').text(data.brch_address);
			currentUser.find('.brnphno').text(data.brch_phno);
			currentUser.find('.brnContact').text(data.brch_contactno);
			currentUser.find('.brnTin').text(data.brch_tin);
			currentUser.find('.brnSales').text(data.brch_sales);
			currentUser.find('.brnService').text(data.brch_service_tax);
			currentUser.find('.brnShops').text(data.brch_shops);
			currentUser.find('.brchhalf').text(data.brch_half);
			},"json");
		$('.newBranchform').hide('blind',500,function(){ $(this).remove(); });
	}
}

function editBranch(){
	
	
	if($('.newBranchform').length){
		
	}else{
	$this = $(this);
	var userid 	= $this.attr('data-id');
	
	var name 	= $this.parent().parent().find('.brnName').text();
	var code 	= $this.parent().parent().find('.brnCode').text();
	var compNameID 	= $this.parent().parent().find('.compName').attr('data-id');
	var Address = $this.parent().parent().find('.brnAdd').text();
	var Phno 	= $this.parent().parent().find('.brnphno').text();
	var Contact = $this.parent().parent().find('.brnContact').text();
	var Tin 	= $this.parent().parent().find('.brnTin').text();
	var Sales 	= $this.parent().parent().find('.brnSales').text();
	var Service = $this.parent().parent().find('.brnService').text();
	var Shops 	= $this.parent().parent().find('.brnShops').text();
	var brchalf = $this.parent().parent().find('.brchhalf').text();
		
	
	$('.list-leavesu').before('<form class="newBranchform field-style"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Branch Name</translate></td>'+
									'<td ><input type="text" name="branch_name" id="branch_name" value="'+name+'" class="brhname"/></td>'+
								  '<td><input type="hidden" name="userid" id="userid" value="'+userid+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Company Name</translate></td>'+
									'<td><select name="company_nameid" id="company_nameid"><option selected="selected" value="">---select---</option></select></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Branch Code</translate></td>'+
									'<td ><input type="text" name="branch_code" id="branch_code" value="'+code+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Address</translate></td>'+
									'<td><textarea name="branch_address" id="address" >'+Address+'</textarea></td>'+
								  '</tr>'+	
								   '<tr>'+
									'<td><translate>Ph no</translate></td>'+
									'<td><input type="text" name="phnum" id="phnum" value="'+Phno+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Email</translate></td>'+
									'<td><input type="text" name="contact_details" id="contact_details" value="'+Contact+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Trader Identification Number</translate></td>'+
									'<td><input type="text" name="tin_num" id="tin_num" value="'+Tin+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Shops & Establishments license Number</translate></td>'+
									'<td><input type="text" name="shop_estb_licencenum" id="shop_estb_licencenum" value="'+Shops+'"/></td>'+
								  '</tr>'+
								 
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button updateBranch" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelNewLeave" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	
	$.getJSON(serviceURLHR + 'Company.php?action=load',function(data){
		leaves = data.companyList;
		$.each(leaves, function(index, leaves) {
									 
							$('#company_nameid').append('<option value="'+leaves.id+'">'+leaves.company_name+'</option>');
							
		});	
		setTimeout(function(){ $('#company_nameid').val(compNameID); },10);
	});
	
	$('.newLeave').show('blind');
		if(brchalf=="1")
		{
			$('#chk_halfday').prop('checked', true);
		}
	}
	
	
	
}


function getExitInterviewList(){

//alert(serviceURLHR);
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	$.getJSON(serviceURLHR + "exitinterview-details.php?action=list",function(data){
		var leaves = data.exitinterviewDetails;	
		
		//console.log(leaves);
		if(leaves.length > 0){
			permissions_user = leaves[leaves.length -1 ].permissions[0].user_id;
		}else{
			permissions_user = 1;
		}
			if(permissions_user!=1)
			{
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			    if(permissions_add==1)
				{ class_add='addNewExitInterview';}
				else{class_add='addNewCompany_right';}
			}
			else
			{
				class_add='addNewExitInterview';
			}
			
		
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leavesu">'+
								   '<tr>'+
											'<td  colspan="12" align="right" class="'+class_add+'"><img src="images/icon-add.png"  width="20" height="20" />Add Exit Interview</td>'+ '</tr>'+
										  '<tr>'+
										    '<td ><translate>Name</translate></td>'+
											'<td ><translate>Notes</translate></td>'+
											'<td ><translate>Leaving Date</translate></td>'+
											'<td ><translate>Settled On</translate></td>'+
											'<td ><translate>Notice Served</translate></td>'+
											'<td ><translate>Fit to be rehired</translate></td>'+
											'<td ><translate>Experience letter Issued</translate></td>'+
											'<td ><translate>PF Settlement Details Submitted</translate></td>'+
											'<td ><translate>PF Form Submitted</translate></td>'+
											'<td ><translate>PF Amt Settled</translate></td>'+
											'<td ><translate>Edit</translate></td>'+
											'<td >Delete</td>'+
										 '</tr>'+
										'</table>')	;
			

				if(permissions_user!=1)
			{
			
			permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_del = leaves[leaves.length -1 ].permissions[0].delete_right;
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			}
			if(permissions_user!=1)
			{
			   if(permissions_edit==1){  classedit='editCompany';  }else{classedit='editCompany_right';}
			   if(permissions_del==1){  classdel='removeCompany';  }else{classdel='removeCompany_right';}
			}
			else
			{
				classedit='editExitInterview'; 
				classdel='removeExitInterview';
			}

			$.each(leaves, function(index,leaves){
								
					if(leaves.notice_served == 1){var noticeserved = 'yes';	}else { var noticeserved = 'no'; }
					if(leaves.fit_to_rehired == 1){var fitrehired = 'yes';	}else { var fitrehired = 'no'; }
					if(leaves.experience_letr_issued == 1){var experience_letrissued = 'yes'; }else { var experience_letrissued = 'no'; }
					if(leaves.pf_details_submit == 1){var pf_detailsubmit = 'yes';}else { var pf_detailsubmit = 'no'; }
					if(leaves.pf_form_submit == 1){var pf_formsubmit = 'yes';}else { var pf_formsubmit = 'no'; }
					if(leaves.pf_amt_settled == 1){var pf_amtsettled = 'yes';}else { var pf_amtsettled = 'no'; }
			
					$('.list-leavesu').append( '<tr class="company_'+leaves.exit_intv_id+'">'+
														
														'<td  class="empnam" data-id="'+leaves.emp_id+'">'+leaves.e_fname+'</td>'+
														'<td  class="exitnotes">'+leaves.notes+'</td>'+
														'<td  class="leavedt">'+leaves.leave_dt+'</td>'+
														'<td  class="settledt">'+leaves.settled_date+'</td>'+
														'<td  class="noticeserv">'+noticeserved+'</td>'+
														'<td  class="fitrehired">'+fitrehired+'</td>'+
														'<td  class="expissued">'+experience_letrissued+'</td>'+
														'<td  class="pfdtsubmit">'+pf_detailsubmit+'</td>'+
														'<td  class="pfrmsubmit">'+pf_formsubmit+'</td>'+
														'<td  class="pfamtsettle">'+pf_amtsettled+'</td>'+
														'<td width=""><img data-id="'+leaves.exit_intv_id+'" src="'+editIconpen+'" class="'+classedit+'" alt="Edit Exit Interview"/></td>'+													
														'<td width=""><img data-id="'+leaves.exit_intv_id+'" src="'+removeIcon+'" class="'+classdel+'" alt="Delete Exit Interview" /></td>'+
													 '</tr>');				
			});
			$('.list-leavesu').show('blind',500);
		
	});	
}

/*function selectcountry1(){
$.ajax({
   url: serviceURLHR+"get.php",
   success: function(data){ 
     $("#country1").html(data);
	setTimeout(function(){ $("#country1").val(country_selected); },100);
	
   }
 });
}*/



function addNewExitInterview()
{
	
	$('.saveExitInterview').attr('disabled',false);
	if($('.ExitInterview_details_form').length){
		
	}else{
	$('.list-leavesu').before('<form class="ExitInterview_details_form field-style">'+
						'<table width="100%" border="0" cellspacing="0" cellpadding="0" class="newLeave" style="display:none;">'+
						  '<tr>'+
							'<td width="26%">&nbsp;</td>'+
							'<td width="74%"><div class="div-result"></div></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Name</td>'+
							'<td><select name="memberResignid" id="employeeResign" style="width:100px;" ><option value="">Member</option></select></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Notes</td>'+
							'<td><input type="text" name="exit_notes" id="exit_notes" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Leaving Date</td>'+
							'<td><input type="text" name="leaving_dt" id="leaving_dt" class="edit_form_date"  /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Settled On </td>'+
							'<td><input type="text" name="settled_on_date" id="settled_on_date" class="edit_form_date" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Notice Served </td>'+
							'<td><input type="checkbox" name="notice_served" id="notice_served" value="1" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Fit to be rehired </td>'+
							'<td><input type="checkbox" name="fit_rehired" id="fit_rehired" value="1" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Experience letter Issued</td>'+
							'<td><input type="checkbox" name="experience_issued" id="experience_issued" value="1" /></td>'+
						  '</tr>'+
						   '<tr>'+
							'<td height="25">PF Settlement Details Submitted </td>'+
							'<td><input type="checkbox" name="pf_settle_submitted" id="pf_settle_submitted" value="1" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">PF Form - Submitted </td>'+
							'<td><input type="checkbox" name="pf_form_submit" id="pf_form_submit" value="1" /></td>'+
						  '</tr>'+
						   '<tr>'+
							'<td height="25">PF Amt Settled </td>'+
							'<td><input type="checkbox" name="pf_amt_settled" id="pf_amt_settled" value="1" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td>&nbsp;</td>'+
							'<td><input type="button" value="Submit" class="color-button saveExitInterview" style="visibility:visible">'+
							'<input type="button" name="button" class="color-button cancelNewExitinterview" id="button" value="Cancel" /></td>'+
						  '</tr>'+
						  '</table>'+
						  '</form>');
	$('.newLeave').show('blind',500);
	}
	loadEmployeeResign();
	//loadCompany();
}



function loadEmployeeResign(){	

	
	$.getJSON(serviceURLHR + 'EmployeeResign.php?action=load',function(data){
																			
		imdsupervisor = data.imdsupervisor;
		//console.log(imdsupervisor);
		$.each(imdsupervisor, function(index, imdsupervisor) {
									
				$('#employeeResign').append('<option value="'+imdsupervisor.e_id+'">'+imdsupervisor.e_fname	+'</option>');
							
		});	
	});
}
function saveExitInterview()
{
	
	var company_name = $('#company_name').val();
	var company_address = $('#company_address').val();
	var company_phone = $('#company_phone').val();
	var company_mobile = $('#company_mobile').val();
	var company_email = $('#company_email').val();
 
	
		$('.savecompany').attr('disabled',true);
		dataString = $('.ExitInterview_details_form').serialize();
		$.post( serviceURLHR+ "exitinterview-details.php?action=insert",dataString,function(data){
			var leaves = data.leaves
			//alert(JSON.stringify(leaves));
			if(leaves.notice_served == 1){var noticeserved = 'yes';	}else { var noticeserved = 'no'; }
			if(leaves.fit_to_rehired == 1){var fitrehired = 'yes';	}else { var fitrehired = 'no'; }
			if(leaves.experience_letr_issued == 1){var experience_letrissued = 'yes'; }else { var experience_letrissued = 'no'; }
			if(leaves.pf_details_submit == 1){var pf_detailsubmit = 'yes';}else { var pf_detailsubmit = 'no'; }
			if(leaves.pf_form_submit == 1){var pf_formsubmit = 'yes';}else { var pf_formsubmit = 'no'; }
			if(leaves.pf_amt_settled == 1){var pf_amtsettled = 'yes';}else { var pf_amtsettled = 'no'; }
			
			
			$('.list-leavesu').append( '<tr class="company_'+leaves.exit_intv_id+'">'+
									                    '<td  class="empnam">'+leaves.e_fname+'</td>'+
														'<td  class="exitnotes">'+leaves.notes+'</td>'+
									                    '<td  class="leavedt">'+leaves.leave_dt+'</td>'+
														'<td  class="settledt">'+leaves.settled_date+'</td>'+
														'<td  class="noticeserv">'+noticeserved+'</td>'+
														'<td  class="fitrehired">'+fitrehired+'</td>'+
														'<td  class="expissued">'+experience_letrissued+'</td>'+
														'<td  class="pfdtsubmit">'+pf_detailsubmit+'</td>'+
														'<td  class="pfrmsubmit">'+pf_formsubmit+'</td>'+
														'<td  class="pfamtsettle">'+pf_amtsettled+'</td>'+
														'<td width="5%"><img data-id="'+leaves.exit_intv_id+'" src="'+editIconpen+'" class="editExitInterview"/></td>'+													
														'<td width="5%"><img data-id="'+leaves.exit_intv_id+'" src="'+removeIcon+'" class="removeExitInterview"/></td>'+
													 '</tr>');	
			$('.ExitInterview_details_form').hide('blind',500,function(){ $(this).remove(); });
			//window.location.reload();
		},'json');		
	
	
	
}

function editExitInterview(){
	
//	$('#tablelist').html('');
	if($('.ExitInterview_details_form').length){
		
	}else{
	$this = $(this);
	
	var userid 	= $this.attr('data-id');
		
	var exit_note = $this.parent().parent().find('.exitnotes').text();
	var leave_dates = $this.parent().parent().find('.leavedt').text();
	var settle_dates  = $this.parent().parent().find('.settledt').text();	
	
	$('.list-leavesu').before('<form class="ExitInterview_details_form field-style">'+
						'<table width="100%" border="0" cellspacing="0" cellpadding="0" class="newLeave" style="display:none;">'+
						  '<tr>'+
							'<td width="26%">&nbsp;</td>'+
							'<td width="74%"><div class="div-result"></div></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Name</td>'+
							'<td><select name="memberResignid" id="employeeResign" class="EMPRESIGN" style="width:100px;" ><option value="" selected="selected">Member</option></select></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Notes</td>'+
							'<td><input type="text" name="exit_notes" id="exit_notes" value="'+exit_note+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Leaving Date</td>'+
							'<td><input type="hidden" name="exit_intv_id" id="exit_intv_id"  value="'+userid+'"  /><input type="text" name="leaving_dt" id="leaving_dt" class="edit_form_date" value="'+leave_dates+'"  /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Settled On </td>'+
							'<td><input type="text" name="settled_on_date" id="settled_on_date" class="edit_form_date" value="'+settle_dates+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Notice Served </td>'+
							'<td><input type="checkbox" name="notice_served" id="notice_served"  /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Fit to be rehired </td>'+
							'<td><input type="checkbox" name="fit_rehired" id="fit_rehired" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Experience letter Issued</td>'+
							'<td><input type="checkbox" name="experience_issued" id="experience_issued" /></td>'+
						  '</tr>'+
						   '<tr>'+
							'<td height="25">PF Settlement Details Submitted </td>'+
							'<td><input type="checkbox" name="pf_settle_submitted" id="pf_settle_submitted" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">PF Form - Submitted </td>'+
							'<td><input type="checkbox" name="pf_form_submit" id="pf_form_submit" /></td>'+
						  '</tr>'+
						   '<tr>'+
							'<td height="25">PF Amt Settled </td>'+
							'<td><input type="checkbox" name="pf_amt_settled" id="pf_amt_settled" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td>&nbsp;</td>'+
							'<td><input type="button" value="Submit" class="color-button updateExitInterview" style="visibility:visible">'+
							'<input type="button" name="button" class="color-button cancelNewExitinterview" id="button" value="Cancel" /></td>'+
						  '</tr>'+
						  '</table>'+
						  '</form>');
	
	var compNameID 	= $this.parent().parent().find('.empnam').attr('data-id');
	
	$.getJSON(serviceURLHR + 'EmployeeResign.php?action=load',function(data){
		imdsupervisor = data.imdsupervisor;
		$.each(imdsupervisor, function(index, imdsupervisor) {
									 
							$('.EMPRESIGN').append('<option value="'+imdsupervisor.e_id+'">'+imdsupervisor.e_fname	+'</option>');							
		});	
		setTimeout(function(){ $('.EMPRESIGN').val(compNameID); },10);
	});
	
	
	
	var notice_served   = $this.parent().parent().find('.noticeserv').text();	
	var fit_rehired   = $this.parent().parent().find('.fitrehired').text();	
	var expernce_issued   = $this.parent().parent().find('.expissued').text();	
	var pf_dtsubmit   = $this.parent().parent().find('.pfdtsubmit').text();	
	var pf_frmsubmit   = $this.parent().parent().find('.pfrmsubmit').text();
	var pf_amtsettle   = $this.parent().parent().find('.pfamtsettle').text();
	
	
		if(notice_served == 'yes'){	$('#notice_served').attr('checked','checked');}	
		if(fit_rehired == 'yes'){ $('#fit_rehired').attr('checked','checked');}	
		if(expernce_issued == 'yes'){ $('#experience_issued').attr('checked','checked');}	
		if(pf_dtsubmit == 'yes'){ $('#pf_settle_submitted').attr('checked','checked');}	
		if(pf_frmsubmit == 'yes'){ $('#pf_form_submit').attr('checked','checked');}	
		if(pf_amtsettle == 'yes'){ $('#pf_amt_settled').attr('checked','checked');}	

	
	
	$('.newLeave').show('blind',500);
	}
	loadEmployeeResign();
	//loadDepartment();
	//setTimeout(function(){ $('#department_name').val(departmenyid); },500);
}
  

function updateExitInterview()
{
	var branch_name = $('#branch_name').val();
	var branch_code = $('#branch_code').val();
	var branch_address = $('#branch_address').val();
	
	
	
		var ExitInterviewDetals = $('.ExitInterview_details_form').serialize();
		//console.log(branchDetails);
		//var companynameid 	= $('#company_nameid option:selected').text();
		//var companyid 	= $('#company_nameid option:selected').val();
		var exitid	= $('#exit_intv_id').val();
	
		$.post(serviceURLHR + "exitinterview-details.php?action=update&ext_intvid="+exitid,ExitInterviewDetals,function(data){
			/*var currentUser = $('.branch_'+userid);
			currentUser.find('.brnName').text(data.branch_name);
			currentUser.find('.brnCode').text(data.brch_code);			
			currentUser.find('.compName').text(companynameid);
			currentUser.find('.compName').attr('data-id',companyid);
			currentUser.find('.brnAdd').text(data.brch_address);
			currentUser.find('.brnphno').text(data.brch_phno);
			currentUser.find('.brnContact').text(data.brch_contactno);*/
			
			},"json");
		$('.ExitInterview_details_form').hide('blind',500,function(){ $(this).remove(); });
	
}

function removeExitInterview(){
	

var checkstr =  confirm('are you sure you want to delete this?');
if(checkstr == true){
 var did = $(this).attr('data-id');
	$this = $(this);
	$.get(serviceURLHR + "exitinterview-details.php?action=removeded&did="+did,function(){
		$this.parent().parent().remove();															 
	});
}else{
return false;
}

	
}



function companyManagement(){

//alert(serviceURLHR);
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	$.getJSON(serviceURLHR + "company-details.php?action=list",function(data){
		var leaves = data.companyDetails;	
		
		//console.log(leaves);
		if(leaves.length > 0){
			permissions_user = leaves[leaves.length -1 ].permissions[0].user_id;
		}else{
			permissions_user = 1;
		}
			if(permissions_user!=1)
			{
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			    if(permissions_add==1)
				{ class_add='addNewCompany';}
				else{class_add='addNewCompany_right';}
			}
			else
			{
				class_add='addNewCompany';
			}
		
		
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leavesu">'+
								   '<tr>'+
											'<td width="15%" colspan="9" align="right" class="'+class_add+'"><img src="images/icon-add.png"  width="20" height="20" />Add Company</td>'+ '</tr>'+
										  '<tr>'+
										    '<td width=""><translate>Name</translate></td>'+
											'<td width=""><translate>Address</translate></td>'+
											'<td width=""><translate>Phone No</translate></td>'+
											'<td width=""><translate>Mobile No</translate></td>'+
											'<td width=""><translate>E-mail</translate></td>'+
											'<td width=""><translate>PF Code No</translate></td>'+
											'<td width=""><translate>Edit</translate></td>'+
											'<td width="">Delete</td>'+
										 '</tr>'+
										'</table>')	;
			

				if(permissions_user!=1)
			{
			
			permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_del = leaves[leaves.length -1 ].permissions[0].delete_right;
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			}
			if(permissions_user!=1)
			{
			   if(permissions_edit==1){  classedit='editCompany';  }else{classedit='editCompany_right';}
			   if(permissions_del==1){  classdel='removeCompany';  }else{classdel='removeCompany_right';}
			}
			else
			{
				classedit='editCompany'; 
				classdel='removecompany';
			}

			$.each(leaves, function(index,leaves){

			
					$('.list-leavesu').append( '<tr class="company_'+leaves.id+'">'+
														
														'<td width="" class="cmpName">'+leaves.company_name+'</td>'+
														'<td width="" class="cmpAdd">'+leaves.company_address+'</td>'+
														'<td width="" class="cmpph">'+leaves.company_phone+'</td>'+
														'<td width="" class="cmpmb">'+leaves.company_mobile+'</td>'+
														'<td width="" class="cmpEmail">'+leaves.company_email+'</td>'+
														'<td width="" class="pf_code_no">'+leaves.pf_code_num+'</td>'+
														'<td width=""><img data-id="'+leaves.id+'" src="'+editIconpen+'" class="'+classedit+'" alt="Edit Company"/></td>'+													
														'<td width=""><img data-id="'+leaves.id+'" src="'+removeIcon+'" class="'+classdel+'" alt="Delete Company" /></td>'+
													 '</tr>');				
			});
			$('.list-leavesu').show('blind',500);
		
	});	
}
//branchList();

function branchList(){
//alert(serviceURLHR);
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	$.getJSON(serviceURLHR + "manageBranch.php?act=list",function(data){
		var leaves = data.leaves;	
		
		
		if(leaves.length > 0){
			permissions_user = leaves[leaves.length -1 ].permissions[0].user_id;
		}else{
			permissions_user = 1;
		}
			if(permissions_user!=1)
			{
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			    if(permissions_add==1)
				{ class_add='addNewBranch';}
				else{class_add='addNewBranch_right';}
			}
			else
			{
				class_add='addNewBranch';
			}
		
		
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leavesu">'+
								   '<tr>'+
											'<td width="15%" colspan="10" align="right" class="'+class_add+'"><img src="images/icon-add.png"  width="20" height="20" />Add Branch</td>'+ '</tr>'+
										  '<tr>'+
											'<td width=""><translate>Branch Name</translate></td>'+
											'<td width=""><translate>Branch Code</translate></td>'+
											'<td width=""><translate>Company</translate></td>'+
											'<td width=""><translate>Address</translate></td>'+
											'<td width=""><translate>Ph no</translate></td>'+
											'<td width=""><translate>Email</translate></td>'+
											'<td width=""><translate>Trader Identification Number</translate></td>'+
											'<td width=""><translate>S & E lic No</translate></td>'+
											'<td width=""><translate>Edit</translate></td>'+
											'<td width="">Delete</td>'+
										 '</tr>'+
										'</table>')	;
			

				if(permissions_user!=1)
			{
			
			permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_del = leaves[leaves.length -1 ].permissions[0].delete_right;
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			}
			if(permissions_user!=1)
			{
			   if(permissions_edit==1){  classedit='editBranch';  }else{classedit='editBranch_right';}
			   if(permissions_del==1){  classdel='removeBranch';  }else{classdel='removeBranch_right';}
			}
			else
			{
				classedit='editBranch'; 
				classdel='removeBranch';
			}

			$.each(leaves, function(index,leaves){

			
					$('.list-leavesu').append( '<tr class="branch_'+leaves.branch_id+'">'+
														
														'<td width="" class="brnName">'+leaves.branch_name+'</td>'+
														'<td width="" class="brnCode">'+leaves.brch_code+'</td>'+
														'<td width="" class="compName" data-id="'+leaves.comp_id+'">'+leaves.company_name+'</td>'+
														'<td width="" class="brnAdd">'+leaves.brch_address+'</td>'+
														'<td width="" class="brnphno">'+leaves.brch_phno+'</td>'+
														'<td width="" class="brnContact">'+leaves.brch_contactno+'</td>'+
														'<td width="" class="brnTin">'+leaves.brch_tin+'</td>'+
														'<td width="" class="brnShops">'+leaves.brch_shops+'</td>'+
														'<td width=""><img data-id="'+leaves.branch_id+'" src="'+editIconpen+'" class="'+classedit+'" alt="Edit Branch"/></td>'+													
														'<td width=""><img data-id="'+leaves.branch_id+'" src="'+removeIcon+'" class="'+classdel+'" alt="Delete Branch" /></td>'+
													 '</tr>');				
			});
			$('.list-leavesu').show('blind',500);
		
	});	
}

function employeeLists(){
	//alert("emp");
}

function departmentList(){
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	$.getJSON(serviceURLHR + "manageDepartment.php?act=list",function(data){
		var leaves = data.leaves; 
		
		
		if(leaves.length > 0 ){
				permissions_user = leaves[leaves.length -1 ].permissions[0].user_id;
		}else{
				permissions_user = 1;
		}
			if(permissions_user!=1)
			{
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			    if(permissions_add==1)
				{ class_add='addNewDepartment';}
				else{class_add='addNewDepartment_right';}
			}
			else
			{
				class_add='addNewDepartment';
			}
		
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leavesu">'+
								    '<tr>'+
											'<td width="15%" colspan="3" align="right" class="'+class_add+'"><img src="images/icon-add.png" class="'+class_add+'" width="20" height="20" />Add Department</td>'+
											
										 '</tr>'+
										  '<tr>'+
											'<td width="23%"><translate>Department Name</translate></td>'+
											'<td width="5%"><translate>Edit</translate></td>'+
											'<td width="5%">Delete</td>'+
										 '</tr>'+
										'</table>')	;
			
			if(leaves.length > 0 ){
			permissions_user = leaves[leaves.length -1 ].permissions[0].user_id;
			}else{
				permissions_user = 1;
		}
			if(permissions_user!=1)
			{
			//permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_del = leaves[leaves.length -1 ].permissions[0].delete_right;
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			//console.log(permissions_user);
			$.each(leaves, function(index,leaves){
       if(permissions_edit==1)
	   {  classedit='editDepartment';  }else{classedit='editDepartment_right';}
       if(permissions_del==1)
	   {  classdel='removeDepartment';  }else{classdel='removeDepartment_right';}
	   
					$('.list-leavesu').append( '<tr class="department_'+leaves.depart_id+'">'+
														'<td width="23%" class="drpName">'+leaves.depart_name+'</td>'+
														'<td width="5%"><img data-id="'+leaves.depart_id+'" src="'+editIconpen+'" class="'+classedit+'"/></td>'+
														'<td width="5%"><img data-id="'+leaves.depart_id+'" src="'+removeIcon+'" class="'+classdel+'"/></td>'+
													 '</tr>');	
					
			});
			} ///if end for permission
			
			else
			{
							$.each(leaves, function(index,leaves){
				
				//alert(leaves.permissions);
				
					$('.list-leavesu').append( '<tr class="department_'+leaves.depart_id+'">'+
														'<td width="23%" class="drpName">'+leaves.depart_name+'</td>'+
														'<td width="5%"><img data-id="'+leaves.depart_id+'" src="'+editIconpen+'" class="editDepartment"/></td>'+
														'<td width="5%"><img data-id="'+leaves.depart_id+'" src="'+removeIcon+'" class="removeDepartment"/></td>'+
													 '</tr>');	
					
			});
			}///else end for permission
			
			
			
			
			$('.list-leavesu').show('blind',500);
		
	});	
}

////////////////////////////////////////Rights checking//////////////////////////////////

function removeDepartment_right()
{
alert("Sorry You Don't Have Enough Permission To Delete Department");	
}
function editDepartment_right()
{
alert("Sorry You Don't Have Enough Permission To Edit Department");	
}
function addNewDepartment_right()
{
alert("Sorry You Don't Have Enough Permission To Add Department");	
}
function editBranch_right()
{
alert("Sorry You Don't Have Enough Permission To Edit Branch");	
}
function removeBranch_right()
{
alert("Sorry You Don't Have Enough Permission To Delete Branch");	
}
function addNewBranch_right()
{
alert("Sorry You Don't Have Enough Permission To Add Branch");	
}
function addNewDesignation_right()
{
alert("Sorry You Don't Have Enough Permission To Add Designation");	
}
function editDesignation_right()
{
alert("Sorry You Don't Have Enough Permission To Edit Designation");	
}
function removeDesignation_right()
{
alert("Sorry You Don't Have Enough Permission To Delete Designation");	
}

function addNewreporttime_right()
{
alert("Sorry You Don't Have Enough Permission To Add Report Time");	
}
function removereporttime_right()
{
alert("Sorry You Don't Have Enough Permission To Delete Report Time");	
}
function editreporttime_right()
{
alert("Sorry You Don't Have Enough Permission To Edit Report Time");	
}

function addNewdevice_right()
{
alert("Sorry You Don't Have Enough Permission To Add Device");	
}
function editdevice_right()
{
alert("Sorry You Don't Have Enough Permission To Edit Device");	
}
function removedevice_right()
{
alert("Sorry You Don't Have Enough Permission To Delete Device");	
}

////////////////////////////////////////Rights checking//////////////////////////////////
loadCompany();

function loadCompany(){
	
	$.getJSON(serviceURLHR + 'Company.php?action=load',function(data){
		company = data.companyList;
		$.each(company, function(index, company) {
									 
							$('#company_nameid').append('<option value="'+company.id+'">'+company.company_name+'</option>');
							
		});	
	});
}


function BranchManagement(){
	
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	$.getJSON(serviceURLHR + "manageBranch.php?act=list",function(data){
		var leaves = data.leaves;
			$('#tablelist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaves">'+
										  '<tr>'+
											'<td width="23%"><translate>Branch Name</translate></td>'+
											'<td width="23%"><translate>Branch Code</translate></td>'+
											'<td width="23%"><translate>Address</translate></td>'+
											'<td width="23%"><translate>Ph no</translate></td>'+
											'<td width="23%"><translate>Email</translate></td>'+
											'<td width="23%"><translate>TIN</translate></td>'+
											'<td width="23%"><translate>Sales Tax No</translate></td>'+
											'<td width="23%"><translate>Service Tax No</translate></td>'+
											'<td width="23%"><translate>Shops & Establishments license Numbers</translate></td>'+
											'<td width="5%">Delete</td>'+
										 '</tr>'+
										'</table>')	

			$.each(leaves, function(index,leaves){
				
				
				
					$('.list-leaves').append( '<tr>'+
														'<td width="23%">'+leaves.branch_name+'</td>'+
														'<td width="23%">'+leaves.brch_code+'</td>'+
														'<td width="23%">'+leaves.brch_address+'</td>'+
														'<td width="23%">'+leaves.brch_phno+'</td>'+
														'<td width="23%">'+leaves.brch_contactno+'</td>'+
														'<td width="23%">'+leaves.brch_tin+'</td>'+
														'<td width="23%">'+leaves.brch_sales+'</td>'+
														'<td width="23%">'+leaves.brch_service_tax+'</td>'+
														'<td width="23%">'+leaves.brch_shops+'</td>'+
														'<td width="5%"><img data-id="'+leaves.branch_id+'" src="'+removeIcon+'" class="removeBranch"/></td>'+
													 '</tr>');				
			});
			$('.list-leaves').show('blind',500);
		
	});	
}

function addNewBranch()
{
	$('.saveBranch').attr('disabled',false);
	if($('.newBranchform').length){
		
	}else{
	$('.list-leavesu').before('<form class="newBranchform field-style"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Branch Name</translate></td>'+
									'<td><input type="text" name="branch_name" id="branch_name" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Company Name</translate></td>'+
									'<td><select name="company_nameid" id="company_nameid"><option selected="selected" value="">---select---</option></select></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Branch Code</translate></td>'+
									'<td ><input type="text" name="branch_code" id="branch_code" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Address</translate></td>'+
									'<td><textarea name="branch_address" id="branch_address" /></textarea></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Ph no</translate></td>'+
									'<td><input type="text" name="phnum" id="phnum" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Email</translate></td>'+
									'<td><input type="text" name="contact_details" id="contact_details" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Trader Identification Number</translate></td>'+
									'<td><input type="text" name="tin_num" id="tin_num" /></td>'+
								  '</tr>'+
								  
								  '<tr>'+
									'<td><translate>Shops & Establishments license Number</translate></td>'+
									'<td><input type="text" name="shop_estb_licencenum" id="shop_estb_licencenum" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button saveBranch" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelNewLeave" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	$('.newLeave').show('blind',500);
	}
	loadCompany();
}

function saveBranch()
{
	
	/*if ($.trim($("#leaveTitle").val()).length != 0) 
	{
		dataString = $('.newBranchform').serialize();
		$.post( serviceURLHR+ "manageBranch.php?act=insert",dataString,function(data){
			var leaves = data.leaves
			$('.list-leaves').append( '<tr class="branch_'+leaves.id+'">'+
														'<td width="23%" class="brnName">'+leaves.branch_name+'</td>'+
														'<td width="23%" class="brnCode">'+leaves.brch_code+'</td>'+
														'<td width="23%" class="brnAdd">'+leaves.brch_address+'</td>'+
														'<td width="23%" class="brnphno">'+leaves.brch_phno+'</td>'+
														'<td width="23%" class="brnContact">'+leaves.brch_contactno+'</td>'+
														'<td width="23%" class="brnTin">'+leaves.brch_tin+'</td>'+
														'<td width="23%" class="brnShops">'+leaves.brch_shops+'</td>'+
														'<td width="5%"><img data-id="'+leaves.id+'" src="'+editIconpen+'" class="editBranch"/></td>'+													
														'<td width="5%"><img data-id="'+leaves.id+'" src="'+removeIcon+'" class="removeBranch"/></td>'+
													 '</tr>');	
			$('.newBranchform').hide('blind',500,function(){ $(this).remove(); });
		},'json');
	}
	else
	{
		alert('Please Enter Branch Name');	
	}*/
	
	
	var branch_name = $('#branch_name').val();
	var company_nameid = $('#company_nameid').val();
	var branch_code = $('#branch_code').val();
	var branch_address = $('#branch_address').val();
	var phnum = $('#phnum').val();
	var contact_details = $('#contact_details').val();
	var tin_num = $('#tin_num').val();
	var shop_estb_licencenum = $('#shop_estb_licencenum').val();
	
	if(branch_name == ''){
		alert('Branch Name is required');$('#branch_name').focus();
	}else if(company_nameid == ''){
		alert('Company Name is required');$('#company_nameid').focus();
	}
	else if(branch_code == ''){
		alert('Branch Code is required');$('#branch_code').focus();
	}else if(branch_address == ''){
		alert('Branch Address is required');$('#branch_address').focus();
	}else if(phnum == ''){
		alert('Phone is required');$('#phnum').focus();
	}else if(contact_details == ''){
		alert('Email required');$('#contact_details').focus();
	}else if(contact_details != '' && !ValidateEmailEmp(contact_details)){
		alert('Email is Invalid. Please try another');$('#contact_details').focus();
	}else if(tin_num == ''){
		alert('Trader Identification Number is required');$('#tin_num').focus();
	}else if(shop_estb_licencenum == ''){
		alert('Shops And Establishments license Number is required');$('#shop_estb_licencenum').focus();
	}else{
		$('.saveBranch').attr('disabled',true);
		dataString = $('.newBranchform').serialize();
		var depart_name = $('#company_nameid option:selected').text();
		$.post( serviceURLHR+ "manageBranch.php?act=insert",dataString,function(data){
			var leaves = data.leaves
			$('.list-leavesu').append( '<tr class="branch_'+leaves.id+'">'+
														'<td width="23%" class="brnName">'+leaves.branch_name+'</td>'+
														'<td width="23%" class="brnCode">'+leaves.brch_code+'</td>'+
														'<td width="23%" class="CompanyNm">'+depart_name+'</td>'+
														'<td width="23%" class="brnAdd">'+leaves.brch_address+'</td>'+
														'<td width="23%" class="brnphno">'+leaves.brch_phno+'</td>'+
														'<td width="23%" class="brnContact">'+leaves.brch_contactno+'</td>'+
														'<td width="23%" class="brnTin">'+leaves.brch_tin+'</td>'+
														'<td width="23%" class="brnShops">'+leaves.brch_shops+'</td>'+
														'<td width="5%"><img data-id="'+leaves.id+'" src="'+editIconpen+'" class="editBranch"/></td>'+													
														'<td width="5%"><img data-id="'+leaves.id+'" src="'+removeIcon+'" class="removeBranch"/></td>'+
													 '</tr>');	
			$('.newBranchform').hide('blind',500,function(){ $(this).remove(); });
			window.location.reload();
		},'json');		
	}
	
	
}

function updateDepartment()
{
	
	var branchDetails = $('.newDepartmentform').serialize();
	
	var leaveTitle 	= $('#leaveTitle').val();
	var userid	= $('#userid').val();
	if(leaveTitle == ''){
		alert('Deparrtment Name is required')	;
		$('#leaveTitle').focus();
	}else{
		$.post(serviceURLHR + "DeptUpdate.php?act=update",branchDetails,function(data){
			var currentUser = $('.department_'+userid);
			
			currentUser.find('.drpName').text(leaveTitle);
			
		});
		$('.newDepartmentform').hide('blind',500,function(){ $(this).remove(); });
	}
}

function editDepartment(){
	
	if($('.newDepartmentform').length){
		
	}else{
	$this = $(this);
	var userid 	= $this.attr('data-id');
	
	
	var name 	= $this.parent().parent().find('.drpName').text();
	
	
	$('.list-leavesu').before('<form class="newDepartmentform field-style"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Department Name</translate></td>'+
									'<td><input type="text" name="leaveTitle" id="leaveTitle" value="'+name+'" /></td>'+
									'<td><input type="hidden" name="userid" id="userid" value="'+userid+'" /></td>'+
								    '</tr>'+
								  

								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button updateDepartment" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelNewDepartment" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	$('.newLeave').show('blind',500);
	
	}
	
	
}


function addNewDepartment(){
//	$('#tablelist').html('');
$('.saveDepartment').attr('disabled',false);
	if($('.newDepartmentform').length){
		
	}else{
	$('.list-leavesu').before('<form class="newDepartmentform field-style"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Department Name</translate></td>'+
									'<td><input type="text" name="leaveTitle" id="leaveTitle" /></td>'+
								  '</tr>'+
								  

								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button saveDepartment" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelNewDepartment" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	$('.newLeave').show('blind',500);
	}
}

function saveDepartment(){	

	if ($.trim($("#leaveTitle").val()).length != 0) {
		$('.saveDepartment').attr('disabled',true);
	dataString = $('.newDepartmentform').serialize();
	$.post( serviceURLHR+ "manageDepartment.php?act=insert",dataString,function(data){
		var leaves = data.leaves
					
		$('.list-leavesu').append( '<tr class="department_'+leaves.id+'">'+
									'<td width="23%" class="drpName">'+leaves.depart_name+'</td>'+
									'<td width="5%"><img data-id="'+leaves.id+'" src="'+editIconpen+'" class="editDepartment"/></td>'+
									'<td width="5%"><img data-id="'+leaves.id+'" src="'+removeIcon+'" class="removeDepartment"/></td>'+
									'</tr>');	
			$('.newDepartmentform').hide('blind',500,function(){ $(this).remove(); });
		
	},'json');
	}
	else
	{
		alert('Please Enter Department');	
	}
	
}

function removeDepartment(){
	

var checkstr =  confirm('are you sure you want to delete this?');
if(checkstr == true){
 var did = $(this).attr('data-id');
	
	$this = $(this);
	$.get(serviceURLHR + "manageDepartment.php?act=removeded&did="+did,function(){
		$this.parent().parent().remove();															 
	});
}else{
return false;
}

	
}



loadDepartment();

function loadDepartment(){
	
	$.getJSON(serviceURLHR + 'department.php?action=load',function(data){
		department = data.department;
		$.each(department, function(index, department) {
									 
							$('#department_name').append('<option value="'+department.depart_id+'">'+department.depart_name+'</option>');
							
		});	
	});
}

function designationList(){
	
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	$.getJSON(serviceURLHR + "manageDesignation.php?act=list",function(data){
		var leaves = data.leaves; 
		
		
		if(leaves.length > 0){
			permissions_user = leaves[leaves.length -1 ].permissions[0].user_id; //
		}else{
				permissions_user = 1;
		}
			if(permissions_user!=1)
			{
			//permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_del = leaves[leaves.length -1 ].permissions[0].delete_right;
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			}
			
			if(permissions_user!=1)
			{
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			    if(permissions_add==1)
				{ class_add='addNewDesignation';}
				else{class_add='addNewDesignation_right';}
			}
			else
			{
				class_add='addNewDesignation';
			}
			
		
			if(permissions_user!=1)
			{
			   if(permissions_edit==1){  classedit='editDesignation';  }else{classedit='editDesignation_right';}
			   if(permissions_del==1){  classdel='removeDesignation';  }else{classdel='removeDesignation_right';}
			}
			else
			{
				classedit='editDesignation'; 
				classdel='removeDesignation';
			}

			
		
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leavesu">'+
								  	  '<tr>'+
		'<td width="15%" colspan="5" align="right" class="'+class_add+'"><img src="images/icon-add.png" class="" width="20" height="20" />Add Designation</td>'+
											
										 '</tr>'+
										  '<tr>'+
											'<td width="23%"><translate>Designation Name</translate></td>'+
											'<td width="23%"><translate>Department Name</translate></td>'+
											'<td width="23%"><translate>Rank</translate></td>'+
											'<td width="5%"><translate>Edit</translate></td>'+
											'<td width="5%">Delete</td>'+
										 '</tr>'+
										'</table>')	

			$.each(leaves, function(index,leaves){
				
					$('.list-leavesu').append( '<tr class="designation_'+leaves.desig_id+'">'+
														'<td width="23%" class="desgName">'+leaves.desig_name+'</td>'+
														'<td width="23%" class="departName" data-id="'+leaves.depart_id+'">'+leaves.depart_name+'</td>'+
														'<td width="23%" class="departRank">'+leaves.depart_rank+'</td>'+
														'<td width="5%"><img data-id="'+leaves.desig_id+'" src="'+editIconpen+'" class="'+classedit+'"/></td>'+
														'<td width="5%"><img data-id="'+leaves.desig_id+'" src="'+removeIcon+'" class="'+classdel+'"/><input type="hidden" value="'+leaves.desig_rights+'" name="desigs" id="desigs" class="desigss"></td>'+
													 '</tr>');				
			});
			$('.list-leavesu').show('blind',500);
		
	});	
}

function editDesignation(){
//	$('#tablelist').html('');
$('.newDesignationform').remove();
	if($('.newDesignationform').length){
		
	}else{
	$this = $(this);
	var userid 	= $this.attr('data-id');
	
	var name 			= $this.parent().parent().find('.desgName').text();
	var departnames 	= $this.parent().parent().find('.departName').text();
	//var subdepartname 	= $this.parent().parent().find('.departSubName').text();
	var rankdepart 		= $this.parent().parent().find('.departRank').text();
	var departmenyid 	= $this.parent().parent().find('.departName').attr('data-id');
	var desigss         =$this.parent().parent().find('.desigss').val(); 
	
	//alert(departnames);
	
	
	$('.list-leavesu').before('<form class="newDesignationform field-style"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Designation Name</translate></td>'+
									'<td><input type="text" name="designationame" id="designationame" value="'+name+'" /></td>'+
									'<td><input type="hidden" name="userid" id="userid" value="'+userid+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Department Name</translate></td>'+
									'<td><select name="department_name" id="department_name"><option selected="selected" value="">---select---</option></select></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Rank</translate></td>'+
									'<td><input type="text" name="department_rank" id="department_rank" value="'+rankdepart+'" /></td>'+
								  '</tr>'+
								  '<tr id="save_btn_div">'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button UpdateDesignation" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelDesignation" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	
	$.getJSON(serviceURLHR + 'department.php?action=load',function(data){
		department = data.department;
		
		$.each(department, function(index, department) {
									 
							$('#department_name').append('<option value="'+department.depart_id+'">'+department.depart_name+'</option>');
							$('#department_name').val(departmenyid);
		});	
	});
	//setTimeout(function(){ $('#department_name').val(departmenyid); },500);
	
	$.getJSON(serviceURLHR + 'load_menu.php?action=load',function(data){
			menu = data.menu;
			var menu_row='<tr><td>Rights</td><td><table>';
			$.each(menu, function(index, menu) {
								  
		//$result = file_get_contents(serviceURLHR + 'branch.php?action=load'); alert($result);
		if(menu.menu_name!='Productivity Tracking'){
			if (desigss.indexOf(menu.menu_id) > -1 ) {
					menu_row=menu_row+'<tr><td><input style="height:15px"  type="checkbox" id="checkadd'+menu.menu_id+'" name="checkadd[]" value="'+menu.menu_id+'" checked="checked"><span>'+menu.menu_name+'</span></td></tr>';
			} else {
					menu_row=menu_row+'<tr><td><input style="height:15px"  type="checkbox" id="checkadd'+menu.menu_id+'" name="checkadd[]" value="'+menu.menu_id+'"><span>'+menu.menu_name+'</span></td></tr>';
			}
		}

		
			});	
			menu_row=menu_row+'</table></td></tr>';
			$('#save_btn_div').before(menu_row);
		});
	
	$('.newLeave').show('blind',500);
	}
	
}

function UpdateDesignation(){
	
	var designationame = $('#designationame').val();
	var department_name = $('#department_name').val();
	var department_rank = $('#department_rank').val();

	if(designationame == ''){
		alert('Designation Name is required');
	}else if(department_name == ''){
		alert('Despartment Name is required');
	}else if(department_rank == ''){
		alert('Rank Name is required');
	}else{
		var designationDetails = $('.newDesignationform').serialize();
		var departmentname 	= $('#department_name option:selected').text();
		var userid	= $('#userid').val();
		$.post(serviceURLHR + "DesigUpdate.php?act=update",designationDetails,function(data){
			var currentUser = $('.designation_'+userid);
			currentUser.find('.desgName').text(data.desig_name);
			currentUser.find('.departName').text(departmentname);
			//currentUser.find('.departSubName').text(data.depart_sub_name);
			currentUser.find('.departRank').text(data.depart_rank);
			currentUser.find('.desigss').val(data.desig_rights);
		},"json");
		$('.newDesignationform').hide('blind',500,function(){ $(this).remove(); });
	}
}

function addNewDesignation(){
//	$('#tablelist').html('');
$('.newDesignationform').remove();
	if($('.newDesignationform').length){
		
	}
	else {
		
	$('.list-leavesu').before('<form class="newDesignationform field-style"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Designation Name</translate></td>'+
									'<td><input type="text" name="designationame" id="designationame" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Department Name</translate></td>'+
									'<td><select name="department_name" id="department_name"><option selected="selected" value="">---select---</option></select></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Rank</translate></td>'+
									'<td><input type="text" name="department_rank" id="department_rank" /></td>'+
								  '</tr>'+
								  '<tr id="save_btn_div">'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button saveDesignation" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelDesignation" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
		$.getJSON(serviceURLHR + 'load_menu.php?action=load',function(data){
			menu = data.menu;
			var menu_row='<tr><td>Rights</td><td><table>';
			$.each(menu, function(index, menu) {	
				if(menu.menu_name!='Productivity Tracking'){
					menu_row=menu_row+'<tr><td><input style="height:15px"  type="checkbox" id="checkadd'+menu.menu_id+'" name="checkadd[]" value="'+menu.menu_id+'"><span>'+menu.menu_name+'</span></td></tr>';
				}
			});	
			menu_row=menu_row+'</table></td></tr>';
			$('#save_btn_div').before(menu_row);
		});
	
	$('.newLeave').show('blind',500);
	}
	loadDepartment();
}

function saveDesignation(){
	var designationame = $('#designationame').val();
	var department_name = $('#department_name').val();
	var department_rank = $('#department_rank').val();
	if(designationame == ''){
		alert('Designation Name is Required')	;$('#designationame').focus();
	}else if(department_name == ''){
		alert('Department Name is Required')	;$('#department_name').focus();
	}else if(department_rank == ''){
		alert('Rank is Required')	;$('#department_rank').focus();
	}else{
		dataString = $('.newDesignationform').serialize(); 
		var depart_name = $('#department_name option:selected').text();
		$.post( serviceURLHR+ "manageDesignation.php?act=insert",dataString,function(data){
			var leaves = data.leaves
			if(leaves.desig_name=='Already Saved Data')
			{
				$('.list-leavesu').append( '<tr>'+
			'<td width="23%" colspan="5" align="center" style="color:#FF0000; font-size:18px" >'+leaves.desig_name+'</td>'+
										'</tr>');
			}
			else
			{						
				$('.list-leavesu').append( '<tr>'+
					'<td width="23%">'+leaves.desig_name+'</td>'+
					'<td width="23%">'+depart_name+'</td>'+
					'<td width="23%">'+leaves.depart_rank+'</td>'+
					'<td width="5%"><img data-id="'+leaves.id+'" src="'+editIconpen+'" class="editDesignation"/></td>'+
					'<td width="5%"><img data-id="'+leaves.id+'" src="'+removeIcon+'" class="removeDesignation"/></td>'+
					'</tr>');
			}
			$('.newDesignationform').hide('blind',500,function(){ $(this).remove(); });			
			window.location.reload();
		},'json');
	}
}

function removeDesignation(){
	

var checkstr =  confirm('are you sure you want to delete this?');
if(checkstr == true){
 var did = $(this).attr('data-id');
	$this = $(this);
	$.get(serviceURLHR + "manageDesignation.php?act=removeded&did="+did,function(){
		$this.parent().parent().remove();															 
	});
}else{
return false;
}

	
}


//-----------------------------------------------Start Report Timing----------------------

loadBranch();

function loadBranch(){
	$.getJSON(serviceURLHR + 'branch.php?action=load',function(data){
		branch = data.branch;
		
		$.each(branch, function(index, branch) {
									 
							$('#branch').append('<option value="'+branch.branch_id+'">'+branch.branch_name	+'</option>');
							
		});	
	});
}

/*function reportTime(){
	k=1;
	$.getJSON(serviceURLHR + "manageReportime.php?action=viewtiming",function(data){
		var timing = data.timing;
			class_add='addNewreporttime';
		$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:block" cellpadding="0" class="list-leavesu">'+
								   '<tr>'+
					'<td width="15%" colspan="8" align="right" class="'+class_add+'"><img src="images/icon-add.png" class="" width="20" height="20" />Add Report Time</td>'+
										  '<tr>'+
											'<td width=""><translate>Sl No</translate></td>'+
											'<td width=""><translate>Branch</translate></td>'+
											'<td width=""><translate>Report Timing</translate></td>'+
											'<td width=""><translate>Report Late Time</translate></td>'+
											'<td width=""><translate>Half Day</translate></td>'+
											'<td width=""><translate>Full Day</translate></td>'+
											'<td width=""><translate>Edit</translate></td>'+
											'<td width="">Delete</td>'+
										 '</tr>'+
										'</table>')	;
		
		permissions_user = timing[timing.length -1 ].permissions[0].user_id; //alert(permissions_user); //
			if(permissions_user!=1)
			{
			//permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_edit = timing[timing.length -1 ].permissions[0].edit_right;
			permissions_del = timing[timing.length -1 ].permissions[0].delete_right;
			permissions_add = timing[timing.length -1 ].permissions[0].add_right;
			}
			
			if(permissions_user!=1)
			{
			permissions_add = timing[timing.length -1 ].permissions[0].add_right;
			    if(permissions_add==1)
				{ class_add='addNewreporttime';}
				else{class_add='addNewreporttime_right';}
			}
			else
			{
				class_add='addNewreporttime';
			}
			
		
			if(permissions_user!=1)
			{
			   if(permissions_edit==1){  classedit='editreporttime';  }else{classedit='editreporttime_right';}
			   if(permissions_del==1){  classdel='removereporttime';  }else{classdel='removereporttime_right';}
			}
			else
			{
				classedit='editreporttime'; 
				classdel='removereporttime';
			}

		
		
		
			

			$.each(timing, function(index,timing){
				
				if(index >= 0)
				{
					$('.list-leavesu').append( '<tr class="reportime_'+timing.reptime_id+'">'+
														'<td width="">'+k+'</td>'+
														'<td width="" class="branch_id" data-id="'+timing.brch_id+'">'+timing.branch_name+'</td>'+
														'<td width="" class="report_time">'+timing.report_time+''+timing.time_in+'</td>'+
														'<td width="" class="late_time">'+timing.late_time+''+timing.time_in+'</td>'+
														'<td width="" class="half_day">'+timing.half_day+'</td>'+
														'<td width="" class="full_day">'+timing.full_day+'</td>'+
														'<td width=""><img data-id="'+timing.reptime_id+'" src="'+editIconpen+'" class="'+classedit+'"/></td>'+
														'<td width=""><img data-id="'+timing.reptime_id+'" src="'+removeIcon+'" class="'+classdel+'"/></td>'+
													 '</tr>');	
					
				}
				else
				{
							$('.list-leavesu').append( '<tr class="reportime_'+timing.reptime_id+'">'+
														'<td width="" colspan="8" align="center">No Result Found</td>'+
								
													 '</tr>');
				}
					
					k++;
			});
			$('.list-leavesu').show('blind',500);
		
	});	
}*/

function reportTime(){
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	k=1;
	$.getJSON(serviceURLHR + "manageReportime.php?action=viewtiming",function(data){
		var timing = data.timing;
		//alert(timing);
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaves">'+
										  '<tr>'+
											'<td width="15%">Sl No</td>'+
											'<td width="15%">Branch</td>'+
											'<td width="15%">Report Timing</td>'+
											'<td width="15%">Report Late Time</td>'+
											'<td width="10%">Half Day</td>'+
											'<td width="10%">Full Day</td>'+
											'<td width="10%">Edit</td>'+
											'<td width="5%"><img src="images/icon-add.png" class="addNewreporttime" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(timing, function(index,timing){
				
				
				
					$('.list-leaves').append( '<tr class="reportime_'+timing.reptime_id+'">'+
														'<td width="15%">'+k+'</td>'+
														'<td width="15%" class="branch_id" data-id="'+timing.brch_id+'">'+timing.branch_name+'</td>'+
														'<td width="15%" class="report_time">'+timing.report_time+''+timing.time_in+'</td>'+
														'<td width="15%" class="late_time">'+timing.late_time+''+timing.time_in+'</td>'+
														'<td width="15%" class="half_day">'+timing.half_day+'</td>'+
														'<td width="15%" class="full_day">'+timing.full_day+'</td>'+
														'<td width="5%"><img data-id="'+timing.reptime_id+'" src="'+editIconpen+'" class="editreporttime"/></td>'+
														'<td width="5%"><img data-id="'+timing.reptime_id+'" src="'+removeIcon+'" class="removereporttime"/></td>'+
													 '</tr>');		
					k++;
			});
			$('.list-leaves').show('blind',500);
		
	});	
}

function display_days_cell(value)
{
	if(value=='W')
	{
		$('.days_cell').hide();
		$('.days_hours_cell').show();
		$('.employees_cell').hide();
	}
	else if(value=='I')
	{
		$('.days_cell').show();
		$('.days_hours_cell').hide();
		$('.employees_cell').hide();
	}
	else
	{
		$('.employees_cell').show();
		$('.days_hours_cell').hide();
		$('.days_cell').hide();
	}
}

function addNewDayRow() {
	daysrowprint=$('.days_cell:first').clone();	
	var numItems = $('.reporting_day_wise').length;
	//numItems++;
	daysrowprint.find('.reporting_day_wise').attr('name','reporting_day_wise'+numItems+'[]');
	daysrowprint.find('.reporting_day_wise').val('');
	daysrowprint.find('.time').val('');
	daysrowprint.find('.addNewDayRowCell').html('');
	$( "tr.days_cell:last" ).after(daysrowprint);
	$('.time').clockpicker();
}


function addNewreporttime(){
	$('.savereporttime').attr('disabled',false);
	if($('.newReportimrform').length){
		
	}else{
	$('.list-leaves').before('<form class="newReportimrform field-style">'+
		'<table width="100%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
			'<tr>'+
				'<td width="25%">&nbsp;</td>'+
				'<td width="25%">&nbsp;</td>'+
				'<td width="50%">&nbsp;</td>'+
			'</tr>'+
			'<tr>'+
				'<td><translate>Branch</translate></td>'+
				'<td><select name="branch" id="branch" style="width:200px;" onchange="load_emp_under_brnch_modified(this.value)"><option value="">Select One</option></select></td>'+
				'<td></td>'+
			'</tr>'+
			'<tr>'+
				'<td><translate>Reporting Time Based On</translate></td>'+
				'<td>'+
					'<select name="reporting_time_type" id="reporting_time_type" style="width:200px;" onChange="display_days_cell(this.value)">'+
						'<option value="W">Whole Week</option>'+
						'<option value="I">Day Wise</option>'+
						/*'<option value="E">Employee Wise</option>'+*/
					'</select>'+
				'</td>'+
				'<td></td>'+
			'</tr>'+
			'<tr class="days_cell" style="display:none">'+
				'<td><translate>Day</translate></td>'+
				'<td>'+
					'<select name="reporting_day_wise0[]" class="reporting_day_wise" style="width:200px;" multiple>'+
						'<option value="Sun">Sunday</option>'+
						'<option value="Mon">Monday</option>'+
						'<option value="Tue">Tuesday</option>'+
						'<option value="Wed">Wednesday</option>'+
						'<option value="Thu">Thursday</option>'+
						'<option value="Fri">Friday</option>'+
						'<option value="Sat">Saturday</option>'+
					'</select>'+
				'</td>'+
				'<td>'+
					'<table>'+
						'<tr>'+
							'<td><translate>Full day working hours </translate><input name="report_hours_full[]" type="text"  class="time" style="width:75px;" /></td>'+
							'<td><translate>Half day working hours </translate><input name="report_hours_half[]" type="text"  class="time" style="width:75px;" /></td>'+
							'<td class="addNewDayRowCell"><a href="#" class="addNewDayRow" onclick="addNewDayRow()"><translate>Add More</translate></a></td>'+
						'</tr>'+
					'</table>'+
				'</td>'+
			'</tr>'+
			/*'<tr class="employees_cell" style="display:none">'+
				'<td><translate>Employee List</translate></td>'+
				'<td>'+
					'<select name="emp_list0[]" class="Searchemp_list reporting_employee_wise" multiple>'+
					'</select>'+
				'</td>'+
				'<td>'+
					'<table>'+
						'<tr>'+
							'<td><translate>Full day working hours </translate><input name="report_hours_full[]" type="text"  class="time" style="width:75px;" /></td>'+
							'<td><translate>Half day working hours </translate><input name="report_hours_half[]" type="text"  class="time" style="width:75px;" /></td>'+
							'<td class="addNewEmployeeRowCell"><a href="#" class="addNewEmployeeRow" onclick="addNewEmployeeRow()"><translate>Add More</translate></a></td>'+
						'</tr>'+
					'</table>'+
				'</td>'+
			'</tr>'+*/
			'<tr class="days_hours_cell" >'+
				'<td><translate>Full day working hours</translate></td>'+
				'<td><input name="report_hours_full_whole" type="text"  class="time" style="width:75px;" /></td>'+
			'</tr>'+
			'<tr class="days_hours_cell" >'+
				'<td><translate>Half day working hours</translate></td>'+
				'<td><input name="report_hours_half_whole" type="text"  class="time" style="width:75px;" /></td>'+
			'</tr>'+
			'<tr>'+
				'<td><translate>Max late coming</translate></td>'+
				'<td><input type="text" name="late_coming" id="late_coming" class="time" style="width:150px;" /></td>'+
			'</tr>'+
			'<tr>'+
				'<td><translate>Max early going</translate></td>'+
				'<td><input type="text" name="early_going" id="early_going" class="time" style="width:150px;" /></td>'+
			'</tr>'+
			'<tr>'+
				'<td>&nbsp;</td>'+
				'<td><input type="button" name="button" class="color-button savereporttime" id="button" value="Submit" />'+
				'<input type="button" name="button" class="color-button cancelreporttime" id="button" value="Cancel" /></td>'+
			'</tr>'+
			'<tr>'+
				'<td>&nbsp;</td>'+
				'<td>&nbsp;</td>'+
			'</tr>'+
		'</table>'+
	'</form>');
	$('.time').clockpicker();
	$('.newLeave').show('blind',500);
	 //$('#basicExample').timepicker();
	 //$('#basicExample2').timepicker();
	}
	loadBranch();
	//loadEmpBrnch_modified(0);
}

function Updatereporttime() {
	if(!$('#branch').val())
	{
		alert('Please select a branch'); $('#branch').focus();	
	}
	else if(!$('#late_coming').val())
	{
		alert('Please select max late time'); $('#late_coming').focus();	
	}
	else if(!$('#early_going').val())
	{
		alert('Please select max early going time'); $('#early_going').focus();	
	}
	else{
		$('.updatereporttime').attr('disabled',true);
		var reporting_time_id=$('.reporting_time_id').val();
		dataString = $('.newReportimrform').serialize();
		var branch_names = $('#branch option:selected').text();
		$.post( serviceURLHR+ "manageReportime.php?action=update&branch_name="+branch_names,dataString,function(data){
			$('.list-leaves tr.reporting_row_'+reporting_time_id).replaceWith(data); 
			$('.newReportimrform').hide('blind',500,function(){ $(this).remove(); });
		},'html');
	}
}

function cancelreporttime(){
	$('.newReportimrform').hide('blind',500,function(){ $(this).remove(); });
}

function savereporttime(){	
	if(!$('#branch').val())
	{
		alert('Please select a branch'); $('#branch').focus();	
	}
	else if(!$('#late_coming').val())
	{
		alert('Please select max late time'); $('#late_coming').focus();	
	}
	else if(!$('#early_going').val())
	{
		alert('Please select max early going time'); $('#early_going').focus();	
	}
	else{
		$('.savereporttime').attr('disabled',true);
		dataString = $('.newReportimrform').serialize();
		var branch_names = $('#branch option:selected').text();
		$.post( serviceURLHR+ "manageReportime.php?action=insert&branch_name="+branch_names,dataString,function(data){
			$('.empty_row_class').remove();
			$('.list-leaves').append(data); 
			$('.newReportimrform').hide('blind',500,function(){ $(this).remove(); });
		},'html');
	}
}

function editReportTime(){
	
	//	$('#tablelist').html('');
	if($('.newReportimrform').length){
		
	}else{
		$this = $(this);
		var reportid 	= $this.attr('data-id');
		$('.list-leaves').before('<form class="newReportimrform field-style">'+
			'<table width="100%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
				'<tr>'+
					'<td width="25%">&nbsp;</td>'+
					'<td width="25%">&nbsp;</td>'+
					'<td width="50%">&nbsp;</td>'+
				'</tr>'+
				'<tr>'+
					'<td><translate>Branch</translate><input type="hidden" name="reporting_time_id" class="reporting_time_id" /></td>'+
					'<td><select name="branch" id="branch" class="branch" style="width:200px;"></select></td>'+
					'<td></td>'+
				'</tr>'+
				'<tr>'+
					'<td><translate>Reporting Time Based On</translate></td>'+
					'<td>'+
						'<select name="reporting_time_type" id="reporting_time_type" style="width:200px;" onChange="display_days_cell(this.value)">'+
							'<option value="W">Whole Week</option>'+
							'<option value="I">Day Wise</option>'+
						'</select>'+
					'</td>'+
					'<td></td>'+
				'</tr>'+
				'<tr class="days_cell" style="display:none">'+
					'<td><translate>Day</translate></td>'+
					'<td>'+
						'<select name="reporting_day_wise0[]" class="reporting_day_wise" style="width:200px;" multiple>'+
							
						'</select>'+
					'</td>'+
					'<td>'+
						'<table>'+
							'<tr>'+
								'<td><translate>Full day working hours </translate><input name="report_hours_full[]" type="text" class="report_hours_full time" style="width:75px;" /></td>'+
								'<td><translate>Half day working hours </translate><input name="report_hours_half[]" type="text"  class="report_hours_half time" style="width:75px;" /></td>'+
								'<td class="addNewDayRowCell"><a href="#" class="addNewDayRow" onclick="addNewDayRow()"><translate>Add More</translate></a></td>'+
							'</tr>'+
						'</table>'+
					'</td>'+
				'</tr>'+
				'<tr class="days_hours_cell" >'+
					'<td><translate>Full day working hours</translate></td>'+
					'<td><input name="report_hours_full_whole" type="text" id="report_hours_full_whole"  class="time" style="width:75px;" /></td>'+
				'</tr>'+
				'<tr class="days_hours_cell" >'+
					'<td><translate>Half day working hours</translate></td>'+
					'<td><input name="report_hours_half_whole" id="report_hours_half_whole" type="text"  class="time" style="width:75px;" /></td>'+
				'</tr>'+
				'<tr>'+
					'<td><translate>Max late coming</translate></td>'+
					'<td><input type="text" name="late_coming" id="late_coming" class="time" style="width:150px;" /></td>'+
				'</tr>'+
				'<tr>'+
					'<td><translate>Max early going</translate></td>'+
					'<td><input type="text" name="early_going" id="early_going" class="time" style="width:150px;" /></td>'+
				'</tr>'+
				'<tr>'+
					'<td>&nbsp;</td>'+
					'<td><input type="button" name="button" class="color-button updatereporttime" id="button" value="Update" />'+
					'<input type="button" name="button" class="color-button cancelreporttime" id="button" value="Cancel" /></td>'+
				'</tr>'+
				'<tr>'+
					'<td>&nbsp;</td>'+
					'<td>&nbsp;</td>'+
				'</tr>'+
			'</table>'+
		'</form>');
		$('.time').clockpicker();
		loadBranch();
		$.getJSON( serviceURLHR+ "manageReportime.php?action=edit_repoting&reportid="+reportid,function(data){
			timing = data.timing;
			day_list = data.day_details;
			
			$('.branch').val(timing[0].branch_id);
			$('.reporting_time_id').val(timing[0].id);
			$('#reporting_time_type').val(timing[0].based_on);
			if(timing[0].based_on!='W')
			{
				$('.days_hours_cell').hide();
				$('.days_cell').show();
				$('.reporting_day_wise').html(day_list);
				$('.report_hours_full').val(timing[0].working_hours);
				$('.report_hours_half').val(timing[0].halfday_hours);
			}
			else
			{
				//$('.reporting_day_wise').html(day_list);
				$('#report_hours_full_whole').val(timing[0].working_hours);
				$('#report_hours_half_whole').val(timing[0].halfday_hours);	
			}
			$('#late_coming').val(timing[0].max_late_coming);
			$('#early_going').val(timing[0].max_early_going);
			$('.newLeave').show('blind',500);
		});		
	}
}

function removereporttime(){
	var checkstr =  confirm('are you sure you want to delete this?');
	if(checkstr == true){
 		var did = $(this).attr('data-id');
		$this = $(this);
		$.get(serviceURLHR + "manageReportime.php?action=removeded&did="+did,function(){
			$this.parent().parent().remove();															 
		});
	}else{
		return false;
	}
}
//----------------------------------------------End Report Timing----------------------

//--------------------------------------Employee Grouping---------------------------------//

function employee_grouping() {
	$.get(serviceURLHR + "manageReportime.php?action=viewempgroup",function(data){
		$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaves">'+
			'<tr>'+
				'<td width=""><translate>Title</translate></td>'+
				'<td width=""><translate>Type</translate></td>'+
				'<td width=""><translate>Related Shift/Earning/Deduction</translate></td>'+
				'<td width=""><translate>Edit</translate></td>'+
				'<td width=""><img src="images/icon-add.png" class="addNewEmployeeGroup" width="20" height="20" /></td>'+
			'</tr>'+
		'</table>');
		
		$('.list-leaves').append(data);
		$('.list-leaves').show('blind',500);
		$('.expand_parent_row').click(function () {
			var currentDetails = $(this).next('.row_to_expand');
			$('.row_to_expand').not(currentDetails).hide();
			currentDetails.toggle();
		});
	});	
}

function load_ED(base_val,selectValue) {
	if($('#branch').val())
	{
		selectValue = (selectValue === "undefined")?"":selectValue;
		if(base_val=='S')
		{
			$('.ED_combo_cell').hide();
			$.getJSON(serviceURLHR + 'manageReportime.php?action=list_shift_period&branchid='+$('#branch').val(),function(data){
					shift_list = data.shifts;
					$('.shift_combo').html('');
					$.each(shift_list, function(index, shift_list) {									 
						$('.shift_combo').append('<option value="'+shift_list.id+'">'+shift_list.from_time+' - '+shift_list.to_time+'</option>');
					});
					$('.shift_combo').val(selectValue);
					//$('.e_d_combo').append('<option value="newearning">Add New Earning</option>');
			});
			
			$( "tr.Shift_combo_cell:nth-child(1)" ).remove();
			$('.Shift_combo_cell').after('<tr class="Shift_combo_cell">'+
				'<td>From : <input type="text" name="shift_from" class="shift_date" /></td>'+
				'<td>To : <input type="text" name="shift_to" class="shift_date" /></td>'+
			'</tr>');
			$('.shift_date').datepicker({dateFormat:"dd-mm-yy"});
			$('.Shift_combo_cell').show();
		}
		else
		{
			$('.Shift_combo_cell').hide();
			if(base_val=='E')
			{
				$.getJSON(serviceURLHR + 'manage_earning_deduction.php?act=list_earning_type',function(data){
					e_d_list = data.earningtype;
					$('.e_d_combo').html('');
					$.each(e_d_list, function(index, e_d_list) {									 
						$('.e_d_combo').append('<option value="'+e_d_list.id+'">'+e_d_list.name+'</option>');
					});
					$('.e_d_combo').append('<option value="newearning">Add New Earning</option>');
					$('.e_d_combo').val(selectValue);
					$('.ED_combo_cell').show();
				});	
			}
			else if(base_val=='D')
			{
				$.getJSON(serviceURLHR + 'manage_earning_deduction.php?act=list_deduction_type',function(data){
					e_d_list = data.deductionstype;	
					$('.e_d_combo').html('');
					$.each(e_d_list, function(index, e_d_list) {									 
						$('.e_d_combo').append('<option value="'+e_d_list.id+'">'+e_d_list.name+'</option>');
					});	
					$('.e_d_combo').append('<option value="newdeduction">Add New Deduction</option>');
					$('.e_d_combo').val(selectValue);
					$('.ED_combo_cell').show();
				});
			}
		}
	}
	else
	{
		alert('Please select branch.')	;
		$('.emp_group_basis').val(0);
	}
}

function check_ed_combo_val(earn_combo_val) {
	if(earn_combo_val == 'newearning'){
		$("body").append('<div class="newEmployeeDetails" style="display:none; padding:25px;">'+
			'<form class="newSingleAttributeForm">'+
				'<table width="800" height="200" border="0" cellpadding="0" cellspacing="0">'+
					'<tr>'+
						'<td width="200"><translate>Earning</translate></td>'+
						'<td width="400"><input type="text" name="attribute" value="" id="attribute" /></td>'+
						'<td width="200">&nbsp;</td>'+
						'<td width="200">&nbsp;</td>'+
					'</tr>'+
					'<tr>'+
						'<td width="200"><translate>Added to</translate></td>'+
						'<td width="400"><input type="radio" name="added_to" value="C"><translate>Cash</translate><br><input type="radio" name="added_to" value="B"><translate>Bank</translate></td>'+
						'<td width="200">&nbsp;</td>'+
						'<td width="200">&nbsp;</td>'+
					'</tr>'+
					'<tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="saveNewEarningGroup"  class="color-button saveSingleAttrDetails" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelNewEarningGroup" style="float:left;" value="Cancel" /></td>'+
					'</tr>'+
				'</table>'+
			'</form>'+
		'</div>');
		$('.newEmployeeDetails').show('fade',300);
		$('.newEmployeeDetails').center();	
	}
	else if(earn_combo_val == 'newdeduction')
	{
		$("body").append('<div class="newEmployeeDetails" style="display:none; padding:25px; ">'+
			'<form class="newSingleAttributeForm">'+
				'<table  height="200" border="0" cellpadding="0" cellspacing="0">'+
					'<tr>'+
						'<td width="200"><translate>Deduction</translate></td>'+
						'<td width="400"><input type="text" name="attribute" value="" id="attribute" /></td>'+
						'<td width="200">&nbsp;</td>'+
						'<td width="200">&nbsp;</td>'+
					'</tr>'+
					'<tr>'+
						'<td width="200"><translate>Deducted from</translate></td>'+
						'<td width="400"><input type="radio" name="added_to" value="C"><translate>Cash</translate><br><input type="radio" name="added_to" value="B"><translate>Bank</translate></td>'+
						'<td width="200">&nbsp;</td>'+
						'<td width="200">&nbsp;</td>'+
					'</tr>'+
					'<tr>'+
						'<td width="200"><translate>Mess fare</translate></td>'+
						'<td width="400"><input type="checkbox" name="mess_fare_flag" value="1" id="mess_fare_flag" /></td>'+
						'<td width="200">&nbsp;</td>'+
						'<td width="200">&nbsp;</td>'+
					'</tr>'+
					'<tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="saveNewDeductionGroup"  class="color-button saveSingleAttrDetails" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelNewDeductionGroup" style="float:left;" value="Cancel" /></td>'+
					'</tr>'+
				'</table>'+
			'</form>'+
		'</div>');
		$('.newEmployeeDetails').show('fade',300);
		$('.newEmployeeDetails').center();	
	}
}

function addNewGroupRow() {
	grouprowprint=$('.group_cell:first').clone()
	var numItems = $('.group_cell').length;
	grouprowprint.attr('id','new_group_row'+numItems);	
	grouprowprint.find('.group_title').val('');
	grouprowprint.find('.emp_group_basis').val('S');
	grouprowprint.find('.e_d_combo').html('');
	grouprowprint.find('.ED_combo_cell').hide();
	grouprowprint.find('.Searchemp_list').val('');
	grouprowprint.find('.addNewGroupRowCell').html('<a href="#" class="deleteNewGroupRow" onclick="deleteNewGroupRow('+numItems+')"><translate>Delete</translate></a>');
	$( "tr.group_cell:last" ).after(grouprowprint);	
}

function deleteNewGroupRow(numItems)
{
	$('#new_group_row'+numItems).remove();	
}

function add_employee_grouping() {
	$.get(serviceURLHR + "manageReportime.php?action=AddEmpGroupForm",function(data){
		if($('.newEmpGroupform').length){
		
		}else{
			$('.list-leaves').before('<form class="newEmpGroupform field-style">'+
				'<table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
					'<tr>'+
						'<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
					'</tr>'+
					'<tr class="group_cell">'+
						'<td>Title : </td>'+
						'<td><input type="text" name="group_title" class="group_title" ></td>'+
					'</tr>'+
					'<tr>'+
						'<td>Branch : </td>'+
						'<td>'+
							'<select name="branch" id="branch" class="branch" onchange="load_emp_under_brnch_modified(this.value);load_ED();">'+
								'<option value="">Select One</option>'+	
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td>Based on :</td>'+
						'<td>'+
							'<select name="emp_group_basis" class="emp_group_basis" onchange="load_ED(this.value)">'+
								'<option value="">Select One</option>'+	
								'<option value="S">Shift</option>'+	
								'<option value="E">Earning</option>'+	
								'<option value="D">Deduction</option>'+	
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr class="Shift_combo_cell" style="display:none">'+
						'<td>Shift :</td>'+
						'<td>'+
							'<select name="shift_combo" class="shift_combo" >'+
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr class="ED_combo_cell" style="display:none">'+
						'<td>E&D :</td>'+
						'<td>'+
							'<select name="e_d_combo" class="e_d_combo" onchange="javascript:check_ed_combo_val(this.value);">'+
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td>Emp List : </td>'+
						'<td>'+
							'<select name="emp_list[]" class="Searchemp_list" multiple>'+
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td>&nbsp;</td>'+
						'<td><input type="button" name="button" class="color-button saveempgroup" id="button" value="Submit" />'+
						'<input type="button" name="button" class="color-button cancelempgroup" id="button" value="Cancel" /></td>'+
					'</tr>'+
					'<tr>'+
						'<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
					'</tr>'+
				'</table>'+
			'</form>');
			loadBranch();
			//loadEmpBrnch_modified(0);
			$('.newLeave').show('blind',500);
		}
	});	
}

function SaveEmpGroup()
{
	$('.saveempgroup').attr('disabled',true);
	dataString = $('.newEmpGroupform').serialize();
	if($('.emp_group_basis').val()== 'S')
	{
		var related_name=$('.shift_combo option:selected').text();	
	}
	else
	{
		var related_name=$('.e_d_combo option:selected').text();	
	}
	$.post( serviceURLHR+ "manageReportime.php?action=insert_emp_group&related_name="+related_name,dataString,function(data){
			$('.list-leaves').append(data);
			$('.empty_row_class').remove();
			alert('Employee Group successfully added.');
			$('.saveempgroup').attr('disabled',false);
			$('.newEmpGroupform').hide('blind',500,function(){ $(this).remove(); });
	},'html');
}

function updateempgroup()
{
	$('.updateempgroup').attr('disabled',true);
	dataString = $('.newEmpGroupform').serialize();
	if($('.emp_group_basis').val()== 'S')
	{
		var related_name=$('.shift_combo option:selected').text();	
	}
	else
	{
		var related_name=$('.e_d_combo option:selected').text();	
	}
	var group_id=$('#group_id').val();
	$.post( serviceURLHR+ "manageReportime.php?action=update_emp_group_details&related_name="+related_name,dataString,function(data){
			$('.list-leaves tr.group_row_'+group_id).replaceWith(data);
			alert('Employee Group successfully updated.');
			$('.updateempgroup').attr('disabled',false);
			$('.newEmpGroupform').hide('blind',500,function(){ $(this).remove(); });
	},'html');
}

function DeleteEmpGroup() {
	$this = $(this);
	var group_id 	= $this.attr('data-id');
	$.post( serviceURLHR+ "manageReportime.php?action=delete_emp_group&group_id="+group_id,function(data){
			$('.list-leaves tr.group_row_'+group_id).remove(data);
			alert('Employee Group successfully deleted.');
			//$('.updateempgroup').attr('disabled',false);
			//$('.newEmpGroupform').hide('blind',500,function(){ $(this).remove(); });
	},'html');
}

function EditEmpGroup()
{
	if($('.newEmpGroupform').length){
		
	}else{
		$this = $(this);
		var groupid 	= $this.attr('data-id');
			$('.list-leaves').before('<form class="newEmpGroupform field-style">'+
				'<table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
					'<tr>'+
						'<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
					'</tr>'+
					'<tr class="group_cell">'+
						'<td>Title : </td>'+
						'<td><input type="text" name="group_title" class="group_title" ><input type="hidden" name="group_id" id="group_id" class="group_id" ></td>'+
					'</tr>'+
					'<tr>'+
						'<td>Based on :</td>'+
						'<td>'+
							'<select name="emp_group_basis" class="emp_group_basis" onchange="load_ED(this.value)">'+
								'<option value="S">Shift</option>'+	
								'<option value="E">Earning</option>'+	
								'<option value="D">Deduction</option>'+	
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr class="Shift_combo_cell" style="display:none">'+
						'<td>Shift :</td>'+
						'<td>'+
							'<select name="shift_combo" class="shift_combo" >'+
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr class="ED_combo_cell" style="display:none">'+
						'<td>E&D :</td>'+
						'<td>'+
							'<select name="e_d_combo" class="e_d_combo" onchange="javascript:check_ed_combo_val(this.value);">'+
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td>Branch : </td>'+
						'<td>'+
							'<select name="branch" id="branch" class="branch" onchange="load_emp_under_brnch_modified(this.value)">'+
								'<option value="">Select One</option>'+	
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td>Emp List : </td>'+
						'<td>'+
							'<select name="emp_list[]" class="Searchemp_list" multiple>'+
							'</select>'+
						'</td>'+
					'</tr>'+
					'<tr>'+
						'<td>&nbsp;</td>'+
						'<td><input type="button" name="buttonhkjhkjk" class="color-button updateempgroup" id="button" value="Update"  />'+
						'<input type="button" name="button" class="color-button cancelempgroup" id="button" value="Cancel" /></td>'+
					'</tr>'+
					'<tr>'+
						'<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
					'</tr>'+
				'</table>'+
			'</form>');
			loadBranch();
			//loadEmpBrnch_modified(0);
			
		$.getJSON( serviceURLHR+ "manageReportime.php?action=edit_emp_group&group_id="+groupid,function(data){
			group = data.employee_details;
			emplist = data.emp_list;
			//alert(emplist);
			//$.each(group, function(index, group) {
				$('.group_title').val(group[0].title);
				$('.group_id').val(group[0].id);
				$('.emp_group_basis').val(group[0].based_on);
				if(group[0].based_on!='S')
				{
					$('.ED_combo_cell').show();
					load_ED(group[0].based_on,group[0].related_ed);
					//$('.e_d_combo').val(group[0].related_ed);
				}
				else
				{
					$('.Shift_combo_cell').show();
					load_ED(group[0].based_on,group[0].related_ed);
					//$('.shift_combo').val(group[0].related_ed);
				}
				$('.branch').val(group[0].branch_id);
				$('.Searchemp_list').html(emplist);
			//});
			$('.newLeave').show('blind',500);
		});
	}
}

//-----------------------------------------------Shifting Periods-------------------------//

function shifting_periods() {
	$.get(serviceURLHR + "manageReportime.php?action=viewshifting",function(data){
		$('#masterlist').html(data);
		$('.expand_parent_row').click(function () {
			var currentDetails = $(this).next('.row_to_expand');
			$('.row_to_expand').not(currentDetails).hide();
			currentDetails.toggle();
		});
		$('.list-leaves').show('blind',500);
	});
}

function addNewShiftBranch() {
	if($('.newReportimrform').length){
		
	}else{
		$('.list-leaves').before('<form class="newShiftform field-style">'+
			'<table width="100%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
				'<tr>'+
					'<td width="25%">&nbsp;</td>'+
					'<td width="25%">&nbsp;</td>'+
					'<td width="50%">&nbsp;</td>'+
				'</tr>'+
				'<tr>'+
					'<td><translate>Branch</translate></td>'+
					'<td><select name="branch" id="branch" style="width:200px;" onchange="load_working_hours_branch(this.value)"><option value="">Select One</option></select></td>'+
					'<td></td>'+
				'</tr>'+
				'<tr  class="shift_cell">'+
					'<td><translate>From</translate><input name="shift_from_hours[]" type="text"  class="time" style="width:75px;" /></td>'+
					'<td><translate>To</translate><input name="shift_to_hours[]" type="text"  class="time" style="width:75px;" /></td>'+
					'<td class="addNewShiftRowCell"><a href="#" class="addNewShiftRow" onclick="addNewShiftRow()"><translate>Add More</translate></a></td>'+
				'</tr>'+
				'<tr>'+
					'<td>&nbsp;</td>'+
					'<td><input type="button" name="button" class="color-button saveshifttime" id="button" value="Submit" /><input type="button" name="button" class="color-button cancelshifttime" onclick="cancelshifttime()" id="button" value="Cancel" /></td>'+
				'</tr>'+
			'</table>'+
		'</form>');
		
		$('.time').clockpicker();
		$('.newLeave').show('blind',500);
		loadBranch();
	}
}

function cancelshifttime() {
	$('.newShiftform').remove();
	$('.info_span').remove();
}

function addNewShiftRow() {
	shiftrowprint=$('.shift_cell:first').clone()
	var numItems = $('.shift_cell').length;
	shiftrowprint.attr('id','new_shift_row'+numItems);	
	shiftrowprint.find('.time').val('');
	shiftrowprint.find('.addNewShiftRowCell').html('<a href="#" class="deleteNewShiftRow" onclick="deleteNewShiftRow('+numItems+')"><translate>Delete</translate></a>');
	shiftrowprint.find('.update_ids').remove();
	$( "tr.shift_cell:last" ).after(shiftrowprint);
	$('.time').clockpicker();
}

function load_working_hours_branch(branchid) {
	$.get(serviceURLHR + "manageReportime.php?action=working_hours_branch&branchid="+branchid,function(data){
		$('.newShiftform').before('<div class="info_span alert alert-warning alert-dismissible fade in">'+data+'</div>');	
	});
}


function deleteNewShiftRow(numItems)
{
	$('#new_shift_row'+numItems).remove();	
}

function SaveShiftingPeriods() {
	if($('#branch').val())
	{
		$('.saveshifttime').attr('disabled',true);
		dataString = $('.newShiftform').serialize();
		$.post( serviceURLHR+ "manageReportime.php?action=insert_shift",dataString,function(data){
				shifting_periods();
				alert('Shifts successfully added.');
				$('.saveshifttime').attr('disabled',false);
		},'html');
	}
	else
	{
		alert('Please select branch.')	
	}
}


//--------------company----------------------

function companyList(){
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	$.getJSON(serviceURLHR + "manageCompany.php?act=list",function(data){
		var leaves = data.leaves;
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaves">'+
										  '<tr>'+
											'<td width="23%"><translate>Post Name</translate></td>'+
											'<td width="23%"><translate>Department Name</translate></td>'+
											'<td width="23%"><translate>Rank</translate></td>'+
											'<td width="5%"><translate>Edit</translate></td>'+
											'<td width="5%"><img src="images/icon-add.png" class="addNewcompany" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(leaves, function(index,leaves){
				
				
				
					$('.list-leaves').append( '<tr class="company_'+leaves.comprank_id+'">'+
														'<td width="23%" class="desgName">'+leaves.post_name+'</td>'+
														'<td width="23%" class="departName" data-id="'+leaves.depart_id+'">'+leaves.depart_name+'</td>'+
														'<td width="23%" class="departRank">'+leaves.comp_rank+'</td>'+
														'<td width="5%"><img data-id="'+leaves.comprank_id+'" src="'+editIconpen+'" class="editcompany"/></td>'+
														'<td width="5%"><img data-id="'+leaves.comprank_id+'" src="'+removeIcon+'" class="removecompany"/></td>'+
													 '</tr>');				
			});
			$('.list-leaves').show('blind',500);
		
	});	
}



function updatecompany(){
	
	//if ($.trim($("#companyname").val()).length != 0) {
	//if ($.trim($("#department_name").val()) != '') {
	
	var company_name = $('#company_name').val();
	var company_address = $('#company_address').val();
	var company_phone = $('#company_phone').val();
	var company_mobile = $('#company_mobile').val();
	var company_email = $('#company_email').val();
	var pf_code_no = $('#pf_code_no').val();
	
	
		
	var designationDetails = $('.company_details_form').serialize();	
	
	var userid	= $('#userid').val();
	
	$.post(serviceURLHR + "company-details.php?action=update",designationDetails,function(data){
		var currentUser = $('.company_'+userid);
		currentUser.find('.cmpName').text(data.company_name);
		currentUser.find('.cmpAdd').text(company_address);
		currentUser.find('.cmpph').text(data.company_phone);
		currentUser.find('.cmpmb').text(data.company_mobile);
		currentUser.find('.cmpEmail').text(data.company_email);
		currentUser.find('.pf_code_no').text(data.pf_code_num);
		
	},"json");
	$('.company_details_form').hide('blind',500,function(){ $(this).remove(); });
	/*}else
	{
		alert('Please Select Department');	
	}
}else
	{
		alert('Please Enter Post');	
	}*/
}



function addNewCompany()
{
	
	$('.savecompany').attr('disabled',false);
	if($('.company_details_form').length){
		
	}else{
	$('.list-leavesu').before('<form class="company_details_form field-style">'+
						'<table width="100%" border="0" cellspacing="0" cellpadding="0" class="newLeave" style="display:none;">'+
						  '<tr>'+
							'<td width="26%">&nbsp;</td>'+
							'<td width="74%"><div class="div-result"></div></td>'+
						  '</tr>'+
						 '<tr>'+
							'<td height="25">Name</td>'+
							'<td><input type="text" name="company_name" class="company_name" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Address</td>'+
							'<td><input type="text" name="company_address" class="company_address" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Phone No </td>'+
							'<td><input type="text" name="company_phone" class="company_phone" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Mobile No </td>'+
							'<td><input type="text" name="company_mobile" class="company_mobile" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">E-mail </td>'+
							'<td><input type="text" name="company_email" class="company_email" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">PF Code No </td>'+
							'<td><input type="text" name="pf_code_no" class="pf_code_no" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Logo</td>'+
							'<td><input type="file" name="company_logo" class="company_logo" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td>&nbsp;</td>'+
							'<td><input type="button" value="Submit" class="color-button savecompany" style="visibility:visible">'+
							'<input type="button" name="button" class="color-button cancelNewCompany" id="button" value="Cancel" /></td>'+
						  '</tr>'+
						  '</table>'+
						  '</form>');
	$('.newLeave').show('blind',500);
	}
	//loadCompany();
}


function savecompany()
{
	
	var company_name = $('#company_name').val();
	var company_address = $('#company_address').val();
	var company_phone = $('#company_phone').val();
	var company_mobile = $('#company_mobile').val();
	var company_email = $('#company_email').val();
	var pf_code_no = $('#pf_code_no').val();

	
		$('.savecompany').attr('disabled',true);
		dataString = $('.company_details_form').serialize();
		$.post( serviceURLHR+ "company-details.php?action=insert",dataString,function(data){
			var leaves = data.leaves
			$('.list-leavesu').append( '<tr class="company_'+leaves.id+'">'+
														'<td width="23%" class="cmpName">'+leaves.company_name+'</td>'+
														'<td width="23%" class="cmpAdd">'+leaves.company_address+'</td>'+
														'<td width="23%" class="cmpph">'+leaves.company_phone+'</td>'+
														'<td width="23%" class="cmpmb">'+leaves.company_mobile+'</td>'+
														'<td width="23%" class="cmpEmail">'+leaves.company_email+'</td>'+
														'<td width="23%" class="PFcodeno">'+leaves.pf_code_num+'</td>'+
														'<td width="5%"><img data-id="'+leaves.id+'" src="'+editIconpen+'" class="editCompany"/></td>'+													
														'<td width="5%"><img data-id="'+leaves.id+'" src="'+removeIcon+'" class="removecompany"/></td>'+
													 '</tr>');	
			$('.company_details_form').hide('blind',500,function(){ $(this).remove(); });
			//window.location.reload();
		},'json');		
	
	
	
}

function editCompany(){
	
//	$('#tablelist').html('');
	if($('.company_details_form').length){
		
	}else{
	$this = $(this);
	
	var userid 	= $this.attr('data-id');
	
	var comp_name = $this.parent().parent().find('.cmpName').text();
	var comp_add  = $this.parent().parent().find('.cmpAdd').text();
	var comp_ph   = $this.parent().parent().find('.cmpph').text();
	var comp_mob  = $this.parent().parent().find('.cmpmb').text();
	var comp_email  = $this.parent().parent().find('.cmpEmail').text();
	var pf_codeno  = $this.parent().parent().find('.pf_code_no').text();
	
	
	
	$('.list-leavesu').before('<form class="company_details_form field-style">'+
						'<table width="100%" border="0" cellspacing="0" cellpadding="0" class="newLeave" style="display:none;">'+
						  '<tr>'+
							'<td width="26%">&nbsp;</td>'+
							'<td width="74%"><div class="div-result"></div></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Name</td>'+
							'<td><input type="text" name="company_name" id="company_name" value="'+comp_name+'" /></td>'+
							'<td><input type="hidden" name="userid" id="userid" value="'+userid+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Address</td>'+
							'<td><input type="text" name="company_address" id="company_address" value="'+comp_add+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Phone No </td>'+
							'<td><input type="text" name="company_phone" id="company_phone" value="'+comp_ph+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Mobile No </td>'+
							'<td><input type="text" name="company_mobile" id="company_mobile" value="'+comp_mob+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">E-mail </td>'+
							'<td><input type="text" name="company_email" id="company_email" value="'+comp_email+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">PF Code No </td>'+
							'<td><input type="text" name="pf_code_no" id="pf_code_no" value="'+pf_codeno+'" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td height="25">Logo</td>'+
							'<td><input type="file" name="company_logo" id="company_logo" /></td>'+
						  '</tr>'+
						  '<tr>'+
							'<td>&nbsp;</td>'+
							'<td><input type="button" value="Submit" class="color-button updatecompany" style="visibility:visible">'+
							'<input type="button" name="button" class="color-button cancelNewCompany" id="button" value="Cancel" /></td>'+
						  '</tr>'+
						  '</table>'+
						  '</form>');
	
	
	$('.newLeave').show('blind',500);
	}
	//loadDepartment();
	//setTimeout(function(){ $('#department_name').val(departmenyid); },500);
}


function removecompany(){
	

var checkstr =  confirm('are you sure you want to delete this?');
if(checkstr == true){
 var did = $(this).attr('data-id');
	$this = $(this);
	$.get(serviceURLHR + "company-details.php?action=removeded&did="+did,function(){
		$this.parent().parent().remove();															 
	});
}else{
return false;
}

	
}

//--------------End company----------------------

/*function branchlist(){
	alert('aaa');	
}*/



function removeBranch(){
	

var checkstr =  confirm('are you sure you want to delete this?');
if(checkstr == true){
 var did = $(this).attr('data-id');
	$this = $(this);
	$.get(serviceURLHR + "manageBranch.php?act=removeded&did="+did,function(){
		$this.parent().parent().remove();															 
	});
}else{
return false;
}

}

$(document).ajaxError(function(event, request, settings) {
	$('#busy').hide();
	//alert("Error accessing the server");
});


//----------------------------------------------------------------------------------------------------//Listing

var catlist;
function employeelist(pagenum,emp_post){ 


if(emp_post=='finance')
{
	$('#mang').attr('class','btn-tab-02');
	$('#evry').attr('class','btn-tab-01');
	$('#sup').attr('class','btn-tab-01');
	$('#emps').attr('class','btn-tab-01');
}
else if(emp_post=='finance')
{
	$('#sup').attr('class','btn-tab-02');
	$('#evry').attr('class','btn-tab-01');
	$('#mang').attr('class','btn-tab-01');
	$('#emps').attr('class','btn-tab-01');
}
else if(emp_post=='accounts')
{
	$('#mang').attr('class','btn-tab-02');
	$('#evry').attr('class','btn-tab-01');
	$('#sup').attr('class','btn-tab-01');
	$('#emps').attr('class','btn-tab-01');
}
else if(emp_post=='accounts')
{
	$('#sup').attr('class','btn-tab-02');
	$('#evry').attr('class','btn-tab-01');
	$('#mang').attr('class','btn-tab-01');
	$('#emps').attr('class','btn-tab-01');
}	
else if(emp_post=='marketing')
{
	$('#mang').attr('class','btn-tab-02');
	$('#evry').attr('class','btn-tab-01');
	$('#sup').attr('class','btn-tab-01');
	$('#emps').attr('class','btn-tab-01');
}
else if(emp_post=='marketing')
{
	$('#sup').attr('class','btn-tab-02');
	$('#evry').attr('class','btn-tab-01');
	$('#mang').attr('class','btn-tab-01');
	$('#emps').attr('class','btn-tab-01');
}	
	
else if(emp_post=='manager')
{
$('#mang').attr('class','btn-tab-02');
$('#evry').attr('class','btn-tab-01');
$('#sup').attr('class','btn-tab-01');
$('#emps').attr('class','btn-tab-01');
	}else if(emp_post=='supervisor')
{
$('#sup').attr('class','btn-tab-02');
$('#evry').attr('class','btn-tab-01');
$('#mang').attr('class','btn-tab-01');
$('#emps').attr('class','btn-tab-01');
	}else if(emp_post=='employee')
{
$('#emps').attr('class','btn-tab-02');
$('#evry').attr('class','btn-tab-01');
$('#mang').attr('class','btn-tab-01');
$('#sup').attr('class','btn-tab-01');
	}else{$('#evry').attr('class','btn-tab-02');$('#emps').attr('class','btn-tab-01');
$('#mang').attr('class','btn-tab-01');
$('#sup').attr('class','btn-tab-01');}

var imgs='';var dateformat='';var dateformat1=''; var dateformat2='';
var jsonURL = serviceURLHR + "employeelist.php" ;
//var jsonURL = serviceURLHR + "employeelist_sort.php" ;

$('#busy').show();
			$.getJSON(jsonURL,{ 
			   page: pagenum,
			   emp_post: emp_post
			},
            function(data) { 
				$('#busy').hide();
  				$('#tablelist').html('');
				employeeslist = data.name;
		 		$('#headername').html('Cutlery List');
				var num=1;
				var i=1;var cnt=0;var name=''; 
				$.each(employeeslist, function(index, employeeslist) {
					if(employeeslist.e_id !=null){					  
						f_name=employeeslist.e_fname;	
						m_name=employeeslist.e_mname;	
						l_name=employeeslist.e_lname;	
						e_mail=employeeslist.e_mail;
						e_mailtitle=employeeslist.e_mail;
						e_mail = e_mail.substr(0,28);
						e_mob=employeeslist.e_mob;
						e_post=employeeslist.e_post;
						e_empid=employeeslist.employee_id;
						if(employeeslist.photo=='')
						{
							 photo='noimg.jpg';
						}
						else
						{ 
				        	if(employeeslist.e_gender=='Male' && employeeslist.photo=='noimg.jpg')
				        	{
					     		photo='noimg.jpg'; 
					        }
				        	else if(employeeslist.e_gender=='Female' && employeeslist.photo=='noimg.jpg')
				        	{ 
					     		photo='Female.PNG'; 
				         	}
						 	else
						 	{
			             		photo=employeeslist.photo;	
							}
						}
			   			e_in=employeeslist.time_in;	
			  			e_out=employeeslist.time_out;	
			  			e_inloc=employeeslist.time_inloc;	
			  			e_outloc=employeeslist.time_outloc;	
			  
			  
			  			employeename = f_name+' '+l_name;
			  			employeename = employeename.substr(0,20);
			  
			   			if(employeeslist.clock_status==1)
                  		{
							var btnval = 'Clocked-In';				 
						 	var bt_id=   'clockedout';
						 	var btncolor ='button-color-login';
						 	var emp_in=e_in;
						 	var empin_loc=e_inloc;
           		  		}
						else
				   		{
            	 			var btnval = 'Clocked-Out';
				 			var bt_id=   'clockedin';
				 			var btncolor ='button-color-logout';
				  			var emp_in=e_out;
		 					var empin_loc=e_outloc;
				   		}
						if(employeeslist.status==1)
                   		{
				       		var imgsts= 'images/bullet_green.png';
					   		var imgval= 1;
				   		}
				   		else
				   		{
					   		var imgsts= 'images/bullet_orange.png';
					   		var imgval= 0;
				   		}
			
				     	$('#tablelist').append('<div class="employee-cell"><div class="clocked-in"><span class="clocked-status" style="width:1px"> <input type="button" name="btn" class="btn_'+employeeslist.e_id+' '+btncolor+'" id="'+bt_id+'" nums="'+num+'" value="'+btnval+'" style="width:80px"  /><input type="hidden" name="txt"  class="txt_'+employeeslist.e_id+'" id="txt_id" value="'+employeeslist.clock_status+'"/></span><a href="timesheet-individual.html?employees='+employeeslist.e_id+'"><span class="clocked-time" data-times="'+emp_in+'" id="e_time'+num+'" >'+emp_in+'</span></a></div> <div class="employee-foto"><a href="profile-view.php?employ_id='+employeeslist.e_id+'"><img src="'+HRPATH+'upload/image/'+photo+'" alt="" border="0" width="170" height="172" /></a></div><div class="employee-designation">'+e_post+'</div><a class="findurl" href="profile-view.php?employ_id='+employeeslist.e_id+'" data-link="'+ employeeslist.e_id + '" id="emps_id'+num+'"><h2 style="font-size:15px; font-weight:bold;"><translate>'+employeename+'</translate></h2></a><h3 title="'+e_mailtitle+'">'+e_mail+'</h3><div style="float:left"><h4>Emp Code:'+e_empid+'</h4></div><div class="timesheet-nav"><a href="timesheet-individual.php?employees='+employeeslist.e_id+'"><translate>Timesheet</translate></a></div></div>');
					}
					num++;
					i++;
				});
		
				$.getJSON(serviceURLHR+"listing.php?loadtime=1",function(responce){
					var timeDetails = responce.timeDetails;											   
					$.each(timeDetails, function(index, timeDetails) {
						var empid = timeDetails.e_id;
						$('.btn_'+empid).attr('id','clockin');
						$('.btn_'+empid).value('clockout');
					});	
				});
				$('#submitid').css("display","none");
		  		$('#num').val(i);
		   		pagination(pagenum,0,'pagenum');
			});

}
function showclocktime(i)
{
//var cur_time=new Time("h:i:s");
	var currentTime = new Date()
	var hours = currentTime.getHours()
	var minutes = currentTime.getMinutes()
	var seconds = currentTime.getSeconds()

	if (minutes < 10)
	minutes = "0" + minutes
if (seconds < 10){
	seconds = "0" + seconds}
	var suffix = "AM";
	if (hours >= 12) {
	suffix = "PM";
	hours = hours - 12;
	}
	if (hours == 0) {
	hours = 12;
	}
var cur_time= "0"+hours + ":" + minutes + " " + suffix+ "" ;
	 $('#e_time'+i).html(cur_time);
}
function  pagination(pagenum,ingredient,divname)
{
$.ajax({
   url: serviceURLHR+"employeelistpagination.php?page="+pagenum+"&ingredient="+ingredient,
   success: function(data){
	 
          $("#"+divname+"" ).html(data);
	 
   }
 });	
}
function gonextpage(page)
{ 
	employeelist(page);
}





$('#clockin').live('click',function(){
	$(this).val('Clocked-In');		

	$(this).attr('id','clockout');
	

var id=$("#clockout").attr('id');
var num=$(this).attr('nums');
	var currentItem	 = id;
	
	/*var times=$("#e_time"+num).attr('data-times');
	alert(times);
  $('#e_time'+num).html(times);*/
//alert(currentItem);
	insert(currentItem,num);
showclocktime(num);

//	clock_status_update(currentItem,num);

	 

});

$('#clockout').live('click',function(){

	$(this).val('Clocked-Out');		

	$(this).attr('id','clockin');	
	
var id=$("#clockin").attr('id');
var num=$(this).attr('nums');
//alert(aa);
/*var times=$("#e_time"+num).attr('data-times');
	alert(times);
$('#e_time'+num).html(times);*/
	var currentItem	 = id;
//alert(currentItem);
	update(currentItem,num);

	showclocktime(num)

});







function insert(currentItem,num)

 {

	var e_id=$("#emps_id"+num).attr('data-link');
//alert(e_id);
	//var in_out = $('#in_out').val();

	

	var dataString ={ ClockIn:"ClockIn",e_id:e_id}

	

	$.post(serviceURLHR+"listing.php",dataString,function(data){

	
	})


 }

 

 

 

 function update(currentItem,num)

 {
	 

var e_id=$("#emps_id"+num).attr('data-link');
//alert(e_id);
	var dataString1 ={ ClockOut:"ClockOut",e_id:e_id}

	$.post(serviceURLHR+"listing.php",dataString1,function(data){

		//alert(data);												

})

 }

 

 
 



function totalTimeCalculation(empId){

	

	 var totalTime=0 ;



	$.getJSON(serviceURLHR+"listing.php?empID="+empId,function(data){

			timePeriod = data.timePeriod;



			$.each(timePeriod, function(index, timePeriod) {



				diff = (new Date( timePeriod.e_date+ " "+ timePeriod.e_out).getTime() - new Date(timePeriod.e_date + " "+ timePeriod.e_in).getTime())/1000;


				totalTime +=parseFloat(diff); 



			});	

			$('.txt_'+empId).parent().append(rectime(totalTime));

		

	})

		

		

}

 

function rectime(secs) {

	var hr = Math.floor(secs / 3600);

	var min = Math.floor((secs - (hr * 3600))/60);

	var sec = secs - (hr * 3600) - (min * 60);

	

	while (min.length < 2) {min = '0' + min;}

	while (sec.length < 2) {sec = '0' + min;}

	if (hr) hr += ':';

	return hr + min + ':' + sec;

}

/************ Device**********************/

function deviceList(){
	
	$.getJSON(serviceURLHR + "manageDevice.php?act=list",function(data){
		var leaves = data.leaves;
		
		
		
		class_add='addNewdevice';
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:block" cellpadding="0" class="list-leavesu">'+
								  '<tr>'+
											'<td width="15%" colspan="4" align="right" class="'+class_add+'"><img src="images/icon-add.png" class="" width="20" height="20" />Add Device</td>'+
											
										 '</tr>'+
										  '<tr>'+
											'<td width="23%"><translate>Branch Name</translate></td>'+
											'<td width="23%"><translate>Device Id</translate></td>'+
											'<td width="5%"><translate>Edit</translate></td>'+
											'<td width="5%">Delete</td>'+
										 '</tr>'+
										'</table>');	
		
			permissions_user = leaves[leaves.length -1 ].permissions[0].user_id;
			if(permissions_user && permissions_user!=1)
			{
			//permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_edit = leaves[leaves.length -1 ].permissions[0].edit_right;
			permissions_del = leaves[leaves.length -1 ].permissions[0].delete_right;
			permissions_add = leaves[leaves.length -1 ].permissions[0].add_right;
			  if(permissions_edit==1)
	          {  classedit='editdevice';  }else{classedit='editdevice_right';}
              if(permissions_del==1)
	          {  classdel='removedevice';  }else{classdel='removedevice_right';}
			  if(permissions_add==1){ class_add='addNewdevice';}else{class_add='addNewdevice_right';}
			  
			  
            }else
			{
				classedit='editdevice'; 
				classdel='removedevice'; 
				class_add='addNewdevice';
			}
		
		
		
			
			$('.list-leavesu').show('blind',500);
			if(data.leaves==null){
					
					$('.list-leavesu').append( '<tr class="no_rcd">'+
														'<td width="23%" colspan="4"><translate>No records found</translate></td>'+
													 '</tr>');	
			}
			else{
				$.each(leaves, function(index,leaves){
					
					
					
						$('.list-leavesu').append( '<tr class="device_'+leaves.dev_id+'">'+
															'<td width="23%" class="branchName" data-id="'+leaves.branch_id+'">'+leaves.branch_name+'</td>'+
															'<td width="23%" class="deviceId" >'+leaves.device_name+'</td>'+
															'<td width="5%"><img data-id="'+leaves.dev_id+'" src="'+editIconpen+'" class="'+classedit+'"/></td>'+
															'<td width="5%"><img data-id="'+leaves.dev_id+'" src="'+removeIcon+'" class="'+classdel+'"/></td>'+
														 '</tr>');				
				});
			}
		
	});
	
}

function addNewdevice(){ 
  $('.savedevice').attr('disabled',false);
	if($('.newdeviceform').length){
		
	}else{
	$('.list-leavesu').before('<form class="newdeviceform field-style"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newDevice">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Branch</translate></td>'+
									'<td><select name="branch" id="branch"><option selected="selected" value="">---select---</option></select></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Device Id</translate></td>'+
									'<td><input type="text" name="device_name" id="device_name" /></td>'+
								  '</tr>'+
								  

								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button savedevice" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button canceldevice" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	$('.newDevice').show('blind',500);
	loadBranch();
	}
	
}

function savedevice(){	

  
	var branch = $("#branch").val();
	var device_name = $("#device_name").val();
	
	if(branch == ''){
		alert('Branch is required')	;
		$("#branch").focus();
	}else if(device_name == ''){
		alert('Device Id is required')	;
		$("#device_name").focus();
	}else{
		$('.savedevice').attr('disabled',true);
			dataString = $('.newdeviceform').serialize();
			var branch_name = $('#branch option:selected').text();
			$.post( serviceURLHR+ "manageDevice.php?act=insert",dataString,function(data){
				var leaves = data.leaves
				if($('.no_rcd').length){
					$('.no_rcd').remove();
				}
				$('.list-leavesu').append( '<tr>'+
											'<td width="23%" class="branchName" data-id="'+leaves.branch_id+'">'+branch_name+'</td>'+
											'<td width="23%" class="deviceId">'+leaves.device_name+'</td>'+
											'<td width="5%"><img data-id="'+leaves.id+'" src="'+editIconpen+'" class="editdevice"/></td>'+
											'<td width="5%"><img data-id="'+leaves.id+'" src="'+removeIcon+'" class="removedevice"/></td>'+
											'</tr>');	
					$('.newdeviceform').hide('blind',500,function(){ $(this).remove(); });
				
			},'json');
	}
}
function editdevice(){
	
	if($('.newdeviceform').length){
		
	}else{
	$this = $(this);
	var userid 	= $this.attr('data-id');
	
	var name 			= $this.parent().parent().find('.branchName').text();
	var deviceid	    = $this.parent().parent().find('.deviceId').text();
	var branchid 	    = $this.parent().parent().find('.branchName').attr('data-id');

	
	$('.list-leavesu').before('<form class="newdeviceform field-style"><table width="50%" border="0" style="display:none" cellspacing="0" cellpadding="0" class="newLeave">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  
								  '<tr>'+
									'<td><translate>Branch</translate></td>'+
									'<td><select name="branch" id="branch"><option selected="selected" value="">---select---</option></select></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Device Id</translate></td>'+
									'<td><input type="text" name="device_name" id="device_name" value="'+deviceid+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><input type="hidden" name="userid" id="userid" value="'+userid+'" /></td>'+
									'<td><input type="button" name="button" class="color-button Updatedevice" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button canceldevice" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	
	
	$('.newLeave').show('blind',500);
	}
	loadBranch();
	setTimeout(function(){ $('#branch').val(branchid); },500);
}
function updatedevice(){
	
	var branch = $("#branch").val();
	var device_name = $("#device_name").val();
	
	if(branch == ''){
		alert('Branch is required')	;
		$("#branch").focus();
	}else if(device_name == ''){
		alert('Device Id is required')	;
		$("#device_name").focus();
	}else{
	
			dataString = $('.newdeviceform').serialize();
			var branch_name = $('#branch option:selected').text();
		
			var userid	= $('#userid').val();
			
			$.post(serviceURLHR + "manageDevice.php?act=update",dataString,function(data){
				var currentUser = $('.device_'+userid);
				currentUser.find('.branchName').text(branch_name);
				currentUser.find('.deviceId').text(data.device_name);
				
			},"json");
			$('.newdeviceform').hide('blind',500,function(){ $(this).remove(); });
			
			
	}
		
}

function removedevice(){
	
	var checkstr =  confirm('are you sure you want to delete this?');
	if(checkstr == true){
	 var did = $(this).attr('data-id');
		$this = $(this);
		$.get(serviceURLHR + "manageDevice.php?act=remove&did="+did,function(){
			$this.parent().parent().remove();															 
		});
	}else{
	return false;
	}
	
}

/************** device end********************/