var url = "submit-request-call.php"; // The server-side script
function handleHttpResponse() {
  if (http.readyState == 4) {
    results = http.responseText;
	if(results=="success")
	{
	document.requestCallForm.reset();
	document.getElementById('response_text').innerHTML = "<p class='success'>Thank you for your interest.</p>";
	}
	else
		{		
		document.getElementById('response_text').innerHTML = "<p class='failed'>The Form is Not able to Successfully Send due to server Problem, Please Try Later</p>";
		}
  }
}
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('response_text').style.display='';
	document.getElementById('response_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 checkForm(contact_form)
{
	
	// First Name Validation
	if(contact_form.region.value=="")
	{
		contact_form.region.className = "error";
		document.getElementById("errorMsg").innerHTML = "Please select your Region.";
		document.getElementById("errorMsg").style.display = "block";
		contact_form.region.focus();
		return false;
	}
	else {
		contact_form.region.className = "success";
		document.getElementById("errorMsg").style.display = "none";		
	}
	
	// Name Validation
	if(contact_form.name.value=="")
	{
		contact_form.name.className = "error";
		document.getElementById("errorMsg").innerHTML = "Please enter your Name.";
		document.getElementById("errorMsg").style.display = "block";
		contact_form.name.focus();
		return false;
	}
	else {
		contact_form.name.className = "success";
		document.getElementById("errorMsg").style.display = "none";		
	}
	
	// Title Validation
	if(contact_form.title.value=="")
	{
		contact_form.title.className = "error";
		document.getElementById("errorMsg").innerHTML = "Please enter Title.";
		document.getElementById("errorMsg").style.display = "block";
		contact_form.title.focus();
		return false;
	}
	else {
		contact_form.title.className = "success";
		document.getElementById("errorMsg").style.display = "none";		
	}
	
	// Phone Validation
	if(contact_form.phone.value=="")
	{
		contact_form.phone.className = "error";
		document.getElementById("errorMsg").innerHTML = "Please enter your Phone Number.";
		document.getElementById("errorMsg").style.display = "block";
		contact_form.phone.focus();
		return false;
	}
	if (isNaN(contact_form.phone.value)==true)
	{
		document.getElementById("errorMsg").innerHTML = "Please enter a valid Phone Number.";
		document.getElementById("errorMsg").style.display = "block";
		contact_form.phone.focus();
		contact_form.phone.value = "";
		return false;
	}
	else {
		contact_form.phone.className = "success";
		document.getElementById("errorMsg").style.display = "none";
	}
	
	// Email Validation
	if(contact_form.email.value=="")
	{
		contact_form.email.className = "error";
		document.getElementById("errorMsg").innerHTML = "Please enter your Email ID.";
		document.getElementById("errorMsg").style.display = "block";
		contact_form.email.focus();
		return false;
	}
		if (!contact_form.email.value.match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/))
		{
			contact_form.email.className = "error";
			document.getElementById("errorMsg").innerHTML = "Please enter a valid Email ID.";
			document.getElementById("errorMsg").style.display = "block";
			contact_form.email.focus();
			contact_form.email.value = "";
			return false;
		}
		else {
			contact_form.email.className = "success";
			document.getElementById("errorMsg").style.display = "none";
		}
	
	// Company Validation
	if(contact_form.company.value=="")
	{
		contact_form.company.className = "error";
		document.getElementById("errorMsg").innerHTML = "Please enter Company Name.";
		document.getElementById("errorMsg").style.display = "block";
		contact_form.company.focus();
		return false;
	}
	else {
		contact_form.company.className = "success";
		document.getElementById("errorMsg").style.display = "none";		
	}
	
	// Reason For Call Validation
	if(contact_form.reason.value=="")
	{
		contact_form.reason.className = "error";
		document.getElementById("errorMsg").innerHTML = "Please enter the reason for call.";
		document.getElementById("errorMsg").style.display = "block";
		contact_form.reason.focus();
		return false;
	}
	else {
		contact_form.reason.className = "success";
		document.getElementById("errorMsg").style.display = "none";		
	}
	

	//SendEmailData(contact_form);
	//styleChange();
	return true;
	
}

// TEXT FIELD STYLE CHANGE ----------------

function styleChange() 
{
	document.getElementById('errorMsg').innerHTML = "";
	for(i=0; i<document.requestCallForm.getElementsByTagName('input').length; i++) 
	{
		document.requestCallForm.getElementsByTagName('input')[i].className = "";
	}
}