function isCharsInBag (s, bag)
{
    var i;
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return(false);
    }
    return true;
}
  
function isValidChar(testingStr, userStr)
{
	var condition = true; 

	for(counter=0; counter < testingStr.length; counter++)
	{
		if(testingStr.indexOf(userStr.charAt(counter)) == -1)
		{
			condition = false;
		}
	}
	
	return condition;
}
function EmailCheck(email){
		
		if(email.value==''){
			alert("Please Enter Email Address");
            email.focus();            
            return false;
		}
		if ( !this.isCharsInBag( email.value, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._@-" ))
		{
		      
            alert("Invalid Email Address");
            email.focus();            
            return false;
		}
	
	if(email.value != '')
	   {
		var str=email.value;	
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var sdot=str.indexOf(dot,ldot+1);

		if (str.indexOf(at)==-1){
			alert("Invalid Email Address");
            email.focus();            
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			alert("Invalid Email Address");
            email.focus();            
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		if (str.substring(ldot+1)==''){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if (str.substring(sdot+1)==''){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if(str.lastIndexOf(".") == str.length-1)
		 {
		 	alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
	}//end of else
	return true;
}
function validateForm()
{
	var yname = document.frm.txtname;
	if (yname.value == "")
	{
		alert("Please Fill the 'Your Name' field.");
		yname.focus();
		return false;
	}
	var email = document.frm.txtemail;
	if(!this.EmailCheck(email))
	{
		return false;
	}
	return true;
}