var ajaxManager=Jade.AjaxManager();
{//Controles---------------------------------------------------------------------------------------------------------------------------------------------------
	var cmdOk=Jade.Objects.Button(Jade.Lang.Get('accept'));
	cmdOk.Location(0, 573, 495, 24);
	//cmdOk.Add();
	var cmdCancel=Jade.Objects.Button(Jade.Lang.Get('cancel'));
	cmdCancel.Location(505, 573, 495, 24);
	//cmdCancel.Add();

	var gpWorkday=Jade.Objects.Container();
	gpWorkday.Location(0,0,1000,40);
	gpWorkday.SetStyle('transparent');
	gpWorkday.Add();
	var lblWorkday=Jade.Objects.Text(Jade.Lang.Get('workday')+' :');
	lblWorkday.Location(15,15,200,20);
	lblWorkday.Add(gpWorkday);
	var cmbWorkdays=Jade.Objects.ComboBox();
	cmbWorkdays.Location(210,10,780,20);
	cmbWorkdays.Add(gpWorkday);
	
	{//Pestaņas------------------------------------------------------------------------------------------------------------------------------------------------
		var tabsWorkday=Jade.Objects.Tabs();
		tabsWorkday.Location(0,50,1000,492);
		tabsWorkday.Add();
	}
	{//Pestaņa: Datos------------------------------------------------------------------------------------------------------------------------------------------
		tabsWorkday.AddTab(Jade.Lang.Get('data'));
		{//Encabezado------------------------------------------------------------------------------------------------------------------------------------------
			var lblCode=Jade.Objects.Text(Jade.Lang.Get('code')+':');
			lblCode.Location(15,15,100,20);
			lblCode.Add(tabsWorkday.tabpages[0]);
			var txtCode=Jade.Objects.TextBox();
			txtCode.Location(115,10,100,20);
			txtCode.Add(tabsWorkday.tabpages[0]);

			var lblDescription=Jade.Objects.Text(Jade.Lang.Get('description')+':');
			lblDescription.Location(230,15,100,20);
			lblDescription.Add(tabsWorkday.tabpages[0]);
			var txtDescription=Jade.Objects.TextBox();
			txtDescription.Location(330,10,655,20)
			txtDescription.Add(tabsWorkday.tabpages[0]);
		}
		{//Turnos----------------------------------------------------------------------------------------------------------------------------------------------
			var gpWorkdayType=Jade.Objects.Container();
			gpWorkdayType.Location(10,30,980,85);
			gpWorkdayType.SetStyle('transparent');
			gpWorkdayType.Add(tabsWorkday.tabpages[0]);
	
			var optShift1=Jade.Objects.Option(Jade.Lang.Get('day_shift'));
			optShift1.Location(15,10,150,20);
			optShift1.Add(gpWorkdayType);
	
			var optShift2=Jade.Objects.Option(Jade.Lang.Get('night_shift'));
			optShift2.Location(15,35,150,20);
			optShift2.Add(gpWorkdayType);

			var optShift3=Jade.Objects.Option(Jade.Lang.Get('rotation_shift'));
			optShift3.Location(15,60,150,20);
			optShift3.Add(gpWorkdayType);
	
			var chkSearchVariant=Jade.Objects.CheckBox(Jade.Lang.Get('search_best_variant'));
			chkSearchVariant.Location(380,10,500,20);
			chkSearchVariant.Add(gpWorkdayType);

			var chkJustifyIncidence=Jade.Objects.CheckBox(Jade.Lang.Get('justify_incidence_from_start'));
			chkJustifyIncidence.Location(380,35,500,20);
			chkJustifyIncidence.Add(gpWorkdayType);

			var chkExtendWorkday=Jade.Objects.CheckBox(Jade.Lang.Get('expand_workday'));
			chkExtendWorkday.Location(380,60,500,20);
			chkExtendWorkday.Add(gpWorkdayType);			
		}
		{//Primera sesion--------------------------------------------------------------------------------------------------------------------------------------
			var gpFistSession=Jade.Objects.Container();
			gpFistSession.Location(10,120,980,110);
			gpFistSession.SetStyle('transparent');
			gpFistSession.Add(tabsWorkday.tabpages[0]);
			
			var lbl_1_Title=Jade.Objects.Text(Jade.Lang.Get('first_session')+':');
			lbl_1_Title.Location(15,10,100,20);
			lbl_1_Title.Add(gpFistSession);
			
			var lbl_1_StartEntry=Jade.Objects.Text(Jade.Lang.Get('start_entry')+':');
			lbl_1_StartEntry.Location(225,20,150,20);
			lbl_1_StartEntry.Add(gpFistSession);

			var txt_1_StartEntry=Jade.Objects.TimeBox(false);
			txt_1_StartEntry.Location(400,15,60,20);
			txt_1_StartEntry.Add(gpFistSession);
			
			var lbl_1_EndEntry=Jade.Objects.Text(Jade.Lang.Get('end_entry')+':');
			lbl_1_EndEntry.Location(475,20,150,20);
			lbl_1_EndEntry.Add(gpFistSession);

			var txt_1_EndEntry=Jade.Objects.TimeBox(false);
			txt_1_EndEntry.Location(650,15,60,20);
			txt_1_EndEntry.Add(gpFistSession);
			
			var lbl_1_SessionStart=Jade.Objects.Text(Jade.Lang.Get('session_start')+':');
			lbl_1_SessionStart.Location(725,20,150,20);
			lbl_1_SessionStart.Add(gpFistSession);

			var txt_1_SessionStart=Jade.Objects.TimeBox(false);
			txt_1_SessionStart.Location(900,15,60,20);
			txt_1_SessionStart.Add(gpFistSession);
			
			var lbl_1_StartExit=Jade.Objects.Text(Jade.Lang.Get('start_exit')+':');
			lbl_1_StartExit.Location(225,50,150,20);
			lbl_1_StartExit.Add(gpFistSession);

			var txt_1_StartExit=Jade.Objects.TimeBox(false);
			txt_1_StartExit.Location(400,45,60,20);
			txt_1_StartExit.Add(gpFistSession);
			
			var lbl_1_EndExit=Jade.Objects.Text(Jade.Lang.Get('end_exit')+':');
			lbl_1_EndExit.Location(475,50,150,20);
			lbl_1_EndExit.Add(gpFistSession);

			var txt_1_EndExit=Jade.Objects.TimeBox(false);
			txt_1_EndExit.Location(650,45,60,20);
			txt_1_EndExit.Add(gpFistSession);
			
			var lbl_1_SessionEnd=Jade.Objects.Text(Jade.Lang.Get('session_exit')+':');
			lbl_1_SessionEnd.Location(725,50,150,20);
			lbl_1_SessionEnd.Add(gpFistSession);

			var txt_1_SessionEnd=Jade.Objects.TimeBox(false);
			txt_1_SessionEnd.Location(900,45,60,20);
			txt_1_SessionEnd.Add(gpFistSession);
			
			var lbl_1_TotalTime=Jade.Objects.Text(Jade.Lang.Get('first_session_hours')+':');
			lbl_1_TotalTime.Location(225,80,300,20);
			lbl_1_TotalTime.Add(gpFistSession);

			var txt_1_TotalTime=Jade.Objects.TimeBox(false);
			txt_1_TotalTime.Location(550,75,60,20);
			txt_1_TotalTime.Add(gpFistSession);
		}
		{//Segunda sesion--------------------------------------------------------------------------------------------------------------------------------------
			var gpSecondSession=Jade.Objects.Container();
			gpSecondSession.Location(10,235,980,110);
			gpSecondSession.SetStyle('transparent');
			gpSecondSession.Add(tabsWorkday.tabpages[0]);
			
			var lbl_2_Title=Jade.Objects.Text(Jade.Lang.Get('second_session')+':');
			lbl_2_Title.Location(15,10,100,20);
			lbl_2_Title.Add(gpSecondSession);
			
			var lbl_2_StartEntry=Jade.Objects.Text(Jade.Lang.Get('start_entry')+':');
			lbl_2_StartEntry.Location(225,20,150,20);
			lbl_2_StartEntry.Add(gpSecondSession);

			var txt_2_StartEntry=Jade.Objects.TimeBox(false);
			txt_2_StartEntry.Location(400,15,60,20);
			txt_2_StartEntry.Add(gpSecondSession);
			
			var lbl_2_EndEntry=Jade.Objects.Text(Jade.Lang.Get('end_entry')+':');
			lbl_2_EndEntry.Location(475,20,150,20);
			lbl_2_EndEntry.Add(gpSecondSession);

			var txt_2_EndEntry=Jade.Objects.TimeBox(false);
			txt_2_EndEntry.Location(650,15,60,20);
			txt_2_EndEntry.Add(gpSecondSession);
			
			var lbl_2_SessionStart=Jade.Objects.Text(Jade.Lang.Get('session_start')+':');
			lbl_2_SessionStart.Location(725,20,150,20);
			lbl_2_SessionStart.Add(gpSecondSession);

			var txt_2_SessionStart=Jade.Objects.TimeBox(false);
			txt_2_SessionStart.Location(900,15,60,20);
			txt_2_SessionStart.Add(gpSecondSession);
			
			var lbl_2_StartExit=Jade.Objects.Text(Jade.Lang.Get('start_exit')+':');
			lbl_2_StartExit.Location(225,50,150,20);
			lbl_2_StartExit.Add(gpSecondSession);

			var txt_2_StartExit=Jade.Objects.TimeBox(false);
			txt_2_StartExit.Location(400,45,60,20);
			txt_2_StartExit.Add(gpSecondSession);
			
			var lbl_2_EndExit=Jade.Objects.Text(Jade.Lang.Get('end_exit')+':');
			lbl_2_EndExit.Location(475,50,150,20);
			lbl_2_EndExit.Add(gpSecondSession);

			var txt_2_EndExit=Jade.Objects.TimeBox(false);
			txt_2_EndExit.Location(650,45,60,20);
			txt_2_EndExit.Add(gpSecondSession);
			
			var lbl_2_SessionEnd=Jade.Objects.Text(Jade.Lang.Get('session_exit')+':');
			lbl_2_SessionEnd.Location(725,50,150,20);
			lbl_2_SessionEnd.Add(gpSecondSession);

			var txt_2_SessionEnd=Jade.Objects.TimeBox(false);
			txt_2_SessionEnd.Location(900,45,60,20);
			txt_2_SessionEnd.Add(gpSecondSession);
			
			var lbl_2_TotalTime=Jade.Objects.Text(Jade.Lang.Get('second_session_hours')+':');
			lbl_2_TotalTime.Location(225,80,300,20);
			lbl_2_TotalTime.Add(gpSecondSession);

			var txt_2_TotalTime=Jade.Objects.TimeBox(false);
			txt_2_TotalTime.Location(550,75,60,20);
			txt_2_TotalTime.Add(gpSecondSession);
		}
		{//Limites---------------------------------------------------------------------------------------------------------------------------------------------
			var gpWorkdayLimits=Jade.Objects.Container();
			gpWorkdayLimits.Location(10,350,980,50);
			gpWorkdayLimits.SetStyle('transparent');
			gpWorkdayLimits.Add(tabsWorkday.tabpages[0]);

			var lbl_Limits=Jade.Objects.Text(Jade.Lang.Get('workday_limits')+':');
			lbl_Limits.Location(15,10,100,20);
			lbl_Limits.Add(gpWorkdayLimits);
			
			var lbl_Limits_Start=Jade.Objects.Text(Jade.Lang.Get('workday_begins')+':');
			lbl_Limits_Start.Location(225,20,175,20);
			lbl_Limits_Start.Add(gpWorkdayLimits);

			var txt_Limits_Start=Jade.Objects.TimeBox(false);
			txt_Limits_Start.Location(400,15,60,20);
			txt_Limits_Start.Add(gpWorkdayLimits);
			
			var lbl_Limits_End=Jade.Objects.Text(Jade.Lang.Get('workday_ends')+':');
			lbl_Limits_End.Location(475,20,175,20);
			lbl_Limits_End.Add(gpWorkdayLimits);

			var txt_Limits_End=Jade.Objects.TimeBox(false);
			txt_Limits_End.Location(650,15,60,20);
			txt_Limits_End.Add(gpWorkdayLimits);
		}
	}
	{//Pestaņa: Variantes--------------------------------------------------------------------------------------------------------------------------------------
		tabsWorkday.AddTab(Jade.Lang.Get('variants'));
		
		var cmVariants=Jade.Grids.ColumnModel();
		cmVariants.Add(Jade.Grids.SimpleColumn({key: 'number', text: Jade.Lang.Get('num'), width: '50'}));
		cmVariants.Add(Jade.Grids.TextColumn({key: 'description', text: Jade.Lang.Get('description'), width: '420'}));
		cmVariants.Add(Jade.Grids.ComboColumn({key: 'workday', text: Jade.Lang.Get('workday'), width: '350'}));
		cmVariants.Add(Jade.Grids.ButtonColumn({key: 'button', text: '', width: '140', sortable: false}));
		var grVariants=Jade.Grids.Grid(cmVariants);
		grVariants.Location(5,40,990,420);
		grVariants.Add(tabsWorkday.tabpages[1]);
		
		var cmdNewVariant=Jade.Objects.Button();
		cmdNewVariant.Location(10,10,980,20);
		cmdNewVariant.SetText(Jade.Lang.Get('new_variant'));
		cmdNewVariant.Add(tabsWorkday.tabpages[1]);
		
		cmdNewVariant.onclick=function(){
			var row=grVariants.NewRow([grVariants.rows.length+1,'','00000',[$.lng('erease'),'delete']], '');
			var combo = row.cells[2].references.object;
			for(var j in aWorkdays){
				combo.AddItem(aWorkdays[j].Text,j);
			}
		}
		grVariants.columnmodel.columns[3].oncellclick=function(cell){
			cell.references.row.Delete();
		}
	}
	{//Pestaņa: Costes-----------------------------------------------------------------------------------------------------------------------------------------
		tabsWorkday.AddTab(Jade.Lang.Get('payrolls'));
		
		var cmPayrolls=Jade.Grids.ColumnModel();
		cmPayrolls.Add(Jade.Grids.ComboColumn({key: 'number', text: Jade.Lang.Get('payroll'), width: '410'}));
		cmPayrolls.Add(Jade.Grids.ComboColumn({key: 'description', text: Jade.Lang.Get('day_type'), width: '410'}));
		cmPayrolls.Add(Jade.Grids.ButtonColumn({key: 'button', text: '', width: '140', sortable: false}));
		var grPayrolls=Jade.Grids.Grid(cmPayrolls);
		grPayrolls.Location(5,40,990,420);
		grPayrolls.Add(tabsWorkday.tabpages[2]);
	
		var cmdNewPayroll=Jade.Objects.Button();
		cmdNewPayroll.Location(10,10,980,20);
		cmdNewPayroll.SetText(Jade.Lang.Get('new_profile_payroll'));
		cmdNewPayroll.Add(tabsWorkday.tabpages[2]);
	
		cmdNewPayroll.onclick=function(){
			var row=grPayrolls.NewRow(['0','0000',[$.lng('erease'),'delete']]);
			var combo=row.cells[0].references.object;
			for(var j in aPayrolls){ combo.AddItem(aPayrolls[j].Text,j); }
			combo=row.cells[1].references.object;
			for(var j in aDayTypes){ combo.AddItem(aDayTypes[j].Text,j); }
		}
		grPayrolls.columnmodel.columns[2].oncellclick=function(cell){
			cell.references.row.Delete();
		}
	}
	{//Pestaņa: Incidencias------------------------------------------------------------------------------------------------------------------------------------
		tabsWorkday.AddTab(Jade.Lang.Get('incidences'));
		
		var lblBreak=Jade.Objects.Text(Jade.Lang.Get('workday_break')+' :');
		lblBreak.Location(10,15,200,20);
		lblBreak.Add(tabsWorkday.tabpages[3]);
		var cmbBreak=Jade.Objects.ComboBox();
		cmbBreak.Location(210,10,780,20);
		cmbBreak.Add(tabsWorkday.tabpages[3]);		
		
		var chkEvents1=Jade.Objects.CheckBox(Jade.Lang.Get('justify_delay'));
		chkEvents1.Location(10,40,700,20);
		chkEvents1.Add(tabsWorkday.tabpages[3]);
		var chkEvents2=Jade.Objects.CheckBox(Jade.Lang.Get('justify_event'));
		chkEvents2.Location(10,60,700,20);
		chkEvents2.Add(tabsWorkday.tabpages[3]);
		var chkEvents3=Jade.Objects.CheckBox(Jade.Lang.Get('justify_events_inside'));
		chkEvents3.Location(10,80,700,20);
		chkEvents3.Add(tabsWorkday.tabpages[3]);
		var chkEvents4=Jade.Objects.CheckBox(Jade.Lang.Get('not_justify_entries_or_exits'));
		chkEvents4.Location(10,100,700,20);
		chkEvents4.Add(tabsWorkday.tabpages[3]);
		
		var gpMMTimes=Jade.Objects.Container();
		gpMMTimes.Location(10,120,980,150);
		gpMMTimes.SetStyle('transparent');
		gpMMTimes.Add(tabsWorkday.tabpages[3]);

		var cmMMTimes=Jade.Grids.ColumnModel();
		cmMMTimes.Add(Jade.Grids.ComboColumn({key: 'controlled', text: Jade.Lang.Get('controlled_incident'), width: '220'}));
		cmMMTimes.Add(Jade.Grids.ComboColumn({key: 'updated', text: Jade.Lang.Get('update_incident'), width: '220'}));
		cmMMTimes.Add(Jade.Grids.ComboColumn({key: 'control', text: Jade.Lang.Get('control'), width: '180'}));
		cmMMTimes.Add(Jade.Grids.CheckColumn({key: 'force', text: Jade.Lang.Get('force'), width: '70'}));
		cmMMTimes.Add(Jade.Grids.TimeColumn({key: 'time', text: Jade.Lang.Get('ntime'), width: '70'}));
		cmMMTimes.Add(Jade.Grids.CheckColumn({key: 'real', text: Jade.Lang.Get('real'), width: '70'}));
		cmMMTimes.Add(Jade.Grids.ButtonColumn({key: 'button', text: '', width: '120', sortable: true}));
		var grMMTimes=Jade.Grids.Grid(cmMMTimes);
		grMMTimes.Location(5,38,970,105);
		grMMTimes.Add(gpMMTimes);
		
		var cmdNewMMTime=Jade.Objects.Button();
		cmdNewMMTime.Location(10,10,960,20);
		cmdNewMMTime.SetText(Jade.Lang.Get('new_maxmin_time'));
		cmdNewMMTime.Add(gpMMTimes);
		
		cmdNewMMTime.onclick=function(){
			var row=grMMTimes.NewRow(['0','0','0','0','00000','0',[$.lng('erease'),'delete']], '');
			var combo=row.cells[0].references.object;
			for(var j in aEvents){ if(aEvents[j].Codigo>='0009'){ combo.AddItem(aEvents[j].Text,j); } }
						
			combo=row.cells[1].references.object;
			for(var j in aEvents){ if(aEvents[j].Codigo>'0005'){ combo.AddItem(aEvents[j].Text,j); } }
						
			combo=row.cells[2].references.object;
			combo.AddItem(Jade.Lang.Get('min_time'),'0');
			combo.AddItem(Jade.Lang.Get('max_time'),'1');
		}
		grMMTimes.columnmodel.columns[6].oncellclick=function(cell){
			cell.references.row.Delete();
		}
		
		var gpEventAccepted=Jade.Objects.Container();
		gpEventAccepted.Location(10,275,980,175);
		gpEventAccepted.SetStyle('transparent');
		gpEventAccepted.Add(tabsWorkday.tabpages[3]);
		
		var cmEventAccepted=Jade.Grids.ColumnModel();
		cmEventAccepted.Add(Jade.Grids.ComboColumn({key: 'day_type', text: Jade.Lang.Get('day_type'), width: '250'}));
		cmEventAccepted.Add(Jade.Grids.HourColumn({key: 'from', text: Jade.Lang.Get('from'), width: '110'}));
		cmEventAccepted.Add(Jade.Grids.HourColumn({key: 'to', text: Jade.Lang.Get('to'), width: '110'}));
		cmEventAccepted.Add(Jade.Grids.ComboColumn({key: 'incidence', text: Jade.Lang.Get('incidence'), width: '350'}));
		cmEventAccepted.Add(Jade.Grids.ButtonColumn({key: 'button', text: '', width: '120', sortable: true}));
		var grEventAccepted=Jade.Grids.Grid(cmEventAccepted);
		grEventAccepted.Location(5,38,970,130);
		grEventAccepted.Add(gpEventAccepted);
		
		var cmdNewEventAccepted=Jade.Objects.Button();
		cmdNewEventAccepted.Location(10,10,960,20);
		cmdNewEventAccepted.SetText(Jade.Lang.Get('new_event_accepted_time'));
		cmdNewEventAccepted.Add(gpEventAccepted);
		
		cmdNewEventAccepted.onclick=function(){
			var row=grEventAccepted.NewRow(['0','0000','0000','0','<div class="icon delete"></div>'+Jade.Lang.Get('erease')], '');
			var combo=row.cells[0].references.object;
			for(var j in aDayTypes){ combo.AddItem(aDayTypes[j].Text,j); }
			combo=row.cells[3].references.object;
			for(var j in aEvents){ if(aEvents[j].Codigo >'0009' || aEvents[j].Codigo=='0000' ){ combo.AddItem(aEvents[j].Text,j); } }
		}
		grEventAccepted.columnmodel.columns[4].oncellclick=function(cell){
			cell.references.row.Delete();
		}
	}
	{//Pestaņa: Presencia obligatorio
		tabsWorkday.AddTab(Jade.Lang.Get('obligatory_time'));

		var chkObligatory1=Jade.Objects.CheckBox(Jade.Lang.Get('enable_obligatory_time'));
		chkObligatory1.Location(10,10,500,20);
		chkObligatory1.Add(tabsWorkday.tabpages[4]);
	
		var gpObligatory=Jade.Objects.Container();
		gpObligatory.Location(10,25,980,195);
		gpObligatory.SetStyle('transparent');
		gpObligatory.Add(tabsWorkday.tabpages[4]);

		var lbl_1_Title=Jade.Objects.Text(Jade.Lang.Get('incidence_to_update')+':');
		lbl_1_Title.Location(10,15,200,20);
		lbl_1_Title.Add(gpObligatory);
	
		var cmbObligatoryIncidence=Jade.Objects.ComboBox();
		cmbObligatoryIncidence.Location(210,15,760,20);
		cmbObligatoryIncidence.Add(gpObligatory);

		var gp_1_Obligatory=Jade.Objects.Container();
		gp_1_Obligatory.Location(10,40,475,130);
		gp_1_Obligatory.SetStyle('transparent');
		gp_1_Obligatory.Add(gpObligatory);
		var lbl_1_Obligatory=Jade.Objects.Text(Jade.Lang.Get('first_session')+':');
		lbl_1_Obligatory.Location(10,10,200,20);
		lbl_1_Obligatory.Add(gp_1_Obligatory);
		var lbl_1_Obligatory_From=Jade.Objects.Text(Jade.Lang.Get('from')+':');
		lbl_1_Obligatory_From.Location(110,35,150,20);
		lbl_1_Obligatory_From.Add(gp_1_Obligatory);	
		var txt_1_Obligatory_From=Jade.Objects.TimeBox(false);
		txt_1_Obligatory_From.Location(270,30,100,20)
		txt_1_Obligatory_From.Add(gp_1_Obligatory);	
		var lbl_1_Obligatory_To=Jade.Objects.Text(Jade.Lang.Get('to')+':');
		lbl_1_Obligatory_To.Location(110,65,150,20);
		lbl_1_Obligatory_To.Add(gp_1_Obligatory);
		var txt_1_Obligatory_To=Jade.Objects.TimeBox(false);
		txt_1_Obligatory_To.Location(270,60,100,20)
		txt_1_Obligatory_To.Add(gp_1_Obligatory);
		var cmd_1_Obligatory=Jade.Objects.Button(Jade.Lang.Get('copy_from_first_session'));
		cmd_1_Obligatory.Location(10,95,455,20);
		cmd_1_Obligatory.Add(gp_1_Obligatory);	
		
		var gp_2_Obligatory=Jade.Objects.Container();
		gp_2_Obligatory.Location(495,40,475,130);
		gp_2_Obligatory.SetStyle('transparent');
		gp_2_Obligatory.Add(gpObligatory);
		var lbl_2_Obligatory=Jade.Objects.Text(Jade.Lang.Get('second_session')+':');
		lbl_2_Obligatory.Location(10,10,200,20);
		lbl_2_Obligatory.Add(gp_2_Obligatory);
		var lbl_2_Obligatory_From=Jade.Objects.Text(Jade.Lang.Get('from')+':');
		lbl_2_Obligatory_From.Location(110,35,150,20);
		lbl_2_Obligatory_From.Add(gp_2_Obligatory);	
		var txt_2_Obligatory_From=Jade.Objects.TimeBox(false);
		txt_2_Obligatory_From.Location(270,30,100,20)
		txt_2_Obligatory_From.Add(gp_2_Obligatory);	
		var lbl_2_Obligatory_To=Jade.Objects.Text(Jade.Lang.Get('to')+':');
		lbl_2_Obligatory_To.Location(110,65,150,20);
		lbl_2_Obligatory_To.Add(gp_2_Obligatory);
		var txt_2_Obligatory_To=Jade.Objects.TimeBox(false);
		txt_2_Obligatory_To.Location(270,60,100,20)
		txt_2_Obligatory_To.Add(gp_2_Obligatory);
		var cmd_2_Obligatory=Jade.Objects.Button();
		cmd_2_Obligatory.Location(10,95,455,20);
		cmd_2_Obligatory.SetText();
		cmd_2_Obligatory.Add(gp_2_Obligatory);

		chkObligatory1.onchange=function(){
			if(this.GetCheck()){ Jade.FX.Show(gpObligatory); }
			else{ Jade.FX.Hide(gpObligatory); }
		}
		cmd_1_Obligatory.onclick=function(){
			txt_1_Obligatory_From.SetValue(txt_1_SessionStart.GetValue());
			txt_1_Obligatory_To.SetValue(txt_1_SessionEnd.GetValue());
		}
		cmd_2_Obligatory.onclick=function(){
			txt_2_Obligatory_From.SetValue(txt_2_SessionStart.GetValue());
			txt_2_Obligatory_To.SetValue(txt_2_SessionEnd.GetValue());
		}
	}
	{//Pestaņa: Fuera de horario
		/*
		tabsWorkday.AddTab(Jade.Lang.Get('out_of_bounds'));
		var chkExEvents_Allow=Jade.Objects.CheckBox(Jade.Lang.Get('allow_extensible_events'));
		chkExEvents_Allow.Location(10,10,500,20);
		chkExEvents_Allow.Add(tabsWorkday.tabpages[5]);

		var gp_StartExEvents=Jade.Objects.Container();
		gp_StartExEvents.Location(10,25,980,70);
		gp_StartExEvents.SetStyle('transparent');
		gp_StartExEvents.Add(tabsWorkday.tabpages[5]);
		var lbl_StartExEvents=Jade.Objects.Text(Jade.Lang.Get('start_event_out')+':');
		lbl_StartExEvents.Location(10,10,600,20);
		lbl_StartExEvents.Add(gp_StartExEvents);
		var opt_StartExEvents_1=Jade.Objects.Option(Jade.Lang.Get('start_event_punch'));
		opt_StartExEvents_1.Location(20,35,400,20);
		opt_StartExEvents_1.Add(gp_StartExEvents);
		var opt_StartExEvents_2=Jade.Objects.Option(Jade.Lang.Get('start_event_session'));
		opt_StartExEvents_2.Location(420,35,400,20);
		opt_StartExEvents_2.Add(gp_StartExEvents);

		var gp_EndExEvents=Jade.Objects.Container();
		gp_EndExEvents.Location(10,105,980,120);
		gp_EndExEvents.SetStyle('transparent');
		gp_EndExEvents.Add(tabsWorkday.tabpages[5]);
		var lbl_EndExEvents=Jade.Objects.Text(Jade.Lang.Get('close_event_out')+':');
		lbl_EndExEvents.Location(10,10,600,20);
		lbl_EndExEvents.Add(gp_EndExEvents);
		var opt_EndExEvents_1=Jade.Objects.Option(Jade.Lang.Get('close_event_punch'));
		opt_EndExEvents_1.Location(20,35,400,20);
		opt_EndExEvents_1.Add(gp_EndExEvents);
		var opt_EndExEvents_2=Jade.Objects.Option(Jade.Lang.Get('close_event_session'));
		opt_EndExEvents_2.Location(20,60,400,20);
		opt_EndExEvents_2.Add(gp_EndExEvents);
		var opt_EndExEvents_3=Jade.Objects.Option(Jade.Lang.Get('close_event_hours'));
		opt_EndExEvents_3.Location(20,85,270,20);
		opt_EndExEvents_3.Add(gp_EndExEvents);
		var txt_EndExEvents_3=Jade.Objects.TimeBox(false);
		txt_EndExEvents_3.Location(290,80,100,20)
		txt_EndExEvents_3.Add(gp_EndExEvents);
		Jade.FX.Hide(txt_EndExEvents_3);
		
		chkExEvents_Allow.onchange=function(){
			if(this.GetCheck()){ 
				Jade.FX.Show(gp_StartExEvents);
				Jade.FX.Show(gp_EndExEvents);
			}
			else{
				Jade.FX.Hide(gp_StartExEvents);
				Jade.FX.Hide(gp_EndExEvents);
			}
		}
		opt_EndExEvents_3.onchange=function(){
			if(this.GetCheck()){ Jade.FX.Show(txt_EndExEvents_3); }
			else{ Jade.FX.Hide(txt_EndExEvents_3); }
		}
		*/
	}
	tabsWorkday.tabs[0].onclick();
}
{//Ajax basic--------------------------------------------------------------------------------------------------------------------------------------------------
	ajaxManager.Create('basic');
	{//DayTypes------------------------------------------------------------------------------------------------------------------------------------------------
		var aDayTypes=[];
		var ajaxDayTypes=Jade.AjaxDB("SELECT * FROM TIPO_DIA{c} ORDER BY Codigo");
		ajaxDayTypes.Add(ajaxManager,'basic');
		ajaxDayTypes.oncomplete=function(){
			if(!this.json.error){
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					aDayTypes[item.Codigo]={};
					aDayTypes[item.Codigo].Text=item.Codigo+" - "+item.Descripcion;
					aDayTypes[item.Codigo].Codigo=item.Codigo;
					aDayTypes[item.Codigo].Descripcion=item.Descripcion;
					aDayTypes[item.Codigo].Laborable=item.Laborable;
				}
			}
			else{ Jade.Debug.Add(this.text); }
		}
	}
	{//Events--------------------------------------------------------------------------------------------------------------------------------------------------
		var aEvents=[];
		var ajaxEvents=Jade.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{ Jade.Debug.Add(this.text); }
		}
	}
	{//Workdays------------------------------------------------------------------------------------------------------------------------------------------------
		var aWorkdays=[];
		var ajaxWorkdays=Jade.AjaxDB("SELECT * 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;
					aWorkdays[item.Codigo].TotalPrimera=item.TotalPrimera;
					aWorkdays[item.Codigo].TotalSegunda=item.TotalSegunda;
				}
			}
			else{ Jade.Debug.Add(this.text); }
		}
	}
	{//Payrolls------------------------------------------------------------------------------------------------------------------------------------------------
		var aPayrolls=[];
		var ajaxPayrolls=Jade.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{ Jade.Debug.Add(this.text); }
		}
	}
	{//Events--------------------------------------------------------------------------------------------------------------------------------------------------
		var aBreaks=[];
		var ajaxBreaks=Jade.AjaxDB("SELECT * FROM INTERRUPCIONES{c} ORDER BY Codigo");
		ajaxBreaks.Add(ajaxManager,'basic');
		ajaxBreaks.oncomplete=function(){
			if(!this.json.error){
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					aBreaks[item.Codigo]={};
					aBreaks[item.Codigo].Text=item.Codigo+" - "+item.Descripcion;
					aBreaks[item.Codigo].Codigo=item.Codigo;
					aBreaks[item.Codigo].Descripcion=item.Descripcion;
					aBreaks[item.Codigo].Valorada=item.Valorada;
				}
			}
			else{ Jade.Debug.Add(this.text); }
		}
	}
}
{//Ajax Manager------------------------------------------------------------------------------------------------------------------------------------------------
	ajaxManager.group['basic'].Start();
	ajaxManager.group['basic'].oncomplete=function(){
		for(var i in aEvents){ cmbObligatoryIncidence.AddItem(aEvents[i].Text,i); }
		for(var i in aBreaks){ cmbBreak.AddItem(aBreaks[i].Text,i); }
		cmbWorkdays.onchangekey=function(){ LoadWorkday(); }
		for(var i in aWorkdays){ cmbWorkdays.AddItem(aWorkdays[i].Text,i); }
	}
}
{//Ajax functions----------------------------------------------------------------------------------------------------------------------------------------------
	function LoadWorkday(){
		var workday_id=cmbWorkdays.selectedKey;
		var ajaxWorkday=Jade.AjaxDB("SELECT * FROM HORARIOS{c} WHERE Codigo='"+workday_id+"'",Ajax.Dontwait);
		ajaxWorkday.oncomplete=function(){
			if(!this.json.error){
				if(this.json.row.length!=0){
					var item =this.json.row[0];
					txtCode.SetText(item.Codigo);
					txtDescription.SetText(item.Descripcion);
					
					chkSearchVariant.SetCheck(item.ControlVariante==1);
					chkJustifyIncidence.SetCheck(item.JustificarIncidencias==1);
					chkExtendWorkday.SetCheck(item.HorarioExtendido==1);
					
					cmbObligatoryIncidence.SetSelectedKey(item.IdInterrupcion);
					chkEvents1.SetCheck(item.JustificarRetrasoCalendario==1);
					chkEvents2.SetCheck(item.JustificarIncidenciaEntrada==1);
					chkEvents3.SetCheck(item.JustificarSoloSesion==1);
					chkEvents4.SetCheck(item.JustificarTiempoSession==1);
					
					txt_1_StartEntry.SetValue(item.InicioEntrada1);
					txt_1_EndEntry.SetValue(item.FinEntrada1);
					txt_1_SessionStart.SetValue(item.EntradaTeorica1);
					txt_1_StartExit.SetValue(item.InicioSalida1);
					txt_1_EndExit.SetValue(item.FinSalida1);
					txt_1_SessionEnd.SetValue(item.SalidaTeorica1);
					txt_1_TotalTime.SetValue(Jade.DateTime.MinutesToHour(item.TotalPrimera));
					
					txt_2_StartEntry.SetValue(item.InicioEntrada2);
					txt_2_EndEntry.SetValue(item.FinEntrada2);
					txt_2_SessionStart.SetValue(item.EntradaTeorica2);
					txt_2_StartExit.SetValue(item.InicioSalida2);
					txt_2_EndExit.SetValue(item.FinSalida2);
					txt_2_SessionEnd.SetValue(item.SalidaTeorica2);
					txt_2_TotalTime.SetValue(Jade.DateTime.MinutesToHour(item.TotalSegunda));
					
					txt_Limits_Start.SetValue(item.Desde);
					txt_Limits_End.SetValue(item.Hasta);

					chkObligatory1.SetCheck(item.ObligatorioDesde1!='');
					cmbObligatoryIncidence.SetSelectedKey(item.ObligatorioIdIncidencia);
					txt_1_Obligatory_From.SetValue(item.ObligatorioDesde1);
					txt_1_Obligatory_To.SetValue(item.ObligatorioHasta1);
					txt_2_Obligatory_From.SetValue(item.ObligatorioDesde2);
					txt_2_Obligatory_To.SetValue(item.ObligatorioHasta2);
					
					//chkExEvents_Allow.SetCheck(item.JustificarFueraHorario==1);
					
					switch(item.TipoHorario){
						case '0':
							optShift1.SetCheck(true);
							break;
						case '1':
							optShift2.SetCheck(true);
							break;
						case '2':
							optShift3.SetCheck(true);
							break;
					}
					/*
					switch(item.ModoInicioIncidenciaFuera){
						case '0':
							opt_StartExEvents_1.SetCheck(true);
							break;
						case '1':
							opt_StartExEvents_2.SetCheck(true);
							break;
					}
					
					switch(item.ModoFinIncidenciaFuera){
						case '0':
							opt_EndExEvents_1.SetCheck(true);
							break;
						case '1':
							opt_EndExEvents_2.SetCheck(true);
							break;						
						case '3':
							opt_EndExEvents_3.SetCheck(true);
							break;
					}
					*/
				}
			}
			else{ Jade.Debug.Add(this.text); }
		}
		var ajaxObligatory=Jade.AjaxDB("SELECT * FROM HORARIO_VARIANTES{c} WHERE IdHorarioPadre='"+workday_id+"'",Ajax.Dontwait);
		ajaxObligatory.oncomplete=function(){
			if(!this.json.error){
				grVariants.ClearRows();
				if(this.json.row.length!=0){
					for(var i=0,iLen=this.json.row.length;i<iLen;i++){
						var item=this.json.row[i];
						var row=grVariants.NewRow([item.IdVariante,item.Descripcion,'',[$.lng('erease'),'delete']]);
						var combo = row.cells[2].references.object;
						for(var j in aWorkdays){ combo.AddItem(aWorkdays[j].Text,j); }
						combo.SetSelectedKey(item.IdHorario);
					}
				}
			}
			else{ Jade.Debug.Add(this.text); }
		}
		var ajaxPayroll=Jade.AjaxDB("SELECT * FROM HORARIO_COSTES{c} WHERE IdHorario='"+workday_id+"'",Ajax.Dontwait);
		ajaxPayroll.oncomplete=function(){
			grPayrolls.ClearRows();
			if(!this.json.error){
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					var row=grPayrolls.NewRow([item.IdCoste,item.IdTipoDia,[$.lng('erease'),'delete']]);
					var combo=row.cells[0].references.object;
					for(var j in aPayrolls){ combo.AddItem(aPayrolls[j].Text,j); }
					combo.SetSelectedKey(item.IdCoste);
					combo=row.cells[1].references.object;
					for(var j in aDayTypes){ combo.AddItem(aDayTypes[j].Text,j); }
					combo.SetSelectedKey(item.IdTipoDia);					
				}
			}
			else{ Jade.Debug.Add(this.text); }
		}
		var ajaxMMEvent=Jade.AjaxDB("SELECT * FROM HORARIO_INCIDENCIAS{c} WHERE IdHorario='"+workday_id+"'",Ajax.Dontwait);
		ajaxMMEvent.oncomplete=function(){
			if(!this.json.error){
				grMMTimes.ClearRows();
				for(var i=0,iLen=this.json.row.length;i<iLen;i++){
					var item=this.json.row[i];
					var row=grMMTimes.NewRow([item.IdIncidenciaControlar,item.IdIncidenciaActualizar,item.Maximo,item.ForzarMinimo,item.Tiempo,item.TiempoReal,[$.lng('erease'),'delete']]);
					var combo = row.cells[0].references.object;
					for(var j in aEvents){ if(aEvents[j].Codigo >='0009'){ combo.AddItem(aEvents[j].Text,j); } }
					combo.SetSelectedKey(item.IdIncidenciaControlar);
					combo = row.cells[1].references.object;
					for(var j in aEvents){ if(aEvents[j].Codigo >'0005'){ combo.AddItem(aEvents[j].Text,j); } }
					combo.SetSelectedKey(item.IdIncidenciaActualizar);
					combo = row.cells[2].references.object;
					combo.AddItem(Jade.Lang.Get('min_time'),'0');
					combo.AddItem(Jade.Lang.Get('max_time'),'1');
					combo.SetSelectedKey(item.Maximo);
				}
			}
			else{ Jade.Debug.Add(this.text); }
		}
		var ajaxEvent=Jade.AjaxDB("SELECT * FROM PERF_INC_LIM{c} WHERE IdHorario='"+workday_id+"'",Ajax.Dontwait);
		ajaxEvent.oncomplete=function(){
			if(!this.json.error){
				grEventAccepted.ClearRows();
				if(this.json.row.length!=0){
					for(var i=0,iLen=this.json.row.length;i<iLen;i++){
						var item=this.json.row[i];
						var row=grEventAccepted.NewRow([item.IdTipoDia,item.Desde,item.Hasta,item.IdIncidencia,[$.lng('erease'),'delete']]);
						var combo = row.cells[0].references.object;
						for(var j in aDayTypes){
							combo.AddItem(aDayTypes[j].Text,j);
						}
						combo.SetSelectedKey(item.IdTipoDia);
						
						combo = row.cells[3].references.object;
						for(var j in aEvents){
							if(aEvents[j].Codigo >'0009' || aEvents[j].Codigo=='0000' ){ combo.AddItem(aEvents[j].Text,j); }
						}
						combo.SetSelectedKey(item.IdIncidencia);
						
					}
				}
			}
			else{ Jade.Debug.Add(this.text); }
		}		
	}
}
