/*******************XMLHTTP OBJECT VARIABLES********************/
/***************************************************************/

var url = "inc/engine.php?a="; // The server-side script for GET procedures
var url2 = 'inc/engine.php'; // The server-side script for POST procedures
var isWorking = false;
var http = getHTTPObject(); // We create the HTTP Object

function checkMail()
{
	var x = document.forms.contactform.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(x)) {
		return 0;
	}
	return 1;
	
}

function contacthandler() {
	if (document.forms.contactform.name.value == "") {
		alert("Please Enter Your Name!");
		return 0;
		location.href="sep.html";
	}
	
	if (document.forms.contactform.email.value == "") {
		alert("Please Enter Your Email Address!");
		return 0;
		location.href="sep.html";
	}
	
	if (checkMail()==0) {
		alert("Please Enter A Valid Email Address!");
		return 0;
		location.href="sep.html";
	}
	
	if (http) {
	   var command = 'a=cform&name='+document.forms.contactform.name.value+'&email='+document.forms.contactform.email.value+'&update='+document.forms.contactform.update.value+'&message='+document.forms.contactform.message.value;

	  
	  //For File Upload, include: &pic='+document.forms.form1.browsepic.value

	  http.open("POST", url2, false);
	  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  http.send(command);

		
	  if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
			//document.getElementById('actionstatus').innerHTML = http.responseText;
	  		//document.getElementById('actionstatus').style.display='block';
			if (http.responseText != '') {
				alert(http.responseText+" (Please try re-sending your message)");
			} else {
				alert("Message Sent! Thank you for contacting us!");
				window.location.href="http://www.bytekraft.com/sep.html";
			}
			http = getHTTPObject();
	  	}
	  }
	}
	
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

