// JavaScript Document
// Function for Checking Valid Email
// By Stanley  dtd. Aug 25, 2004
function isEmail(cntrl)
{
	{
		emailid = cntrl.value;
		if (emailid.indexOf(' ') > 0)
		{
			alert("Space is not allowed in Email Address !!!");
			return false;
		}
		if ((emailid.indexOf('@') == 0) || (emailid.indexOf('.') == 0))
		{
			alert("'.' or '@'  not allowed as first character in Email Address !!!");
			return false;		
		}
		if ((emailid.indexOf('@') == -1) || (emailid.indexOf('.') == -1))
		{
			alert("Please enter valid E-mail Address");
			return false;
		}
		var Dot= emailid.split('.');
		var Atr= emailid.split('@');
		if (Atr.length>2)
		{
			alert("Invalid Position Of '@' in E-mail Address");
			return false;
		}
		var AtPos=emailid.indexOf('@');
		var DotPos=emailid.indexOf('.');
		var DotLPos=emailid.lastIndexOf('.');

		if (Dot.length>2)
		{
			if (emailid.indexOf('@')>emailid.lastIndexOf('.'))
			{
				alert("Invalid Position Of '.' in E-mail Address");
				return false;
			}
			if (AtPos>DotPos) //---------- .@
			{
				if ((AtPos-DotPos)<2)
				{
					alert("Invalid Position Of '.' in E-mail Address");
					return false;
				}
			}
			else
			{
				if ((DotPos-AtPos)<2)
				{
					alert("Invalid Position Of '.' in E-mail Address");
					return false;
				}
			}
			if ((DotLPos-AtPos)<2)
			{
				alert("Invalid Position Of '.' in E-mail Address");
				return false;
			}
		}
		else
		{
			if (AtPos>DotPos) //---------- .@
			{
				if ((AtPos-DotPos)<2)
				{
					alert("Invalid Position Of '.' in E-mail Address");
					return false;
				}
			}
			else
			{
				if ((DotPos-AtPos)<2)
				{
					alert("Invalid Position Of '.' in E-mail Address");
					return false;
				}
			}				
		}
		if (DotLPos>(emailid.length-3))
		{
			alert("Invalid Length after '.'  !!!");
			return false;
		}
	}
	return true;
}

// for removing spaces
function trim(st)
{
	if(st.length > 0)
	{
		re = / +$/g; 
		newval = st.replace(re,"")
		re = /^ +/g;
		newvala = newval.replace(re,"")
		return newvala;
	}
	return ""
}

