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";


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);
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('.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('.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 "ReportTime"	:reportTime();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;
	}
});



$('.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 companyManagement = 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"></td>'+
						  '</tr>'+
						  '</table>'+
						  '</form>');
	
		$('.company-management').show('blind',500);
	
		$.getJSON(serviceURLHR + "company-details.php?action=list",function(data){
				$('.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 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('.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 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-leaves').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>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>');
	$('.newLeave').show('blind');
		if(brchalf=="1")
		{
			$('#chk_halfday').prop('checked', true);
		}
	}
	
	
	
}

//branchList();

function branchList(){
//alert(serviceURLHR);
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	$.getJSON(serviceURLHR + "manageBranch.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=""><translate>Branch Name</translate></td>'+
											'<td width=""><translate>Branch Code</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=""><img src="images/icon-add.png" alt="Add New Branch" class="addNewBranch" width="20" height="20" style="max-width: none !important;" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(leaves, function(index,leaves){
					
				
					$('.list-leaves').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="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="editBranch" alt="Edit Branch"/></td>'+													
														'<td width=""><img data-id="'+leaves.branch_id+'" src="'+removeIcon+'" class="removeBranch" alt="Delete Branch" /></td>'+
													 '</tr>');				
			});
			$('.list-leaves').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;
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaves">'+
										  '<tr>'+
											'<td width="23%"><translate>Department Name</translate></td>'+
											'<td width="5%"><translate>Edit</translate></td>'+
											'<td width="5%"><img src="images/icon-add.png" class="addNewDepartment" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(leaves, function(index,leaves){
				
				
				
					$('.list-leaves').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>');				
			});
			$('.list-leaves').show('blind',500);
		
	});	
}

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%"><img src="images/icon-add.png" class="addNewBranch" width="20" height="20" /></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-leaves').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>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);
	}
}

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');	
	}*/
	
	$('.saveBranch').attr('disabled',true);
	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{
		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');		
	}
	
	
}

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-leaves').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-leaves').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(){	
$('.saveDepartment').attr('disabled',true);
	if ($.trim($("#leaveTitle").val()).length != 0) {
	dataString = $('.newDepartmentform').serialize();
	$.post( serviceURLHR+ "manageDepartment.php?act=insert",dataString,function(data){
		var leaves = data.leaves
					
		$('.list-leaves').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; 
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaves">'+
										  '<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%"><img src="images/icon-add.png" class="addNewDesignation" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(leaves, function(index,leaves){
				
					$('.list-leaves').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="editDesignation"/></td>'+
														'<td width="5%"><img data-id="'+leaves.desig_id+'" src="'+removeIcon+'" class="removeDesignation"/><input type="hidden" value="'+leaves.desig_rights+'" name="desigs" id="desigs" class="desigss"></td>'+
													 '</tr>');				
			});
			$('.list-leaves').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-leaves').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-leaves').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-leaves').append( '<tr>'+
			'<td width="23%" colspan="5" align="center" style="color:#FF0000; font-size:18px" >'+leaves.desig_name+'</td>'+
										'</tr>');
			}
			else
			{						
				$('.list-leaves').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(){
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	k=1;
	$.getJSON(serviceURLHR + "manageReportime.php?action=viewtiming",function(data){
		var timing = data.timing;
		
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leaves">'+
										  '<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=""><img src="images/icon-add.png" class="addNewreporttime" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(timing, function(index,timing){
				
				if(index >= 0)
				{
				
					$('.list-leaves').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="editreporttime"/></td>'+
														'<td width=""><img data-id="'+timing.reptime_id+'" src="'+removeIcon+'" class="removereporttime"/></td>'+
													 '</tr>');	
					
				}
				else
				{
							$('.list-leaves').append( '<tr class="reportime_'+timing.reptime_id+'">'+
														'<td width="" colspan="8" align="center">No Result Found</td>'+
								
													 '</tr>');
				}
					
					k++;
			});
			$('.list-leaves').show('blind',500);
		
	});	
}


function addNewreporttime(){
//	$('#tablelist').html('');

$('.savereporttime').attr('disabled',false);
	if($('.newReportimrform').length){
		
	}else{
	$('.list-leaves').before('<form class="newReportimrform 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" style="width:200px;"></select></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Reporting Time</translate></td>'+
									'<td><input id="basicExample" name="reportime" type="text"  class="time" style="width:75px;" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Reporting Late Time</translate></td>'+
									'<td><input id="basicExample2" name="reportlatetime" type="text"  class="time" style="width:75px;" /></td>'+
								  '</tr>'+
								   '<tr>'+
									'<td><translate>Half Day(Hr)</translate></td>'+
									'<td><input type="text" name="halfday" id="halfday" style="width:150px;" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Full Day(Hr)</translate></td>'+
									'<td><input type="text" id="fullday" name="fullday" 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>');
	$('.newLeave').show('blind',500);
	 $('#basicExample').timepicker();
	 $('#basicExample2').timepicker();
	}
	loadBranch();
}

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

function savereporttime(){	
$('.savereporttime').attr('disabled',true);
var branch = $('#branch').val();
var basicExample = $('#basicExample').val();
var basicExample2 = $('#basicExample2').val();
var halfday = $('#halfday').val();
var fullday = $('#fullday').val();

if(branch == ''){
	alert('Branch is Required')	;$('#branch').focus();
}else if(basicExample == ''){
	alert('Reporting Time is Required')	;$('#basicExample').focus();
}else if(basicExample2 == ''){
	alert('Reporting Late Time is Required')	;$('#basicExample2').focus();
}else if(halfday == ''){
	alert('Half Day(Hr) is Required')	;$('#halfday').focus();
}else if(fullday == ''){
	alert('Full Day(Hr) is Required')	;$('#fullday').focus();
}else{

	dataString = $('.newReportimrform').serialize();
	var branch_names = $('#branch option:selected').text();
	$.post( serviceURLHR+ "manageReportime.php?action=insert",dataString,function(data){
		var timing = data.timing;
		$('.list-leaves').append( '<tr class="reportime_'+timing.reptime_id+'">'+
														'<td width="15%">'+k+'</td>'+
														'<td width="15%">'+branch_names+'</td>'+
														'<td width="15%">'+timing.report_time+''+timing.time_in+'</td>'+
														'<td width="15%">'+timing.late_time+''+timing.time_in+'</td>'+
														'<td width="15%">'+timing.half_day+'</td>'+
														'<td width="15%">'+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>');
			$('.newReportimrform').hide('blind',500,function(){ $(this).remove(); });
	},'json');
	
	}
}

function editreporttime(){
	
	//	$('#tablelist').html('');
	if($('.newReportimrform').length){
		
	}else{
	$this = $(this);
	var reportid 	= $this.attr('data-id');
	//alert(userid);
	var name 			= $this.parent().parent().find('.branch_id').attr('data-id');
	var reporttime 	= $this.parent().parent().find('.report_time').text();
	//var subdepartname 	= $this.parent().parent().find('.departSubName').text();
	var latetime 		= $this.parent().parent().find('.late_time').text();
	var halfday 	= $this.parent().parent().find('.half_day').text();
	var fullday 	= $this.parent().parent().find('.full_day').text();
	
	
	$('.list-leaves').before('<form class="newReportimrform 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" style="width:200px;"><option selected="selected" value="">---select---</option></select><input type="hidden" name="reportid" id="reportid" value="'+reportid+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Reporting Time</translate></td>'+
									'<td><input id="basicExample" name="reportime" type="text"  class="time" style="width:75px;" value="'+reporttime+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Reporting Late Tim</translate></td>'+
									'<td><input id="basicExample2" name="reportlatetime" type="text"  class="time" style="width:75px;" value="'+latetime+'" /></td>'+
								  '</tr>'+
								   '<tr>'+
									'<td><translate>Half Day(Hr)</translate></td>'+
									'<td><input type="text" name="halfday" id="halfday" style="width:150px;" value="'+halfday+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Full Day(Hr)</translate></td>'+
									'<td><input type="text" id="fullday" name="fullday" style="width:150px;"  value="'+fullday+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button Updatereporttime" 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>');
	
	
	$('.newLeave').show('blind',500);
	}
	$('#basicExample').timepicker();
	$('#basicExample2').timepicker();
	loadBranch();
	setTimeout(function(){ $('#branch').val(name); },500);
}

function Updatereporttime(){
	
	var branch = $('#branch').val();
	var basicExample = $('#basicExample').val();
	var basicExample2 = $('#basicExample2').val();
	var halfday = $('#halfday').val();
	var fullday = $('#fullday').val();
	
	if(branch == ''){
		alert('Branch is Required')	;$('#branch').focus();
	}else if(basicExample == ''){
		alert('Reporting Time is Required')	;$('#basicExample').focus();
	}else if(basicExample2 == ''){
		alert('Reporting Late Time is Required')	;$('#basicExample2').focus();
	}else if(halfday == ''){
		alert('Half Day(Hr) is Required')	;$('#halfday').focus();
	}else if(fullday == ''){
		alert('Full Day(Hr) is Required')	;$('#fullday').focus();
	}else{
		var reportDetails = $('.newReportimrform').serialize();
		var departmentname 	= $('#branch option:selected').text();
		var userid	= $('#reportid').val();
		$.post(serviceURLHR + "manageReportime.php?action=update",reportDetails,function(data){
			var timing = data.timing
			var currentUser = $('.reportime_'+userid);
			currentUser.find('.branch_id').text(departmentname);
			currentUser.find('.report_time').text(timing.report_time);
			currentUser.find('.late_time').text(timing.late_time);
			currentUser.find('.half_day').text(timing.half_day);
			currentUser.find('.full_day').text(timing.full_day);
		},"json");
		$('.newReportimrform').hide('blind',500,function(){ $(this).remove(); });
	}
}


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----------------------

//--------------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 editcompany(){
//	$('#tablelist').html('');
	if($('.newcompanyform').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');
	
	
	//alert(departnames);
	
	
	$('.list-leaves').before('<form class="newcompanyform 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>Post Name</translate></td>'+
									'<td><input type="text" name="companyname" id="companyname" 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="company_rank" id="company_rank" value="'+rankdepart+'" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button Updatecompany" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelcompany" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	
	
	$('.newLeave').show('blind',500);
	}
	loadDepartment();
	setTimeout(function(){ $('#department_name').val(departmenyid); },500);
}

function Updatecompany(){
	
	if ($.trim($("#companyname").val()).length != 0) {
	if ($.trim($("#department_name").val()) != '') {
		
	var designationDetails = $('.newcompanyform').serialize();
	
	var departmentname 	= $('#department_name option:selected').text();
	
	var userid	= $('#userid').val();
	
	$.post(serviceURLHR + "companyUpdate.php?act=update",designationDetails,function(data){
		var currentUser = $('.company_'+userid);
		currentUser.find('.desgName').text(data.post_name);
		currentUser.find('.departName').text(departmentname);
		//currentUser.find('.departSubName').text(data.depart_sub_name);
		currentUser.find('.departRank').text(data.comp_rank);
		
	},"json");
	$('.newcompanyform').hide('blind',500,function(){ $(this).remove(); });
	}else
	{
		alert('Please Select Department');	
	}
}else
	{
		alert('Please Enter Post');	
	}
}

function addNewcompany(){
//	$('#tablelist').html('');
	if($('.newcompanyform').length){
		
	}else{
	$('.list-leaves').before('<form class="newcompanyform 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>Post Name</translate></td>'+
									'<td><input type="text" name="companyname" id="companyname" /></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="company_rank" id="company_rank" /></td>'+
								  '</tr>'+
								  

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

function savecompany(){	
if ($.trim($("#companyname").val()).length != 0) {
	if ($.trim($("#department_name").val()) != '') {
	dataString = $('.newcompanyform').serialize();
	var depart_name = $('#department_name option:selected').text();
	$.post( serviceURLHR+ "manageCompany.php?act=insert",dataString,function(data){
		var leaves = data.leaves
					
		$('.list-leaves').append( '<tr>'+
									'<td width="23%">'+leaves.post_name+'</td>'+
									'<td width="23%">'+depart_name+'</td>'+
									'<td width="23%">'+leaves.comp_rank+'</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>');	
			$('.newcompanyform').hide('blind',500,function(){ $(this).remove(); });
		
	},'json');
	}
	else
	{
		alert('Please Select Department');	
	}
}else
	{
		alert('Please Enter Post');	
	}
}

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 + "manageCompany.php?act=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;
			$('#masterlist').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>Device Id</translate></td>'+
											'<td width="5%"><translate>Edit</translate></td>'+
											'<td width="5%"><img src="images/icon-add.png" class="addNewdevice" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>');	
			
			$('.list-leaves').show('blind',500);
			if(data.leaves==null){
					
					$('.list-leaves').append( '<tr class="no_rcd">'+
														'<td width="23%" colspan="4"><translate>No records found</translate></td>'+
													 '</tr>');	
			}
			else{
				$.each(leaves, function(index,leaves){
					
					
					
						$('.list-leaves').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="editdevice"/></td>'+
															'<td width="5%"><img data-id="'+leaves.dev_id+'" src="'+removeIcon+'" class="removedevice"/></td>'+
														 '</tr>');				
				});
			}
		
	});
	
}

function addNewdevice(){ 
  $('.savedevice').attr('disabled',false);
	if($('.newdeviceform').length){
		
	}else{
	$('.list-leaves').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(){	

  $('.savedevice').attr('disabled',true);
	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();
			$.post( serviceURLHR+ "manageDevice.php?act=insert",dataString,function(data){
				var leaves = data.leaves
				if($('.no_rcd').length){
					$('.no_rcd').remove();
				}
				$('.list-leaves').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-leaves').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********************/