function lastFormPE(step)
{
	$('#person_add_' + step).hide();
	$('#person_add_title_'+step).hide();
	step--;
	$('#submit_'+step).prop('disabled','');
	$('#person_add_' + step).show();
	$('#person_add_title_'+step).show();
}


function ajax_person(step)
{
	var msg = $('#person_add_message').hide();
	var sbm = $('#submit_'+step).prop('disabled','disabled');
	var sContainer = $('#person_add_container > div');
	var tContainer = $('#person_add_title > div');
	var str = $('form[name=form_person_'+step+']').serialize(); //alert(str);

	$.ajax({
			   type: "POST",
			   url: 'http://myfc.ru/action/person_edit.php',
			   data: str,
			   dataType: 'json',
				success: function(data){
							if (typeof(data) !== 'object')
							{
								alert("Произошла непредвиденная ошибка");
								return false;
							}	
							else
							{
								if(typeof(data.errors) != 'undefined')
								{
									if(data.errors)
									{
										if(typeof(data.message) != 'undefined')
										{
											msg.html(data.message).show();
											sbm.prop('disabled','');
										}
										return false;
									}
								}
							}				
							
							sContainer.hide();
							tContainer.hide();
							step++;	
							if(!tContainer.is('#person_add_title_'+step))						
							{
								tContainer.add('<div id="person_add_title_' + step + '">').hide().appendTo('#person_add_title');
							}
							if(typeof(data.title) != 'undefined')
							{
								$('#person_add_title_'+step).html(data.title).show();
							}
							
							if(!sContainer.is('#person_add_'+step))
							{
								sContainer = sContainer.add('<div id="person_add_' + step + '">').hide().appendTo('#person_add_container');
							}
							
							if(typeof(data.rbody) != 'undefined')
							{
								$('#person_add_'+step).html(data.rbody).show();
							}
						},
				error: function (data, status, e)
						{
							alert(e);
							sbm.prop('disabled','');
						}
		});
  return false;

}

function ajaxFileUpload(frm)
{
		var but = $('#buttonUpload').hide();
		var fload = $('#floading').show();
		var sbm = $('#'+frm+' input[type=submit]').prop('disabled','disabled');
		
		//alert($('#'+frm+' input[type=submit]').size());
		
		$.ajaxFileUpload
		(
			{
				url:'http://myfc.ru/action/person_edit.php', 
				secureuri:false,
				cloneElementId: ['fileToUpload', 'update'], //id элементов для клонирования
				nameAction: ['paction', 'photo_upload'],
				dataType: 'json',
				success: function (data, status)
				{
					if (typeof(data) !== 'object')
					{
						alert("Произошла непредвиденная ошибка");
						fload.hide();
						but.show();
						sbm.prop('disabled','');
						return false;
					}	
					if(typeof(data.errors) != 'undefined')
					{
						if(data.errors)
						{
							alert(data.message);
							fload.hide();
							sbm.prop('disabled','');
							but.show();
						}
						else
						{
							//alert(data.message);
							var form = $('#'+frm);
							if(typeof(data.photo_id) != 'undefined')
							{
								var input = $('<input type="hidden" name="photo_id" value="'+data.photo_id+'" />');
								$(input).appendTo(form);
							}
							$('#fileToUpload').prop('disabled', 'disabled');
							fload.hide();
							$('#photo_loaded').show();
							sbm.prop('disabled','');
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
					fload.hide();
					but.show();
					sbm.prop('disabled','');
				}
			}
		)
		
		
		return false;
}
