// Ajax Contact Javascript

var file_url = 'scripts/ajaxcontact.php'; // the url for ajaxcontact.php

function getXHTTP( ) {
  var xhttp;
   try {   // The following "try" blocks get the XMLHTTP object for various browsers…
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
 		 // This block handles Mozilla/Firefox browsers...
	    try {
	      xhttp = new XMLHttpRequest();
	    } catch (e3) {
	      xhttp = false;
	    }
      }
    }
  return xhttp; // Return the XMLHTTP object
}

var http = getXHTTP(); // This executes when the page first loads.

function sendemail() {
	var msg = encodeURI(document.getElementById("msg").value);
	var name = encodeURI(document.getElementById("name").value);
	var email = encodeURI(document.getElementById("email").value);
	var phone = encodeURI(document.getElementById("phone").value);
	var faux = encodeURI(document.getElementById("faux").value);		
	var cf_stage = encodeURI(document.getElementById("cf_stage").value);	
	document.getElementById('send').disabled = true; 
	document.getElementById('send').value = 'Processing ...';
	document.getElementById('processing').style.display = 'block';

var url = file_url;
var params = 'msg=' + msg +'&name=' + name + '&phone=' + phone + '&email=' + email + '&faux=' + faux + '&cf_stage=' + cf_stage;
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Connection", "close");
http.onreadystatechange = handleResponse;
http.send(params);

return false; // if there is a submit button, this makes sure it doesn't submit the form if there is javascript.

}

function handleResponse() {
    if(http.readyState == 4 && http.status == 200){
        var response = http.responseText; // These following lines get the response and update the page
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
			cf_init();
        }
    }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function cf_init() {
	if (document.getElementById("contactform") != null) {		
	document.getElementById("contactform").onsubmit = sendemail; // This replaces the no javascript submit action with the ajax submit action. 
	}
}<!-- 

 -->