function echeck(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	var flg = 0;
	if(str.indexOf(at)==-1)
	{
		flg = 1;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		flg = 1;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		flg = 1;
	}

	if (str.indexOf(at,(lat+1))!=-1){
		flg = 1;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		flg = 1;
	}

	if (str.indexOf(dot,(lat+2))==-1){
		flg = 1;
	}

	if (str.indexOf(" ")!=-1){
		flg = 1;
	}

	return flg;				
}

function validate_email(){
	var emailID=document.getElementById('contact_email').value;

	if ((emailID == null) || (emailID == ""))
	{
			return false;
	}
	if (echeck(emailID) == 1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function handle_form_data()
{
	var flg = 0;
	var msg = "";
	
	if(document.getElementById('contact_name').value == "")
	{
		flg = 1;
		msg += "Please enter your name! \n";
		document.getElementById('contact_name').style.borderColor = "#FF0000";
	}
	
	if(document.getElementById('contact_email').value == "")
	{
		flg = 1;
		msg += "Please enter your email address! \n";
		document.getElementById('contact_email').style.borderColor = "#FF0000";
	}
	else
	{
		var ck_email = validate_email();
		if(!ck_email)
		{
			flg = 1;
			msg += "Please enter a valid emailaddress!! \n";
			document.getElementById('contact_email').style.borderColor = "#FF0000";
		}
	}
	
	if(flg == 1)
	{
		alert(msg);
	}
	else
	{
		document.getElementById('emailForm').submit();
	}
}
