// xmlHttp creation AJAX function GetXmlHttpObject() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } // Sent contact form function sendForm() { var contactform = document.getElementById("form"); var nameerror = document.getElementById("error_name"); var emailerror = document.getElementById("error_email"); var reasonerror = document.getElementById("error_reason"); var messageerror = document.getElementById("error_message"); var thename = contactform.name.value; var theemail = contactform.email.value; var thereason = contactform.reason.value; var themessage = contactform.message.value; // the encodeURI is used for multiline php support // Check if at least 1 field is filled if(thename != "" && theemail != "" && thereason != "" && themessage != "") { document.getElementById("formbuttons").innerHTML = "Busy sending..." nameerror.style.display = "none"; // Send the data using AJAX xmlHttp=GetXmlHttpObject(); if (xmlHttp == null) { alert ("Your browser isn't supported."); return; } var url = "contact/formsend"; var poststr = "thename=" + encodeURI(thename) + "&theemail=" + encodeURI(theemail) + "&thereason=" + encodeURI(thereason) + "&themessage=" + encodeURI(themessage); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState == 4) { document.getElementById("formdiv").innerHTML = xmlHttp.responseText; } } xmlHttp.open('POST', url, true); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Content-length", poststr.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(poststr); } else { if(thename == "") { nameerror.style.display = "block"; } else { nameerror.style.display = "none"; } if(theemail == "") { emailerror.style.display = "block"; } else { emailerror.style.display = "none"; } if(thereason == "") { reasonerror.style.display = "block"; } else { reasonerror.style.display = "none"; } if(themessage == "") { messageerror.style.display = "block"; } else { messageerror.style.display = "none"; } } }