| Server IP : 185.252.147.100 / Your IP : 216.73.216.43 Web Server : nginx/1.27.3 System : Linux mitrofanov.ru 6.1.0-37-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22) x86_64 User : mitr ( 1000) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /www/html/auto.mitrofanov.ru/public/wp-content/themes/greenshift/ |
Upload File : |
const rentDay = document.getElementById("rentDay"),
priceAuto = document.getElementById("priceAuto"),
firstPaySlider = document.getElementById("firstPaySlider"),
firstPayInput = document.getElementById("firstPayInput"),
autoCalcPrice = document.getElementById("autoCalcPrice"),
calcForm = document.getElementById('calcForm'),
ranges = calcForm.querySelectorAll('input[type="range"]'),
texts = calcForm.querySelectorAll('input[type="text"]'),
payDay = document.getElementById('payDay'),
sumDay = document.getElementById('sumDay'),
payWeek = document.getElementById('payWeek'),
rentWeek = document.getElementById('rentWeek'),
sumWeek = document.getElementById('sumWeek'),
loanButtons = document.getElementById('loanButtons');
// function keyUp(event) {
// if (event.target.value > 500) {
// let length = event.target.value.length;
// event.target.value = event.target.value.slice(0, length - 1);
// return false;
// }
// }
texts.forEach(function(text) {
text.value = toSpace(text.value);
//text.value = new Intl.NumberFormat("fr-FR").format(text.value);
text.addEventListener("input", function(event) {
text.value = text.value.replaceAll(/\D/g, "");
var max = parseInt(text.max);
// console.log(max);
// console.log(text.value);
// console.log('*******');
if (parseInt(text.value) > max) {
text.value = max;
}
if (text.id == 'priceAuto') {
setRent(text.value);
}
const r = text.closest('div').querySelectorAll('input[type="range"]')[0];
r.value = text.value;
// // if (inputEvent.inputType === "insertText"){
text.value = new Intl.NumberFormat("fr-FR").format(text.value);
// // }
calculator();
});
});
ranges.forEach(function(range) {
range.addEventListener('input', function() {
//console.log(range.value);
const text = range.closest('div').querySelectorAll('input[type="text"]')[0];
//console.log (range.value);
text.value = toSpace(range.value);
if (range.id == 'autoCalcPrice') {
setRent(range.value);
}
calculator();
}, false);
});
loanButtons.querySelectorAll('input[type="radio"]').forEach(function(radio) {
radio.addEventListener('click', function(e) {
//console.log(this);
calculator();
});
});
let val = 70000;
function setRent(price) {
price = Math.round(price);
let p1 = (price * 0.1 >= 70000) ? price * 0.1 : 70000;
let p2 = price * 0.9;
if (val < p1) {
val = p1;
}
if (val > p2) {
val = p2;
}
val = Math.round(val);
firstPaySlider.value = val;
firstPayInput.value = val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
// console.log('p1 ' + p1);
// console.log('p2 ' + p2);
// console.log('val ' + val);
// console.log('=======');
//firstPaySlider.value = (price*0.1 >= 70000 ) ? price*0.1 : 70000;
//firstPayInput.value = (price*0.1).toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
firstPaySlider.max = Math.round(price - price * 0.1);
firstPayInput.max = Math.round(price - price * 0.1);
firstPaySlider.min = (price * 0.1 >= 70000) ? Math.round(price * 0.1) : 70000;
firstPayInput.min = (price * 0.1 >= 70000) ? Math.round(price * 0.1) : 70000;
}
function toSpace(input) {
const val = parseFloat(input.replace(/ /g, ''));
// return val.toLocaleString("fr-FR");
//var val = input.replace(/ /g, '');
//var output = parseInt(processed, 10);
//const val = parseInt(input.value);
//return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
return new Intl.NumberFormat("fr-FR").format(val);
}
function calculator() {
const price = autoCalcPrice.value,
rent = firstPaySlider.value,
loan = loanButtons.querySelector('input[name="radio"]:checked').value;
const a = Math.round((price - rent) / (loan * 365)),
b = Math.round(price * 0.001),
c = Math.round(a + b),
d = a * 7,
e = b * 7,
f = c * 7;
payDay.innerHTML = a.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
rentDay.innerHTML = b.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
sumDay.innerHTML = c.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
payWeek.innerHTML = d.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
rentWeek.innerHTML = e.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
sumWeek.innerHTML = f.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
}