i18n = new I18n();

function PassRecDlg() {
	// Se almacena información útil
	this.passRecDlg = null;
}

PassRecDlg.prototype = {
	open: function() {
		// Se almacena una referencia a este objeto para poder acceder luego a él
		var thisDlg = this;
		
		// Se abre el diálogo del mapa
		$.ajax({
			type: "POST",
			url: i18n.linkTo("mngrPassRecDlg.php"),
			data: {op: "passRecDlg"},
			success: function (data) {
				
				if (data.errorCode) {
					alert("by");
					alert(data.errorMessage);
					return;
				}
				
				var passRecDlg = $(data.passRecDlg);
				passRecDlg.appendTo("body");
				
				// Se le da funcionalidad al botón Enviar
				passRecDlg.find("#recoverPassword").click(function() { thisDlg.recoverPassword(); });
				
				// Se le da funcionalidad al botón cerrar
				passRecDlg.find("#passRec_cerrar").click(function () { thisDlg.close(); });
				
				// Se pone el foco en el input
				passRecDlg.find("#passRecInput input").focus();
				
				// Por último, se almacena la referencia al diálogo
				thisDlg.passRecDlg = passRecDlg;
			},
			dataType: "json",
			async: false
		});
	},
	
	recoverPassword: function() {
		$.ajax({
			type: "POST",
			url: i18n.linkTo("mngrPassRecDlg.php"),
			data: {op: "recoverPassword", email: $("#passRecInput input").val()},
			success: function (data) {
				if (data.errorCode) {
					alert(data.errorMessage);
					return;
				}
				
				$("#passRec_content").html(data.htmlCode);
			},
			dataType: "json",
			async: false
		});
	},
	
	close: function() {
		this.passRecDlg.remove();
	}
};
