function checkEmail(email)
{
		var nLen=email.length;
	   var bValid=true;
		var cValidChars	= "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.@-_";
        //composed only of A-Z,a-z,0-9, '.' , '@' , '-', '_'
		for (var i=0; i<nLen; i++)		        
	        {
			if( cValidChars.indexOf(email.charAt(i).toUpperCase())<0 )
		        {
				bValid = false;
				break;
		        }
	        }
        //exist one '@', and it isn't the first or last character
	   if(email.indexOf('@')!=email.lastIndexOf('@') || email.indexOf('@')<=0 || email.indexOf('@')==nLen-1)
	   {
		bValid = false;
	   }
        //exist at least one '.', and it isn't the first or last character      
	   if( email.indexOf('.')<=0 ||	email.lastIndexOf('.')==nLen-1  )
	   {
		bValid = false;
	   }
        //if exist '-' or '_' , not at the begining or end of email address.
		if(email.indexOf('-')==0 || email.lastIndexOf('-')==nLen-1 || email.indexOf('_')==0 || email.lastIndexOf('_')==nLen-1 )
	        {
			bValid = false;
		}       
        // '.' not immediately after '@'	
		if( email.indexOf('.')==email.indexOf('@')+1 )  
	   {
			bValid = false;
		}       
        //one special char can't immediately follow another 
		var bSpecialChar = false;
		for(var	i=0; i<nLen; i++)
	        {
			if( ".-_@".indexOf( email.charAt(i) )>=0  )
		        {
				if(bSpecialChar)
			        {
					bValid = false;
					break;
			        }
				else
				{       
					bSpecialChar = true;
			        }
		        }
			else
		        {
				bSpecialChar = false;
			}       
		}		        
if (email=="")
{bValid = true;
}						        
		return bValid;  
}