var serviceURLHR =localStorage['serviceURLHR']; 

var hosturl    =localStorage['basicURL'];
var serviceURL = serviceURLHR;	

var sr_LocPath = localStorage['loc_paths'];

//----------------------------------------------------------------------------------------------------//Listing
var ids = getUrlVars()["employees"]; 


var muster_url_month = getUrlVars()["muster_month"];
var muster_url_year = getUrlVars()["muster_year"];
var branch_url_id = getUrlVars()["branch_id"];

var attendance_url_month = getUrlVars()["attendance_month"];
var attendance_url_year = getUrlVars()["attendance_year"];
var brah_url_id = getUrlVars()["brah_id"];

jQuery('.approveTimesheet').live('click',changeTimesheetStatus);
//jQuery('.timesheet_approval').live('click',function(){ timesheet_approval('1','') });
/*jQuery('.timesheet_approval').live('click',function(){ timesheet_approval_u('1','') });*/
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

$(function(){
		   
	//getAllMonths();
	//getAllYear();	
	setTimeout(function(){  // This timeout for overwrite multiple function colling in this part.
						
		
		$('#month_muster').getmonths(muster_url_month);
		$('#year_muster').getYears(new Date().getFullYear());
		$('#month').getmonths(new Date().getMonth()+1);
		$('#year').getYears(new Date().getFullYear());
		$('#month_attendance').getmonths(new Date().getMonth()+1);
		$('#year_attendance').getYears(new Date().getFullYear());
	},200);
	
});




var itemCount=0;
var k=1;
var pageLimit = 15;


function removeCurrentPage(){

$('.paymentMethod').remove();
$('#tablelist table').hide('blind',500,function(){ $(this).remove(); })	
}

///////////////////Auto Load Start/////////////////
$('.payroll-menu li').live('click',function(){
	$this = $(this);
	window.location.hash = $this.attr('data-page');
});

$(document).ready(function(){
   	
	//setTimeout(loadBranch,800);
	setTimeout(loadBranchMusteroll,800);
	setTimeout(loadBranchattendance,800);
	locationHashChanged();	
});
			
//jQuery(window).hashchange( locationHashChanged );													
window.onhashchange = locationHashChanged;		 	

hash=window.location.href.split('#')[1]	

function locationHashChanged() {	

	hash=window.location.href.split('#')[1]	



	if(hash){ 
		$('.btn-tab-active').removeClass('btn-tab-active');
		$('.menu-selected').removeClass('menu-selected');			
		//var menuList = $('.payroll-menu');	
		
		if($('li[data-page="'+hash+'"]').length){
			
			//$('#light-pagination').pagination('updateItems',15);
			$('li[data-page="'+hash+'"]').addClass('menu-selected');
		alert(1);
			
			
			setTimeout(window[hash],100); // call current function	
			currentPage =hash; 
			
			
			
			$("#light-pagination").jui_pagination({
				currentPage: 1,
				visiblePageLinks: 5,
				totalPages: 1,
				onChangePage:window[hash],
			});
			
			
		}else{
			go_to_select();
			$('li[data-page="'+currentPage+'"]').addClass('menu-selected'); 

			
			
			if(hash){
				//window.location.hash =	currentPage;currentPage =hash; 
			}
			
			//currentPage =currentPage;
			
		}
	}else{	$(".Emp_timesheet").css("display", "block");
	$(".Muster_roll_Grid").css("display", "none");
	/*					if(hash=='Timesheet_show')
			{
				$('li[data-page="timesheet_edit"]').addClass('menu-selected'); 
			}*/
		//window.location.hash = "timesheet_edit";
		var att_path=sr_LocPath+'timesheet-individual.php';
		
		if(window.location.pathname==att_path)
		{
			window.location.hash = "Timesheet_show";
		}
		else
		{
		window.location.hash = "timesheet_edit";
		}
		
	
	}
}

///////////////////Auto Load End/////////////////




/*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>');
							
		});	
	});
}*/

//loadBranchMusteroll();

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

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




function employeemusteroll_cpy(pagenum){ 
//alert(pagenum);
//alert(ids);

var month=$("#month_muster").val();

var year=$("#year_muster").val();
var employees=$("#employees").val();



//###########################################################################
if(ids && !employees){
	var brach;
	$.getJSON(serviceURLHR + "muster-roll-individual.php?act=getbranch&eid="+ids,function(data){
		branchid = data.emp.branchid;
		
		employeeselectbranch(branchid);
		
		$('#branch').val(branchid);
		
		setTimeout(function(){ $("#employees").val(ids) },5000);
		
	});
	var employees = ids;
}
///####################################################################

//alert(employees);
//var ids = 65;
//$("#Emp_Name").val() = employees;
if(month==null)
month=new Date().getMonth() + 1;if(year==null)year=new Date().getFullYear();
	$.ajax({
   url: serviceURLHR+"muster-roll-individual.php?page="+pagenum+"&month="+month+"&year="+year+"&employees="+employees,
   success: function(data){
	   $("#employeetimesheet" ).html(data);
   }
 });	
//pagination(pagenum);
selmon();
get_name(employees);
}


/*function startcall()
{
	
	selectmonthfn();
	employeetimesheet(1);
	getAllMonths();
	getAllYear();
}
 function getAllMonths(){
	 
            var cur_year=new Date().getFullYear();
            var obj=document.getElementById("year");         
            for (var i = 2013; i <= 2030; i++)     {                
                opt = document.createElement("option");
                opt.value = i;
                opt.text=i;
                obj.appendChild(opt);
            }
            document.getElementById("year").value = cur_year;
			
			var month1='';
		 	 var cur_mon=new Date().getMonth() + 1;
            var obj=document.getElementById("month");         
            for (var i = 1; i <= 12; i++)     {                
                opt = document.createElement("option");
				if(i<10) i='0'+i;	
				//-------------------------------------//
				if(i==1)month1='January';if(i==2)month1='February';;if(i==3)month1='March';if(i==4)month1='April';if(i==5)month1='May';
if(i==6)month1='Jun';if(i==7)month1='July';;if(i==8)month1='August';if(i==9)month1='September';if(i==10)month1='October';
if(i==11)month1='November';if(i==12)month1='December';
				//---------------------------------------//
                opt.value = i;
                opt.text=month1;
                obj.appendChild(opt);
            }
        document.getElementById("month").value = cur_mon;
         
 }
 
 
 function getAllYear()
 {
	 
            var cur_year=new Date().getFullYear();
            var obj=document.getElementById("year_muster");         
            for (var i = 2013; i <= 2030; i++)     {                
                opt = document.createElement("option");
                opt.value = i;
                opt.text=i;
                obj.appendChild(opt);
            }
            document.getElementById("year_muster").value = cur_year;
			
			var month1='';
		 	 var cur_mon=new Date().getMonth() + 1;
            var obj=document.getElementById("month_muster");         
            for (var i = 1; i <= 12; i++)     {                
                opt = document.createElement("option");
				if(i<10) i='0'+i;	
				//-------------------------------------//
				if(i==1)month1='January';if(i==2)month1='February';;if(i==3)month1='March';if(i==4)month1='April';if(i==5)month1='May';
if(i==6)month1='Jun';if(i==7)month1='July';;if(i==8)month1='August';if(i==9)month1='September';if(i==10)month1='October';
if(i==11)month1='November';if(i==12)month1='December';
				//---------------------------------------//
                opt.value = i;
                opt.text=month1;
                obj.appendChild(opt);
            }
        document.getElementById("month_muster").value = cur_mon;
        	 
 }
*/


jQuery('.searchtimeviewsearch').live('click',function(e){  timesheet_view('1','');e.preventdefault(); });
jQuery('.searchtimeapproval').live('click',function(e){  timesheet_approval('1','');e.preventdefault(); });

function employeemusteroll(pagenum){
	
	var serviceURL =localStorage['serviceURL'];	
	var month=$("#month_muster").val();
	var year=$("#year_muster").val();
	var branch=$("#branch_muster").val();
	
	window.location.href = serviceURL+"timesheet-individual.php?muster_month="+month+"&muster_year="+year+"&branch_id="+branch+"#Muster_Roll_show",

	  $("html").removeAttr('style');
	  $(".employee-tabcells").css("display", "none"); 
	  $(".Emp_timesheet").css("display", "none");

   /*$.ajax({
   url: serviceURL+"timesheet-individual.php?muster_month="+month+"&muster_year="+year+"&branch_id="+branch+"#Muster_Roll_show",
   success: function(data){
	 //alert("test");  
	  document.write(data);
	 // setTimeout(startcall,200);
	  $("html").removeAttr('style');
	  $(".employee-tabcells").css("display", "none"); 
	  $(".Emp_timesheet").css("display", "none");
   }
 });*/	

//window.location.href = "timesheet-individual.php?muster_month="+month+"&muster_year="+year+"&branch_id="+branch+"#Muster_Roll_show";
}


function employeeattendanceroll(pagenum){
	
	var serviceURL = localStorage['serviceURL'];	
	var month=$("#month_attendance").val();
	var year=$("#year_attendance").val();
	var branch=$("#branch_attendance").val();

	location.href=serviceURL+"timesheet-employees-attendance.php?attendance_month="+month+"&attendance_year="+year+"&brah_id="+branch+"#Attendance_show";
  /* $.ajax({
   url: serviceURL+"timesheet-employees-attendance.php?muster_month="+month+"&muster_year="+year+"&branch_id="+branch+"#Attendance_show",
   success: function(data){
	 //alert("test");  
	  document.write(data);
	  
	  $("html").removeAttr('style');
	  $(".employee-tabcells").css("display", "none"); 
	  $(".Emp_timesheet").css("display", "none");
   }
 });	*/

//window.location.href = "timesheet-individual.php?muster_month="+month+"&muster_year="+year+"&branch_id="+branch+"#Muster_Roll_show";
}



function employeeselectbranch(id){
	//alert(id);
	$('#employees').css("display","block");
	$.ajax({
   url: serviceURLHR+"dropdownvalueemployee.php?branchid="+id,
   dataType:"json",
   success: function(data){
	   
	   var employees = data.employees; 
	   $("#employees").html('');
	   $.each(employees,function(index,employees){
     	$("#employees").append('<option value="'+employees.e_id+'">'+employees.e_fname+'</option>');
	 })
	   setTimeout(function(){ get_name(employees); },500);	
	 
	 
   }
 });	
}




employeetimesheet(1);

function employeetimesheet(pagenum){ 


var month=$("#month").val();

var year=$("#year").val();
var employees=$("#employees").val();
var branch = $('#branch').val();


//###########################################################################
if(ids && !employees){
	
	var brach;
	$.getJSON(serviceURLHR + "timesheet-individual.php?act=getbranch&eid="+ids,function(data){
		branchid = data.emp.branchid;
		
		employeeselectbranch(branchid);
		
		//$('#branch').val(branchid);
		
		setTimeout(function(){ $("#employees").val(ids) },500);
		setTimeout(function(){ $("#branch").val(branchid) },5000);
	});
	var employees = ids;
}

///####################################################################

//alert(employees);
//var ids = 65;
//$("#Emp_Name").val() = employees;
if(month==null)
month=new Date().getMonth() + 1;if(year==null)year=new Date().getFullYear();//alert(employees);

if(branch==""){
	alert("Please select branch.");
}
else {
	
var idd=$("#u_ids").val();
if(idd==1)
{
	var employees=employees;
}
else
{
	var employees=idd;
}


	$.ajax({
	   url: serviceURLHR+"manageEmployees.php?action=joindate&month="+month+"&year="+year+"&employees="+employees,
	   success: function(data){
		   
		  if(data == ""){
			  document.getElementById("downs").style.visibility="hidden";
			  $(".employee-tabcells").html('There is no data.');
		  }else { 
		   document.getElementById("downs").style.visibility="visible";
			  	$.ajax({
				   url: serviceURLHR+"timesheet-individual.php?page="+pagenum+"&month="+month+"&year="+year+"&employees="+employees,
				   success: function(data){
					   $("#employeetimesheet" ).html(data);
				   }
			  });
		  }
	   }
   });	
}
pagination(pagenum);
selmon();
//setTimeout(function(){ get_name(employees) },500);
get_name(employees);
}


function get_name(id){

 $.ajax({
		
   url: serviceURLHR+"getnames.php?action=load&employees="+id,
   dataType:"json",
   success: function(data){
	   emp_name=data.emp_name;
	 
	   
	   $.each(emp_name,function(index,emp_name){
								
	    $("#Emp_Name" ).html(emp_name.e_fname+" ");
		})
	 
   }
 });
 //$("#Emp_Name").html(data);
}


function  pagination(pagenum)
{
var month=$("#month").val();
var year=$("#year").val();
var employees=$("#employees").val();


//var employees=65;
if(month==null)month=new Date().getMonth() + 1;if(year==null)year=new Date().getFullYear();
$.ajax({
   url: serviceURLHR+"timesheet-individualspagination.php?page="+pagenum+"&month="+month+"&year="+year+"&employees="+employees,
   success: function(data){
          $("#pagediv" ).html(data);
	 
   }
 });	
}
function gonextpage(page)
{ 
	CutlaryList(page);
}

function dropdownval(num,ing)
{
	$.ajax({
   url: serviceURLHR+"dropdownvalue.php?table=employee&field1=e_fname&field2=e_id&ingvalue="+ing,
   success: function(data){
     $("#employees").append(data);
   }
 });	
}

function Timesheet_show(){
	
	
	var userid=$('.userid').val();
	//$(".Emp_timesheet").css("display", "block");	
	$(".Muster_roll_Grid").css("display", "none");		
	$(".Emp_timesheet").css("display", "block");	
	$(".musteroll").css("display", "none");	
	var hiddenuser_type = $('#hiddenuser_type').val();
	hash=window.location.href.split('#')[1]	;
	
	if(hash=='Timesheet_show')
	{
		var ids='';
	}
	if(hiddenuser_type != 'Subadmin' && ids=='' )
	{
	
		window.location="timesheet-individual.php#Timesheet_show";
	
		
	}
	
	if(hiddenuser_type == 'Subadmin' && ids!='' )
	{
		window.location="timesheet-individual.php?employees="+userid+"#Timesheet_show";
	}
	removeCurrentPage();
	
}

function Muster_Roll_show(){
	$(".Emp_timesheet").css("display", "none");	
	$(".Muster_roll_Grid").css("display", "block");	
	$(".musteroll").css("display", "block");	
	if(!muster_url_year && !muster_url_month && !branch_url_id )
	{window.location="timesheet-individual.php#Muster_Roll_show";}
	if(branch_url_id)
	{
		
		var brnchsplt=branch_url_id.split("#");
		
		setTimeout(function(){$('#branch_muster').val(brnchsplt[0]) },5000);
	}
	if(muster_url_year)
	{
		
		$('#year_muster').val(muster_url_year);
	}
	if(muster_url_month)
	{
		
		$('#month_attendance').val(muster_url_month);
	}
	removeCurrentPage();
}

function Attendance_show(){
	
	
	//window.location="timesheet-employees-attendance.php#Attendance_show";
	if(!attendance_url_month && !attendance_url_year && !brah_url_id )
	{
	window.location="timesheet-employees-attendance.php#Attendance_show";

	}
	if(brah_url_id)
	{
		
		var brnchsplit=brah_url_id.split("#");
		setTimeout(function(){$('#branch_attendance').val(brnchsplit[0]) },5000);
		
	}
	
	if(attendance_url_year)
	{
		
		$('#year_attendance').val(attendance_url_year);
	}
	
	
	if(attendance_url_month)
	{
		setTimeout(function(){$('#month_attendance').val(attendance_url_month) },500);
		
	}
}

function Timesheetshow(){
	
	var hiddenuser_type = $('#hiddenuser_type').val();
	
	if(hiddenuser_type != 'Subadmin'  && ids=='')
	{
		window.location="timesheet-individual.php#Timesheet_show";
	}
}

function MusterRollshow(){
	window.location="timesheet-individual.php#Muster_Roll_show";
}
function leaveRequests(){
	window.location="leave-request.php#leaveRequests";
}
function personalleave(){
	window.location="leave-request.php#personalleave";
}
function addNewpersonalLeaveRequest(){
	window.location="leave-request.php#addNewpersonalLeaveRequest";
}
function timesheet_edit(){
	
	if($('.adjust-timesheet').length){
		$('.edit_time').show();
		$('.list-timesheetapproval').hide();
		$('.report-cell-03').hide();
		$('#light-pagination').hide();
	}else{
		window.location="timesheet-adjustable-form.php#timesheet_edit";
	}
	
	//location.reload();
}



/*function Timesheet_show(){
	window.location="timesheet-individual.php#Timesheet_show";
}*/




function  download(pagenum)
{
	
		//var empid = $('#employees').val();
	
	var bnch=$("#branch").val();
	
	var empid = $('#employees').val();
	
	if(bnch !='')
	{
	window.location = serviceURLHR+"downloadtimesheet.php?employees="+empid;
	}
	else
	{
		alert('Please Select Branch');
	}
/*	alert(pagenum);
	$.ajax({
			type: "POST",
			url:serviceURLHR+"download.php",
			data: 'pagenum='+pagenum,
			success:function(msg){ 
			//$("#subject_div").html(msg);alert()
			//alert(msg);
				window.open('data:application/vnd.ms-excel,' + $('#dvData').html(msg));		
					}
			});*/
}

function  download_muster_roll(pagenum)
{
	var empid = $('#employees').val();
	
	var month=$("#month_muster").val();

var year=$("#year_muster").val();
var branch=$("#branch_muster").val();

//window.location.href = "timesheet-individual.php?muster_month="+month+"&muster_year="+year+"&branch_id="+branch+"#Muster_Roll_show";
	window.location = serviceURLHR+"downloadmusteroll.php?muster_month="+month+"&muster_year="+year+"&branch_id="+branch;
/*	alert(pagenum);
	$.ajax({
			type: "POST",
			url:serviceURLHR+"download.php",
			data: 'pagenum='+pagenum,
			success:function(msg){ 
			//$("#subject_div").html(msg);alert()
			//alert(msg);
				window.open('data:application/vnd.ms-excel,' + $('#dvData').html(msg));		
					}
			});*/
}
function curselmon()
{
	 var year=new Date().getFullYear();
	  var month=new Date().getMonth() + 1;
	  if(month=='01')month1='January';if(month=='02')month1='February';;if(month=='03')month1='March';if(month=='04')month1='April';if(month=='05')month1='May';
if(month=='06')month1='Jun';if(month=='07')month1='July';;if(month=='08')month1='August';if(month=='09')month1='September';if(month=='10')month1='October';
if(month=='11')month1='November';if(month=='12')month1='December';
var data=month1 +' '+ year;
 $("#selmonth").html(data);

}
function selmon(){
var month1='';
var month=$("#month").val();
var year=$("#year").val();	
if(month==null)month=new Date().getMonth() + 1;if(year==null)year=new Date().getFullYear();

if(month.length==1){month='0'+month;}
if(month=='01')month1='January';if(month=='02')month1='February';;if(month=='03')month1='March';if(month=='04')month1='April';if(month=='05')month1='May';
if(month=='06')month1='Jun';if(month=='07')month1='July';;if(month=='08')month1='August';if(month=='09')month1='September';if(month=='10')month1='October';
if(month=='11')month1='November';if(month=='12')month1='December';
var data=month1 +' '+ year;
 $("#selmonth").html(data);
}
//selectmonthfn();
//selectmonthattfn();
function selectmonthfn()
{ 

var obj=document.getElementById("month");  
 opt = document.createElement("option");
                opt.appendChild(document.createTextNode(value));
                opt.selected = selected;
                opt.value = '01';
                opt.text='January';
                obj.appendChild(opt);
}

function selectmonthattfn()
{ 

var obj=document.getElementById("month_attendance");  
 opt = document.createElement("option");
                opt.appendChild(document.createTextNode(value));
                opt.selected = selected;
                opt.value = '01';
                opt.text='January';
                obj.appendChild(opt);
}

function fun_TimesheetPage() {
	var recdate = $('#recdate').val();
	var empid = $('#empid').val();
	var recdate = $('#recdate').val();
	var timepicker_in = $("input[name='timepicker_in']").val();
	var timepicker_out =$("input[name='timepicker_out']").val();
	if(recdate == ''){
		alert ('Date is required')	;
	}else if(empid == ''){
		alert ('Employee Name is required')	;
	}else if(timepicker_in == '' && timepicker_out == ''){
		alert ('Time In or Time Out is required')	;
	}else{
		insert_funtimesheet();
	}
}

function insert_funtimesheet(){
	var formData = $('#frm1').serialize(); //alert(formDatas);
	$('#busy').show();
	//var formData = new FormData($('form')[1]);
	//alert(formData);
	//alert(serviceURLHR);
	//alert(formData);
    $.ajax({
        url: serviceURLHR + 'timesheet_approval_insert.php',  //Server script to process data
        type: 'POST',
        data: formData,
		success: function(data){ 
				$('#busy').hide();
				 $('#frm1').find('input').val('');
				 $('#frm1').find('select').val('');
				//if(data=='success'){
				alert("Request successfully Updated.");
				var hiddenuser_type = $('#hiddenuser_type').val();
				if(hiddenuser_type=='Superadmin')
				window.location="timesheet-adjustable-form.php#timesheet_approval";
				else
				window.location="timesheet-adjustable-form.php#timesheet_view";
			//}
		}
	});	
}

function timesheet_approval(e,pageno){
 $(".report-cell-03").css("display", "block");
 $('#light-pagination').show();
 $('.employee-title').find('h2').text('Approve Attendance');
if(!pageno)
	pageno =1;
	
	if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		
	 var tot = 0;
	/*$(".edit_time").css("display", "none");*/
	//$(".Muster_roll_Grid").css("display", "none");
	$(".edit_time").css("display", "none");
	$(".list-timesheetapproval").css("display", "block");
	
	//var userid=$('.userid').val();var user_name=$('.user_name').val();
	var hiddenuser_type=$('#hiddenuser_type').val();
	var userid=$('.userid').val();
		var searchString = $('.pdtSearchForm').serialize(); 
	$(".searchtimeviewsearch").css("display", "none");
	$(".searchtimeapproval").css("display", "block");
	$('#tablelist').html(''); 
	//var lastPage;
removeCurrentPage();
	$('#tablelist').append('<table width="100%" border="0" cellspacing="0"  cellpadding="0" class="list-leaves list-timesheetapproval">'+
										  '<tr>'+
											'<td width="15%"><translate>Sl No</translate></td>'+
											'<td width="15%"><translate>Employee</translate></td>'+
											'<td width="15%"><translate>Date</translate></td>'+
											'<td width="15%"><translate>TimeIn</translate></td>'+
											'<td width="10%"><translate>TimeOut</translate></td>'+
											'<td width="10%"><translate>Reason</translate></td>'+
											'<td width="14%"><translate>Imm.Supervisor</translate></td>'+
											
										 '</tr>'+
										'</table>')	;
	
		
	$.getJSON(serviceURLHR + "manageLeaves.php?act=loadTimesheetApproval&employee_id="+userid+"&"+searchString+"&page="+pageno,function(data){
		var leaves = data.gettimeapproval;
		//alert(data);
		
		$.each(leaves,function(index,leaves){ 
		
		if(hiddenuser_type=='Superadmin')
		{
		if(leaves.is_blocked == 1)
		{
			viewstatus ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1" requestid="'+leaves.apprv_id+'"  title="Pending" class="approvedTimesheet" width="20" height="20" />';
			
		}else{			
			viewstatus ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0" requestid="'+leaves.apprv_id+'"  title="Approved" class="approvedTimesheet" width="20" height="20" />';
			
		}	
		}
		else
		{
		if(leaves.is_blocked == 1)
		{
			viewstatus ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1" requestid="'+leaves.apprv_id+'"  title="Pending" class="approveTimesheet" width="20" height="20" />';
			
		}else{			
			viewstatus ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0" requestid="'+leaves.apprv_id+'"  title="Approved" class="approveTimesheet" width="20" height="20" />';
			
		}	
		}
							   
	
		var leavedetails='<tr>'+
												
												'<td width="15%">'+k+'</td>'+
												'<td width="15%">'+leaves.e_fname+'</td>'+
												'<td width="15%">'+moment(leaves.edate).format('DD-MM-YYYY')+'</td>'+
												'<td width="15%">'+leaves.ein+'</td>'+
												'<td width="28%">'+leaves.eout+'</td>'+
												'<td width="28%">'+leaves.reason_desc+'</td>'+
												'<td width="6%">'+viewstatus+'</td>'+
												'</tr>';
	
				$('.list-timesheetapproval').append(leavedetails);	
				itemCount =leaves.totalrows;
				lastPage  = leaves.lastPage;
				
				k++;
			});
		
		
		//alert(itemCount);
		/*	$('.list-leaverequests').show('blind',500,
				function(){ $('#light-pagination').pagination('updateItems',itemCount);
			});
			*/
			//alert(lastPage);
			$("#light-pagination").jui_pagination({
				totalPages: lastPage
			});
			
	});
	
	
	
	
}

function changeTimesheetStatus(){
	
		var $this = $(this);
		var newStatus	 = $this.attr('data-status');
		var requestid	= $this.attr('requestid');
		
		$.get(serviceURLHR + "manageLeaves.php?act=changeTimeStatus&reqid="+requestid+"&set="+newStatus,function(){
				
				if(newStatus == 1){
					$this.attr({'src':'images/1388406658_ok-green.png','title':'Approved','data-status':'0'});
				}else{
					$this.attr({'src':'images/1388407735_delete_64.png','title':'Pending','data-status':'1'});
				}
				
				
				
		});
		
	
}

function timesheet_view(e,pageno){
	 $(".report-cell-03").css("display", "block");
		if(!pageno)
	pageno =1;
	if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
	$(".edit_time").css("display", "none");
	var userid=$('.userid').val();
	//$(".Muster_roll_Grid").css("display", "none");
	$(".list-timesheetapproval").css("display", "none");
	$(".list-timesheetview").css("display", "block");
	/*$(".designation").css("display", "block");
	$(".branch").css("display", "block");
	$(".imdatesupervisor").css("display", "block");
	var userid=$('.userid').val();
	var depart_id=$('.depart_id').val();
	$('.header').show('blind',500);
	removeCurrentPage();*/
	//var userid=$('.userid').val();var user_name=$('.user_name').val();var depart_id=$('.depart_id').val();
	
	$(".searchtimeviewsearch").css("display", "block");
	$(".searchtimeapproval").css("display", "none");
	var searchString = $('.pdtSearchForm').serialize(); 

var lastPage;
removeCurrentPage();
	$('#tablelist').append('<table width="100%" border="0" cellspacing="0"  cellpadding="0" class="list-leaves list-timesheetview">'+
										  '<tr>'+
											'<td width="15%"><translate>Sl No</translate></td>'+
											'<td width="15%"><translate>Employee</translate></td>'+
											'<td width="15%"><translate>Date</translate></td>'+
											'<td width="15%"><translate>TimeIn</translate></td>'+
											'<td width="10%"><translate>TimeOut</translate></td>'+
											'<td width="10%"><translate>Reason</translate></td>'+
											'<td width="14%"><translate>Imm.Supervisor</translate></td>'+
											
										 '</tr>'+
										'</table>')	;
	var k=1;

	$.getJSON(serviceURLHR + "manageLeaves.php?act=loadTimesheetview&employee_id="+userid+"&"+searchString,function(data){
		var leaves = data.gettimeapproval;
		

		
		
		$.each(leaves,function(index,leaves){
			
				
				if(leaves.is_blocked == 0)
		{
			viewstatus ='<img src="images/1388406658_ok-green.png" style="cursor:pointer" data-status="0" requestid="'+leaves.id+'"  title="Approved" width="20" height="20" />';
			
		}else{
			viewstatus ='<img src="images/1388407735_delete_64.png" style="cursor:pointer" data-status="1" requestid="'+leaves.id+'"  title="Pending" width="20" height="20" />';
			
		}
		
		if(leaves.e_fname)
		{
	
		var leavedetails='<tr>'+
												
												'<td width="15%">'+k+'</td>'+
												'<td width="15%">'+leaves.e_fname+'</td>'+
												'<td width="15%">'+moment(leaves.edate).format('DD-MM-YYYY')+'</td>'+
												'<td width="15%">'+leaves.ein+'</td>'+
												'<td width="28%">'+leaves.eout+'</td>'+
												'<td width="28%">'+leaves.reason_desc+'</td>'+
												'<td width="6%">'+viewstatus+'</td>'+
												'</tr>';
	
				$('.list-timesheetview').append(leavedetails);	
		
				itemCount =leaves.totalrows;
				lastPage  = leaves.lastPage;
		}		
				k++;
			});
		
		
		//alert(itemCount);
		/*	$('.list-leaverequests').show('blind',500,
				function(){ $('#light-pagination').pagination('updateItems',itemCount);
			});
			*/
			
			$("#light-pagination").jui_pagination({
				totalPages: lastPage,
			});
			
	});
	
	
	
	
}
jQuery.fn.getmonths = function setAllMunths(paymentmonth){
	
	$this = this;
	var currentMonth =paymentmonth;
	$this.html(''); 

var months = ["January", "February", "March", "April", "May", "June",
                  "July", "August", "September", "October", "November", "December"];

	$.each(months,function(index,months){
		if( (parseInt(index)+1) == currentMonth){
			$this.append('<option selected="selected" value="'+ (parseInt(index)+1) +'">'+months+'</option>');	
		}else{
			$this.append('<option value="'+ (parseInt(index)+1) +'">'+months+'</option>');	
		}
		
	});


}

////////////////////////////// Year list //////////////////////////////
jQuery.fn.getYears = function setAllYears(paymentyear){
	$this = this;
	var currentYear =paymentyear; 
	$this.html('');


    var dt = new Date();
	var thisyear =dt.getFullYear(); 
	
	for ( i = 2013; i < (parseInt(thisyear)+1); i ++ ) {  
		if( i == currentYear){
			$this.append('<option selected="selected" value="'+ i +'">'+i+'</option>');	
		}else{
			$this.append('<option value="'+ i +'">'+i+'</option>');	
		}
	}



}


