/*
   This code is used for validating the email address on 
   the 'sample download' form pages.
*/

function validateForm(theForm)
{

  // var theForm = document.forms.shopform;

  if (theForm.email.value == "")
  {
    alert("Please enter your email address");
    theForm.email.focus();
    return (false);
  }
  
  if (theForm.email.value.length < 6)
  {
    alert("Please enter a valid email address");
    theForm.email.focus();
    return (false);
  }

  //
  // Check that the e-mail address contains
  // @ and . - there must be at least one char before the @, and
  // at least one char between the @ and the next . and at
  // least one char following that .
  // i.e. format a@b.c
  //
  var checkOK = "@";
  var checkStr = theForm.email.value;
  var allValid = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    if (ch == checkOK)
	{
	  if (checkOK == "@")
	  {
	    if (i == 0) break;
	    checkOK = ".";
	    i++;
		if (i < checkStr.length)
		{
		  if (checkStr.charAt(i) == "@") break;
		  if (checkStr.charAt(i) == ".") break;
		}
	  }
	  else
	  {
        i++;
		if (i < checkStr.length)
		{
		  if (checkStr.charAt(i) == "@") break;
		  if (checkStr.charAt(i) == ".") break;
		  allValid = true;
		  break;
		}
	  }
	}
  }
  if (!allValid)
  {
    alert("Please enter a valid email address");
    theForm.email.focus();
    return (false);
  }

  return(true);

}
