
var ptt_struct_blank=function(){
	return {personal:[],
	profile_rounding: {add:[], mod:[], del:[], apply: [], unapply: []},
	profile_events: {add:[], mod:[], del:[], apply: [], unapply: []},
	profile_accruals: {add:[], mod:[], del:[], apply: [], unapply: []},
	profile_breaks: {add:[], mod:[], del:[], apply: [], unapply: []},
	profile_payrolls: {add:[], mod:[], del:[], apply: [], unapply: []},
	profile_accessdays: {add:[], mod:[], del:[], apply: [], unapply: []},
	profile_access: {add:[], mod:[], del:[], apply: [], unapply: []},
	profile_accesstime: {add:[], mod:[], del:[], apply: [], unapply: []},
	
	calendar:[],
	duttytime:[],
	status: {add:[], mod:[], del:[]},
	terminal:[],
	notes: {add:[], mod:[], del:[]},
	comments:[]
	};
}
var petition=new ptt_struct_blank();
var xml=new ptt_struct_blank();

{//Funciones formato
	function set_personal_data(control,title,field,value){
		var item='personal';
		if(typeof(value)!="undefined"){
			switch(control.controltype){
				case 'textbox':case 'password':case 'textarea':
					control.SetText(value);
					break;
				case 'checkbox':
					value=value==1;
					control.SetCheck(value);
					break;
				case 'combobox':
					control.SetSelectedKey(value);
					break;
				case 'datepicker':
					control.SetValue(value);
					break;
			}
		}
		if(Jade.isArray(title) && title.length>1){ title=Jade.Lang.Get(title[0])+title[1]; }
		else{ title=Jade.Lang.Get(title); }

		if(Jade.isArray(field) && field.length>1){
			item=field[0];
			field=field[1];
		}
		petition[item][field]={control: control, title: title, value: value};
	}
	function get_control_data(control){
		var value;
		switch(control.controltype){
			case 'textbox':case 'textarea':case 'password':
				return control.GetText();
				break;
			case 'checkbox':
				return control.GetCheck()?'1':'0';
				break;			
			case 'combobox':
				return control.selectedKey;
				break;
			case 'datepicker':
				return control.GetValue();
				break;
		}
	}
	function set_value_format(value, control){
		var type=Jade.isObject(control)?control.controltype:control;
		switch(type){
			case 'password':
				value='●●●●●';
				break; 
			case 'checkbox':case 'bool':
				value=(value==true)?Jade.Lang.Get('yes'):Jade.Lang.Get('no');
				break;
			case 'datepicker':
				value=Jade.Strings.ToDate(value);
				break;
			case 'combobox':
				for(var i=0,iLen=control.items.length;i<iLen;i++){
					if(control.items[i].key==value){ value=control.items[i].text; }
				}
				break;
		}
		return value;
	}
}
{//Ventana de peticiones
	{//Controls
		var pttWindow=Jade.Objects.Window(900,350);
		{//Titulo
			var pptTitle=Jade.Objects.Text(Jade.Lang.Get('made_petitions')+':');
			pptTitle.Location(10,10,400,20);
			pptTitle.Add(pttWindow);

			var pttTabs=Jade.Objects.Tabs();
			pttTabs.Location(10,30,880,280);
			pttTabs.Add(pttWindow);
			
			var pttAccept=Jade.Objects.Button(Jade.Lang.Get('accept'));
			pttAccept.Location(10,318,435,22);
			pttAccept.Add(pttWindow);
			var pttCancel=Jade.Objects.Button(Jade.Lang.Get('cancel'));
			pttCancel.Location(455,318,435,22);
			pttCancel.Add(pttWindow);
		}
		{//Datos personales
			pttTabs.AddTab(Jade.Lang.Get('personal_data'));
			var pttPersonal = Jade.Objects.SimpleGrid();
			pttPersonal.Location(10,5,860,240);
			pttPersonal.AddHeader('&nbsp;',100,'head');
			pttPersonal.AddHeader(Jade.Lang.Get('field'),260);
			pttPersonal.AddHeader(Jade.Lang.Get('value'),500);
			pttPersonal.Add(pttTabs.tabpages[0]);
		}
		{//Perfil
			pttTabs.AddTab(Jade.Lang.Get('profile'));
			var pptTabsProfile=Jade.Objects.Tabs();
			pptTabsProfile.Location(5,5,870,245);
			
			pptTabsProfile.AddTab(Jade.Lang.Get('roundings'));
			var pttProfileRounding=Jade.Objects.SimpleGrid();
			pttProfileRounding.Location(10,5,850,205);
			pttProfileRounding.AddHeader('&nbsp;',100,'head');
			pttProfileRounding.AddHeader(Jade.Lang.Get('day_type'),250);
			pttProfileRounding.AddHeader(Jade.Lang.Get('from'),100);
			pttProfileRounding.AddHeader(Jade.Lang.Get('to'),100);
			pttProfileRounding.AddHeader(Jade.Lang.Get('rounding'),100);
			pttProfileRounding.AddHeader(Jade.Lang.Get('entry_exit'),200);
			pttProfileRounding.Add(pptTabsProfile.tabpages[0]);
			
			pptTabsProfile.AddTab(Jade.Lang.Get('auto_events'));
			var pttProfileEvents=Jade.Objects.SimpleGrid();
			pttProfileEvents.Location(10,5,850,205);
			pttProfileEvents.AddHeader('&nbsp;',100,'head');
			pttProfileEvents.AddHeader(Jade.Lang.Get('day_type'),250);
			pttProfileEvents.AddHeader(Jade.Lang.Get('from'),60);
			pttProfileEvents.AddHeader(Jade.Lang.Get('to'),60);
			pttProfileEvents.AddHeader(Jade.Lang.Get('incidence'),260);
			pttProfileEvents.AddHeader(Jade.Lang.Get('entry_exit'),120);
			pttProfileEvents.Add(pptTabsProfile.tabpages[1]);
			
			pptTabsProfile.AddTab(Jade.Lang.Get('absence'));
			
			pptTabsProfile.AddTab(Jade.Lang.Get('accrual_balance'));
			var pttProfileAccrual=Jade.Objects.SimpleGrid();
			pttProfileAccrual.Location(10,5,850,205);
			pttProfileAccrual.AddHeader('&nbsp;',100,'head');
			pttProfileAccrual.AddHeader(Jade.Lang.Get('accrual'),350);
			pttProfileAccrual.AddHeader(Jade.Lang.Get('ocurrences_allowed'),120);
			pttProfileAccrual.AddHeader(Jade.Lang.Get('time_allowed'),120);
			pttProfileAccrual.AddHeader(Jade.Lang.Get('term'),100);
			pttProfileAccrual.AddHeader(Jade.Lang.Get('year'),60);
			pttProfileAccrual.Add(pptTabsProfile.tabpages[3]);
			

			pptTabsProfile.AddTab(Jade.Lang.Get('breaks'));
			var pttProfileBreaks=Jade.Objects.SimpleGrid();
			pttProfileBreaks.Location(10,5,850,205);
			pttProfileBreaks.AddHeader('&nbsp;',100,'head');
			pttProfileBreaks.AddHeader(Jade.Lang.Get('day_type'), 375);
			pttProfileBreaks.AddHeader(Jade.Lang.Get('break_time'), 375);
			pttProfileBreaks.Add(pptTabsProfile.tabpages[4]);
			
			pptTabsProfile.AddTab(Jade.Lang.Get('payrolls'));
			var pttProfilePayrolls=Jade.Objects.SimpleGrid();
			pttProfilePayrolls.Location(10,5,850,205);
			pttProfilePayrolls.AddHeader('&nbsp;',100,'head');
			pttProfilePayrolls.AddHeader(Jade.Lang.Get('day_type'), 375);
			pttProfilePayrolls.AddHeader(Jade.Lang.Get('payroll'), 375);
			pttProfilePayrolls.Add(pptTabsProfile.tabpages[5]);
			
			pptTabsProfile.AddTab(Jade.Lang.Get('no_access_days'));
			var pttProfileAccessDays=Jade.Objects.SimpleGrid();
			pttProfileAccessDays.Location(10,5,850,205);
			pttProfileAccessDays.AddHeader('&nbsp;',100,'head');
			pttProfileAccessDays.AddHeader(Jade.Lang.Get('from'), 375);
			pttProfileAccessDays.AddHeader(Jade.Lang.Get('to'), 375);
			pttProfileAccessDays.Add(pptTabsProfile.tabpages[6]);
			
			pptTabsProfile.AddTab(Jade.Lang.Get('access'));
			
			pptTabsProfile.AddTab(Jade.Lang.Get('only_access_time'));
			var pttProfileAccessTime=Jade.Objects.SimpleGrid();
			pttProfileAccessTime.Location(10,5,850,205);
			pttProfileAccessTime.AddHeader('&nbsp;',100,'head');
			pttProfileAccessTime.AddHeader(Jade.Lang.Get('day_type'), 350);
			pttProfileAccessTime.AddHeader(Jade.Lang.Get('from'), 200);
			pttProfileAccessTime.AddHeader(Jade.Lang.Get('to'), 200);
			pttProfileAccessTime.Add(pptTabsProfile.tabpages[8]);
			
			pptTabsProfile.Add(pttTabs.tabpages[1]);
		}
		{//Calendario
			pttTabs.AddTab(Jade.Lang.Get('calendar'));
			var pttCalendar=Jade.Objects.SimpleGrid();
			pttCalendar.Location(10,5,860,240);
			pttCalendar.AddHeader('&nbsp;',100,'head');
			pttCalendar.AddHeader(Jade.Lang.Get('date'),90);
			pttCalendar.AddHeader(Jade.Lang.Get('day_type'),90);
			pttCalendar.AddHeader(Jade.Lang.Get('variant'),90);
			pttCalendar.AddHeader(Jade.Lang.Get('small_force_variant'),90);
			pttCalendar.AddHeader(Jade.Lang.Get('incidence'),90);
			pttCalendar.AddHeader(Jade.Lang.Get('workday'),90);
			pttCalendar.AddHeader(Jade.Lang.Get('comments'),220);
			pttCalendar.Add(pttTabs.tabpages[2]);			
		}
		{//Horas estandar
			pttTabs.AddTab(Jade.Lang.Get('dutytime'));
			var pttDuttytime=Jade.Objects.SimpleGrid();
			pttDuttytime.Location(10,5,860,240);
			pttDuttytime.AddHeader('&nbsp;',100,'head');
			pttDuttytime.AddHeader(Jade.Lang.Get('year'),60);
			pttDuttytime.AddHeader(Jade.Lang.Get('month'),160);
			pttDuttytime.AddHeader(Jade.Lang.Get('value'),540);
			pttDuttytime.Add(pttTabs.tabpages[3]);			
		}
		{//Estado
			pttTabs.AddTab(Jade.Lang.Get('status'));
			var pttStatus = Jade.Objects.SimpleGrid();
			pttStatus.Location(10,5,860,240);
			pttStatus.AddHeader('&nbsp;',100,'head');
			pttStatus.AddHeader(Jade.Lang.Get('value'),760);
			pttStatus.Add(pttTabs.tabpages[4]);
		}
		{//Datos en el terminal
			pttTabs.AddTab(Jade.Lang.Get('terminal_data'));
			var pttTerminal = Jade.Objects.SimpleGrid();
			pttTerminal.Location(10,5,860,240);
			pttTerminal.AddHeader('&nbsp;',100,'head');
			pttTerminal.AddHeader(Jade.Lang.Get('field'),380);
			pttTerminal.AddHeader(Jade.Lang.Get('value'),380);
			pttTerminal.Add(pttTabs.tabpages[5]);
		}
		{//Notas
			pttTabs.AddTab(Jade.Lang.Get('notes'));
			var pttNotes=Jade.Objects.SimpleGrid();
			pttNotes.Location(10,5,860,240);
			pttNotes.AddHeader('&nbsp;',100,'head');
			pttNotes.AddHeader(Jade.Lang.Get('date'),95);
			pttNotes.AddHeader(Jade.Lang.Get('time'),95);
			pttNotes.AddHeader(Jade.Lang.Get('text'),570);
			pttNotes.Add(pttTabs.tabpages[6]);
		}
		{//Comentarios
			pttTabs.AddTab(Jade.Lang.Get('comments'));
			var pttComments = Jade.Objects.SimpleGrid();
			pttComments.Location(10,5,860,240);
			pttComments.AddHeader('&nbsp;',100,'head');
			pttComments.AddHeader(Jade.Lang.Get('field'),160);
			pttComments.AddHeader(Jade.Lang.Get('value'),600);
			pttComments.Add(pttTabs.tabpages[7]);
		}
	}
	{//Eventos
		pttCancel.onclick=function(){ pttWindow.Hide(); }
	}
}
function ShowPetitions(){
	if($.Utils.PrivilegeValue('empl_priv')>1){
		var errors=[];
		var newEmployee=(typeof(id)=="undefined");
	
		if($.Strings.Trim(txtCode.GetText())==''){ errors.push(Jade.Strings.Format(Jade.Lang.Get('error_is_blank'),Jade.Lang.Get('code'))); }
		if(newEmployee && txtCode.GetText()!='' && aEmployees[txtCode.GetText()]!=undefined){ errors.push(Jade.Strings.Format(Jade.Lang.Get('error_employee_code_exist'),txtCode.GetText())); }
		if($.Strings.Trim(txtName.GetText())==''){ errors.push(Jade.Strings.Format(Jade.Lang.Get('error_is_blank'),Jade.Lang.Get('name'))); }
	
		if(aDepartments.length=0){ errors.push(Jade.Strings.Format(Jade.Lang.Get('error_is_blank'), COMPANY.department)); }
		if(aCenters.length=0){ errors.push(Jade.Strings.Format(Jade.Lang.Get('error_is_blank'), COMPANY.department)); }
	
	
		if(errors.length!=0){
			var text=Jade.Lang.Get('required_fields')+':<br/>';
			text+='<li>'+errors.join('</li><li>')+'</li>';
			Jade.Objects.MessageBox(text,'info',150);
		}
		else{
			var count_changes=0;
			var firstTab;
			var mustShow=false;

			{//Reset grids
				pttPersonal.Clear();
				pttCalendar.Clear();
				pttDuttytime.Clear();
				pttStatus.Clear();
				pttTerminal.Clear();
				pttNotes.Clear();
				pttComments.Clear();
			
				pttProfileRounding.Clear();
				pttProfileEvents.Clear();
				pttProfileAccrual.Clear();
				pttProfileBreaks.Clear();
				pttProfilePayrolls.Clear();
				pttProfileAccessDays.Clear();
				pttProfileAccessTime.Clear();

				xml=ptt_struct_blank();
			}
			{//Datos personales
				count_changes=0;
				for(var i in petition.personal){
					var oldValue=petition.personal[i].value;
					var newValue=get_control_data(petition.personal[i].control);
					if(oldValue!=newValue && (!newEmployee || (newEmployee && newValue!=''))){
						var control=petition.personal[i].control;
						if(newEmployee){
							pttPersonal.AddStyledItem([Jade.Lang.Get('new_m'),petition.personal[i].title,Jade.Strings.VisualTrim(set_value_format(newValue,control),490)],'petition_new');
							xml.personal.push({field: i,newValue: newValue});
						}
						else{
							pttPersonal.AddStyledItem([Jade.Lang.Get('modify'),petition.personal[i].title,Jade.Strings.VisualTrim(set_value_format(oldValue,control),490)],'petition_mod');
							pttPersonal.AddStyledItem(['','',Jade.Strings.VisualTrim(set_value_format(newValue,control),490)],'petition_mod');
							xml.personal.push({field: i,oldValue: oldValue,newValue: newValue});
						}
						count_changes++;
					}
				}
				if(count_changes!=0){ 
					if(typeof(firstTab)=="undefined"){ firstTab=0; }
					mustShow=true;
				}
				pttTabs.tabs[0].Visible(count_changes!=0);
			}
			{//Profiles
				count_changes=0;
				var profiles_changes=0;
				var firstProfileTab;
				{//Roundings
					for(var i=0, iLen=grRoundings.rows.length;i<iLen;i++){
						var cell=grRoundings.rows[i].cells;
						if(cell[6].value!=cell[7].value){
							switch(cell[6].value){
								case 0:
									pttProfileRounding.AddStyledItem([Jade.Lang.Get('unapply'),cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value), Jade.Strings.ToTime(cell[3].value), cell[4].value], 'petition_del');
									xml.profile_rounding.unapply.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value, rounding: cell[3].value, entryexit: cell[4].references.object.selectedKey});
									break;
								case 1:
									pttProfileRounding.AddStyledItem([Jade.Lang.Get('apply'),cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value), Jade.Strings.ToTime(cell[3].value), cell[4].value], 'petition_new');
									xml.profile_rounding.apply.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value, rounding: cell[3].value, entryexit: cell[4].references.object.selectedKey});
									break;
								case 2:
									pttProfileRounding.AddStyledItem([Jade.Lang.Get('new_m'),cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value), Jade.Strings.ToTime(cell[3].value), cell[4].value], 'petition_new');
									xml.profile_rounding.add.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value, rounding: cell[3].value, entryexit: cell[4].references.object.selectedKey});
									break;
							}
							profiles_changes++;
						}
						else if(cell[0].references.object.selectedKey!=cell[8].value || cell[1].value!=cell[9].value || cell[2].value!=cell[10].value || cell[3].value!=cell[11].value || cell[4].references.object.selectedKey!=cell[12].value){
							pttProfileRounding.AddStyledItem([Jade.Lang.Get('modify'), $.Utils.AAText(aDayTypes, cell[8].value), Jade.Strings.ToTime(cell[9].value), Jade.Strings.ToTime(cell[10].value), Jade.Strings.ToTime(cell[11].value), cell[12].value==0?Jade.Lang.Get('entry'):Jade.Lang.Get('exit')], 'petition_mod');
							pttProfileRounding.AddStyledItem(['', cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value), Jade.Strings.ToTime(cell[3].value), cell[4].value], 'petition_mod');

							xml.profile_rounding.mod.push({
								oldValues: {daytype: cell[8].value, from: cell[9].value, to: cell[10].value, rounding: cell[11].value, entryexit: cell[12].value},
								newValues: {daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value, rounding: cell[3].value, entryexit: cell[4].references.object.selectedKey}
							});
							profiles_changes++;
						}
					}
					for(var i=0, iLen=petition.profile_rounding.del.length; i<iLen; i++){
						var row = petition.profile_rounding.del[i];
						pttProfileRounding.AddStyledItem([Jade.Lang.Get('erease'), $.Utils.AAText(aDayTypes, row.daytype), Jade.Strings.ToTime(row.from), Jade.Strings.ToTime(row.to), Jade.Strings.ToTime(row.rounding), row.entryexit==0?Jade.Lang.Get('entry'):Jade.Lang.Get('exit')], 'petition_del');
						xml.profile_rounding.del.push(row);
						profiles_changes++;
					}
					count_changes+=profiles_changes;
					if(profiles_changes!=0){
						if(typeof(firstProfileTab)=="undefined"){ firstProfileTab=0; }
					}
					pptTabsProfile.tabs[0].Visible(profiles_changes!=0);
				}
				{//Auto events
					profiles_changes=0;
				
					for(var i=0, iLen=grAutoEvents.rows.length;i<iLen;i++){
						var cell=grAutoEvents.rows[i].cells;
						if(cell[6].value!=cell[7].value){
							switch(cell[6].value){
								case 0:
									pttProfileEvents.AddStyledItem([Jade.Lang.Get('unapply'),cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value), cell[3].value, cell[4].value], 'petition_del');
									xml.profile_events.unapply.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value, event: cell[3].references.object.selectedKey, entryexit: cell[4].references.object.selectedKey});
									break;
								case 1:
									pttProfileEvents.AddStyledItem([Jade.Lang.Get('apply'),cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value), cell[3].value, cell[4].value], 'petition_new');
									xml.profile_events.apply.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value, event: cell[3].references.object.selectedKey, entryexit: cell[4].references.object.selectedKey});
									break;
								case 2:
									pttProfileEvents.AddStyledItem([Jade.Lang.Get('new_m'),cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value), cell[3].value, cell[4].value], 'petition_new');
									xml.profile_events.add.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value, event: cell[3].references.object.selectedKey, entryexit: cell[4].references.object.selectedKey});
									break;
							}
							profiles_changes++;
						}
						else if(cell[0].references.object.selectedKey!=cell[8].value || cell[1].value!=cell[9].value || cell[2].value!=cell[10].value || cell[3].references.object.selectedKey!=cell[11].value || cell[4].references.object.selectedKey!=cell[12].value){
							pttProfileEvents.AddStyledItem([Jade.Lang.Get('modify'), $.Utils.AAText(aDayTypes, cell[8].value), Jade.Strings.ToTime(cell[9].value), Jade.Strings.ToTime(cell[10].value), $.Utils.AAText(aEvents, cell[11].value), cell[12].value==0?Jade.Lang.Get('entry'):Jade.Lang.Get('exit')], 'petition_mod');
							pttProfileEvents.AddStyledItem(['', cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value), cell[3].value, cell[4].value], 'petition_mod');
						
							xml.profile_events.mod.push({
								oldValues: {daytype: cell[8].value, from: cell[9].value, to: cell[10].value, event: cell[11].value, entryexit: cell[12].value},
								newValues: {daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value, event: cell[3].references.object.selectedKey, entryexit: cell[4].references.object.selectedKey}
							});

							profiles_changes++;
						}
					}
					for(var i=0, iLen=petition.profile_events.del.length; i<iLen; i++){
						var row = petition.profile_events.del[i];
						pttProfileEvents.AddStyledItem([Jade.Lang.Get('erease'), $.Utils.AAText(aDayTypes, row.daytype), Jade.Strings.ToTime(row.from), Jade.Strings.ToTime(row.to), $.Utils.AAText(aEvents, row.event), row.entryexit==0?Jade.Lang.Get('entry'):Jade.Lang.Get('exit')], 'petition_del');
						xml.profile_events.del.push(row);
						profiles_changes++;
					}
				
					count_changes+=profiles_changes;
					if(profiles_changes!=0){
						if(typeof(firstProfileTab)=="undefined"){ firstProfileTab=1; }
					}
					pptTabsProfile.tabs[1].Visible(profiles_changes!=0);
				}
				{//Absence
					profiles_changes=0;
					pptTabsProfile.tabs[2].Visible(profiles_changes!=0);
				}
				{//Accrual balance
					profiles_changes=0;

					for(var i=0, iLen=grAccrualBalance.rows.length;i<iLen;i++){
						var cell=grAccrualBalance.rows[i].cells;
						if(cell[6].value!=cell[7].value){
							switch(cell[6].value){
								case 0:
									pttProfileAccrual.AddStyledItem([Jade.Lang.Get('unapply'),cell[0].value, cell[1].value, Jade.Strings.ToTime(cell[2].value), cell[3].value, cell[4].value], 'petition_del');
									xml.profile_accruals.unapply.push({accrual: cell[0].references.object.selectedKey, ocurrence: cell[1].value, time: cell[2].value, term: cell[3].references.object.selectedKey, term: cell[4].references.object.selectedKey});
									break;
								case 1:
									pttProfileAccrual.AddStyledItem([Jade.Lang.Get('apply'),cell[0].value, cell[1].value, Jade.Strings.ToTime(cell[2].value), cell[3].value, cell[4].value], 'petition_new');
									xml.profile_accruals.apply.push({accrual: cell[0].references.object.selectedKey, ocurrence: cell[1].value, time: cell[2].value, term: cell[3].references.object.selectedKey, term: cell[4].references.object.selectedKey});
									break;
								case 2:
									pttProfileAccrual.AddStyledItem([Jade.Lang.Get('new_m'),cell[0].value, cell[1].value, Jade.Strings.ToTime(cell[2].value), cell[3].value, cell[4].value], 'petition_new');
									xml.profile_accruals.add.push({accrual: cell[0].references.object.selectedKey, ocurrence: cell[1].value, time: cell[2].value, term: cell[3].references.object.selectedKey, term: cell[4].references.object.selectedKey});
									break;
							}
							profiles_changes++;
						}
						else if(cell[0].references.object.selectedKey!=cell[8].value || cell[1].value!=cell[9].value || cell[2].value!=cell[10].value || cell[3].references.object.selectedKey!=cell[11].value || cell[4].references.object.selectedKey!=cell[12].value){
							pttProfileAccrual.AddStyledItem([Jade.Lang.Get('modify'), $.Utils.AAText(aAccruals, cell[8].value), cell[9].value, Jade.Strings.ToTime(cell[10].value), aTerms[cell[11].value], cell[12].value], 'petition_mod');
							pttProfileAccrual.AddStyledItem(['', cell[0].value, cell[1].value, Jade.Strings.ToTime(cell[2].value), cell[3].value, cell[4].value], 'petition_mod');
						
							xml.profile_accruals.mod.push({
								oldValues: {accrual: cell[8].value, ocurrence: cell[9].value, time: cell[10].value, term: cell[11].value, year: cell[12].value},
								newValues: {accrual: cell[0].references.object.selectedKey, ocurrence: cell[1].value, time: cell[2].value, term: cell[3].references.object.selectedKey, year: cell[4].references.object.selectedKey}
							});
						
							profiles_changes++;
						}
					}
					for(var i=0, iLen=petition.profile_accruals.del.length; i<iLen; i++){
						var row = petition.profile_accruals.del[i];
						pttProfileAccrual.AddStyledItem([Jade.Lang.Get('erease'), $.Utils.AAText(aAccruals, row.accrual), row.ocurrence, Jade.Strings.ToTime(row.time), aTerms[row.term]], 'petition_del');
						xml.profile_accruals.del.push(row);
						profiles_changes++;
					}
				
					count_changes+=profiles_changes;
					if(profiles_changes!=0){
						if(typeof(firstProfileTab)=="undefined"){ firstProfileTab=3; }
					}
					pptTabsProfile.tabs[3].Visible(profiles_changes!=0);
				}
				{//Breaks
					profiles_changes=0;
				
					for(var i=0, iLen=grBreaks.rows.length;i<iLen;i++){
						var cell=grBreaks.rows[i].cells;
						if(cell[3].value!=cell[4].value){
							switch(cell[3].value){
								case 0:
									pttProfileBreaks.AddStyledItem([Jade.Lang.Get('unapply'),cell[0].value, cell[1].value], 'petition_del');
									xml.profile_breaks.unapply.push({daytype: cell[0].references.object.selectedKey, breaktime: cell[1].references.object.selectedKey});
									break;
								case 1:
									pttProfileBreaks.AddStyledItem([Jade.Lang.Get('apply'),cell[0].value, cell[1].value], 'petition_new');
									xml.profile_breaks.apply.push({daytype: cell[0].references.object.selectedKey, breaktime: cell[1].references.object.selectedKey});
									break;
								case 2:
									pttProfileBreaks.AddStyledItem([Jade.Lang.Get('new_m'),cell[0].value, cell[1].value], 'petition_new');
									xml.profile_breaks.add.push({daytype: cell[0].references.object.selectedKey, breaktime: cell[1].references.object.selectedKey});
									break;
							}
							profiles_changes++;
						}
						else if(cell[0].references.object.selectedKey!=cell[5].value || cell[1].references.object.selectedKey!=cell[6].value){
							pttProfileBreaks.AddStyledItem([Jade.Lang.Get('modify'), $.Utils.AAText(aDayTypes, cell[5].value), $.Utils.AAText(aBreaks, cell[6].value)], 'petition_mod');
							pttProfileBreaks.AddStyledItem(['', cell[0].value, cell[1].value], 'petition_mod');
						
							xml.profile_breaks.mod.push({
								oldValues: {daytype: cell[5].value, breaktime: cell[6].value},
								newValues: {daytype: cell[0].references.object.selectedKey, breaktime: cell[1].references.object.selectedKey}
							});

							profiles_changes++;
						}
					}
					for(var i=0, iLen=petition.profile_breaks.del.length; i<iLen; i++){
						var row = petition.profile_breaks.del[i];
						pttProfileBreaks.AddStyledItem([Jade.Lang.Get('erease'), $.Utils.AAText(aDayTypes, row.daytype), $.Utils.AAText(aBreaks, row.breaktime)], 'petition_del');
						xml.profile_breaks.del.push(row);
						profiles_changes++;
					}
				
					count_changes+=profiles_changes;
					if(profiles_changes!=0){
						if(typeof(firstProfileTab)=="undefined"){ firstProfileTab=4; }
					}
					
					pptTabsProfile.tabs[4].Visible(profiles_changes!=0);
				}
				{//Payrolls
					profiles_changes=0;
					
					for(var i=0, iLen=grPayroll.rows.length;i<iLen;i++){
						var cell=grPayroll.rows[i].cells;
						if(cell[3].value!=cell[4].value){
							switch(cell[3].value){
								case 0:
									pttProfilePayrolls.AddStyledItem([Jade.Lang.Get('unapply'),cell[0].value, cell[1].value], 'petition_del');
									xml.profile_payrolls.unapply.push({daytype: cell[0].references.object.selectedKey, payroll: cell[1].references.object.selectedKey});
									break;
								case 1:
									pttProfilePayrolls.AddStyledItem([Jade.Lang.Get('apply'),cell[0].value, cell[1].value], 'petition_new');
									xml.profile_payrolls.apply.push({daytype: cell[0].references.object.selectedKey, payroll: cell[1].references.object.selectedKey});
									break;
								case 2:
									pttProfilePayrolls.AddStyledItem([Jade.Lang.Get('new_m'),cell[0].value, cell[1].value], 'petition_new');
									xml.profile_payrolls.add.push({daytype: cell[0].references.object.selectedKey, payroll: cell[1].references.object.selectedKey});
									break;
							}
							profiles_changes++;
						}
						else if(cell[0].references.object.selectedKey!=cell[5].value || cell[1].references.object.selectedKey!=cell[6].value){
							pttProfilePayrolls.AddStyledItem([Jade.Lang.Get('modify'), $.Utils.AAText(aDayTypes, cell[5].value), $.Utils.AAText(aPayrolls, cell[6].value)], 'petition_mod');
							pttProfilePayrolls.AddStyledItem(['', cell[0].value, cell[1].value], 'petition_mod');
							
							xml.profile_payrolls.mod.push({
								oldValues: {daytype: cell[5].value, payroll: cell[6].value},
								newValues: {daytype: cell[0].references.object.selectedKey, payroll: cell[1].references.object.selectedKey}
							});

							profiles_changes++;
						}
					}
					for(var i=0, iLen=petition.profile_payrolls.del.length; i<iLen; i++){
						var row = petition.profile_payrolls.del[i];
						pttProfilePayrolls.AddStyledItem([Jade.Lang.Get('erease'), $.Utils.AAText(aDayTypes, row.daytype), $.Utils.AAText(aPayrolls, row.payroll)], 'petition_del');
						xml.profile_payrolls.del.push(row);
						profiles_changes++;
					}
					
					count_changes+=profiles_changes;
					if(profiles_changes!=0){
						if(typeof(firstProfileTab)=="undefined"){ firstProfileTab=5; }
					}
					
					pptTabsProfile.tabs[5].Visible(profiles_changes!=0);
				}
				{//No Access days
					profiles_changes=0;
					
					for(var i=0, iLen=grNoAccessDays.rows.length;i<iLen;i++){
						var cell=grNoAccessDays.rows[i].cells;
						if(cell[3].value!=cell[4].value){
							switch(cell[3].value){
								case 0:
									pttProfileAccessDays.AddStyledItem([Jade.Lang.Get('unapply'),$.Strings.ToDate(cell[0].value), $.Strings.ToDate(cell[1].value)], 'petition_del');
									xml.profile_accessdays.unapply.push({from: cell[0].value, to: cell[1].value});
									break;
								case 1:
									pttProfileAccessDays.AddStyledItem([Jade.Lang.Get('apply'), $.Strings.ToDate(cell[0].value), $.Strings.ToDate(cell[1].value)], 'petition_new');
									xml.profile_accessdays.apply.push({from: cell[0].value, to: cell[1].value});
									break;
								case 2:
									pttProfileAccessDays.AddStyledItem([Jade.Lang.Get('new_m'), $.Strings.ToDate(cell[0].value), $.Strings.ToDate(cell[1].value)], 'petition_new');
									xml.profile_accessdays.add.push({from: cell[0].value, to: cell[1].value});
									break;
							}
							profiles_changes++;
						}
						else if(cell[0].value!=cell[5].value || cell[1].value!=cell[6].value){
							pttProfileAccessDays.AddStyledItem([$.Lang.Get('modify'), $.Strings.ToDate(cell[5].value), $.Strings.ToDate(cell[6].value)], 'petition_mod');
							pttProfileAccessDays.AddStyledItem(['', $.Strings.ToDate(cell[0].value), $.Strings.ToDate(cell[1].value)], 'petition_mod');
							
							xml.profile_accessdays.mod.push({
								oldValues: {from: cell[5].value, to: cell[6].value},
								newValues: {from: cell[0].value, to: cell[1].value}
							});

							profiles_changes++;
						}
					}
					for(var i=0, iLen=petition.profile_accessdays.del.length; i<iLen; i++){
						var row = petition.profile_accessdays.del[i];
						pttProfileAccessDays.AddStyledItem([Jade.Lang.Get('erease'), $.Strings.ToDate(row.from), $.Strings.ToDate(row.to)], 'petition_del');
						xml.profile_accessdays.del.push(row);
						profiles_changes++;
					}
					
					count_changes+=profiles_changes;
					if(profiles_changes!=0){
						if(typeof(firstProfileTab)=="undefined"){ firstProfileTab=6; }
					}
					
					pptTabsProfile.tabs[6].Visible(profiles_changes!=0);
				}
				{//Access
					profiles_changes=0;
					pptTabsProfile.tabs[7].Visible(profiles_changes!=0);
				}
				{//Only access time
					profiles_changes=0;
					
					for(var i=0, iLen=grOnlyAccessTime.rows.length;i<iLen;i++){
						var cell=grOnlyAccessTime.rows[i].cells;
						if(cell[4].value!=cell[5].value){
							switch(cell[4].value){
								case 0:
									pttProfileAccessTime.AddStyledItem([Jade.Lang.Get('unapply'), cell[0].value, $.Strings.ToTime(cell[1].value), $.Strings.ToTime(cell[2].value)], 'petition_del');
									xml.profile_accesstime.unapply.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value});
									break;
								case 1:
									pttProfileAccessTime.AddStyledItem([Jade.Lang.Get('apply'), cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value)], 'petition_new');
									xml.profile_accesstime.apply.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value});
									break;
								case 2:
									pttProfileAccessTime.AddStyledItem([Jade.Lang.Get('new_m'), cell[0].value, Jade.Strings.ToTime(cell[1].value), Jade.Strings.ToTime(cell[2].value)], 'petition_new');
									xml.profile_accesstime.add.push({daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value});
									break;
							}
							profiles_changes++;
						}
						else if(cell[0].references.object.selectedKey!=cell[6].value || cell[1].value!=cell[7].value || cell[2].value!=cell[8].value){
							pttProfileAccessTime.AddStyledItem([Jade.Lang.Get('modify'), $.Utils.AAText(aDayTypes, cell[6].value), $.Strings.ToTime(cell[7].value), $.Strings.ToTime(cell[8].value)], 'petition_mod');
							pttProfileAccessTime.AddStyledItem(['', cell[0].value, $.Strings.ToTime(cell[1].value), $.Strings.ToTime(cell[2].value)], 'petition_mod');
							
							xml.profile_accesstime.mod.push({
								oldValues: {daytype: cell[6].value, from: cell[7].value, to: cell[8].value},
								newValues: {daytype: cell[0].references.object.selectedKey, from: cell[1].value, to: cell[2].value}
							});

							profiles_changes++;
						}
					}
					for(var i=0, iLen=petition.profile_accesstime.del.length; i<iLen; i++){
						var row = petition.profile_accesstime.del[i];
						pttProfileAccessTime.AddStyledItem([Jade.Lang.Get('erease'), $.Utils.AAText(aDayTypes, row.daytype), $.Strings.ToTime(row.from), $.Strings.ToTime(row.to)], 'petition_del');
						xml.profile_accesstime.del.push(row);
						profiles_changes++;
					}
					
					count_changes+=profiles_changes;
					if(profiles_changes!=0){
						if(typeof(firstProfileTab)=="undefined"){ firstProfileTab=8; }
					}
					
					pptTabsProfile.tabs[8].Visible(profiles_changes!=0);
				}
				if(count_changes!=0){ 
					if(typeof(firstTab)=="undefined"){ firstTab=1; }
					mustShow=true;
					pptTabsProfile.tabs[firstProfileTab].onclick();
				}

				pttTabs.tabs[1].Visible(count_changes!=0);
			}
			{//Calendar
				count_changes=0;
				for(var i in calendar._changes.year){
					for(var j in calendar._changes.year[i].month){
						for(var k in calendar._changes.year[i].month[j].day){
							var date=i+Jade.Strings.PadLeft(j,'0',2)+Jade.Strings.PadLeft(k,'0',2);
							var item=calendar._changes.year[i].month[j].day[k];
							
							var old;
							if(typeof(calendar._private.year[i])!="undefined" && typeof(calendar._private.year[i].month[j])!="undefined" && typeof(calendar._private.year[i].month[j].day[k])!="undefined"){ old=calendar._private.year[i].month[j].day[k]; }
							else if(typeof(calendar._public.year[i])!="undefined" && typeof(calendar._public.year[i].month[j])!="undefined" && typeof(calendar._public.year[i].month[j].day[k])!="undefined"){ old=calendar._public.year[i].month[j].day[k]; }
							
							
							var old_values=[
								Jade.Lang.Get('modify'),
								Jade.Strings.ToDate(date),
								Jade.Strings.VisualTrim($.Utils.AAText(aDayTypes, old.IdTipoDia),84),
								Jade.Strings.VisualTrim((old.IdVariante!='' && old.IdVariante!=0)?Jade.Lang.Get('variant')+' '+old.IdVariante:Jade.Lang.Get('none_f'),84),
								set_value_format(old.TipoVariante,'bool'),
								Jade.Strings.VisualTrim((old.IdIncidencia!='' && old.IdIncidencia!=0)?$.Utils.AAText(aEvents, old.IdIncidencia):Jade.Lang.Get('none_f'),84),
								Jade.Strings.VisualTrim((old.IdHorario!='' && old.IdHorario!=0)?$.Utils.AAText(aWorkdays, old.IdHorario):Jade.Lang.Get('none_m'),84),
								Jade.Strings.VisualTrim(old.Observaciones,210)
							];
							var new_values=[
								'',
								'',
								Jade.Strings.VisualTrim($.Utils.AAText(aDayTypes, item.IdTipoDia),84),
								Jade.Strings.VisualTrim((item.IdVariante!='' && item.IdVariante!=0)?Jade.Lang.Get('variant')+' '+item.IdVariante:Jade.Lang.Get('none_f'),84),
								set_value_format(item.TipoVariante,'bool'),
								Jade.Strings.VisualTrim((item.IdIncidencia!='' && item.IdIncidencia!=0)?$.Utils.AAText(aEvents, item.IdIncidencia):Jade.Lang.Get('none_f'),84),
								Jade.Strings.VisualTrim((item.IdHorario!='' && item.IdHorario!=0)?$.Utils.AAText(aWorkdays, item.IdHorario):Jade.Lang.Get('none_m'),84),
								Jade.Strings.VisualTrim(item.Observaciones,210)
							];
							pttCalendar.AddStyledItem(old_values,'petition_mod');
							pttCalendar.AddStyledItem(new_values,'petition_mod');
							
							xml.calendar.push({date: date, oldValues: old, newValues: item});
							
							count_changes++;
						}
					}
				}
				
				if(count_changes!=0){
					if(typeof(firstTab)=="undefined"){ firstTab=2; }
					mustShow=true;
				}
				pttTabs.tabs[2].Visible(count_changes!=0);
			}	
			{//Duttytime
				count_changes=0;
				
				for(var i in aDutytime.year){
					for(var j in aDutytime.year[i]){
						var item=aDutytime.year[i][j];
						if(item.value!=item.old){
							pttDuttytime.AddStyledItem([Jade.Lang.Get('modify'), i, Jade.Lang.Get('month_'+j), Jade.DateTime.MinutesToHour(item.old, ':')],'petition_mod');
							pttDuttytime.AddStyledItem(['','','',Jade.DateTime.MinutesToHour(item.value,':')],'petition_mod');
							xml.duttytime.push({year: i, month: j, oldValue: item.old, newValue: item.value});
							count_changes++;
						}
					}
				}
				if(count_changes!=0){ 
					if(typeof(firstTab)=="undefined"){ firstTab=3; }
					mustShow=true;
				}
				
				pttTabs.tabs[3].Visible(count_changes!=0);
			}	
			{//Status
				count_changes=0;
				
				for(var i=0,iLen=grStatus.rows.length;i<iLen;i++){
					var item=grStatus.rows[i];
					if(item.key=='new'){
						pttStatus.AddStyledItem([Jade.Lang.Get('new_m'),Jade.Strings.ToDate(item.cells[1].value)],'petition_new');
						xml.status.add.push(item.cells[1].value);
						count_changes++;
					}
				}
				for(var i=0,iLen=petition.status.mod.length;i<iLen;i++){
					var value=petition.status.mod[i];
					var cell=grStatus.rows[i].cells;
					if(cell[1].value!=value.date){
						pttStatus.AddStyledItem([Jade.Lang.Get('modify'),Jade.Strings.ToDate(value.date)],'petition_mod');
						pttStatus.AddStyledItem(['',Jade.Strings.ToDate(cell[1].value)],'petition_mod');
						xml.status.mod.push({oldValue: value.date, newValue: cell[1].value});
						count_changes++;
					}
				}
				for(var i=0,iLen=petition.status.del.length;i<iLen;i++){
					pttStatus.AddStyledItem([Jade.Lang.Get('erease'),Jade.Strings.ToDate(petition.status.del[i].date)],'petition_del');
					xml.status.del.push(petition.status.del[i].date);
					count_changes++;
				}
				if(count_changes!=0){ 
					if(typeof(firstTab)=="undefined"){ firstTab=4; }
					mustShow=true;
				}
				pttTabs.tabs[4].Visible(count_changes!=0);
			}	
			{//Terminal
				count_changes=0;
				for(var i in petition.terminal){
					var oldValue=petition.terminal[i].value;
					var newValue=get_control_data(petition.terminal[i].control);
					if(oldValue!=newValue && (!newEmployee || (newEmployee && newValue!=''))){
						var control=petition.terminal[i].control;
						if(newEmployee){
							pttTerminal.AddStyledItem([Jade.Lang.Get('new_m'),petition.terminal[i].title,Jade.Strings.VisualTrim(set_value_format(newValue,control),490)],'petition_new');
							xml.terminal.push({field: i,newValue: newValue});
						}
						else{
							pttTerminal.AddStyledItem([Jade.Lang.Get('modify'),petition.terminal[i].title,set_value_format(oldValue,control)],'petition_mod');
							pttTerminal.AddStyledItem(['','',set_value_format(newValue,control)],'petition_mod');
						
							xml.terminal.push({field: i,oldValue: oldValue,newValue: newValue});
						}
						count_changes++;
					}
				}
				if(count_changes!=0){
					if(typeof(firstTab)=="undefined"){ firstTab=5; }
					mustShow=true;
				}
				pttTabs.tabs[5].Visible(count_changes!=0);
			}
			{//Notes
				count_changes=0;
				for(var i=0,iLen=grNotes.rows.length;i<iLen;i++){
					var item=grNotes.rows[i];
					var cell=item.cells;
					if(item.key=='new'){
						pttNotes.AddStyledItem([Jade.Lang.Get('new_m'), $.DateTime.toShowDate(cell[0].value), $.DateTime.toShowTime(cell[1].value), $.Strings.VisualTrim(cell[2].value, 550)], 'petition_new');
						xml.notes.add.push({date: cell[0].value, time: cell[1].value, text: cell[2].value});
						count_changes++;
					}
					else if(cell[2].value!=cell[5].value){
						pttNotes.AddStyledItem([Jade.Lang.Get('modify'), $.DateTime.toShowDate(cell[0].value), $.DateTime.toShowTime(cell[1].value), $.Strings.VisualTrim(cell[5].value, 550)], 'petition_mod');
						pttNotes.AddStyledItem(['', '', '', cell[2].value], 'petition_mod');
						xml.notes.mod.push({oldValues: {date: cell[0].value, time: cell[1].value, text: cell[5].value}, newValues: {date: cell[0].value, time: cell[1].value, text: cell[2].value}});
						count_changes++;
					}
				}
				for(var i=0, iLen=petition.notes.del.length; i<iLen; i++){
					var item=petition.notes.del[i];
					pttNotes.AddStyledItem([$.lng('erease'), $.DateTime.toShowDate(item.date), $.DateTime.toShowTime(item.time), $.Strings.VisualTrim(item.text, 550)], 'petition_del');
					xml.notes.del.push({date: item.date, time: item.time, text: item.text});
					count_changes++;
				}
				if(count_changes!=0){
					if(typeof(firstTab)=="undefined"){ firstTab=6; }
					mustShow=true;
				}
				pttTabs.tabs[6].Visible(count_changes!=0);
			}
			{//Observaciones
				count_changes=0;
				for(var i in petition.comments){
					var oldValue=petition.comments[i].value;
					var newValue=get_control_data(petition.comments[i].control);
					if(oldValue!=newValue && (!newEmployee || (newEmployee && newValue!=''))){
						if(newEmployee){
							pttComments.AddStyledItem([Jade.Lang.Get('new_m'),petition.comments[i].title,Jade.Strings.VisualTrim(set_value_format(newValue,control),490)],'petition_new');
							xml.comments.push({field: i,newValue: newValue});
						}
						else{
							pttComments.AddStyledItem([Jade.Lang.Get('modify'),petition.comments[i].title,Jade.Strings.VisualTrim(oldValue,590)],'petition_mod');
							pttComments.AddStyledItem(['','',Jade.Strings.VisualTrim(newValue,590)],'petition_mod');
							xml.comments.push({field: i,oldValue: oldValue,newValue: newValue});
						}
						count_changes++;
					}
				}
				if(count_changes!=0){ 
					if(typeof(firstTab)=="undefined"){ firstTab=7; }
					mustShow=true;
				}
				pttTabs.tabs[7].Visible(count_changes!=0);
			}
			if(mustShow){
				pttTabs.tabs[firstTab].onclick();
				pttWindow.Show();
				pttAccept.SetEnabled(true);
			}
		}
	}
}
pttAccept.onclick=function(){
	if($.Utils.PrivilegeValue('empl_priv')>1){
		pttAccept.SetEnabled(false);
		var Fecha=Jade.DateTime.toStoreDate(new Date());
		var Hora=Jade.DateTime.toStoreTime(new Date());
		var IdPeticion=Jade.Encrypt.MD5(USER.id+Fecha+Hora);
		
		var newEmployee=(typeof(id)=="undefined");
		var family = (typeof(id)=="undefined")?0:1;

		{//Add petition
			var fields=['IdPeticion','IdUsuario','Fecha','Hora','Familia','Clave','Estado','EstadoEnvio'];
			var values=[IdPeticion,USER.id,Fecha,Hora,family,txtCode.GetText(),'0','0'];
			Jade.AjaxDBSave("PETICIONES{c}",fields,values);
		}
		{//Elementos comunes lineas
			var primaryKey="<PrimaryKey><EmployeeId>"+txtCode.GetText()+"</EmployeeId></PrimaryKey>";
			var fields=['IdPeticion','SubFamilia','Accion','Estado','Valor'];
			var table="PETICIONES_LINEAS{c}";
		}
		{//Empleado nuevo
			if(newEmployee){
				var nEmployee={Nombre:'',IdUbicacion:'',IdCentro:'',IdHorario:'',IdPerfil:'',IdCalendario:''};
				for(var i=0;i<xml.personal.length;i++){
					var item=xml.personal[i];
					for(var j in nEmployee){
						if(item.field==j){
							nEmployee[j]=item.newValue;
							xml.personal.splice(i,1);
							i--;
						}
					}
				}

				var valor="<Petition>"+primaryKey;
				valor+="<NewValues><Name>"+nEmployee.Nombre+"</Name><Department>"+nEmployee.IdUbicacion+"</Department><Center>"+nEmployee.IdCentro+"</Center><Workday>"+nEmployee.IdHorario+"</Workday><Profile>"+nEmployee.IdPerfil+"</Profile><Calendar>"+nEmployee.IdCalendario+"</Calendar></NewValues>";
				valor+="</Petition>";
				
				Jade.AjaxDBSave(table,fields,[IdPeticion,'20','0','0',valor]);
			}
		}
		{//Datos personales
			for(var i=0,iLen=xml.personal.length;i<iLen;i++){
				var item=xml.personal[i];
				var valor="<Petition>"+primaryKey;
				if(!newEmployee){ valor+="<OldValues><field>"+item.field+"</field><value>"+item.oldValue+"</value></OldValues>"; }
				valor+="<NewValues><field>"+item.field+"</field><value>"+item.newValue+"</value></NewValues>";
				valor+="</Petition>";
				Jade.AjaxDBSave(table,fields,[IdPeticion,'0',family,'0',valor]);
			}
		}
		{//Profile
			{//Profile roundings
				//Add
				for(var i=0,iLen=xml.profile_rounding.add.length;i<iLen;i++){
						var item=xml.profile_rounding.add[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To><Rounding>"+item.rounding+"</Rounding><EntryExit>"+item.entryexit+"</EntryExit></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'1','0','0',valor]);
				}
				//Mod
				for(var i=0,iLen=xml.profile_rounding.mod.length;i<iLen;i++){
						var item=xml.profile_rounding.mod[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.newValues.daytype+"</DayType><From>"+item.newValues.from+"</From><To>"+item.newValues.to+"</To><Rounding>"+item.newValues.rounding+"</Rounding><EntryExit>"+item.newValues.entryexit+"</EntryExit></NewValues>";
						valor+="<OldValues><DayType>"+item.oldValues.daytype+"</DayType><From>"+item.oldValues.from+"</From><To>"+item.oldValues.to+"</To><Rounding>"+item.oldValues.rounding+"</Rounding><EntryExit>"+item.oldValues.entryexit+"</EntryExit></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'1','1','0',valor]);
				}
				//Del
				for(var i=0,iLen=xml.profile_rounding.del.length;i<iLen;i++){
						var item=xml.profile_rounding.del[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To><Rounding>"+item.rounding+"</Rounding><EntryExit>"+item.entryexit+"</EntryExit></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'1','2','0',valor]);
				}
				//Apply
				for(var i=0,iLen=xml.profile_rounding.apply.length;i<iLen;i++){
						var item=xml.profile_rounding.apply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To><Rounding>"+item.rounding+"</Rounding><EntryExit>"+item.entryexit+"</EntryExit></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'1','3','0',valor]);
				}			
				//Unapply
				for(var i=0,iLen=xml.profile_rounding.unapply.length;i<iLen;i++){
						var item=xml.profile_rounding.unapply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To><Rounding>"+item.rounding+"</Rounding><EntryExit>"+item.entryexit+"</EntryExit></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'1','4','0',valor]);
				}
			}
			{//Profile autoevents
				//Add
				for(var i=0,iLen=xml.profile_events.add.length;i<iLen;i++){
						var item=xml.profile_events.add[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To><Event>"+item.event+"</Event><EntryExit>"+item.entryexit+"</EntryExit></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'2','0','0',valor]);
				}
				//Mod
				for(var i=0,iLen=xml.profile_events.mod.length;i<iLen;i++){
						var item=xml.profile_events.mod[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.newValues.daytype+"</DayType><From>"+item.newValues.from+"</From><To>"+item.newValues.to+"</To><Event>"+item.newValues.event+"</Event><EntryExit>"+item.newValues.entryexit+"</EntryExit></NewValues>";
						valor+="<OldValues><DayType>"+item.oldValues.daytype+"</DayType><From>"+item.oldValues.from+"</From><To>"+item.oldValues.to+"</To><Event>"+item.oldValues.event+"</Event><EntryExit>"+item.oldValues.entryexit+"</EntryExit></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'2','1','0',valor]);
				}
				//Del
				for(var i=0,iLen=xml.profile_events.del.length;i<iLen;i++){
						var item=xml.profile_events.del[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To><Event>"+item.event+"</Event><EntryExit>"+item.entryexit+"</EntryExit></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'2','2','0',valor]);
				}
				//Apply
				for(var i=0,iLen=xml.profile_events.apply.length;i<iLen;i++){
						var item=xml.profile_events.apply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To><Event>"+item.event+"</Event><EntryExit>"+item.entryexit+"</EntryExit></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'2','3','0',valor]);
				}			
				//Unapply
				for(var i=0,iLen=xml.profile_events.unapply.length;i<iLen;i++){
						var item=xml.profile_events.unapply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To><Event>"+item.event+"</Event><EntryExit>"+item.entryexit+"</EntryExit></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'2','4','0',valor]);
				}
			}
			{//Profile accrual balance
				//Add
				for(var i=0,iLen=xml.profile_accruals.add.length;i<iLen;i++){
						var item=xml.profile_accruals.add[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><Accrual>"+item.accrual+"</Accrual><Ocurrence>"+item.ocurrence+"</Ocurrence><TimeAllowed>"+item.time+"</TimeAllowed><Term>"+item.term+"</Term></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'4','0','0',valor]);
				}
				//Mod
				for(var i=0,iLen=xml.profile_accruals.mod.length;i<iLen;i++){
						var item=xml.profile_accruals.mod[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><Accrual>"+item.newValues.accrual+"</Accrual><Ocurrence>"+item.newValues.ocurrence+"</Ocurrence><TimeAllowed>"+item.newValues.time+"</TimeAllowed><Term>"+item.newValues.term+"</Term></NewValues>";
						valor+="<OldValues><Accrual>"+item.oldValues.accrual+"</Accrual><Ocurrence>"+item.oldValues.ocurrence+"</Ocurrence><TimeAllowed>"+item.oldValues.time+"</TimeAllowed><Term>"+item.oldValues.term+"</Term></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'4','1','0',valor]);
				}
				//Del
				for(var i=0,iLen=xml.profile_accruals.del.length;i<iLen;i++){
						var item=xml.profile_accruals.del[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><Accrual>"+item.accrual+"</Accrual><Ocurrence>"+item.ocurrence+"</Ocurrence><TimeAllowed>"+item.time+"</TimeAllowed><Term>"+item.term+"</Term></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'4','2','0',valor]);
				}
				//Apply
				for(var i=0,iLen=xml.profile_accruals.apply.length;i<iLen;i++){
						var item=xml.profile_accruals.apply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><Accrual>"+item.accrual+"</Accrual><Ocurrence>"+item.ocurrence+"</Ocurrence><TimeAllowed>"+item.time+"</TimeAllowed><Term>"+item.term+"</Term></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'4','3','0',valor]);
				}			
				//Unapply
				for(var i=0,iLen=xml.profile_accruals.unapply.length;i<iLen;i++){
						var item=xml.profile_accruals.unapply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><Accrual>"+item.accrual+"</Accrual><Ocurrence>"+item.ocurrence+"</Ocurrence><TimeAllowed>"+item.time+"</TimeAllowed><Term>"+item.term+"</Term></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'4','4','0',valor]);
				}
			}
			{//Profile breaks
				//Add
				for(var i=0,iLen=xml.profile_breaks.add.length;i<iLen;i++){
						var item=xml.profile_breaks.add[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><BreakTime>"+item.breaktime+"</BreakTime></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'5','0','0',valor]);
				}
				//Mod
				for(var i=0,iLen=xml.profile_breaks.mod.length;i<iLen;i++){
						var item=xml.profile_breaks.mod[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.newValues.daytype+"</DayType><BreakTime>"+item.newValues.breaktime+"</BreakTime></NewValues>";
						valor+="<OldValues><DayType>"+item.oldValues.daytype+"</DayType><BreakTime>"+item.oldValues.breaktime+"</BreakTime></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'5','1','0',valor]);
				}
				//Del
				for(var i=0,iLen=xml.profile_breaks.del.length;i<iLen;i++){
						var item=xml.profile_breaks.del[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><BreakTime>"+item.breaktime+"</BreakTime></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'5','2','0',valor]);
				}
				//Apply
				for(var i=0,iLen=xml.profile_breaks.apply.length;i<iLen;i++){
						var item=xml.profile_breaks.apply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><BreakTime>"+item.breaktime+"</BreakTime></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'5','3','0',valor]);
				}			
				//Unapply
				for(var i=0,iLen=xml.profile_breaks.unapply.length;i<iLen;i++){
						var item=xml.profile_breaks.unapply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><BreakTime>"+item.breaktime+"</BreakTime></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'5','4','0',valor]);
				}
			}
			{//Profile payrolls
				//Add
				for(var i=0,iLen=xml.profile_payrolls.add.length;i<iLen;i++){
						var item=xml.profile_payrolls.add[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><Payroll>"+item.payroll+"</Payroll></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'9','0','0',valor]);
				}
				//Mod
				for(var i=0,iLen=xml.profile_payrolls.mod.length;i<iLen;i++){
						var item=xml.profile_payrolls.mod[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.newValues.daytype+"</DayType><Payroll>"+item.newValues.payroll+"</Payroll></NewValues>";
						valor+="<OldValues><DayType>"+item.oldValues.daytype+"</DayType><Payroll>"+item.oldValues.payroll+"</Payroll></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'9','1','0',valor]);
				}
				//Del
				for(var i=0,iLen=xml.profile_payrolls.del.length;i<iLen;i++){
						var item=xml.profile_payrolls.del[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><Payroll>"+item.payroll+"</Payroll></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'9','2','0',valor]);
				}
				//Apply
				for(var i=0,iLen=xml.profile_payrolls.apply.length;i<iLen;i++){
						var item=xml.profile_payrolls.apply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><Payroll>"+item.payroll+"</Payroll></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'9','3','0',valor]);
				}			
				//Unapply
				for(var i=0,iLen=xml.profile_payrolls.unapply.length;i<iLen;i++){
						var item=xml.profile_payrolls.unapply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><Payroll>"+item.payroll+"</Payroll></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'9','4','0',valor]);
				}
			}
			{//Profile no access days
				//Add
				for(var i=0,iLen=xml.profile_accessdays.add.length;i<iLen;i++){
						var item=xml.profile_accessdays.add[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><From>"+item.from+"</From><To>"+item.to+"</To></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'10','0','0',valor]);
				}
				//Mod
				for(var i=0,iLen=xml.profile_accessdays.mod.length;i<iLen;i++){
						var item=xml.profile_accessdays.mod[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><From>"+item.newValues.from+"</From><To>"+item.newValues.to+"</To></NewValues>";
						valor+="<OldValues><From>"+item.oldValues.from+"</From><To>"+item.oldValues.to+"</To></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'10','1','0',valor]);
				}
				//Del
				for(var i=0,iLen=xml.profile_accessdays.del.length;i<iLen;i++){
						var item=xml.profile_accessdays.del[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><From>"+item.from+"</From><To>"+item.to+"</To></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'10','2','0',valor]);
				}
				//Apply
				for(var i=0,iLen=xml.profile_accessdays.apply.length;i<iLen;i++){
						var item=xml.profile_accessdays.apply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><From>"+item.from+"</From><To>"+item.to+"</To></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'10','3','0',valor]);
				}			
				//Unapply
				for(var i=0,iLen=xml.profile_accessdays.unapply.length;i<iLen;i++){
						var item=xml.profile_accessdays.unapply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><From>"+item.from+"</From><To>"+item.to+"</To></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'10','4','0',valor]);
				}
			}
			{//Profile only access time
				//Add
				for(var i=0,iLen=xml.profile_accesstime.add.length;i<iLen;i++){
						var item=xml.profile_accesstime.add[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'13','0','0',valor]);
				}
				//Mod
				for(var i=0,iLen=xml.profile_accesstime.mod.length;i<iLen;i++){
						var item=xml.profile_accesstime.mod[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.newValues.daytype+"</DayType><From>"+item.newValues.from+"</From><To>"+item.newValues.to+"</To></NewValues>";
						valor+="<OldValues><DayType>"+item.oldValues.daytype+"</DayType><From>"+item.oldValues.from+"</From><To>"+item.oldValues.to+"</To></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'13','1','0',valor]);
				}
				//Del
				for(var i=0,iLen=xml.profile_accesstime.del.length;i<iLen;i++){
						var item=xml.profile_accesstime.del[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'13','2','0',valor]);
				}
				//Apply
				for(var i=0,iLen=xml.profile_accesstime.apply.length;i<iLen;i++){
						var item=xml.profile_accesstime.apply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<NewValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To></NewValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'13','3','0',valor]);
				}			
				//Unapply
				for(var i=0,iLen=xml.profile_accesstime.unapply.length;i<iLen;i++){
						var item=xml.profile_accesstime.unapply[i];
						var valor="<Petition>"+primaryKey;
						valor+="<OldValues><DayType>"+item.daytype+"</DayType><From>"+item.from+"</From><To>"+item.to+"</To></OldValues>";
						valor+="</Petition>";
						Jade.AjaxDBSave(table, fields,[IdPeticion,'13','4','0',valor]);
				}
			}
		}
		{//Calendar
			for(var i=0,iLen=xml.calendar.length;i<iLen;i++){
				var oVal=xml.calendar[i].oldValues;
				var nVal=xml.calendar[i].newValues;
				var valor="<Petition><PrimaryKey><EmployeeId>"+txtCode.GetText()+"</EmployeeId><Date>"+xml.calendar[i].date+"</Date></PrimaryKey>";
				valor+="<OldValues><Daytype>"+oVal.IdTipoDia+"</Daytype><Variant>"+oVal.IdVariante+"</Variant><ForceVariant>"+(oVal.TipoVariante?1:0)+"</ForceVariant><Event>"+oVal.IdIncidencia+"</Event><Workday>"+oVal.IdHorario+"</Workday><Comments>"+oVal.Observaciones+"</Comments></OldValues>";
				valor+="<NewValues><Daytype>"+nVal.IdTipoDia+"</Daytype><Variant>"+nVal.IdVariante+"</Variant><ForceVariant>"+(nVal.TipoVariante?1:0)+"</ForceVariant><Event>"+nVal.IdIncidencia+"</Event><Workday>"+nVal.IdHorario+"</Workday><Comments>"+nVal.Observaciones+"</Comments></NewValues>";
				valor+="</Petition>";
				Jade.AjaxDBSave(table,fields,[IdPeticion,'14','1','0',valor]);
			}
		}
		{//Horas estandar
			for(var i=0, iLen=xml.duttytime.length; i<iLen; i++){
				var value = xml.duttytime[i];
				var valor="<Petition><PrimaryKey><EmployeeId>"+txtCode.GetText()+"</EmployeeId><Year>"+value.year+"</Year><Month>"+value.month+"</Month></PrimaryKey>";
				valor += "<NewValues><value>"+value.newValue+"</value></NewValues><OldValues><value>"+value.oldValue+"</value></OldValues></Petition>";
				Jade.AjaxDBSave(table, fields, [IdPeticion, '15', '1', '0', valor]);
			}
		}
		{//Estado
			for(var i=0, ilen=xml.status.add.length; i<ilen; i++){
				var valor="<Petition>"+primaryKey+"<NewValues><Date>"+xml.status.add[i]+"</Date></NewValues></Petition>";
				Jade.AjaxDBSave(table, fields, [IdPeticion, '16', '0', '0', valor]);
			}
			for(var i=0, ilen=xml.status.mod.length; i<ilen; i++){
				var valor="<Petition>"+primaryKey+"<NewValues><Date>"+xml.status.mod[i].newValue+"</Date></NewValues><OldValues><Date>"+xml.status.mod[i].oldValue+"</Date></OldValues></Petition>";
				Jade.AjaxDBSave(table, fields, [IdPeticion, '16', '1', '0', valor]);
			}
			for(var i=0, ilen=xml.status.del.length; i<ilen; i++){
				var valor="<Petition>"+primaryKey+"<OldValues><Date>"+xml.status.del[i]+"</Date></OldValues></Petition>";
				Jade.AjaxDBSave(table, fields, [IdPeticion, '16', '2', '0', valor]);
			}
		}
		
		{//Datos en el terminal
			for(var i=0,iLen=xml.terminal.length;i<iLen;i++){
				var item=xml.terminal[i];
				var valor="<Petition>"+primaryKey;
				if(!newEmployee){ valor+="<OldValues><field>"+item.field+"</field><value>"+item.oldValue+"</value></OldValues>"; }
				valor+="<NewValues><field>"+item.field+"</field><value>"+item.newValue+"</value></NewValues>";
				valor+="</Petition>";
				Jade.AjaxDBSave(table,fields,[IdPeticion,'17',family,'0',valor]);
			}
		}
		{//Notes
			for(var i=0, ilen=xml.notes.add.length; i<ilen; i++){
				var item=xml.notes.add[i];
				var valor="<Petition>"+primaryKey+"<NewValues><Date>"+item.date+"</Date><Time>"+item.time+"</Time><Text>"+item.text+"</Text></NewValues></Petition>";
				Jade.AjaxDBSave(table, fields, [IdPeticion, '18', '0', '0', valor]);
			}
			for(var i=0, ilen=xml.notes.mod.length; i<ilen; i++){
				var item=xml.notes.mod[i];
				var valor="<Petition>"+primaryKey;
				valor+="<NewValues><Date>"+item.newValues.date+"</Date><Time>"+item.newValues.time+"</Time><Text>"+item.newValues.text+"</Text></NewValues>";
				valor+="<OldValues><Date>"+item.oldValues.date+"</Date><Time>"+item.oldValues.time+"</Time><Text>"+item.oldValues.text+"</Text></OldValues>";
				valor+="</Petition>";
				Jade.AjaxDBSave(table, fields, [IdPeticion, '18', '1', '0', valor]);
			}
			for(var i=0, ilen=xml.notes.del.length; i<ilen; i++){
				var item=xml.notes.del[i];
				var valor="<Petition>"+primaryKey+"<OldValues><Date>"+item.date+"</Date><Time>"+item.time+"</Time><Text>"+item.text+"</Text></OldValues></Petition>";
				Jade.AjaxDBSave(table, fields, [IdPeticion, '18', '2', '0', valor]);
			}
			
			
		}
		{//Observaciones
			for(var i=0,iLen=xml.comments.length;i<iLen;i++){
				var item=xml.comments[i];
				var valor="<Petition>"+primaryKey;
				if(!newEmployee){ valor+="<OldValues><field>"+item.field+"</field><value>"+item.oldValue+"</value></OldValues>"; }
				valor+="<NewValues><field>"+item.field+"</field><value>"+item.newValue+"</value></NewValues>";
				valor+="</Petition>";
				
				Jade.AjaxDBSave(table,fields,[IdPeticion,'19',family,'0',valor]);
			}
		}
		
		if(typeof(id)!="undefined"){ Jade.Redirect("?employee&id="+id); }
		else{ Jade.Redirect("?employees"); }
	}
	pttWindow.Hide();
}
