//Initialise The HTTP Request Object Variable
var xmlHttp;
///////////////

// AJAX XML Function
// The purpose of the function is to solve the problem of 
// creating different XMLHTTP objects for different browsers
function GetXmlHttpObject() {
  
  var xmlHttp=null;
  
  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;
 
}

function submitData(name,companyName,phone,noticeArea) {

    //Create An Instance Of The XML HTTP Object
    xmlHttp = GetXmlHttpObject()
    ///////////////////////////////////////////
    
    //Ensure That The Current Browser Supports
    //The XML HTTP Object 
    if(xmlHttp == null) {
      alert ("Browser does not support HTTP Request");
      return;
    }
    //////////////////////////////////////////
    
    var url = '';
    
    url += 'resources/includes/submitData.php';
    url += '?action=create&name='+name+'&companyName='+companyName+'&phone='+phone;
      
    //Prepare The URL And Then
    //Append A Random ID To The URL String To Ensure 
    //That The Page Returned Is Not A Cached One  
    url=url+"&sid="+Math.random();
    //////////////////////////////////////////////
    
    //Make The Request  
    if(navigator.appName == "Microsoft Internet Explorer") {
      xmlHttp.open("POST",url,false);    
    }else xmlHttp.open("POST",url,true);    
    
    //Change The Destination Div On Receiving
    //A Valid Ready State
    xmlHttp.onreadystatechange = function () {
      if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200 || xmlHttp.status == 304) {
          if(xmlHttp.responseText == 1) {
            //The Process Was Successful
			noticeArea.innerHTML = '<span style="margin:15px 0 0px 50%; display:block"><img src="resources/images/header-form-tick.png" style="float:left; margin-left:-36px;" alt="" /></span><p style="float:left; width:235px; margin-left:15px;"><span style="font-size:15px; font-weight:bold; color:black;">Successfully sent</span>.<br><strong>We will be in touch soon.</strong> If you&#039;d like to talk to someone straight away, please call us on <strong class="whitespace:nowrap;">0845 36 77 200</strong>.</p><span class="clear-all"></span>';

			//Hide The LI Elements
			document.getElementById('main-name-field').className = 'hidden';
			document.getElementById('main-company-field').className = 'hidden';
			document.getElementById('main-phone-field').className = 'hidden';
			document.getElementById('main-form-buttons').className = 'hidden';						
			//-------------------
            
          }else { 
            //The Process Was NOT Successful             
            noticeArea.innerHTML = 'Failure Message Goes Here';
          }      
        }
      }
    }
    
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");  
    xmlHttp.send(null);  
    /////////////////////////// 
}