function validate(thisForm)
{
	with(thisForm)
	{
		if(trim(thisForm.pollEmail.value)=="")
		{
			alert("Please Enter Email-Id.");
			thisForm.pollEmail.focus();
			return false;
		}

		if(trim(thisForm.pollEmail.value)!="")
		{
			if(!emailValidation(trim(thisForm.pollEmail.value)))
			{
				thisForm.pollEmail.focus();
				return false;
			}
		}
	}
}

function emailValidation(value)
{
	if(trim(value)=="")
	{
		alert("Please Enter Email-Id.");
		return false;
	}
	else
	{
		if (echeck(trim(value),'Email Id')==false)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

function echeck(str,name) 
{
	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 "+name)
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid "+name)
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid "+name)
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid "+name)
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid "+name)
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid "+name)
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid "+name)
		return false
	 }

	 return true					
}
function LTrim( value ) 
{
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) 
{
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) 
{
	
	return LTrim(RTrim(value));
	
}