var url = "submit-reqcall.php"; // The server-side script
function handleHttpResponse() {
  if (http.readyState == 4) {
    results = http.responseText;
	if(results=="success")
	{
	document.reqCallForm.reset();
	document.getElementById('reponse_text').innerHTML = "<p>Thank you for your interest.</p>";
	setTimeout('timeOut()', 5000);
	}
	else
		{
		
		document.getElementById('reponse_text').innerHTML = "<p>The Form is Not able to Successfully Send due to server Problem, Please Try Later</p>";
		setTimeout('timeOut()', 5000);
		}
  }
}
var http; // We create the HTTP Object

function SendEmailData(email_form) {
	http = getHTTPObject();
	var form_var="fo=1" ;
	for(i=0;i<email_form.elements.length; i++)
	{
		form_var = form_var + "&" + email_form.elements[i].name + "=" + email_form.elements[i].value ;
	}
	http.onreadystatechange = handleHttpResponse;
	http.open("POST", url, true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send(form_var);
	document.getElementById('reponse_text').style.display='';
	document.getElementById('reponse_text').innerHTML="<p>Sending The Data.. Wait Please!</p>" ;
 }
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;
}

function timeOut() {
	document.getElementById("reponse_text").style.display = "none";
}

function checkForm(contactForm)
{
	
	if(contactForm.selRegion.value=="")
	{
		alert("Please choose your region!");
		contactForm.selRegion.focus();
		return false;
	}
	
	if(contactForm.name.value=="")
	{
		alert("Name field should not be blank!");
		contactForm.name.focus();
		return false;
	}
	
	if(contactForm.phone.value=="")
	{
		alert("Phone field should not be blank!") ;
		contactForm.phone.focus() ;
		return false;
	}
	if(isNaN(contactForm.phone.value)==true)
	{
		alert("Phone number must be numeric") ;
		contactForm.phone.focus();
		contactForm.phone.value="";
		return false;
	}
	
	if(contactForm.email.value=="")
	{
		alert("Email field should not be blank!");
		contactForm.email.focus();
		return false;
	}
	if (!contactForm.email.value.match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/))
	{
		alert("Enter a valid E-mail ID!");
		contactForm.email.focus();
		contactForm.email.value="";
		return false;
	}
	
	if(contactForm.title.value=="")
	{
		alert("Title field should not be blank!");
		contactForm.title.focus();
		return false;
	}
	
	if(contactForm.company.value=="")
	{
		alert("Company field should not be blank!");
		contactForm.company.focus();
		return false;
	}

	if(contactForm.selAboutUs.value=="")
	{
		alert("Please choose how did you hear about us!");
		contactForm.selAboutUs.focus();
		return false;
	}

	if(contactForm.selPleaseCallMe.value=="")
	{
		alert("Please call me field should not be blank!");
		contactForm.selPleaseCallMe.focus();
		return false;
	}

	if(contactForm.reasonForCall.value=="")
	{
		alert("Reason for call field should not be blank!");
		contactForm.reasonForCall.focus();
		return false;
	}

	SendEmailData(contactForm); 
	return false ;
}
