function $(id) { return document.getElementById(id); }
function hide(){$('error').style.display="none";};
function check_post(){
if(ValidateForm()==true){
var h=null;
var para ='email='+encodeURIComponent($('email').value)
			+'&subject='+encodeURIComponent($('subject').value)
			+'&message='+encodeURIComponent($('message').value)
			+'&referer='+encodeURIComponent($('referer').value);
			
			
if (window.XMLHttpRequest) {
h = new XMLHttpRequest();
} else if (window.ActiveXObject)
{h = new ActiveXObject("Microsoft.XMLHTTP");}
if (h != null)
{
	h.open("POST", "main/includes/mail.php", true);
	h.setRequestHeader(
      "Content-Type",
      "application/x-www-form-urlencoded");
	$('error').style.display="block";
	$('error').innerHTML='<img src="main/images/ajax2.gif" >';
	h.send(para);
}
//ajax event
h.onreadystatechange = function(){
if(h.readyState<4){

}
if (h.readyState==4)
{
var a=h.responseText;
$('error').style.display="block";
$('error').innerHTML= a;
window.setTimeout("hide()", 7000);
}
}	
}
}

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 ValidateForm(){
	var emailID=document.frmSample.email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
