function registration(urlSendPri,urlSendSec) {
	$("#registrationLoader").removeClass("hide");
	$("#registrationButton").addClass("hide");
	$.ajax({
		type: "POST",
		dataType: 'json',
		url: urlSendPri+urlSendSec+"ajax/registrati.php",
		data: {
			email : $('#email').val(), 
			username : $('#usernameReg').val(), 
			password : $('#passwordReg').val(),
			nome : $('#nome').val(),
			cognome : $('#cognome').val()
		},
		//Evento di riuscita
		success: function(response){
			if(response == ''){
				$("#emailError").hide();
				$("#emailError").html('');
				$("#usernameRegError").hide();
				$("#usernameRegError").html('');
				$("#passwordRegError").hide();
				$("#passwordRegError").html('');
				$("#nomeError").hide();
				$("#nomeError").html('');
				$("#cognomeError").hide();
				$("#cognomeError").html('');
				$("#registrationForm").remove();
				$("#dialogRegistration").dialog('option','height',150);
				$("#registrationComplete").show();
				$("#registrationComplete").append(''
					+'Registraione completata<br />'
					+'Tra pochi istanti riceverai una mail per confermare l\'indirizzo<br /><br />'
					+'Attendi il reindirizzamento'
				);
				setTimeout(function(){
					window.location.reload();
				}, 1000);
			} else {
				if(response.emailError != undefined){
					$("#emailError").show();
					$("#emailError").html(response.emailError);
				} else {
					$("#emailError").hide();
					$("#emailError").html('');
				}
				if(response.usernameError != undefined){
					$("#usernameRegError").show();
					$("#usernameRegError").html(response.usernameError);
				} else {
					$("#usernameRegError").hide();
					$("#usernameRegError").html('');
				}
				if(response.passwordError != undefined){
					$("#passwordRegError").show();
					$("#passwordRegError").html(response.passwordError);
				} else {
					$("#passwordRegError").hide();
					$("#passwordRegError").html('');
				}
				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('');
				}
			}
			$("#registrationLoader").addClass("hide");
			$("#registrationButton").removeClass("hide");
			return false;
		},
		error: function(){
			$("#error_msg").addClass('show');
			$("#error_msg").html('C\'è un problema riprovare');
		}
	});
}

$(function(){
	//Dialog
	$('#dialogRegistration').dialog({
		autoOpen: false,
		width: 350,
		height: 410,
		modal: true,
		draggable: false,
		position: ['top','center'],
		resizable: false
	});
	
	// Dialog Link
	$('#open_dialogRegistration').click(function(){
		$('#dialogRegistration').dialog('open');
		$('#email').val('');
		$("#emailError").hide();
		$("#emailError").html('');
		$('#usernameReg').val('');
		$("#usernameRegError").hide();
		$("#usernameRegError").html('');
		$('#passwordReg').val('');
		$("#passwordRegError").hide();
		$("#passwordRegError").html('');
		$('#nome').val('');
		$("#nomeError").hide();
		$("#nomeError").html('');
		$('#cognome').val('');
		$("#cognomeError").hide();
		$("#cognomeError").html('');
		return false;
	});
	
	
});
