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 HRPATH 			=HRPATH+'addHRM1/';
var editIcon = "images/edit.png";
var editIconpen = "images/pen.png";
var removeIcon = "images/delete.png";





jQuery('.stat_emp').live('click',statusemp);
jQuery('.addNewstatus').live('click',addNewstatus);
jQuery('.savestatus').live('click',savestatus);
jQuery('.editstatus').live('click',editstatus);
jQuery('.Updatestatus').live('click',Updatestatus);

jQuery('.Cancelstatus').live('click',function(){ $('.newLeave').hide('blind',500);});

jQuery('.removestatus').live('click',removestatus);
jQuery('.empstlist').live('change',changestatus);

jQuery('.user_setings').live('click',userset);//subha

jQuery('.gratuity').live('click',gratuity);
jQuery('.addNewyearsett').live('click',addNewyearsett);
jQuery('.savegratuity').live('click',savegratuity);
jQuery('.editgrtyear').live('click',editgrtyear);
jQuery('.Updategratyear').live('click',Updategratyear);
jQuery('.removegratyr').live('click',removegratyr);

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

jQuery('.editgrtyear_right').live('click',editgrtyear_right);
jQuery('.removegratyr_right').live('click',removegratyr_right);
jQuery('.addNewyearsett_right').live('click',addNewyearsett_right);

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


$(document).ready(function() {
						   
						  var depart_id=$('.depart_id').val(); 
						  if(depart_id == 3)
						   {
							   changeBranch();
						   }
						   });

$(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 "Status Of Employee" : statusemp();break;
		case "User Settings" : userset();break;
		case "GratuityYear" : gratuity();break;		
		
	}
	
	
});

loadempstat();

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

function addNewyearsett_right()
{
alert("Sorry You Don't Have Enough Permission To Add New Gratuity");	
}
function editgrtyear_right()
{
alert("Sorry You Don't Have Enough Permission To Edit Gratuity");	
}
function removegratyr_right()
{
alert("Sorry You Don't Have Enough Permission To Delete Gratuity");	
}
//////////////////rights checking///////////


/*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					
	}														
}*/


$('#prdaddates').live('click',function(){ 
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	//alert();
	});
$('#yr_tos').live('click',function(){ 
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	//alert();
	});


function loadempstat(){
	$.getJSON(serviceURLHR + 'branch.php?action=loadstst',function(data){
		branch = data.branch;	
		$.each(branch, function(index, branch) {							 
							$('.empstlist').append('<option value="'+branch.id+'">'+branch.emply_stat+'</option>');
							
		});	
	});
}

function loadempstat_gt(){
	$.getJSON(serviceURLHR + 'branch.php?action=loadstst',function(data){
		branch = data.branch;	
		$('#empname').append('<option >Select</option>');
		$.each(branch, function(index, branch) {							 
							$('#empname').append('<option value="'+branch.id+'">'+branch.emply_stat+'</option>');
							
		});	
	});
}

function changestatus()
{
	var emp=$('.empstlist').val(); 
	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+"&emp="+emp,
		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;	
				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{
			   		//photo=employeeslist.photo;
						
				        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;">'+employeename+'</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+'"><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');
		  
	});

}
//----------------------------------------start user settings-------------------------

function userset(){ 
 
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	k=1;
	$.getJSON(serviceURLHR + "branch.php?action=userstt",function(data){
		var users = data.users; //alert(users);
		//alert(timing);
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" style="display:none" cellpadding="0" class="list-leavesu">'+
								  '<tr>'+
											'<td width="15%" colspan="6" align="center"><b><translate>PRIVILEGE SETTINGS</translate></b></td>'+'</tr>'+
											
										  '<tr>'+
											'<td width="15%"><translate>Sl Nos</translate></td>'+
											'<td width="15%"><translate>Name</translate></td>'+
											'<td width="10%"><translate>View</translate></td>'+
											'<td width="10%"><translate>Edit</translate></td>'+
											'<td width="10%"><translate>Delete</translate></td>'+
											'<td width="5%"><translate>Update</translate></td>'+
										 '</tr>'+
										'</table>')	

			$.each(users, function(index,users){
				
				
				
					$('.list-leavesu').append( '<tr class="reportime_'+users.e_id+'">'+
														'<td width="15%">'+k+'</td>'+
						'<td width="15%" class="branch_id" data-id="'+users.e_id+'">'+users.e_fname+'</td>'+
						'<td width="5%"><input type="checkbox" name="chkv'+k+'" id="chkv'+k+'" value="1"></td>'+
						'<td width="5%"><input type="checkbox" name="chke'+k+'" id="chke'+k+'" value="1"></td>'+
						'<td width="5%"><input type="checkbox" name="chkd'+k+'" id="chkd'+k+'" value="1"></td>'+
					    '<td width="5%"><img data-id="'+users.e_id+'" src="'+removeIcon+'" class="removestatus"/></td>'+
													 '</tr>');		
					k++;
			});
			$('.list-leavesu').show('blind',500);
		
	});	

}
//----------------------start gratuity------------------------------------------------//

jQuery('.cancelgrat').live('click',function(){ $('.yearsetform').hide('blind',500,function(){ $(this).remove(); }) });

function gratuity(){ 
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	k=1;
	$.getJSON(serviceURLHR + "manageempstatus.php?action=gratuty",function(data){
		var timing = data.timing;
	
			if(timing	!== null){
				permissions_user = timing[timing.length -1 ].permissions[0].user_id;
			}else{
				permissions_user = 1;
			}
			
		//	permissions_user = timing[timing.length -1 ].permissions[0].user_id;
			
			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_edit==1)
	               {  classedit='editgrtyear';  }else{classedit='editgrtyear_right';}
                   if(permissions_del==1)
	               {  classdel='removegratyr';  }else{classdel='removegratyr_right';}
				   if(permissions_add==1)
				    { class_add='addNewyearsett';}else{class_add='addNewyearsett_right';}
            }

			else
			{   classedit='editgrtyear'; 
				class_add='addNewyearsett';
				classdel='removegratyr';
			}

		//alert(timing);
			$('#masterlist').html('<table width="100%" border="0" cellspacing="0" cellpadding="0" class="list-leavesu">'+
								  	  '<tr>'+
											'<td width="15%" colspan="7" align="right" class="'+class_add+'"><img src="images/icon-add.png" class="" width="20" height="20" />Add Gratuity</td>'+
											
										 '</tr>'+
										  '<tr>'+
									/*		'<td width="15%"><translate>Sl Nos</translate></td>'+*/
											'<td width="15%"><translate>Year From</translate></td>'+
										    '<td width="15%"><translate>Year To</translate></td>'+
											'<td width="15%"><translate>Number Of Days</translate></td>'+
											/*'<td width="15%"><translate>Time Period</translate></td>'+*/
											'<td width="10%"><translate>Edit</translate></td>'+
											'<td width="5%">Delete</td>'+
										 '</tr>'+
										'</table>')	

			$.each(timing, function(index,timing){
				if(timing.id){
				if(timing.year_to==6)
				{
					var yearto_val='  Year > 5 ';
				}
				else
				{
					var yearto_val=timing.year_to;
				}
		{var yerss='Year <= 1 And Year';}if(timing.time_period==3){var yerss='Year >= 3 And Year< 5';}if(timing.time_period==5){var yerss=' Year > 5';}
				
					$('.list-leavesu').append( '<tr class="reportime_'+timing.id+'">'+
														/*'<td width="15%">'+k+'</td>'+*/
						'<td width="15%" class="yrfrm" data-id="'+timing.id+'">'+parseInt(timing.year_from)+'</td>'+
						'<td width="15%" class="yrto" data-id="'+timing.id+'">'+yearto_val+'</td>'+
            '<td width="15%" class="numdys" data-id="'+timing.id+'">'+timing.num_days+'<input type="hidden" name="hidstat" id="hidstat" value="'+timing.emp_status+'" ></td>'+
/*			'<td width="15%" class="empst" data-id="'+timing.id+'">'+yerss+'<input type="hidden" name="hidyrp" id="hidyrp" value="'+timing.time_period+'"></td>'+*/
														'<td width="5%"><img data-id="'+timing.id+'" src="'+editIconpen+'" class="'+classedit+'"/></td>'+
														'<td width="5%"><img data-id="'+timing.id+'" src="'+removeIcon+'" class="'+classdel+'"/></td>'+
													 '</tr>');		
					k++;
				}
			});
			$('.list-leavesu').show('blind',500);
		
	});	
}



function addNewyearsett(){
	
	
//	$('#tablelist').html('');
$('#empname').empty();
loadempstat_gt();

	if($('.yearsetform').length){
		
	}else{
	$('.list-leavesu').before('<form class="yearsetform 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>Year From</translate></td>'+
									'<td><select name="yr_frm" id="yr_frm"><option selected="selected">---select Year From---</option><option value="0"> 0 </option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select></td>'+
								  '</tr>'+
								
								  '<tr>'+
									'<td><translate>Year To</translate></td>'+
									'<td><select name="yr_to" id="yr_to"><option selected="selected">---select Year To---</option><option value="0"> 0 </option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">  Year > 5 </option></select></td>'+
								  '</tr>'+								
							
										  '<tr>'+
									'<td><translate>Number Of Days</translate></td>'+
									'<td><input id="numdays" name="numdays" type="text"  class="time" style="width:75px;" /></td>'+
								  '</tr>'+	
								  
                              /*        '<tr>'+
									'<td><translate>Status Of Employee</translate></td>'+
									'<td><select name="empname" id="empname"></select></td>'+
								  '</tr>'+
								  
								       '<tr>'+
									'<td><translate>Time Period</translate></td>'+
									'<td><select name="yearp" id="yearp"><option selected="selected">---select Time Period---</option><option value="1"> Year <= 1 And Year< 3 </option><option value="3"> Year >= 3 And Year< 5 </option><option value="5">  Year > 5 </option></select></td>'+
								  '</tr>'+*/
								  
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button savegratuity" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelgrat" 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 savegratuity(){	

	/*var frmdat=$('#prdaddates').val();
	var todat=$('#yr_tos').val();
	  var a = frmdat;
      var b = todat; 
      var date = new Date(frmdat);
	  


      if (parseFloat(a) < parseFloat(b))
	  {
        var dat=1;  // less than
	  }
      else if (parseFloat(a) == parseFloat(b))
	  {
        var dat=1;   // equal
	  }
      else if (parseFloat(a) > parseFloat(b))
	  {
        var dat=0;  // greater than
	  }
      else
	  {
         var dat=0;   // error
	  }
		
		if(dat == 1)
		{*/
		var yr_frm=$('#yr_frm').val();
		var yr_tos=$('#yr_to').val();
		var nums=$('#numdays').val();
		
		if(yr_frm=='' || yr_frm=='' || nums=='')
		{
			alert("Please Enter All Fields");
		}
		else
		{
		
		
	dataString = $('.yearsetform').serialize(); 
	//var branch_names = $('#branch option:selected').text();
	
$.post( serviceURLHR+ "manageempstatus.php?action=grt_insert",dataString,function(data){
		var timing = data.timing;
		if(timing.year_from!='Already Saved Data')
		{
			
						if(timing.year_to==6)
				{
					var yearto_val='  Year > 5 ';
				}
				else
				{
					var yearto_val=timing.year_to;
				}	
			
			
			
		$('.list-leavesu').append( '<tr class="reportime_'+timing.id+'">'+
														
										'<td width="15%" class="yrfrm">'+ parseInt(timing.year_from)+'</td>'+
										'<td width="15%" class="yrto">'+yearto_val+'</td>'+
				'<td width="15%" class="numdys">'+timing.num_days+'</td>'+
			/*'<td width="15%" class="empst">'+timing.time_period+'<input type="hidden" name="hidyrp" id="hidyrp" value="'+timing.time_period+'" class="yrpss'+timing.id+'"></td>'+*/
					'<td width="5%"><img data-id="'+timing.id+'" src="'+editIconpen+'" class="editgrtyear"/></td>'+
				'<td width="5%"><img data-id="'+timing.id+'" src="'+removeIcon+'" class="removegratyr"/></td>'+
													 '</tr>');
		}
		else
		{
					$('.list-leavesu').append( '<tr class="reportime_'+timing.id+'" >'+
												         '<td width="15%" colspan="6" align="center" style="color:#FF0000;">'+timing.year_from+'</td>'+
														
													 '</tr>');
		}
		
		
			$('.yearsetform').hide('blind',500,function(){ $(this).remove(); });
		
	},'json');
		}
		/*}
		else
		{
			alert("To Date Should Be Greater Than From Date");
		}
*/

}

function editgrtyear(){
	
	$('#empname').empty();
loadempstat_gt();
	//	$('#tablelist').html('');
	if($('.yearsetform').length){
		
	}else{
	$this = $(this);
	var reportid 	= $this.attr('data-id');
	//alert(userid);
	var ids 	= $this.parent().parent().find('.editgrtyear').attr('data-id');
	var yrfrm 	= $this.parent().parent().find('.yrfrm').text(); 
    var yrto 	= $this.parent().parent().find('.yrto').text();
	var nums 	= $this.parent().parent().find('.numdys').text();
/*    var empstat 	= $this.parent().parent().find('#hidstat').val();
	var yrps 	= $this.parent().parent().find('#hidyrp').val();*/
	
	/*if(yrps==1)
		{var yerss='Year <= 1 And Year';}if(yrps==3){var yerss='Year >= 3 And Year< 5';}if(yrps==5){var yerss=' Year > 5';}*/
	
	$('.list-leavesu').before('<form class="yearsetform 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;<input type="hidden" name="reportid" id="reportid" value="'+ids+'" /></td>'+
								  '</tr>'+
					  '<tr>'+
									'<td><translate>Year From</translate></td>'+
									'<td><select name="yr_frm" id="yr_frm"><option selected="selected">---select Year From---</option><option value="0"> 0 </option><option value="1.1">1</option><option value="2.1">2</option><option value="3.1">3</option><option value="4.1">4</option><option value="5.1">5</option></select></td>'+
								  '</tr>'+
								  	  '<tr>'+
									'<td><translate>Year To</translate></td>'+
									'<td><select name="yr_to" id="yr_to"><option selected="selected">---select Year To---</option><option value="0"> 0 </option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">  Year > 5 </option></select></td>'+
								  '</tr>'+	
							
								'<tr>'+
									'<td><translate>Number Of Days</translate></td>'+
									'<td><input id="numdays" name="numdays" type="text"   style="width:75px;" value="'+nums+'" /></td>'+
								  '</tr>'+	
							/*	  								'<tr>'+
									'<td><translate>Status Of Employee</translate></td>'+
									'<td><select name="empname" id="empname"></select></td>'+
								  '</tr>'+	
								  '<tr>'+
									'<td><translate>Time Period</translate></td>'+
									'<td><select name="yearp" id="yearp"><option selected="selected">---select Time Period---</option><option value="1"> Year <= 1 And Year< 3 </option><option value="3"> Year >= 3 And Year< 5 </option><option value="5">  Year > 5 </option></select></td>'+
								  '</tr>'+*/
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button Updategratyear" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelgrat" id="button" value="Cancel" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	if(yrfrm==0)
	{
			$('#yr_frm').val(yrfrm);
	}else
	{
	$('#yr_frm').val(yrfrm+'.1');
	}
	if(isNaN(yrto))
	{
	$('#yr_to').val(6);
	}
	else
	{
		$('#yr_to').val(yrto);
	}
	$('.newLeave').show('blind',500);
	}
	$('#basicExample').timepicker();
	$('#basicExample2').timepicker();
	setTimeout(function(){ $('#empname').val(empstat); },500);
	setTimeout(function(){ $('#yearp').val(yrps); },500);
}

function Updategratyear(){
	

		
	var reportDetails = $('.yearsetform').serialize();
	

	var userid	= $('#reportid').val();
	
	
	/*var frmdat=$('#prdaddates').val();
	var todat=$('#yr_tos').val();
	  var a = frmdat;
      var b = todat; 
      var date = new Date(frmdat);
	  


      if (parseFloat(a) < parseFloat(b))
	  {
        var dat=1;  // less than
	  }
      else if (parseFloat(a) == parseFloat(b))
	  {
        var dat=1;   // equal
	  }
      else if (parseFloat(a) > parseFloat(b))
	  {
        var dat=0;  // greater than
	  }
      else
	  {
         var dat=0;   // error
	  }
	  
	if(dat == 1)
		{*/
	
	$.post(serviceURLHR + "manageempstatus.php?action=update_yr",reportDetails,function(data){
		var timing = data.timing; 
				if(timing.year_to==6)
				{
					var yearto_val='  Year > 5 ';
				}
				else
				{
					var yearto_val=timing.year_to;
				}
													
		var currentUser = $('.reportime_'+userid);
		currentUser.find('.yrfrm').text(parseInt(timing.year_from));
        currentUser.find('.yrto').text(yearto_val);
		currentUser.find('.numdys').text(timing.num_days);
		currentUser.find('.empst').text(yerss);
		//currentUser.find('.empss').text('d');
		//currentUser.find('.empss').val(timing.emp_status);alert();
		//$this.parent().parent().find('#hidstat').val(timing.emp_status);
	 //$('.empss'+userid).val(timing.emp_status); 
	 //alert(timing.emp_status);
		
	},"json");
	$('.yearsetform').hide('blind',500,function(){ $(this).remove(); });

	/*	}
		
		else
		{
			alert("To Date Should Be Greater Than From Date");
		}*/
}




function removegratyr(){
	

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

	
}
//----------------------------------------------start emp status----------------------
//employee status adding section-sgk
function statusemp(){ 
	//$('.header').show('blind',500);
	//removeCurrentPage();alert('ddd');
	k=1;
	$.getJSON(serviceURLHR + "manageempstatus.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%"><translate>Sl Nos</translate></td>'+
											'<td width="15%"><translate>Status</translate></td>'+
											'<td width="10%"><translate>Edit</translate></td>'+
											'<td width="5%"><img src="images/icon-add.png" class="addNewstatus" width="20" height="20" /></td>'+
										 '</tr>'+
										'</table>')	

			$.each(timing, function(index,timing){
				
				
				
					$('.list-leaves').append( '<tr class="reportime_'+timing.id+'">'+
														'<td width="15%">'+k+'</td>'+
														'<td width="15%" class="branch_id" data-id="'+timing.id+'">'+timing.emply_stat+'</td>'+
														'<td width="5%"><img data-id="'+timing.id+'" src="'+editIconpen+'" class="editstatus"/></td>'+
														'<td width="5%"><img data-id="'+timing.id+'" src="'+removeIcon+'" class="removestatus"/></td>'+
													 '</tr>');		
					k++;
			});
			$('.list-leaves').show('blind',500);
		
	});	
}
//employee status adding section-sgk
function addNewstatus(){
//	$('#tablelist').html('');


	if($('.empstatform').length){
		
	}else{
	$('.list-leaves').before('<form class="empstatform 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>Employee Status</translate></td>'+
									'<td><input id="stat" name="stat" type="text"  class="time" style="width:75px;" /></td>'+
								  '</tr>'+
								
								
							
								  

								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button savestatus" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelcompany" id="button" value="Cancel" onclick="remove_emp_status_form()" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
	$('.newLeave').show('blind',500);
	 $('#basicExample').timepicker();
	 $('#basicExample2').timepicker();
	}
	loadBranch();
}

function remove_emp_status_form()
{
	$('.empstatform').remove();
}

function savestatus(){	
	var stat = $('#stat').val();
	if(stat == ''){
		alert('Status is required')	;$('#stat').focus();
	}else{
		dataString = $('.empstatform').serialize(); 
		//var branch_names = $('#branch option:selected').text();
		$.post( serviceURLHR+ "manageempstatus.php?action=insert",dataString,function(data){
			var timing = data.timing
			$('.list-leaves').append( '<tr class="reportime_'+timing.id+'">'+
															'<td width="15%">'+k+'</td>'+
															 '<td width="15%">'+timing.emply_stat+'</td>'+
						'<td width="5%"><img data-id="'+timing.id+'" src="'+editIconpen+'" class="editstatus"/></td>'+
					'<td width="5%"><img data-id="'+timing.id+'" src="'+removeIcon+'" class="removestatus"/></td>'+
														 '</tr>');
				$('.empstatform').hide('blind',500,function(){ $(this).remove(); });
		},'json');
	}
}
function editstatus(){
	
	//	$('#tablelist').html('');
	if($('.empstatform').length){
		
	}else{
	$this = $(this);
	var reportid 	= $this.attr('data-id');
	//alert(userid);
	var name 			= $this.parent().parent().find('.branch_id').attr('data-id');//alert(name);
	var emplystat 	= $this.parent().parent().find('.branch_id').text();

	
	
	$('.list-leaves').before('<form class="empstatform 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;<input type="hidden" name="reportid" id="reportid" value="'+reportid+'" /></td>'+
								  '</tr>'+
								 
								  '<tr>'+
									'<td><translate>Employee Status</translate></td>'+
									'<td><input id="basicExamplef" name="reportime" type="text"   style="width:75px;" value="'+emplystat+'" /></td>'+
								  '</tr>'+
								 
								
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button Updatestatus" id="button" value="Submit" />'+
									'<input type="button" name="button" class="color-button cancelcompany" id="button" value="Cancel" onclick="remove_emp_status_form()" /></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 Updatestatus(){
	
	var status = $('#basicExamplef').val();
	if(status == ''){
		alert('Status is  Required')	;
		$('#basicExamplef').focus();
	}else{
		var reportDetails = $('.empstatform').serialize();
		var departmentname 	= $('#branch option:selected').text();
		var userid	= $('#reportid').val();
		$.post(serviceURLHR + "manageempstatus.php?action=update",reportDetails,function(data){
			var timing = data.timing
			var currentUser = $('.reportime_'+userid);
			currentUser.find('.branch_id').text(timing.emply_stat);
		},"json");
		$('.empstatform').hide('blind',500,function(){ $(this).remove(); });
	}
}

function removestatus(){
	

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

	
}

//----------------------------------------------End emp status----------------------

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





