function createContactUs() {
const formId = 'contactUs';
closeForm( formId );
const body = document.body;
const container = document.createElement('div');
container.id = formId;
container.style = `
position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
background: white; padding: 25px; border: 1px solid #ccc;
box-shadow: 0 4px 8px rgba(0,0,0,0.4); z-index: 1010;
text-align: left; max-width: 520px; min-width: 320px;
`;
const form = document.createElement('form');
form.method = 'post';
form.action = 'https://io.trebeste.no/form';
form.setAttribute('data-hs-ignore', 'true');
const storedSrcV = getCookie('_tbv_Src');
const storedFbclidV = getCookie('_tbv_fbclid');
const storedGclidV = getCookie('_tbv_gclid');
const storedSrcT = getCookie('_tbt_Src');
const storedFbclidT = getCookie('_tbt_fbclid');
const storedGclidT = getCookie('_tbt_gclid');
form.innerHTML = `
Kontaktskjema
`;
const sendBtn = document.createElement('button');
sendBtn.type = 'submit';
sendBtn.innerHTML = 'Send kontaktskjema';
sendBtn.style = 'padding: 10px 15px; background: #2E94D2; color: #FFFFFF; border: none; border-radius: 3px; cursor: pointer;';
const closeBtn = document.createElement('button');
closeBtn.type = 'button';
closeBtn.textContent = 'Lukk';
closeBtn.style = 'padding: 10px 15px; margin-left: 10px; background: #6C757D; color: #FFFFFF; border: none; border-radius: 3px; cursor: pointer;';
closeBtn.addEventListener('click', function () {
closeForm( formId );
});
form.appendChild(sendBtn);
form.appendChild(closeBtn);
form.onsubmit = async function (e) {
e.preventDefault();
const formData = new FormData(form);
const name = formData.get('Name');
const email = formData.get('Email');
const desc = formData.get('Message');
try {
const response = await fetch(form.action, {
method: 'POST',
body: formData
});
if (response.ok) {
const data = await response.json();
showResponseMessage('Takk! Vi har sendt din melding.', 'success');
closeForm( formId );
} else {
showResponseMessage('Det oppsto en feil ved sending av skjema.', 'error');
}
} catch {
showResponseMessage('Nettverksfeil. Prøv igjen senere.', 'error');
}
};
container.appendChild(form);
body.appendChild(container);
body.style.overflow = 'hidden';
}