Загрузка данных
document.addEventListener("DOMContentLoaded", () => {
const phoneInput = document.querySelector('input[name="phone"]');
if (phoneInput) {
phoneInput.addEventListener("input", (e) => {
let value = e.target.value.replace(/\D/g, "");
if (value.startsWith("7") || value.startsWith("8"))
value = value.substring(1);
let formatted = "+7 ";
if (value.length > 0) formatted += "(" + value.substring(0, 3);
if (value.length > 3) formatted += ") " + value.substring(3, 6);
if (value.length > 6) formatted += "-" + value.substring(6, 8);
if (value.length > 8) formatted += "-" + value.substring(8, 10);
e.target.value = formatted;
});
}
const pass = document.getElementById("password");
const confirm = document.getElementById("password_confirm");
const errorMsg = document.getElementById("pass-error");
const submitBtn = document.querySelector(".reg-button");
const bar = document.querySelector(".strength-bar");
if (pass && confirm) {
function validatePasswords() {
if (confirm.value.length > 0 && pass.value !== confirm.value) {
if (errorMsg) errorMsg.style.display = "block";
confirm.style.borderColor = "#ff4b4b";
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.style.opacity = "0.5";
}
} else {
if (errorMsg) errorMsg.style.display = "none";
confirm.style.borderColor = "var(--border-color)";
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.style.opacity = "1";
}
}
}
pass.addEventListener("input", () => {
validatePasswords();
if (bar) {
const val = pass.value;
bar.className = "strength-bar";
if (val.length > 0 && val.length < 6) bar.classList.add("weak");
else if (val.length >= 6 && /[0-9]/.test(val) && /[A-Z]/.test(val))
bar.classList.add("strong");
else if (val.length >= 6) bar.classList.add("medium");
}
});
confirm.addEventListener("input", validatePasswords);
}
const btnPrivate = document.getElementById('btn-private');
const btnCompany = document.getElementById('btn-company');
const typeInput = document.getElementById('user-type');
const labelName = document.getElementById('label-name');
btnPrivate.addEventListener('click', () => {
btnPrivate.classList.add('active');
btnCompany.classList.remove('active');
typeInput.value = 'private';
labelName.innerText = 'ФИО';
});
btnCompany.addEventListener('click', () => {
btnCompany.classList.add('active');
btnPrivate.classList.remove('active');
typeInput.value = 'company';
labelName.innerText = 'Название компании';
});
const dropBtn = document.querySelector(".dropbtn");
const dropContent = document.querySelector(".dropdown-content");
const langText = document.getElementById("languageText");
if (dropBtn && dropContent) {
dropBtn.addEventListener("click", (e) => {
e.stopPropagation();
dropContent.classList.toggle("show");
});
document.querySelectorAll(".dropdown-content a").forEach((link) => {
link.addEventListener("click", (e) => {
e.preventDefault();
if (langText) langText.textContent = link.getAttribute("data-lang");
dropContent.classList.remove("show");
});
});
}
const track = document.getElementById("track");
if (track) {
const slides = document.querySelectorAll(".slide");
let currentIndex = 3;
let isTransitioning = false;
function updateCarousel(animate = true) {
track.style.transition = animate
? "transform 0.6s cubic-bezier(0.22, 1, 0.36, 1)"
: "none";
slides.forEach((s, i) =>
s.classList.toggle("active", i === currentIndex),
);
const viewportWidth = track.parentElement.offsetWidth;
const slideWidth = slides[0].offsetWidth;
const gap = parseInt(getComputedStyle(track).gap);
const centerOffset = (viewportWidth - slideWidth) / 2;
const position = -(currentIndex * (slideWidth + gap)) + centerOffset;
track.style.transform = `translateX(${position}px)`;
}
function moveSlide(direction) {
if (isTransitioning) return;
isTransitioning = true;
currentIndex += direction;
updateCarousel();
}
track.addEventListener("transitionend", () => {
isTransitioning = false;
if (currentIndex === slides.length - 1) {
currentIndex = 1;
updateCarousel(false);
} else if (currentIndex === 0) {
currentIndex = slides.length - 2;
updateCarousel(false);
}
});
window.addEventListener("resize", () => updateCarousel(false));
window.addEventListener("load", () => updateCarousel(false));
}
});