var openForm = ""; var req; function toggleContactForm(id) { if (openForm == id) { hideContactForm(); } else if (hideContactForm()) { openForm = id; document.getElementById(openForm).style.display = 'block'; } } function abortContactForm() { hideContactForm(); } function hideContactForm() { if (openForm != "") { if (confirm('Vill du stänga kontaktformuläret?')) { doHideContactForm(); return true; } return false; } return true; } function doHideContactForm() { var theForm = document.getElementById('form_' + openForm); document.getElementById(openForm).style.display = 'none'; theForm.cfName.value = ''; theForm.cfEmail.value = ''; theForm.cfPhone.value = ''; //theForm.cfSubject.value = ''; theForm.cfText.value = ''; openForm = ""; } function submitCF(contextPath, prId, distId) { var theForm = document.getElementById('form_' + openForm); if (theForm.cfName.value.length == 0) { alert('Namn måste anges'); return; } else if (theForm.cfText.value.length == 0) { alert('Meddelande måste anges'); return; } else if (theForm.cfEmail.value.length == 0) { alert('E-postadress måste anges'); return; } else if (!isEmail(theForm.cfEmail.value)) { alert('E-postadressen är inte giltig'); return; } var params = 'name=' + escape(encodeURI(theForm.cfName.value)); params += '&email=' + escape(encodeURI(theForm.cfEmail.value)); params += '&phone=' + escape(encodeURI(theForm.cfPhone.value)); //params += '&subject=' + escape(encodeURI(theForm.cfSubject.value)); params += '&lang=' + escape(encodeURI('sv')); params += '&text=' + escape(encodeURI(theForm.cfText.value)); params += '&id=' + openForm.substring(openForm.indexOf("_")+1, openForm.length); params += '&pressreleaseId=' + prId; params += '&distributionId=' + distId; doPostRequest(contextPath + '/servlet/ContactPersonEmailServlet', params, onEmailSent); } function onEmailSent() { if (req.readyState == 4) { if (req.status == 200) { alert('Meddelandet skickat!'); doHideContactForm(); } else { alert('Ett problem uppstod när meddelandet skulle skickas'); } } }