
function check()
{
if(document.form.Fname.value=="")
{	
alert("Please enter the Name");
document.form.Fname.focus();	
}
else
if(document.form.Email.value=="")
{
alert("Please enter your Email Address");
document.form.Email.focus();
}

				else
					{
							
	var txt;
	var stringarray;
	var cnt;
	var invalid;
	var alpbet;

		alpbet=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];

		var txt=(document.form.Email.value);
		var inv;
		if (txt.length >0)
		{
				stringarray=txt.split("");
				invalid = false;
				inv=false;
				for (var j=0; j< alpbet.length; j++)
				   {
				     if (stringarray[0].toUpperCase() == alpbet[j] || stringarray[0]==alpbet[j] )
				     {
				        invalid = false;
				        break;
				     }
				     else
				        invalid = true;
				  	}

				   if (invalid == true)
				   {
				      alert("Please enter valid E-mail starting with an alphabet");
				      document.form.Email.focus();
				      return false;
				   }
		}
		
		// Checks that no other character should be entered except the alphanumeric characters, @ and a dot 
		
		for (var i=0; i<txt.length; i++)
		{
			for (var j=0; j<alpbet.length; j++)
			{
				     if (stringarray[i].toUpperCase() == alpbet[j])
				     {
				          inv = false;
				          break;
				      }
				      else
				      {
				   		if ((stringarray[i] == "1")||(stringarray[i] == "2")||(stringarray[i] == "3")||(stringarray[i] == "4")||(stringarray[i] == "5") || (stringarray[i] == "6")||(stringarray[i] == "7")||(stringarray[i] == "8")||(stringarray[i] == "9")||(stringarray[i] == "0"))
				     	{
				            inv = false;
				            break;
				       }
				       if (stringarray[i] == "@")
				       {
				             inv = false;
				             break;
				        }
				        if (stringarray[i] == ".")
				        {
				               inv = false;
				               break;
				        }
				        if (stringarray[i] == "_")
				        {
				              inv = false;
				              break;
				        }
				       if (stringarray[i] == "-")
				    	{
				             inv = false;
				             break;
				     	}
				      
				             inv=true;
				       }
				}
				if (inv == true)
				break;
		}

				  if (inv == true)
				  {
				     alert("Please enter valid E-mail id, only @ and . are allowed");
					 document.form.Email.focus();
				     return false;
				  }


					// Dot cannot be the last character of the id
				  
				  
				  if (txt.length == (txt.lastIndexOf(".")+1))
				  {
				    alert("Please enter valid E-mail id, dot cannot be the last character");
					document.form.Email.focus();
					return false;
				  }
				  
				    
				  
				// .and @ cannot appear in the consecutive positions
				  
				  
				var index1=0;
				var checkStr = (document.form.Email.value);

				for (var i=0; i<checkStr.length; i++)
				{
				  	if(checkStr.charAt(i)=='.')
				  	{
				     	index1=i;
				     	if(checkStr.charAt(i-1)=='.' || checkStr.charAt(i-1)=='@' || checkStr.charAt(i+1)=='.' || checkStr.charAt(i+1)=='@')
				     	{
				      		alert("Please enter valid E-mail");
				      		document.form.Email.focus();
				      		return false;
				     	}
				  	}

				}
				// Checks for the missing @

				if (txt.indexOf("@") == -1)
				  {
					alert("Please enter valid E-mail, @ missing");
					document.form.Email.focus();
				     return false;
				  }
				  
				  
				  
				  // Checks for the missing dot

				  if (txt.indexOf(".") == -1)
				  {
					alert("Please enter valid E-mail, dot missing");
					document.form.Email.focus();
				     return false;
				  }
					
				 				  
				  
				  
				  //Checks that there should be atleast 3 characters before @
				  
				  if (txt.indexOf("@")<3)
				  {
				   	alert("Please enter valid E-mail, @ not at correct position");
					document.form.Email.focus();
				    return false;
				  }
				  
				  				  
					// Checks for more than one occurences of @
				  
				  cnt=0;
				  for (var i=0; i<stringarray.length; i++)
				  {
				      if (stringarray[i] == "@")
				     {
				          cnt= cnt + 1;
				     }
				  }

				  if (cnt > 1)
				  {
				    alert("Please enter valid E-mail, more than 1 @ not allowed");
					document.form.Email.focus();
				    return false;
				  }
					
					
					
				var checkOK =
				"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@._-";
				var allValid = true;

				for (i = 0;  i < checkStr.length;  i++)
				{
				   ch = checkStr.charAt(i);
				   for (j = 0;  j < checkOK.length;  j++)
				      if (ch == checkOK.charAt(j))
				         break;
				   if (j == checkOK.length)
				   {
				      allValid = false;
				      break;
				   }
				}

				if (!allValid)
				{
				    //alert("Please enter only letter, digit and \"@._-\" characters in the email");
					alert("Please enter valid E-mail id");
					document.form.Email.focus();
				   return false;
				}
else
if(document.form.cell.value=="")
{
alert("Please enter your Phone/Cell No.");
document.form.cell.focus();
}
else
if(document.form.comment.value=="")
{
alert("Please write your query");
document.form.comment.focus();
}
else
{
document.form.submit();
}
}
}
