﻿function EventValidator(theForm)
{
  var checkStr = theForm.FirstName.value;
  var allValid = true;
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    if (ch == "'")
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please put a space instead of ' in the First Name field.");
    theForm.participant_fname.focus();
    return (false);
  }


  if (theForm.FirstName.value == "")
  {
    alert("Please enter your first name in the \"First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }

  if (theForm.FirstName.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }

  if (theForm.FirstName.value.length > 75)
  {
    alert("Please enter at most 75 characters in the \"First Name\" field.");
    theForm.FirstName.focus();
    return (false);
  }


  var checkStr = theForm.LastName.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    if (ch == "'")
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please put a space instead of ' in the Last Name field.");
    theForm.LastName.focus();
    return (false);
  }


  if (theForm.LastName.value == "")
  {
    alert("Please enter your last name in the \"Last Name\" field.");
    theForm.LastName.focus();
    return (false);
  }

  if (theForm.LastName.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Last Name\" field.");
    theForm.LastName.focus();
    return (false);
  }

  if (theForm.LastName.value.length > 75)
  {
    alert("Please enter at most 75 characters in the \"Last Name\" field.");
    theForm.LastName.focus();
    return (false);
  }

  if (theForm.Title.value == "")
  {
    alert("Please enter your title for the \"Title\" field.");
    theForm.Title.focus();
    return (false);
  }

  if (theForm.Title.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Title\" field.");
    theForm.Title.focus();
    return (false);
  }

  if (theForm.Title.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"Title\" field.");
    theForm.Title.focus();
    return (false);
  }


  if (theForm.Organization.value == "")
  {
    alert("Please enter the name of your organization in the \"Organization\" field.");
    theForm.Organization.focus();
    return (false);
  }

  if (theForm.Organization.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Organization\" field.");
    theForm.Organization.focus();
    return (false);
  }

  if (theForm.Organization.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"Organization\" field.");
    theForm.Organization.focus();
    return (false);
  }

  if (theForm.email.value == "")
  {
    alert("Please enter your email address in the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length < 8)
  {
    alert("Please enter at least 8 characters in the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  var checkStr = theForm.email.value;
  
  if (checkStr.charAt(0) == " ")
  {
    alert("Please do not put space before your email address.");
    theForm.email.focus();
    return (false);
  }


  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz??????????????????????????????????????????????????????????????????????0123456789-@_.";
  var checkStr = theForm.email.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 only letter, digit and @._- characters in the \"Email Address\" field.");
    theForm.email.focus();
    return (false);
  }

  var checkStr = theForm.email.value;
  var emailValid1 = false;
  var emailValid2 = false;

  for (i = 0;  i < checkStr.length;  i++)
  { 
 	ch = checkStr.charAt(i);
 	if (ch == "@")
 	  {
 	   emailValid1 = true;
  	   break;
  	  }
  }

  for (i = 0;  i < checkStr.length;  i++)
  { 
 	ch = checkStr.charAt(i);
 	if (ch == ".")
     {
	   emailValid2 = true;
 	   break;
 	  }
  }
  if (emailValid1 == false || emailValid2 == false)
  {
	alert("Please enter your email address properly.");
   theForm.email.focus();
   return (false);
  }


  if (theForm.areacode.value == "")
  {
    alert("Please enter your area code in the \"Area Code\" field.");
    theForm.areacode.focus();
    return (false);
  }

  if (theForm.areacode.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Area Code\" field.");
    theForm.areacode.focus();
    return (false);
  }

  if (theForm.areacode.value.length > 3)
  {
    alert("Please enter at most 3 characters in the \"Area Code\" field.");
    theForm.areacode.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = theForm.areacode.value;
  var allValid = true;
  var validGroups = 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 digit characters in the \"Area Code\" field.");
    theForm.areacode.focus();
    return (false);
  }

  if (theForm.phonenumber.value == "")
  {
    alert("Please enter your telephone number in the \"Telephone\" field.");
    theForm.phonenumber.focus();
    return (false);
  }

  if (theForm.phonenumber.value.length < 7)
  {
    alert("Please enter at least 7 characters in the \"Telephone\" field.");
    theForm.phonenumber.focus();
    return (false);
  }

  if (theForm.phonenumber.value.length > 8)
  {
    alert("Please enter at most 8 characters in the \"Telephone\" field.");
    theForm.phonenumber.focus();
    return (false);
  }

  var checkOK = "0123456789--";
  var checkStr = theForm.phonenumber.value;
  var allValid = true;
  var validGroups = 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 digit and \"-\" characters in the \"Telephone\" field.");
    theForm.phonenumber.focus();
    return (false);
  }

 if (theForm.EventCode.value == "")
  {
    alert("Please enter the event code in the \"EventCode\" field.");
    theForm.EventCode.focus();
    return (false);
  }
  
  var EventCodeEntered = theForm.EventCode.value;
  EventCodeEntered = EventCodeEntered.toLowerCase();
  //var EventCodeEntered = toLowerCase(theForm.EventCode.value);
  // INSTRUCTIONS: Put the password below in all lower case ONLY!!!
  var EventCodeReal1 = "hockey09";
  var EventCodeReal2 = "hockey09";
  var EventCodeStatus1 = true;	
  var EventCodeStatus2 = true;

  for (i = 0;  i < EventCodeReal1.length;  i++)
  {
  	if (EventCodeEntered.charAt(i) != EventCodeReal1.charAt(i))
	{
	        //alert("Invalid event code.  Please try again.");
          	//theForm.EventCode.focus();
		//return (false);
		EventCodeStatus1 = false;
	}
  }

  for (i = 0;  i < EventCodeReal2.length;  i++)
  {
  	if (EventCodeEntered.charAt(i) != EventCodeReal2.charAt(i))
	{
	        //alert("Invalid event code.  Please try again.");
          	//theForm.EventCode.focus();
		//return (false);
		EventCodeStatus2 = false;
	}
  }
	
  if (!EventCodeStatus1 && !EventCodeStatus2)

  {
  	alert("Invalid event code.  Please try it again.");
    	theForm.EventCode.focus();
    	return (false);
  }
		

  return (true);
}