function doHttpRequest() {  // This function does the AJAX request
  http.open("GET", "/template/formContacts.html", true);
  http.onreadystatechange = getHttpRes;
  http.send(null);
}

function doHttpRequest2() {  // This function does the AJAX request
  //here we need to do validation
  document.getElementById('errorId').innerHTML = '';
  document.getElementById('txtLabel').style.color = '';
  document.getElementById('mailLabel').style.color = '';
  if (document.getElementById('txt').value == '') {
    document.getElementById('errorId').innerHTML = '<span style="color: red">Поле "текст сообщения" обязательно для заполнения</span>';	
    document.getElementById('txtLabel').style.color = 'red';
    return false;
  }
  var mail = document.getElementById('mail').value;
  
  if (mail == '') {
	document.getElementById('errorId').innerHTML = '<span style="color: red">поле E-mail обязательно для заполнения</span>';	
    document.getElementById('mailLabel').style.color = 'red';
    return false;
  }
  var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
  if (!mail.match(re)) {
	document.getElementById('errorId').innerHTML = '<span style="color: red">вы неправильно ввели e-mail адрес</span>';	
    document.getElementById('mailLabel').style.color = 'red';
    return false;
  }
  http.open("GET", "/cms/formContacts.php?name="+document.getElementById('name').value+"&company="+document.getElementById('company').value+"&phone="+document.getElementById('phone').value+"&mail="+document.getElementById('mail').value+"&txt="+document.getElementById('txt').value, true);
  http.onreadystatechange = getHttpRes;
  http.send(null);
}

function getHttpRes() {
  if (http.readyState == 4) { 
    res = http.responseText;  // These following lines get the response and update the page
    document.getElementById('div1').innerHTML = res;
  }
}

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.
