function isEmpty(astring){
		if (astring=="") return true;
		else{
			for(var i=0;i<astring.length;i++){
				if (astring[i] != " ") return false;
			}
		}
			return true;
		}
	function validateEmail(){
		var emailID=document.getElementById("email")		
		if ((emailID.value==null)||(emailID.value=="")){
			//alert("Please enter your email")
			//emailID.focus()
			return false
		}
		if (echeck(emailID.value)==false){
			//emailID.value=""
			//emailID.focus()
			return false
		}
		return true
	}
 
	function echeck(str) {

		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
		 }

 		 return true					
	}
	function validateMessage(){
		document.getElementById("error").innerHTML = "";
		name=document.getElementById("name").value;
		email=document.getElementById("email").value;
		message=document.getElementById("message").value;
		phone=document.getElementById("phone").value;
		var nameE="";
		var emailE="";
		var messageE="";
		if (isEmpty(name)){
			nameE="<li>Name is Required</li>";
		}
		if (isEmpty(email)){
			emailE="<li>Email is Required</li>";
		}else if (!validateEmail()){
			emailE="<li>Invalid email address</li>";
		}
		if (isEmpty(message)){
			messageE="<li>Message is Required</li>";
		}
		if (isEmpty(name) || isEmpty(email) || isEmpty(message) || !validateEmail()){
			//alert("Please fill all required fields.");
			document.getElementById("error").innerHTML = "<ul>"+nameE+emailE+messageE+"</ul>";
			return;
		}
		sendMailAction();
	}
	function sendMailAction(){
	//alert(transfer_no);
		document.getElementById("error").innerHTML = "Sending...";	
		name=document.getElementById("name").value;
		email=document.getElementById("email").value;
		message=document.getElementById("message").value;
		phone=document.getElementById("phone").value;

				//document.getElementById("send").innerHTML="Sending..."
				xmlHttp=GetXmlHttpObject();
				if (xmlHttp==null){
					alert ("Browser does not support HTTP Request");
					return;
				}
				var url="sendmail.php";
				url=url+"?name="+name+"&email="+email+"&message="+message+"&phone="+phone;
				url=url+"&sid="+Math.random();
				xmlHttp.onreadystatechange=stateChangedSendEmail
				xmlHttp.open("GET",url,true)
				xmlHttp.send(null)
			
	}

	function stateChangedSendEmail(){ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 		{				
			if (xmlHttp.responseText != "Message Sent."){
				//document.getElementById("send").innerHTML=xmlHttp.responseText
				document.getElementById("error").innerHTML = "Unable to send message, please try again later.";
				return;				
			}else{
			//window.location = "thankyou.php";		
				document.getElementById("error").innerHTML = "Successfully sent message.";
				document.getElementById("name").value="";
				document.getElementById("email").value="";
				document.getElementById("message").value="";
				document.getElementById("phone").value="";
			}
		}
	}
	
	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;
	}