const districts = {
"ЦАО": [
{ name: "Таганский", minPrice: 34000000 },
{ name: "Пресненский", minPrice: 38000000 },
{ name: "Арбат", minPrice: 36000000 }
],
"САО": [
{ name: "Ховрино", minPrice: 12000000 },
{ name: "Беговой", minPrice: 22000000 }
],
"СВАО": [
{ name: "Свиблово", minPrice: 14000000 },
{ name: "Бутырский", minPrice: 15000000 }
],
"ВАО": [
{ name: "Перово", minPrice: 10500000 },
{ name: "Гольяново", minPrice: 9000000 }
],
"СЗАО": [
{ name: "Куркино", minPrice: 9500000 }
],
"ЗелАО": [
{ name: "Матушкино", minPrice: 7500000 }
],
"ЮАО": [
{ name: "Москворечье-Сабурово", minPrice: 8800000 }
],
"ЮЗАО": [
{ name: "Черёмушки", minPrice: 16500000 },
{ name: "Обручевский", minPrice: 18000000 }
],
"ЮВАО": [
{ name: "Некрасовка", minPrice: 7200000 },
{ name: "Южнопортовый", minPrice: 8500000 }
],
"ЗАО": [
{ name: "Фили-Давыдково", minPrice: 18000000 },
{ name: "Дорогомилово", minPrice: 32000000 }
]
};
// Заполнить список округов при загрузке страницы
document.addEventListener("DOMContentLoaded", populateDistricts);
function populateDistricts() {
const districtSelect = document.getElementById("district");
Object.keys(districts).forEach(district => {
const option = document.createElement("option");
option.value = district;
option.textContent = district;
districtSelect.appendChild(option);
});
}
function updateNeighborhoods() {
const district = document.getElementById("district").value;
const neighborhoodSelect = document.getElementById("neighborhood");
neighborhoodSelect.innerHTML = "";
if (district && districts[district]) {
districts[district].forEach((item) => {
const option = document.createElement("option");
option.value = item.name;
option.textContent = item.name;
neighborhoodSelect.appendChild(option);
});
} else {
const option = document.createElement("option");
option.textContent = "Сначала выберите округ";
neighborhoodSelect.appendChild(option);
}
document.getElementById("minPriceDisplay").innerHTML = "";
}
function updateMinPrice() {
const district = document.getElementById("district").value;
const neighborhood = document.getElementById("neighborhood").value;
const display = document.getElementById("minPriceDisplay");
display.classList.remove("fade-in");
setTimeout(() => {
const area = districts[district]?.find((n) => n.name === neighborhood);
if (area) {
display.innerHTML = `
Минимальная стоимость квартиры: ${area.minPrice.toLocaleString()} ₽`;
display.classList.add("fade-in");
}
}, 100);
}
function toggleMortgageFields() {
const mortgageValue = document.getElementById("mortgage").value;
const fields = document.querySelector(".mortgage-fields");
if (mortgageValue === "yes") {
fields.classList.remove("hidden");
} else {
fields.classList.add("hidden");
}
}
function validateAndCalculate() {
const budget = parseInt(document.getElementById("budget").value);
const district = document.getElementById("district").value;
const neighborhood = document.getElementById("neighborhood").value;
const neighborhoodData = districts[district]?.find(n => n.name === neighborhood);
const minPrice = neighborhoodData ? neighborhoodData.minPrice : 0;
if (!budget || budget < minPrice) {
alert("Ваш бюджет ниже минимальной стоимости квартиры в этом районе. Пожалуйста, выберите другой район.");
return;
}
calculateResults(minPrice);
}
function calculateResults(basePrice) {
const ownershipTerm = parseInt(document.getElementById("ownershipTerm").value);
const strategy = document.getElementById("strategy").value;
const useMortgage = document.getElementById("mortgage").value === "yes";
const factorKRT = document.getElementById("factorKRT").checked ? 0.10 : 0;
const factorMetro = document.getElementById("factorMetro").checked ? 0.12 : 0;
const factorEco = document.getElementById("factorEco").checked ? 0.06 : 0;
const growthRate = 0.06 + factorKRT + factorMetro + factorEco;
const futureValue = basePrice * Math.pow(1 + growthRate, ownershipTerm);
let netProfit = 0;
let annualIncome = 0;
if (strategy === "resale") {
netProfit = futureValue - basePrice;
} else {
const monthlyRent = basePrice * 0.0055;
annualIncome = monthlyRent * 12;
netProfit = (annualIncome * ownershipTerm);
}
const roi = (netProfit / basePrice) * 100;
const resultHTML = `
???? Будущая стоимость: ${futureValue.toLocaleString()} ₽
???? Чистая прибыль: ${netProfit.toLocaleString()} ₽
${strategy === "rent" ? `
???? Доход от аренды в год: ${annualIncome.toLocaleString()} ₽
` : ""}
???? Годовая доходность (ROI): ${roi.toFixed(2)}%
`;
const resultsBlock = document.getElementById("results");
resultsBlock.innerHTML = resultHTML;
resultsBlock.classList.remove("hidden");
document.getElementById("lead-magnet").classList.remove("hidden");
}
function submitLead() {
const phone = document.getElementById("userPhone").value.trim();
if (phone.length < 7) {
alert("Пожалуйста, введите корректный номер телефона.");
return;
}
alert("Спасибо! Мы свяжемся с вами в ближайшее время.");
document.getElementById("userPhone").value = "";
}