{//Controles---------------------------------------------------------------------------------------------------------------------------------------------------
	{//Botones---------------------------------------------------------------------------------------------------------------------------------------------------
		var cmdOk=$.Objects.Button();
		cmdOk.Location(0, 573, 495, 24);
		cmdOk.SetText($.Lang.Get('accept'));
		//cmdOk.Add();
		var cmdCancel=$.Objects.Button();
		cmdCancel.Location(505, 573, 495, 24);
		cmdCancel.SetText($.Lang.Get('cancel'));
		//cmdCancel.Add();
	}
	{//Seleccion---------------------------------------------------------------------------------------------------------------------------------------------------
		var gpHistory=$.Objects.Container();
		gpHistory.Location(0,0,1000,40);
		gpHistory.SetStyle('transparent');
		gpHistory.Add();
		var lblEmployee=$.Objects.Text($.Lang.Get('employee')+' :');
		lblEmployee.Location(15,15,100,20);
		lblEmployee.Add(gpHistory);
		var cmbEmployee=$.Objects.ComboBox();
		cmbEmployee.Location(110,10,445,20);
		cmbEmployee.Add(gpHistory);
		
		$.ControlAdd('searchemployee', [560,10,20,20], gpHistory, cmbEmployee);
		
		var lblPeriod=$.Objects.Text($.Lang.Get('period')+' :');
		lblPeriod.Location(590,15,100,20);
		lblPeriod.Add(gpHistory);
		var cmbMonth=$.Objects.ComboBox();
		cmbMonth.Location(690,10,190,20);
		cmbMonth.Add(gpHistory);
		var cmbYear=$.Objects.ComboBox();
		cmbYear.Location(890,10,100,20);
		cmbYear.Add(gpHistory);

		for(var i=1; i<=12;i++){ cmbMonth.AddItem($.Lang.Get('month_'+i),i); }
		cmbMonth.SetSelectedKey($.DateTime.CurrentMonth());
		for(var i=$.DateTime.CurrentYear()-10,iLen=$.DateTime.CurrentYear()+10;i<=iLen;i++){ cmbYear.AddItem(i,i); }	
		cmbYear.SetSelectedKey($.DateTime.CurrentYear());
	}
	{//Pestaņas
		var tabsHistory=new $.Objects.Tabs();
		tabsHistory.Location(0,50,1000,492);
		tabsHistory.AddTab($.Lang.Get('checks'));
		tabsHistory.AddTab($.Lang.Get('access_checks'));
		tabsHistory.AddTab($.Lang.Get('daily_log'));
		tabsHistory.AddTab($.Lang.Get('accruals'));
		tabsHistory.AddTab($.Lang.Get('weekly_accruals'));
		tabsHistory.AddTab($.Lang.Get('payrolls'));
		tabsHistory.AddTab($.Lang.Get('weekly_payrolls'));
		tabsHistory.Add();
	}
	{//Pestaņa: Fichajes
		var cmChecks=$.Grids.ColumnModel();
		cmChecks.Add($.Grids.SimpleColumn({key: 'date', text: $.Lang.Get('date'), sortable: false, editable: false, width: '110'}));
		cmChecks.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('entry'), sortable: false, width: '100'}));
		cmChecks.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('exit'), sortable: false, width: '100'}));
		cmChecks.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('entry'), sortable: false, width: '100'}));
		cmChecks.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('exit'), sortable: false, width: '100'}));
		cmChecks.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('entry'), sortable: false, width: '100'}));
		cmChecks.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('exit'), sortable: false, width: '100'}));
		cmChecks.Add($.Grids.SimpleColumn({key: 'horario', text: $.Lang.Get('event_workday'), sortable: false, width: '255'}));

		var grChecks=$.Grids.Grid(cmChecks);
		grChecks.Location(5,5,990,424);
		grChecks.Add(tabsHistory.tabpages[0]);
		
		var gpLegendPunch = $.Objects.Container();
		gpLegendPunch.Location(5,430,990,27);
		gpLegendPunch.SetStyle('transparent');
		gpLegendPunch.Add(tabsHistory.tabpages[0]);
		var lblLegendPunch_1 = $.Objects.Text($.Lang.Get('punches_unprocessed'));
		lblLegendPunch_1.Location(10,8,200,20);
		lblLegendPunch_1.Add(gpLegendPunch);
		var  lblLegendPunch_2 = $.Objects.Text($.Lang.Get('punches_processed'));
		lblLegendPunch_2.Location(210,8,200,20);
		lblLegendPunch_2.Add(gpLegendPunch);
		lblLegendPunch_2.style.color = '#6688CF';
	}
	{//Pestaņa: Fichajes de acceso
		var cmAccessChecks=$.Grids.ColumnModel();
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'date', text: $.Lang.Get('date'), sortable: false, width: '110'}));
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('access'), sortable: false, width: '100'}));
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('access'), sortable: false, width: '100'}));
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('access'), sortable: false, width: '100'}));
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('access'), sortable: false, width: '100'}));
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('access'), sortable: false, width: '100'}));
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('access'), sortable: false, width: '100'}));
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('access'), sortable: false, width: '100'}));
		cmAccessChecks.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('access'), sortable: false, width: '100'}));
	
		var grAccessChecks=$.Grids.Grid(cmAccessChecks);
		grAccessChecks.Location(5,5,990,455);
		grAccessChecks.Add(tabsHistory.tabpages[1]);
	}
	{//Pestaņa: Historico
		var cmLog=$.Grids.ColumnModel();
		cmLog.Add($.Grids.SimpleColumn({key: 'date', text: $.Lang.Get('date'), sortable: false, width: '120'}));
		cmLog.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('from'), sortable: false, width: '100'}));
		cmLog.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('to'), sortable: false, width: '100'}));
		cmLog.Add($.Grids.SimpleColumn({key: 'total', text: $.Lang.Get('total'), sortable: false, width: '100'}));
		cmLog.Add($.Grids.SimpleColumn({key: 'event', text: $.Lang.Get('incidence'), sortable: false, width: '300'}));
	
		var grLog=$.Grids.Grid(cmLog);
		grLog.Location(5,30,990,399);
		grLog.Add(tabsHistory.tabpages[2]);
	
		var lblEmployee=$.Objects.Text($.Lang.Get('incidence')+':');
		lblEmployee.Location(15,10,200,20);
		lblEmployee.Add(tabsHistory.tabpages[2]);
		var cmbLog=$.Objects.ComboBox();
		cmbLog.Location(210,5,785,20);
		cmbLog.Add(tabsHistory.tabpages[2]);
		
		var gpLegendLog = $.Objects.Container();
		gpLegendLog.Location(5,430,990,27);
		gpLegendLog.SetStyle('transparent');
		gpLegendLog.Add(tabsHistory.tabpages[2]);
		var lblLegendLog_1 = $.Objects.Text($.Lang.Get('work'));
		lblLegendLog_1.Location(10,8,200,20);
		lblLegendLog_1.Add(gpLegendLog);
		var lblLegendLog_2 = $.Objects.Text($.Lang.Get('system_events'));
		lblLegendLog_2.Location(210,8,200,20);
		lblLegendLog_2.Add(gpLegendLog);
		lblLegendLog_2.style.color = '#6688CF';
		var lblLegendLog_3 = $.Objects.Text($.Lang.Get('user_events'));
		lblLegendLog_3.Location(420,8,260,20);
		lblLegendLog_3.Add(gpLegendLog);
		lblLegendLog_3.style.color = '#FF8C00';
		
	}
	{//Pestaņa: Bolsas-------------------------------------------------------------------------------------------------------------------------------------------------------------
		var cmAccruals=$.Grids.ColumnModel();
		cmAccruals.Add($.Grids.SimpleColumn({key: 'date', text: $.Lang.Get('accrual'), sortable: false, width: '450'}));
		cmAccruals.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('ntime'), sortable: false, width: '100'}));
		cmAccruals.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('n_ocurrences'), sortable: false, width: '100'}));
	
		var grAccruals=$.Grids.Grid(cmAccruals);
		grAccruals.Location(5,5,990,455);
		grAccruals.Add(tabsHistory.tabpages[3]);
	}
	{//Pestaņa: Bolsas semanales-------------------------------------------------------------------------------------------------------------------------------------------------------------
		var cmWeeklyAccruals=$.Grids.ColumnModel();
		cmWeeklyAccruals.Add($.Grids.SimpleColumn({key: 'week', text: $.Lang.Get('week'), sortable: false, width: '350'}));
		cmWeeklyAccruals.Add($.Grids.SimpleColumn({key: 'date', text: $.Lang.Get('accrual'), sortable: false, width: '400'}));
		cmWeeklyAccruals.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('ntime'), sortable: false, width: '100'}));
		cmWeeklyAccruals.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('n_ocurrences'), sortable: false, width: '100'}));
	
		var grWeeklyAccruals=$.Grids.Grid(cmWeeklyAccruals);
		grWeeklyAccruals.Location(5,5,990,455);
		grWeeklyAccruals.Add(tabsHistory.tabpages[4]);
	}
	{//Pestaņa: Costes-------------------------------------------------------------------------------------------------------------------------------------------------------------
		var cmPayroll=$.Grids.ColumnModel();
		cmPayroll.Add($.Grids.SimpleColumn({key: 'week', text: $.Lang.Get('item'), sortable: false, width: '450'}));
		cmPayroll.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('ntime'), sortable: false, width: '100'}));
		cmPayroll.Add($.Grids.SimpleColumn({key: 'date', text: $.Lang.Get('price'), sortable: false, width: '100'}));
		cmPayroll.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('recalc_price'), sortable: false, width: '140'}));
	
		var grPayroll=$.Grids.Grid(cmPayroll);
		grPayroll.Location(5,5,990,455);
		grPayroll.Add(tabsHistory.tabpages[5]);
	}
	{//Pestaņa: Costes semanales-------------------------------------------------------------------------------------------------------------------------------------------------------------
		var cmWeeklyPayroll=$.Grids.ColumnModel();
		cmWeeklyPayroll.Add($.Grids.SimpleColumn({key: 'week', text: $.Lang.Get('week'), sortable: false, width: '350'}));
		cmWeeklyPayroll.Add($.Grids.SimpleColumn({key: 'week', text: $.Lang.Get('item'), sortable: false, width: '320'}));
		cmWeeklyPayroll.Add($.Grids.SimpleColumn({key: 'entry', text: $.Lang.Get('ntime'), sortable: false, width: '70'}));
		cmWeeklyPayroll.Add($.Grids.SimpleColumn({key: 'date', text: $.Lang.Get('price'), sortable: false, width: '70'}));
		cmWeeklyPayroll.Add($.Grids.SimpleColumn({key: 'exit', text: $.Lang.Get('recalc_price'), sortable: false, width: '140'}));
	
		var grWeeklyPayroll=$.Grids.Grid(cmWeeklyPayroll);
		grWeeklyPayroll.Location(5,5,990,455);
		grWeeklyPayroll.Add(tabsHistory.tabpages[6]);	
	}	
	
	
	if(!$.Utils.Privilege('log_punches')){ tabsHistory.tabs[0].Hide(); }
	if(!$.Utils.Privilege('log_access_punches')){ tabsHistory.tabs[1].Hide(); }
	if(!$.Utils.Privilege('log_daily_log')){ tabsHistory.tabs[2].Hide(); }
	if(!$.Utils.Privilege('log_monthly_accruals')){ tabsHistory.tabs[3].Hide(); }
	if(!$.Utils.Privilege('log_weekly_accruals')){ tabsHistory.tabs[4].Hide(); }
	if(!$.Utils.Privilege('log_payroll')){ tabsHistory.tabs[5].Hide(); }
	if(!$.Utils.Privilege('log_weekly_payroll')){ tabsHistory.tabs[6].Hide(); }

}
{//Ajax
	var ajaxManager=$.AjaxManager();
	{//Basic
		ajaxManager.Create('basic');
		{//Employees
			var aEmployees=[];
			var ajaxEmployees=$.AjaxDB("SELECT Codigo,Nombre,Apellidos FROM EMPLEADOS{c} ORDER BY Codigo");
			ajaxEmployees.Add(ajaxManager,'basic');
			ajaxEmployees.oncomplete=function(){
				if(!this.json.error){
					for(var i=0,iLen=this.json.row.length;i<iLen;i++){
						var item=this.json.row[i];
						aEmployees[item.Codigo]={};
						aEmployees[item.Codigo].Text=item.Codigo+" - "+item.Nombre+" "+item.Apellidos;
						aEmployees[item.Codigo].Codigo=item.Codigo;
						aEmployees[item.Codigo].Nombre=item.Nombre;
						aEmployees[item.Codigo].Apellidos=item.Apellidos;
					}
				}
				else{ $.Debug.Add(this.text); }
			}
		}
		{//Events
			var aEvents=[];
			var ajaxEvents=$.AjaxDB("SELECT * FROM INCIDENCIAS{c} ORDER BY Codigo");
			ajaxEvents.Add(ajaxManager,'basic');
			ajaxEvents.oncomplete=function(){
				if(!this.json.error){
					for(var i=0,iLen=this.json.row.length;i<iLen;i++){
						var item=this.json.row[i];
						aEvents[item.Codigo]={};
						aEvents[item.Codigo].Text=item.Codigo+" - "+item.Descripcion;
						aEvents[item.Codigo].Codigo=item.Codigo;
						aEvents[item.Codigo].Descripcion=item.Descripcion;
						aEvents[item.Codigo].Valorada=item.Valorada;
					}
				}
				else{ $.Debug.Add(this.text); }
			}
		}
		{//Accruals
			var aAccruals=[];
			var ajaxAccruals=$.AjaxDB("SELECT * FROM ACUMULADORES{c} ORDER BY Codigo");
			ajaxAccruals.Add(ajaxManager,'basic');
			ajaxAccruals.oncomplete=function(){
				if(!this.json.error){
					for(var i=0,iLen=this.json.row.length;i<iLen;i++){
						var item=this.json.row[i];
						aAccruals[item.Codigo]={};
						aAccruals[item.Codigo].Text=item.Codigo+" - "+item.Descripcion;
						aAccruals[item.Codigo].Codigo=item.Codigo;
						aAccruals[item.Codigo].Descripcion=item.Descripcion;
					}
				}
				else{ $.Debug.Add(this.text); }
			}
		}
		{//Payrolls
			var aPayrolls=[];
			var ajaxPayrolls=$.AjaxDB("SELECT * FROM COSTES{c} ORDER BY Codigo");
			ajaxPayrolls.Add(ajaxManager,'basic');
			ajaxPayrolls.oncomplete=function(){
				if(!this.json.error){
					for(var i=0,iLen=this.json.row.length;i<iLen;i++){
						var item=this.json.row[i];
						aPayrolls[item.Codigo]={};
						aPayrolls[item.Codigo].Text=item.Codigo+" - "+item.Descripcion;
						aPayrolls[item.Codigo].Codigo=item.Codigo;
						aPayrolls[item.Codigo].Descripcion=item.Descripcion;
					}
				}
				else{ $.Debug.Add(this.text); }
			}
		}
		{//PayrollItems
			var aPayrollItems=[];
			var ajaxPayrollItems=$.AjaxDB("SELECT * FROM COSTES_CONCEPTOS{c} ORDER BY Codigo");
			ajaxPayrollItems.Add(ajaxManager,'basic');
			ajaxPayrollItems.oncomplete=function(){
				if(!this.json.error){
					for(var i=0,iLen=this.json.row.length;i<iLen;i++){
						var item=this.json.row[i];
						aPayrollItems[item.Codigo]={};
						aPayrollItems[item.Codigo].Text=item.Codigo+" - "+item.Descripcion;
						aPayrollItems[item.Codigo].Codigo=item.Codigo;
						aPayrollItems[item.Codigo].Descripcion=item.Descripcion;
					}
				}
				else{ $.Debug.Add(this.text); }
			}
		}
		{//Workdays
			var aWorkdays=[];
			var ajaxWorkdays=$.AjaxDB("SELECT Codigo,Descripcion FROM HORARIOS{c} ORDER BY Codigo");
			ajaxWorkdays.Add(ajaxManager,'basic');
			ajaxWorkdays.oncomplete=function(){
				if(!this.json.error){
					for(var i=0,iLen=this.json.row.length;i<iLen;i++){
						var item=this.json.row[i];
						aWorkdays[item.Codigo]={};
						aWorkdays[item.Codigo].Text=item.Codigo+" - "+item.Descripcion;
						aWorkdays[item.Codigo].Codigo=item.Codigo;
						aWorkdays[item.Codigo].Descripcion=item.Descripcion;
					}
				}
				else { $.Debug.Add(this.text); }
			}
		}
	}
	{//Ajax Manager
		ajaxManager.group['basic'].Start();
		ajaxManager.group['basic'].oncomplete = function() {
			for(var i in aEmployees){
				if($.Utils.IsInEmployees(aEmployees[i].Codigo)){
						cmbEmployee.AddItem(aEmployees[i].Text,aEmployees[i].Codigo);
				}
			}
			cmbLog.AddItem($.Lang.Get('all_p_f'),'0');
			for(var i in aEvents){
				cmbLog.AddItem(aEvents[i].Text,aEvents[i].Codigo);
			}
			cmbEmployee.onchangekey=function() { LoadLog(); }
			cmbMonth.onchangekey=function() { LoadLog(); }
			cmbYear.onchangekey=function() { LoadLog(); }
			cmbLog.onchangekey=function() { Load_Log(); }
			LoadLog();
		}
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	var dates=[];
	var data={};
	
	function LoadLog(){
		var month=$.Strings.PadLeft(cmbMonth.selectedKey,'0',2);
		var year=cmbYear.selectedKey;
		var fromDate=year+month+'01';
		var toDate=year+month+'31';
		
		var ajax=$.AjaxDB("SELECT Desde,Hasta FROM PERIODOS_PRESENCIA{c} WHERE Mes='"+month+"'",Ajax.Wait);
		if(!ajax.json.error){
			if(ajax.json.row.length!=0){
				var item=ajax.json.row[0];
				fromDate=item.Desde;
				toDate=item.Hasta;
				if(fromDate>toDate){
					if(month=='01'){
						fromDate = (year-1)+fromDate;
						toDate = year+toDate;
					}
					else if(month=='12'){
						fromDate = year+fromDate;
						toDate = (year+1)+toDate;
					}
				}
				else{
					fromDate = year+fromDate;
					toDate = year+toDate;
				}
			}
		}
		else{ $.Debug.Add(ajax.text); }
		
		data={start: fromDate, end: toDate, month: month, year: year, employee: cmbEmployee.selectedKey};
		
		if($.Utils.Privilege('log_punches')){ Load_Checks(); }
		if($.Utils.Privilege('log_access_punches')){ Load_AccessChecks(); }
		if($.Utils.Privilege('log_daily_log')){ Load_Log(); }
		if($.Utils.Privilege('log_monthly_accruals')){ Load_Accruals(); }
		if($.Utils.Privilege('log_weekly_accruals')){ Load_WeeklyAccruals(); }
		if($.Utils.Privilege('log_payroll')){ Load_Payrolls(); }
		if($.Utils.Privilege('log_weekly_payroll')){ Load_WeeklyPayrolls(); }
	}
	
	function Load_Checks(){
		grChecks.Loading(true);
		grChecks.ClearRows();
		var dates=[];

		var ajaxMng = new $.AjaxManager();
		ajaxMng.Create('basic');

		var ajaxChecks=$.AjaxDB($.Strings.Format("SELECT * FROM FICHAJES{c} WHERE ((Cerrado=1 AND (FechaValor >= '{0}' AND FechaValor <= '{1}')) OR ( Cerrado=0 AND (Fecha >= '{0}' AND Fecha <= '{1}'))) AND IdEmpleado = '{2}' ORDER BY Fecha,Hora",data.start,data.end,data.employee));
		ajaxChecks.Add(ajaxMng,'basic');
		ajaxChecks.oncomplete=function(){
			if(!this.json.error){
				var lastDate='';
				var newDate={};
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item = this.json.row[i];
					var date = (item.FechaValor+item.Fecha).substr(0,8);
					if(lastDate!=date){
						newDate={checks:[],date: date,event:''}
						dates.push(newDate);
						lastDate=date;
					}
					if(item.FechaValor!=""){ newDate.date=item.FechaValor; }
					newDate.checks.push({time: item.Hora.substring(0,2)+':'+item.Hora.substring(2,4), event: item.IdIncidencia, closed: item.Cerrado});
				}
			}
			else{ $.Debug.Add(this.text); }
		}
		
		var ajaxEvents=$.AjaxDB($.Strings.Format("SELECT Fecha,Incidencia,TipoDia FROM CIERRE{c} WHERE Fecha>= '{0}' AND Fecha<='{1}' AND IdEmpleado = '{2}' AND TipoDia <> 'I' AND TipoDia <> 'D' ",data.start,data.end,data.employee));
		ajaxEvents.Add(ajaxMng,'basic');
		ajaxEvents.oncomplete=function() {
			if(!this.json.error){
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					for(var j=0,jLen=dates.length;j<jLen;j++){
						if(this.json.row[i].Fecha==dates[j].date){ dates[j].event = $.utils.AAText(aWorkdays,this.json.row[i].Incidencia); break; }
					}
				}
			}
			else{ $.Debug.Add(this.text); }
		}

		ajaxMng.group['basic'].ProgessiveStart();
		ajaxMng.group['basic'].oncomplete=function(){
			var row={};
			for(var i=0,iLen=dates.length;i<iLen;i++){
				var nChecks=0;
				row = Load_Checks_AddLine(true,dates[i].date,dates[i].event);
				for(var j=0,jLen=dates[i].checks.length;j<jLen;j++){
					if(nChecks==6){
						row = Load_Checks_AddLine(false,dates[i].date,dates[i].event);
						nChecks=0;
					}
					if(dates[i].checks[j].event!='0000'){
						row.cells[nChecks+1].SetValue(dates[i].checks[j].time+' ['+dates[i].checks[j].event+']');
					}
					else{ row.cells[nChecks+1].SetValue(dates[i].checks[j].time); }
					if(dates[i].checks[j].closed=='1'){
						row.cells[nChecks+1].ChangeStyle('blue');
					}
					nChecks++;
				}
				Load_Checks_DrawMissingExit(row, nChecks);
			}
			grChecks.Loading(false);
		}
	}
	function Load_Checks_AddLine(first, date, event){
		var row = grChecks.NewRow([first?$.DateTime.toShowDate(date,true):'','','','','','','',first?event:''],'');
		row.cells[0].ChangeStyle('mark');
		row.cells[7].ChangeStyle('mark');
		row.SetClickable(false);
		return row;
	}
	function Load_Checks_DrawMissingExit(row,nChecks){
		if(nChecks%2!=0){
			row.cells[nChecks+1].SetValue($.Lang.Get('missing_exit'));
			row.cells[nChecks+1].ChangeStyle('red');
		}
	}	
	function Load_AccessChecks() {
		grAccessChecks.Loading(true);
		grAccessChecks.ClearRows()
		var strPrevDate='';
		var ajax=$.AjaxDB($.Strings.Format("SELECT * FROM FICHAJES_ACCESO{c} WHERE Fecha >= '{0}' AND Fecha <= '{1}' AND IdEmpleado = '{2}' ORDER BY Fecha,Hora",data.start,data.end,data.employee), Ajax.Dontwait);
		ajax.oncomplete=function(){
			if(!this.json.error){
				var nChecks = 0;
				var row={};
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					var strDate=item.Fecha;
					if(strDate!=strPrevDate || nChecks==8){
						row=grAccessChecks.NewRow([$.iif(nChecks==6,'',$.DateTime.toShowDate(strDate,true)),'','','','','',''],'');
						row.SetClickable(false);
						row.cells[0].ChangeStyle('mark');
						nChecks=0;
					}
					var strValue=item.Hora.substring(0,2)+':'+item.Hora.substring(2,4);
					if(item.IdIncidencia!='0000'){ strValue+='['+item.IdIncidencia+']'; }
					row.cells[nChecks+1].SetValue(strValue);
					
					if(item.Cerrado=='1'){ row.cells[nChecks+1].ChangeStyle('blue'); }
					else { row.cells[nChecks+1].ChangeStyle(''); }
					
					nChecks++;
					strPrevDate=strDate;
				}
				grAccessChecks.Loading(false);
			}
			else{ $.Debug.Add(ajax.text); }
		}
	}
	function Load_Log() {
		grLog.Loading(true);
		grLog.ClearRows();
		
		var where = '';
		if(cmbLog.selectedKey!='0') { where="AND IdIncidencia='"+cmbLog.selectedKey+"'"; }
		
		var ajax=$.AjaxDB($.Strings.Format("SELECT * FROM CIERRE_DESGLOSE_DIAS{c} WHERE Fecha >= '{0}' AND Fecha <= '{1}' AND IdEmpleado = '{2}' {3} ORDER BY Fecha,HoraInicio",data.start,data.end,data.employee,where),Ajax.Dontwait);
		ajax.oncomplete=function(){
			if(!this.json.error){
				var dates=[];
				var newDate={};
				var lastDate='';
				
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					if(lastDate!=item.Fecha){
						newDate={date: item.Fecha, user: [], system: []};
						dates.push(newDate);
						lastDate=item.Fecha;
					}
					var newLine={};
					newLine.date=$.DateTime.toShowDate(item.Fecha,true);
					newLine.startTime=$.DateTime.toShowTime(item.HoraInicio);
					newLine.endTime=$.DateTime.toShowTime(item.HoraFin);
					newLine.total=$.DateTime.MinutesToHour(item.Total,':');
					newLine.event=item.IdIncidencia;
					if(newLine.event<'S000'){ newDate.user.push(newLine); }
					else { newDate.system.push(newLine);}
				}
				
				for(var i=0,iLen=dates.length;i<iLen;i++){
					var firstDate=true;
					for(var j=0,jLen=dates[i].user.length;j<jLen;j++){
						Load_Log_AddLine(firstDate,dates[i].user[j]);
						firstDate=false;
					}
					dates[i].system.sort(function(a,b){	a=a.event;b=b.event;if(a < b){ return -1; }	else if(a > b){ return 1; } else{ return 0; } });
					for(var j=0,jLen=dates[i].system.length;j<jLen;j++){
						Load_Log_AddLine(firstDate,dates[i].system[j]);
						firstDate=false;
					}
				}
			}
			else{ $.Debug.Add(ajax.text); }
			grLog.Loading(false);
		}
	}
	function Load_Log_AddLine(first,line){
		var row=grLog.NewRow([(first?line.date:''),line.startTime,line.endTime,line.total,$.utils.AAText(aEvents,line.event)],'');
		row.SetClickable(false);
		var style='';
		if(line.event!='0000'){
			if(line.event<'S000'){ style='orange'; }
			else{ style='blue'; }
		}
		row.cells[0].ChangeStyle('mark');
		row.cells[1].ChangeStyle(style);
		row.cells[2].ChangeStyle(style);
		row.cells[3].ChangeStyle(style);
		row.cells[4].ChangeStyle(style);
	}
	function Load_Accruals(){
		grAccruals.Loading(true);
		grAccruals.ClearRows();
		
		var ajax=new $.AjaxDB($.Strings.Format("SELECT IdAcumulador, SUM(TotalVeces) AS Veces, SUM(TotalTiempo) AS Tiempo FROM CIERRE_ACUMULADORES{c} WHERE IdEmpleado='{2}' AND Anho='{1}' AND Mes={0} GROUP BY IdAcumulador, Anho, Mes",data.month,data.year,data.employee), Ajax.Dontwait);
		ajax.oncomplete=function(){
			if(!this.json.error){
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					var row=grAccruals.NewRow([$.utils.AAText(aAccruals, item.IdAcumulador),$.DateTime.MinutesToHour(item.Tiempo,':'),item.Veces],'');
					row.SetClickable(false);
				}
			}
			else{ $.Debug.Add(ajax.text); }
			grAccruals.Loading(false);		
		}
	}
	function Load_WeeklyAccruals(){
		grWeeklyAccruals.Loading(true);
		grWeeklyAccruals.ClearRows();
		
		var lastWeek='';
		var ajax=new $.AjaxDB($.Strings.Format("SELECT Anho, Semana, IdAcumulador, SUM(TotalVeces) AS Veces, SUM(TotalTiempo) AS Tiempo FROM CIERRE_ACUMULADORES{c} WHERE IdEmpleado='{2}' AND Anho='{1}' AND Mes={0} GROUP BY IdAcumulador, Anho, Mes, Semana ORDER BY Semana,IdAcumulador",data.month,data.year,data.employee), Ajax.Dontwait);
		ajax.oncomplete=function(){
			if(!this.json.error){
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					var row=grWeeklyAccruals.NewRow([lastWeek==item.Semana ? '': $.DateTime.WeekFormat(item.Semana, data.year),$.utils.AAText(aAccruals, item.IdAcumulador),$.DateTime.MinutesToHour(item.Tiempo,':'),item.Veces],'');
					row.SetClickable(false);
					row.cells[0].ChangeStyle('mark')
					lastWeek=item.Semana;
				}
			}
			else{ $.Debug.Add(ajax.text); }
			grWeeklyAccruals.Loading(false);
		}
	}
	function Load_Payrolls(){
		grPayroll.Loading(true);
		grPayroll.ClearRows();
		
		var ajax=$.AjaxDB($.Strings.Format("SELECT IdCosteConcepto, SUM(Precio) AS TotalPrecio, SUM(Tiempo) AS TotalTiempo FROM CIERRE_COSTES{c} WHERE IdEmpleado='{2}' AND Anho='{1}' AND Mes={0} GROUP BY IdCosteConcepto, Anho, Mes",data.month,data.year,data.employee), Ajax.Dontwait);
		ajax.oncomplete=function(){
			if(!this.json.error){
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					var row=grPayroll.NewRow([$.utils.AAText(aPayrollItems, item.IdCosteConcepto), $.DateTime.MinutesToHour(item.TotalTiempo,':'), $.Convert.ToFloat(item.TotalPrecio)], '');
					row.SetClickable(false);
				}
			}
			else{ $.Debug.Add(ajax.text); }
			grPayroll.Loading(false);
		}
	}
	function Load_WeeklyPayrolls(){
		grWeeklyPayroll.Loading(true);
		grWeeklyPayroll.ClearRows();
		var lastWeek='';
		var ajax=$.AjaxDB($.Strings.Format("SELECT Semana, IdCosteConcepto, SUM(Precio) AS TotalPrecio, SUM(Tiempo) AS TotalTiempo FROM CIERRE_COSTES{c} WHERE IdEmpleado='{2}' AND Anho='{1}' AND Mes={0} GROUP BY IdCosteConcepto, Anho, Mes, Semana ORDER BY Semana, IdCosteConcepto",data.month,data.year,data.employee),Ajax.Dontwait);
		ajax.oncomplete=function(){
			if(!this.json.error){
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					var row = grWeeklyPayroll.NewRow([lastWeek==item.Semana ? '': $.DateTime.WeekFormat(item.Semana, data.year), $.utils.AAText(aPayrollItems,item.IdCosteConcepto), $.DateTime.MinutesToHour(item.TotalTiempo,':'), $.Convert.ToFloat(item.TotalPrecio)], '');
					row.SetClickable(false);
					row.cells[0].ChangeStyle('mark');
					lastWeek=item.Semana;
				}
			}
			else{ $.Debug.Add(ajax.text); }
			grWeeklyPayroll.Loading(false);
		}
	}