(function(){
document.addEventListener(“DOMContentLoaded”, function() {
const edadInput = document.getElementById(“edad”);
const aporteInput = document.getElementById(“aporte”);
const edadVal = document.getElementById(“edadVal”);
const aporteVal = document.getElementById(“aporteVal”);
const fondoEl = document.getElementById(“fondo”);
const rentaEl = document.getElementById(“renta”);
const tasaAnualUSD = 0.04; // 4%
const tasaAnualPesos = 0.18; // 18%
function formatoMoneda(valor, moneda) {
if (!isFinite(valor)) return “-“;
if (moneda === “usd”) {
return “$” + Number(valor).toLocaleString(“en-US”, {minimumFractionDigits: 0});
} else {
return “$” + Number(valor).toLocaleString(“es-AR”, {minimumFractionDigits: 0});
}
}
function cotizar() {
const edad = parseInt(edadInput.value, 10);
const aporte = parseFloat(aporteInput.value);
var sexoEl = document.querySelector(‘input[name=”sexo”]:checked’);
var monedaEl = document.querySelector(‘input[name=”moneda”]:checked’);
const sexo = sexoEl ? sexoEl.value : ‘hombre’;
const moneda = monedaEl ? monedaEl.value : ‘ars’;
const edadRetiro = (sexo === “mujer”) ? 60 : 65;
const meses = Math.max(0, (edadRetiro – edad) * 12);
let tasaMensual;
if (moneda === “usd”) {
tasaMensual = tasaAnualUSD / 12;
} else {
tasaMensual = tasaAnualPesos / 12;
}
const mesesRenta = (sexo === “mujer”) ? 189 : 150;
var fondo = 0;
if (meses > 0) {
fondo = aporte * ((Math.pow(1 + tasaMensual, meses) – 1) / tasaMensual);
} else {
fondo = aporte;
}
fondo = Math.floor(fondo); // sin decimales
const renta = Math.floor(fondo / mesesRenta); // renta mensual sin decimales
fondoEl.textContent = formatoMoneda(fondo, moneda);
rentaEl.textContent = formatoMoneda(renta, moneda);
}
function actualizarAporteLabel() {
const monedaEl = document.querySelector(‘input[name=”moneda”]:checked’);
const moneda = monedaEl ? monedaEl.value : ‘ars’;
const aporte = parseFloat(aporteInput.value);
const prefix = (moneda === “usd”) ? “USD ” : “$”;
aporteVal.textContent = prefix + aporte.toLocaleString();
}
document.querySelectorAll(‘input[name=”sexo”], input[name=”moneda”]’).forEach(function(input) {
input.addEventListener(“change”, function() {
if (input.name === “moneda”) {
// Alternar solo un checkbox
document.querySelectorAll(‘input[name=”moneda”]’).forEach(function(c) {
if (c !== input) c.checked = false;
});
}
if (input.name === “sexo”) {
// Alternar solo un sexo
document.querySelectorAll(‘input[name=”sexo”]’).forEach(function(c) {
if (c !== input) c.checked = false;
});
}
// Actualizar aportes y cotizar
if (input.name === “moneda”) {
if (input.value === “usd” && !input.checked) {
// si se deselecciona USD, vuelves a ARS
document.querySelector(‘input[name=”moneda”][value=”ars”]’).checked = true;
}
if (input.value === “ars” && !input.checked) {
document.querySelector(‘input[name=”moneda”][value=”usd”]’).checked = true;
}
}
if (input.name === “sexo”) {
if (input.value === “mujer” && !input.checked) {
document.querySelector(‘input[name=”sexo”][value=”hombre”]’).checked = true;
}
if (input.value === “hombre” && !input.checked) {
document.querySelector(‘input[name=”sexo”][value=”mujer”]’).checked = true;
}
}
// Ajustar los límites de los rangos
const monedaEl = document.query
