// JavaScript Document
function cutChars(s, c)
		{
			var s1, x;
			x = s1 = "";
			l = s.length;
			for(i = 0; i < l; i++)
				if((x = s.charAt(i)) != c)
					s1+=x;
			return s1;
		}
		function isCharsInBag (s, bag)
		{  
			var i;
			for (i = 0; i < s.length; i++)
			{   
		       
				var c = s.charAt(i);
				if (bag.indexOf(c) == -1) return false;
			}
			return true;
		}
		function validateEmail(emailid)
		{
			if (emailid.charAt(0) == ' ')
			{
			alert("Email cannot have spaces");
			
			return false;
			}
			emailid = cutChars(emailid, " ");
			if(cutChars(emailid, ' ') == '')
			{
				return true;
			}
			at = emailid.indexOf("@");
			if(at <= -1) //one @ shd be there, not as the 1st char tho'
			{
				alert("Invlaid Emailid - no @");
				return false;
			}
			at1 = emailid.indexOf("@", at + 1);
			if(at1 != -1) //only one @ shd be there
			{
				alert("Invlaid Emailid - only one @");
				return false;
			}
			dot = emailid.indexOf(".", at + 1);
			if(dot - at < 2) //. shd be present, with atleast 1 char after @
			{
				alert("Invlaid Emailid - @.");
				return false;
			}
			if(emailid.indexOf(".@") != -1) //. shd not be just b4 @
			{
				alert("Invlaid Emailid - .@");
				return false;
			}
			if(emailid.indexOf("..") != -1)
			{
				alert("Invlaid Emailid - ..");
				return false;
			}
			if(emailid.charAt(emailid.length - 1) == "." || emailid.charAt(emailid.length - 2) == ".")
			{
				alert("Invlaid Emailid - last two chars");
				return false;
			}
			return true;
		}