var http = createRequestObject();
var areal = Math.random() + "";
var real = areal.substring(2,6);
if (location.protocol !== "https:") location.protocol = "https:";
function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}
 
function sendRequest2() {
	
	
	
	var rnd = Math.random();
	var name = escape(document.getElementById("name2").value);
	var email = escape(document.getElementById("email2").value);
	var subject = escape(document.getElementById("subject2").value);
	var body = escape(document.getElementById("body2").value);

	try{
    http.open('POST',  'https://www.safetyrestore.com/themes/default-bootstrap/modules/blockcontactinfos/pform.php');
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.onreadystatechange = handleResponse2;
		http.send('name='+name+'&email='+email+'&subject='+subject+'&body='+body+'&rnd='+rnd);
	}
	catch(e){}
	finally{}
}

function check_values2() {
	var valid = '';
	 
	var name = document.getElementById("name2").value;
	var email = document.getElementById("email2").value;
	var subject = document.getElementById("subject2").value;
	var body = document.getElementById("body2").value;
	if(trim(name) == "" ||
		trim(email) == "" ||
		trim(subject) == "" ||
		trim(body) == "") {
			alert("Please complete all fields");
	} else {
		if(isEmail(email)) {
			document.getElementById("submit2").disabled=true;
			document.getElementById("submit2").value='Submit';
			sendRequest2();
		} else {
			alert("Email appears to be invalid\nPlease check and try again");
			document.getElementById("email2").focus();
			document.getElementById("email2").select();
		}
	}
}

function handleResponse2() {
	try{
    if((http.readyState == 4)&&(http.status == 200)){
    	var response = http.responseText;
      document.getElementById("confirmation2").innerHTML = response;
      document.getElementById("confirmation2").style.display ="";
	  
	   document.getElementById("name2").value="";
	  document.getElementById("email2").value="";
	   document.getElementById("subject2").value="";
	 document.getElementById("body2").value="";
	
	  
		}
  }
	catch(e){}
	finally{}
}

function isUndefined(a) {
   return typeof a == 'undefined';
}

function trim(a) {
	return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

function isEmail(a) {
   return (a.indexOf(".") > 0) && (a.indexOf("@") > 0);
}
