function updateData(urlSendPri,urlSendSec) {
	$("#updateDataLoader").removeClass("hide");
	$("#updateDataButton").addClass("hide");
	$.ajax({
		type: "POST",
		dataType: 'json',
		url: urlSendPri+urlSendSec+"ajax/updateData.php",
		data: {
			nome : $('#nome').val(),
			cognome : $('#cognome').val(),
			utentiId : $('#userId').text()
		},
		//Evento di riuscita
		success: function(response){
			if(response == ''){
				$("#nomeError").hide();
				$("#nomeError").html('');
				$("#cognomeError").hide();
				$("#cognomeError").html('');
				$("#updateDataForm").remove();
				$("#updatePassForm").remove();
				$("#dialogUpdate").dialog('option','height',100);
				$("#updateComplete").show();
				$("#updateComplete").append(''
					+'Dati modificati<br />'
				);
				setTimeout(function(){
					window.location.reload();
				}, 1000);
			} else {
				if(response.nomeError != undefined){
					$("#nomeError").show();
					$("#nomeError").html(response.nomeError);
				} else {
					$("#nomeError").hide();
					$("#nomeError").html('');
				}
				if(response.cognomeError != undefined){
					$("#cognomeError").show();
					$("#cognomeError").html(response.cognomeError);
				} else {
					$("#cognomeError").hide();
					$("#cognomeError").html('');
				}
			}
			$("#updateDataLoader").addClass("hide");
			$("#updateDataButton").removeClass("hide");
			return false;
		},
		error: function(){
			$("#error_msg").addClass('show');
			$("#error_msg").html('C\'è un problema riprovare');
		}
	});
}

function updatePass(urlSendPri,urlSendSec) {
	$("#updatePassLoader").removeClass("hide");
	$("#updatePassButton").addClass("hide");
	$.ajax({
		type: "POST",
		dataType: 'json',
		url: urlSendPri+urlSendSec+"ajax/updatePass.php",
		data: {
			oldPass : $('#oldPass').val(),
			newPass : $('#newPass').val(),
			utentiId : $('#userId').text()
		},
		//Evento di riuscita
		success: function(response){
			if(response == ''){
				$("#oldPassError").hide();
				$("#oldPassError").html('');
				$("#newPassError").hide();
				$("#newPassError").html('');
				$("#updatePassForm").remove();
				$("#updateDataForm").remove();
				$("#dialogUpdate").dialog('option','height',100);
				$("#updateComplete").show();
				$("#updateComplete").append(''
					+'Password modificata<br />'
				);
				setTimeout(function(){
					window.location.reload();
				}, 1000);
			} else {
				if(response.oldPassError != undefined){
					$("#oldPassError").show();
					$("#oldPassError").html(response.oldPassError);
				} else {
					$("#oldPassError").hide();
					$("#oldPassError").html('');
				}
				if(response.newPassError != undefined){
					$("#newPassError").show();
					$("#newPassError").html(response.newPassError);
				} else {
					$("#newPassError").hide();
					$("#newPassError").html('');
				}
			}
			$("#updatePassLoader").addClass("hide");
			$("#updatePassButton").removeClass("hide");
			return false;
		},
		error: function(){
			$("#error_msg").addClass('show');
			$("#error_msg").html('C\'è un problema riprovare');
		}
	});
}

$(function(){
	//Dialog
	$('#dialogUpdate').dialog({
		autoOpen: false,
		width: 350,
		height: 400,
		modal: true,
		draggable: false,
		position: ['top','center'],
		resizable: false
	});
	
	// Dialog Link
	$('#open_dialogUpdate').click(function(){
		$('#dialogUpdate').dialog('open');
		$('#oldPass').val('');
		$("#oldPassError").hide();
		$("#newPass").val('');
		$('#newPassError').hide();
		$("#usernameRegError").hide();
		$("#usernameRegError").html('');
		$('#passwordReg').val('');
		$("#passwordRegError").hide();
		$("#passwordRegError").html('');
		$("#nomeError").hide();
		$("#nomeError").html('');
		$("#cognomeError").hide();
		$("#cognomeError").html('');
		return false;
	});
	
	//Dialog
	$('#dialogUpdateAvatar').dialog({
		autoOpen: false,
		width: 350,
		height: 400,
		modal: true,
		draggable: false,
		position: ['top','center'],
		resizable: false
	});
	
	// Dialog Link
	$('#open_dialogUpdateAvatar').click(function(){
		$('#dialogUpdateAvatar').dialog('open');
		return false;
	});
	
});
