function checkvalid()
{
	if(validate() == true)
	{
		document.frmemail.submit();
	}
}

function validate()
{
	var email = document.frmemail.txtemail.value;
	
	if(ltrim(email).length < 1)
	{
		alert("Please enter email id");
		document.frmemail.txtemail.focus();
		return false;
	}

	if(isvalid_email(email) == false)
	{
		alert("Please check your Email Id");
		document.frmemail.txtemail.focus();
		return false;
	}
	return true;
}

function ltrim(str)
{
	var i;
	var newstr = "";
	var char;
	var flag = 0;

	for(i=0;i<str.length;i++)
	{
		char = str.charAt(i);
		if(char >= 'a' && char <= 'z')
		{
			newstr = newstr.concat(char);
			flag = 1;
		}
		if(char >= 'A' && char <= 'Z')
		{
			newstr = newstr.concat(char);
			flag = 1;
		}
		if(char >= '0' && char <= '9')
		{
			newstr = newstr.concat(char);
			flag = 1;
		}	
		if(flag == 1)
		{
			if(char == ' ' || char == "-" || char == '-' || char == "@")
			{
				newstr = newstr.concat(char);
			}
		}
	}
	return newstr;
}	 

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;

function isvalid_email(str)
{
	return emailfilter.test(str);
}