${q.question[language]}
`;
options.innerHTML = "";
if (q.input) {
const input = document.createElement("input");
input.type = "text";
input.required = true;
input.style = "width:100%; padding:8px; margin-bottom:10px; border:1px solid #ccc; border-radius:6px; font-family:Poppins,sans-serif;";
options.appendChild(input);
const next = document.createElement("button");
next.innerText = "Dalje";
next.style = "padding:8px 16px; border:none; background:#1881f4; color:#fff; border-radius:6px; cursor:pointer; font-family:Poppins,sans-serif;";
next.on-click = () => {
answers.push(input.value.trim());
current++;
if (current < questions.length) {
showQuestion();
} else {
submitLead();
}
};
options.appendChild(next);
} else {
q.options[language].forEach(opt => {
const btn = document.createElement("button");
btn.innerText = opt;
btn.style = "margin:5px 0; padding:10px; border:1px solid #ccc; border-radius:6px; background:#f9f9f9; cursor:pointer; width:100%; font-size:15px; color:#1881f4; font-family:Poppins,sans-serif;";
btn.on-click = () => {
answers.push(opt);
current++;
showQuestion();
};
options.appendChild(btn);
});
}
}
function submitLead() {
question.innerHTML = "Hvala! Javit ćemo vam se ubrzo. 👋";
options.innerHTML = "";
const message = `
Novi upit:
1. Usluga: ${answers[0]}
2. Budžet: ${answers[1]}
3. Ime: ${answers[2]}
4. Email: ${answers[3]}
`;
fetch("https://formsubmit.co/ajax/[email protected]", {
method: "POST",
headers: { "Content-Type": "application/json", "Accept": "application/json" },
body: JSON.stringify({
name: answers[2],
email: answers[3],
message: message,
_subject: "Novo upit od Sale agent"
})
}).then(() => {
setTimeout(() => {
leadBot.style.display = "none";
overlay.style.display = "none";
toggle.style.display = "block";
}, 3000);
});
}
toggle.on-click = () => {
leadBot.style.display = "block";
overlay.style.display = window.innerWidth > 768 ? "block" : "none";
toggle.style.display = "none";
current = 0;
answers = [];
showQuestion();
};
closeBtn.on-click = () => {
leadBot.style.display = "none";
overlay.style.display = "none";
toggle.style.display = "block";
};
overlay.on-click = () => {
leadBot.style.display = "none";
overlay.style.display = "none";
toggle.style.display = "block";
};
// Open only on the homepage once per session
if (window.location.pathname === "/" && !sessionStorage.getItem("leadBotShown")) {
setTimeout(() => {
leadBot.style.display = "block";
showQuestion();
if (window.innerWidth > 768) overlay.style.display = "block";
sessionStorage.setItem("leadBotShown", "true");
}, 7000);
} else {
// Ensure bot is always visible on other pages but doesn't automatically open
leadBot.style.display = "block";
overlay.style.display = window.innerWidth > 768 ? "block" : "none";
}