$(".btn#add").click(function (){
	$('#full_name_err').html("");
	$('#login_name_err').html("");
	$('#pwd1_err').html("");
	$('#pwd2_err').html("");
	$('#email_err').html("");
	$('#phone_err').html("");
    $.ajax({
		url: "quan_tri_vien/them",
		type: "POST",
		data: $("#add_frm").serialize(),
		success: function (data, textStatus, jqXHR)
		{
			result = jQuery.parseJSON(data);
			if (result.success == "1")
			{   
				filter();
				$('#addAdmin').modal('hide');
			}
			else
			{
				for (var key in result.errors)
				{
					$('#'+key).html(result.errors[key]);
				}
			}
			
		},
               
	});
        
});

$('#editUser').on('show.bs.modal', function(e) {
	var id = $(e.relatedTarget).data('us-id');
	$.ajax({
		url: "nguoi_dung/id/" + id,
		type: "POST",
		success: function (data, textStatus, jqXHR)
		{
			result = jQuery.parseJSON(data);
			if (result.success=="1")
			{
				item = result.item;
				$("#edit_cellphone").val(item['cellphone']);
				$("#edit_acc_balanced").val(item['acc_balanced']);
			}else
			{
				console.log("Item not found !");
			}
		}
	});
	
	$(".btn#edit").click(function(){
		$.ajax({
			url: "nguoi_dung/sua/" + id,
			type: "POST",
			data: $("#edit_frm").serialize(),
			success: function (data, textStatus, jqXHR)
			{
				result = jQuery.parseJSON(data)
				console.log(result);
				if (result.success=="1"){
					filter();
					$('#editUser').modal('hide');
				}else
				{
					console.log("Edit error !");
				}
			}
		});
	});
});

$('#deleteUser').on('show.bs.modal', function(e) {
	var id = $(e.relatedTarget).data('us-id');
	$(".btn#delete").click(function(){
		$.ajax({
			url: "nguoi_dung/xoa/" + id,
			type: "POST",
			success: function (data, textStatus, jqXHR)
			{
				result = jQuery.parseJSON(data)
				if (result.success=="1"){
					filter();
					$('#deleteUser').modal('hide');
				}else
				{
					console.log("Delete error !");
				}
			}
		});
	});
});

(function($){
    $.fn.setCursorToTextEnd = function() {
        $initialVal = this.val();
        this.val($initialVal + ' ');
        this.val($initialVal);
    };
})(jQuery);