 
function hideDetails(str,i)
{

	if(str=='A')	
	{
		document.getElementById("card_no_"+i).disabled=true;
		document.getElementById("shift_start_"+i).disabled=true;
		document.getElementById("shift_end_"+i).disabled=true;
		document.getElementById("time_in_"+i).disabled=true;
		document.getElementById("time_out_"+i).disabled=true;
		document.getElementById("work_hrs_"+i).disabled=true;
		document.getElementById("ot_hrs_"+i).disabled=true;
		document.getElementById("leave_code_"+i).disabled=true;
//		document.getElementById("other_official_tour_"+i).disabled=true;
		
	}
	else if(str=='L')
	{
		document.getElementById("card_no_"+i).disabled=true;
		document.getElementById("shift_start_"+i).disabled=true;
		document.getElementById("shift_end_"+i).disabled=true;
		document.getElementById("time_in_"+i).disabled=true;
		document.getElementById("time_out_"+i).disabled=true;
		document.getElementById("work_hrs_"+i).disabled=true;
		document.getElementById("ot_hrs_"+i).disabled=true;
		document.getElementById("leave_code_"+i).disabled=false;
//		document.getElementById("other_official_tour_"+i).disabled=true;
		
	}
	else if(str=='P')
	{
		document.getElementById("card_no_"+i).disabled=false;
		document.getElementById("shift_start_"+i).disabled=false;
		document.getElementById("shift_end_"+i).disabled=false;
		document.getElementById("time_in_"+i).disabled=false;
		document.getElementById("time_out_"+i).disabled=false;
		document.getElementById("work_hrs_"+i).disabled=false;
		document.getElementById("ot_hrs_"+i).disabled=false;
		document.getElementById("leave_code_"+i).disabled=true;
//		document.getElementById("other_official_tour_"+i).disabled=true;
		
	}
	else if(str=='official_tour')
	{
		document.getElementById("card_no_"+i).disabled=true;
		document.getElementById("shift_start_"+i).disabled=true;
		document.getElementById("shift_end_"+i).disabled=true;
		document.getElementById("time_in_"+i).disabled=true;
		document.getElementById("time_out_"+i).disabled=true;
		document.getElementById("work_hrs_"+i).disabled=true;
		document.getElementById("ot_hrs_"+i).disabled=true;
		document.getElementById("leave_code_"+i).disabled=true;
//		document.getElementById("other_official_tour_"+i).disabled=false;
		
	}
	else
	{
		document.getElementById("card_no_"+i).disabled=false;
		document.getElementById("shift_start_"+i).disabled=false;
		document.getElementById("shift_end_"+i).disabled=false;
		document.getElementById("time_in_"+i).disabled=false;
		document.getElementById("time_out_"+i).disabled=false;
		document.getElementById("work_hrs_"+i).disabled=false;
		document.getElementById("ot_hrs_"+i).disabled=false;
		document.getElementById("leave_code_"+i).disabled=false;
//		document.getElementById("other_official_tour_"+i).disabled=true;
		
	}
}


var secondsPerMinute = 60;
var minutesPerHour = 60;

function convertSecondsToHHMMSS(intSecondsToConvert) {
var hours = convertHours(intSecondsToConvert);
var minutes = getRemainingMinutes(intSecondsToConvert);
minutes = (minutes == 60) ? "00" : minutes;
//var seconds = getRemainingSeconds(intSecondsToConvert);
return hours+":"+minutes;
}

function convertHours(intSeconds) {
var minutes = convertMinutes(intSeconds);
var hours = Math.floor(minutes/minutesPerHour);
return hours;
}
function convertMinutes(intSeconds) {
return Math.floor(intSeconds/secondsPerMinute);
}
function getRemainingSeconds(intTotalSeconds) {
return (intTotalSeconds%secondsPerMinute);
}
function getRemainingMinutes(intSeconds) {
var intTotalMinutes = convertMinutes(intSeconds);
return (intTotalMinutes%minutesPerHour);
}

function HMStoSec1(T) { // h:m:s
  var A = T.split(/\D+/) ; return (A[0]*60 + +A[1])*60 +  0 }
  
  
function calculate_OverTime(i)
{
var working=document.getElementById("work_hrs_"+i).value;
var office_work_hrs=document.getElementById("officework_hrs_"+i).value;
//var late_arrival=document.getElementById("late_arrival_"+i).value;
var time1 = HMStoSec1(working);
var time2 = HMStoSec1(office_work_hrs);
if(time1>time2)
{
	var diff = time1 - time2
	var  OTHOUR=convertSecondsToHHMMSS(diff);
	document.getElementById("ot_hrs_"+i).value=OTHOUR;
	}else
	{
	document.getElementById("ot_hrs_"+i).value=0;
	}
  
//******************************************

}

function calculate_late_arrival(i)
{
 	var InTime=document.getElementById("time_in_"+i).value;
 	var InTimeBrk=InTime.split(':');
	var InTime_hour=InTimeBrk[0];
	var InTime_min=InTimeBrk[1];
  	var InTime_AMPM=document.getElementById("timein_AMPM_"+i).value;

 	var shiftTime=document.getElementById("shift_start_"+i).value;
 	var shiftTimeBrk=shiftTime.split(':');
	var shiftTime_hour=shiftTimeBrk[0];
	var shiftTime_min=shiftTimeBrk[1];
	var shiftstart_AMPM=document.getElementById("shiftstart_AMPM_"+i).value;

		if(InTime_AMPM=='PM' && InTime_hour!='12')	
		{intimevalue=parseInt(InTime_hour)+12;}
		else if(InTime_AMPM=='AM' && InTime_hour=='12')
		{intimevalue=0;}
		else
		{intimevalue=parseInt(InTime_hour);}
		
		if(shiftstart_AMPM=='PM' && shiftTime_hour!='12')	
		{shifttimevalue=parseInt(shiftTime_hour)+12;}
		else if(shiftstart_AMPM=='AM' && shiftTime_hour=='12')
		{shifttimevalue=0;}
		else
		{shifttimevalue=parseInt(shiftTime_hour);}
		
		if(shiftstart_AMPM=='PM' && InTime_AMPM=='AM')
		{
			shifttimevalue_1=12-parseInt(shiftTime_hour);
			shifttimevalue=-(shifttimevalue_1);
			intimevalue=intimevalue;
		}
		
		if(intimevalue>shifttimevalue || intimevalue==shifttimevalue)
		{
			if(parseInt(shiftTime_min)>parseInt(InTime_min))
			{
				
				var Final_outHours=parseInt(intimevalue)-parseInt(shifttimevalue)-1;
				var intermediate_min=parseInt(shiftTime_min)-parseInt(InTime_min);
				var Final_outMin=60-parseInt(intermediate_min);
			}
			else if(parseInt(InTime_min)>parseInt(shiftTime_min))
			{
				
				var Final_outHours=parseInt(intimevalue)-parseInt(shifttimevalue);
				var Final_outMin=parseInt(InTime_min)-parseInt(shiftTime_min);
			}
			else
			if(parseInt(InTime_min)==parseInt(shiftTime_min))
			{
				var Final_outHours=parseInt(intimevalue)-parseInt(shifttimevalue);
				var Final_outMin="00";
			}
		}
		else
		{
			var Final_outHours='0';
			var Final_outMin='0';
		}
	
	var late_Hours=parseInt(Final_outHours)+":"+parseInt(Final_outMin);
	document.getElementById("late_arrival_"+i).value=late_Hours; 
}
function calculate_workhours(i)
{
 
	var InTime=document.getElementById("time_in_"+i).value;
	var InTime_AMPM=document.getElementById("timein_AMPM_"+i).value;
	var InTimeBrk=InTime.split(':');
	var InTime_hour=InTimeBrk[0];
	var InTime_min=InTimeBrk[1];
	
	var OutTime=document.getElementById("time_out_"+i).value;
	var OutTime_AMPM=document.getElementById("timeout_AMPM_"+i).value;
	var OutTimeBrk=OutTime.split(':');
	var OutTime_hour=OutTimeBrk[0];
	var OutTime_min=OutTimeBrk[1];
	
		
		if(InTime_AMPM=='PM' && InTime_hour!='12')	
		{intimevalue=parseInt(InTime_hour)+12;}
		else if(InTime_AMPM=='AM' && InTime_hour=='12')
		{intimevalue=0;}
		else
		{intimevalue=parseInt(InTime_hour);}
		
		if(OutTime_AMPM=='PM' && OutTime_hour!='12')	
		{outtimevalue=parseInt(OutTime_hour)+12;}
		else if(OutTime_AMPM=='AM' && OutTime_hour=='12')
		{outtimevalue=0;}
		else
		{
		outtimevalue=parseInt(OutTime_hour);
		}
		
		if(InTime_AMPM=='PM' && OutTime_AMPM=='AM')
		{
			intimevalue_1=12-parseInt(InTime_hour);
			intimevalue=-(intimevalue_1)
			outtimevalue=outtimevalue;
			 
		}
		 if(InTime_AMPM=='PM' && OutTime_AMPM=='PM' )
		 {
			var outtimevalue=parseInt(InTime_hour)-parseInt(OutTime_hour);
			var intimevalue=24;
			//alert(outtimevalue);alert(intimevalue);
		 }
		
		 if(InTime_AMPM=='AM' && OutTime_AMPM=='AM' )
		 {
		   
		   
		 	if((parseInt(InTime_hour)>parseInt(OutTime_hour))){
			var outtimevalue=  parseInt(InTime_hour)-parseInt(OutTime_hour);
			}else{
			var outtimevalue= parseInt(OutTime_hour)-parseInt(InTime_hour);
			}
			
			var intimevalue=24;
		 
		 }
		
		
			if(parseInt(OutTime_min)>parseInt(InTime_min))
			{
			  if(parseInt(intimevalue)>parseInt(outtimevalue))
 				  Final_outHours=parseInt(intimevalue)-parseInt(outtimevalue) ;			  
			   else			  
 				  Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
				  
				  
				  
				 Final_outMin=parseInt(OutTime_min)-parseInt(InTime_min);
				
			// alert(Final_outMin)
			  
				
			}
			else if(parseInt(InTime_min)>parseInt(OutTime_min))
			{
			
				if(parseInt(intimevalue)>parseInt(outtimevalue))
 				  Final_outHours=parseInt(intimevalue)-parseInt(outtimevalue)-1;			  
			   else			  
 				  Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
				  
			//	var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue)-1;
				var intermediate_min=parseInt(InTime_min)-parseInt(OutTime_min);
				var Final_outMin=60-parseInt(intermediate_min);
			}
			else if(parseInt(InTime_min)==parseInt(OutTime_min))
			{
 				 if(parseInt(outtimevalue)>parseInt(intimevalue)){
					var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
					var Final_outMin="00";}
					else
					{
					var Final_outHours=parseInt(intimevalue)-parseInt(outtimevalue);
					var Final_outMin="00";
					}
				 
			}	
			  
			  
		var Working_Hours=parseInt(Final_outHours)+":"+parseInt(Final_outMin);
		document.getElementById("work_hrs_"+i).value=Working_Hours; 
	
}

function calculate_officeworkhours(i)
{
    var InTime=document.getElementById("shift_start_"+i).value;
	var InTime_AMPM=document.getElementById("shiftstart_AMPM_"+i).value;
	var InTimeBrk=InTime.split(':');
	var InTime_hour=InTimeBrk[0];
	var InTime_min=InTimeBrk[1];

	var OutTime=document.getElementById("shift_end_"+i).value;
	var OutTime_AMPM=document.getElementById("shiftend_AMPM_"+i).value;
	var OutTimeBrk=OutTime.split(':');
	var OutTime_hour=OutTimeBrk[0];
	var OutTime_min=OutTimeBrk[1];
		
		if(InTime_AMPM=='PM' && InTime_hour!='12')	
		{intimevalue=parseInt(InTime_hour)+12;}
		else if(InTime_AMPM=='AM' && InTime_hour=='12')
		{intimevalue=0;}
		else
		{intimevalue=parseInt(InTime_hour);}
		
		if(OutTime_AMPM=='PM' && OutTime_hour!='12')	
		{outtimevalue=parseInt(OutTime_hour)+12;}
		else if(OutTime_AMPM=='AM' && OutTime_hour=='12')
		{outtimevalue=0;}
		else
		{outtimevalue=parseInt(OutTime_hour);}
		
		if(InTime_AMPM=='PM' && OutTime_AMPM=='AM')
		{
			intimevalue_1=12-parseInt(InTime_hour);
			intimevalue=-(intimevalue_1)
			outtimevalue=outtimevalue;
		}
		
			if(parseInt(OutTime_min)>parseInt(InTime_min))
			{
				var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
				var Final_outMin=parseInt(OutTime_min)-parseInt(InTime_min);
			}
			else if(parseInt(InTime_min)>parseInt(OutTime_min))
			{
				var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue)-1;
				var intermediate_min=parseInt(InTime_min)-parseInt(OutTime_min);
				var Final_outMin=60-parseInt(intermediate_min);
			}
			else
			if(parseInt(InTime_min)==parseInt(OutTime_min))
			{
				var Final_outHours=parseInt(outtimevalue)-parseInt(intimevalue);
				var Final_outMin="00";
			}
				 
		var Working_Hours=parseInt(Final_outHours)+":"+parseInt(Final_outMin);
		document.getElementById("officework_hrs_"+i).value=Working_Hours; 
		
	
}


 