﻿
function checkContact()
{
	contact_name=document.getElementById('contact_name').value;
	company=document.getElementById('company').value;
	email=document.getElementById('email').value;
	phone=document.getElementById('phone').value;
	project=document.getElementById('project').value;
	timeline=document.getElementById('timeline').value;
	
	  if(!contact_name){alert("We need the contact name not to be blank."); return;}
	  if(!company){alert("We need the company not to be blank."); return;}
	  if(!email){alert("We need the email not to be blank."); return;}
	  if(!phone){alert("We need the phone not to be blank."); return;}
	  
	  
	  
		var str=email;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }


	  sendMail(contact_name, company, email, phone, project, timeline);
}


function sendMail(contact_name, company, email, phone, project, timeline)
{

if (email.length==0)
  { 
  //document.getElementById("txtHint").innerHTML="";
  return;
  }
  
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
  

  
var url="/ajax/contactsend.asp";
url=url+"?contact_name="+contact_name; 
url=url+"&company="+company; 
url=url+"&email="+email; 
url=url+"&phone="+phone; 
url=url+"&project="+project; 
url=url+"&timeline="+timeline; 
	
//alert(url);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
	
if (xmlHttp.readyState==4)
{ 
//alert(xmlHttp.responseText);
document.getElementById('contactForm').style.display="none";

document.getElementById('postSend').style.display="block";

}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}