function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Your browser doesn't support the XmlHttpRequest object.");
 }
}

var receiveReq = getXmlHttpRequestObject();

function makeRequest(url, param) {
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
   receiveReq.open("POST", url, true);
   receiveReq.onreadystatechange = updatePage; 

   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");

   receiveReq.send(param);
 }   
}

function updatePage() {
 document.getElementById('result').innerHTML = '';
 if (receiveReq.readyState == 4) {
   document.getElementById('result').innerHTML = receiveReq.responseText;

   img = document.getElementById('imgCaptcha'); 

   img.src = 'includes/modules/create_image.php?' + Math.random();
 }
}

function getParam(theForm) {
 var url = 'includes/modules/contact_process.php';

 var postStr = theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value ) +
 "&" + theForm.name.name + "=" + encodeURIComponent( theForm.name.value ) +
 "&" + theForm.email.name + "=" + encodeURIComponent( theForm.email.value ) +
 "&" + theForm.subject.name + "=" + encodeURIComponent( theForm.subject.value ) +
 "&" + theForm.message.name + "=" + encodeURIComponent( theForm.message.value );

 makeRequest(url, postStr);
}
