// JAVASCRIT - Version 2

function formValidator(theForm)
{

  if (theForm.FullName.value == "")
  {
    alert("Please enter a value for the \"Name\" field.");
    theForm.FullName.select();
    theForm.FullName.focus();
    return (false);
  }

  // require at least 3 characters be entered
  if (theForm.FullName.value.length < 3)	
  {
    alert("Please make sure that \"Name\" field was properly completed.");    
    theForm.FullName.select();
    theForm.FullName.focus();
    return (false);
  }

  // allow ONLY alphabets, no symbols or punctuation
  // this can be altered for any "checkOK" string you desire
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
  var checkStr = theForm.FullName.value;
  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 alphabets and spaces in the \"Name\" field.");
    theForm.FullName.select();
    theForm.FullName.focus();
    return (false);
  }

 //**********************************************8
 if (theForm.Username.value == "")
  {
    alert("Please enter a value for the \"User Name\" field.");
    theForm.Username.focus();
    return (false);
  }

  if (theForm.Username.value.length < 2)
  {
    alert("Please make sure that \"User Name\" field was properly completed.");
    theForm.Username.select();
    theForm.Username.focus();
    return (false);
  }
  // check if email field is blank
  var Email=theForm.Mail.value;
  if(Email != "")
  {
   if( (Email.indexOf('@',0) ==-1) || (Email.indexOf('.',0) ==-1))
    {
 	alert("The \"E-Mail\" field is invalid, please try again. It must contain an \"@\" and a \".\" ");
 	theForm.Mail.select();
	theForm.Mail.focus();
  	return false;
    }

  }
  else
  {
   alert("Please enter a value for the \"E-Mail\" field."); 
   theForm.Mail.select();
   theForm.Mail.focus();
   return false;
  }



  //**********************************************
 
 if(theForm.CompanyName.selectedIndex == 0)
	{
		alert("Please select the Centre");
		theForm.CompanyName.focus();
		return(false);
		flag=true;
	}

 // check to see if the Product field is blank
 /*if(theForm.Products.selectedIndex == 0)
	{
		alert("Please select the Problem");
		theForm.Products.focus();
		return(false);
		flag=true;
	}*/
 
  return (true);
}
