var url = "contact-submit.php"; // The server-side script
function handleHttpResponse() {
  if (http.readyState == 4) {
    results = http.responseText;
	if(results=="success")
	{
	document.contactForm.reset();
	document.getElementById('thankyou').style.display = 'block';
	document.getElementById('thankyou').innerHTML = "<h3>Thank you</h3><p>Thank you for your interest . We'll be in contact with you as soon as possible.</p>";
	setTimeout("timedCount()", 10000);
	}
	else
		{
		document.getElementById('thankyou').style.display = 'block';
		document.getElementById('thankyou').innerHTML = "<p>The Form Not able to Successfully Send due to server Problem, Please Try Later.</p>";
		setTimeout("timedCount()", 10000);
		}
  }
}
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('thankyou').style.display = 'block';
	document.getElementById('thankyou').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;
}


// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf(")")==-1)return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


function timedCount(){
	document.getElementById('thankyou').innerHTML = '';
	document.getElementById('thankyou').style.display='none';
}


function checkForm(enquiry_form)

{		
	//var form = enquiry_form;

	if(enquiry_form.name.value=="")
	{
		alert("Please Enter Your First Name") ;
		enquiry_form.name.focus() ;
		return false;
	}

	
	if(enquiry_form.email=="")
	{
		alert("Please Enter Your Email ID!") ;
		enquiry_form.email.focus() ;
		return false;
	}
		if (!enquiry_form.email.value.match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/))
		{
			alert("Please enter a valid E-mail ID!");
			enquiry_form.email.select();
			return false;
		}
	if(enquiry_form.subject.value=="")
	{
		alert("Please Enter Your Subject") ;
		enquiry_form.subject.focus() ;
		return false;
	}
   if(enquiry_form.comments.value=="")
	{
		alert("Please Enter Your Comments") ;
		enquiry_form.comments.focus() ;
		return false;
	}	
  if(enquiry_form.question.value=="")
	{
		alert("Please Enter Your Question") ;
		enquiry_form.question.focus() ;
		return false;
	}		
	
	
	
	SendEmailData(enquiry_form); 
	return false;

}



