// JavaScript Document

function registrationForm_Validator(theForm)
{

  if (theForm.PREFIX.selectedIndex == 0)
  {
    alert("Please select one of the PREFIX options.");
    theForm.PREFIX.focus();
    return (false);
  }

  if (theForm.FIRSTNAME.value == "")
  {
    alert("Please enter a value for the FIRSTNAME field.");
    theForm.FIRSTNAME.focus();
    return (false);
  }

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

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

  if (theForm.LASTNAME.value == "")
  {
    alert("Please enter a value for the LASTNAME field.");
    theForm.LASTNAME.focus();
    return (false);
  }

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

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

  if (theForm.TITLE.value == "")
  {
    alert("Please enter a value for the TITLE field.");
    theForm.TITLE.focus();
    return (false);
  }

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

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

  if (theForm.COMPANY.value == "")
  {
    alert("Please enter a value for the COMPANY field.");
    theForm.COMPANY.focus();
    return (false);
  }

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

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

  if (theForm.ADDRESS.value == "")
  {
    alert("Please enter a value for the ADDRESS field.");
    theForm.ADDRESS.focus();
    return (false);
  }

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

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

  if (theForm.CITY.value == "")
  {
    alert("Please enter a value for the CITY field.");
    theForm.CITY.focus();
    return (false);
  }

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

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

  if (theForm.STATE.value == "")
  {
    alert("Please enter a value for the STATE field.");
    theForm.STATE.focus();
    return (false);
  }

  if (theForm.ZIP.value == "")
  {
    alert("Please enter a value for the ZIP field.");
    theForm.ZIP.focus();
    return (false);
  }

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

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

    if (theForm.country.value.length < 1)
  {
    alert("Please enter at least 1 characters in the Country field.");
    theForm.country.focus();
    return (false);
  }
  
    if (theForm.country.value == "")
  {
    alert("Please enter a value for the country field.");
    theForm.country.focus();
    return (false);
  }
  
  if (theForm.PHONE.value == "")
  {
    alert("Please enter a value for the PHONE field.");
    theForm.PHONE.focus();
    return (false);
  }

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

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

  if (theForm.EMAIL.value == "")
  {
    alert("Please enter a value for the EMAIL field.");
    theForm.EMAIL.focus();
    return (false);
  }

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

  if (theForm.EMAIL.value.length > 55)
  {
    alert("Please enter at most 55 characters in the EMAIL field.");
    theForm.EMAIL.focus();
    return (false);
  }
  // Validate User's Email Address
  	var str_email = document.registrationForm.EMAIL.value;
	var len_email = str_email.length;
	var email_flag = 0;
	var char64_flag = 1;
	var char64_counter = 0;
	var char46_flag = 1;
	for (j=0; j<len_email; j++)	{
		if ((str_email.substring(j,j+1) ==",")||(str_email.substring(j,j+1) ==" ")||(str_email.substring(j,j+1) =="*")||(str_email.substring(j,j+1) ==")")||(str_email.substring(j,j+1) =="(")||(str_email.substring(j,j+1) ==">")||(str_email.substring(j,j+1) =="<")||(str_email.substring(j,j+1) ==":")||(str_email.substring(j,j+1) ==";"))
				{email_flag = 1;}
		if (str_email.substring(j,j+1)=="@")	{char64_flag = 0;	char64_counter++;}
		if (str_email.substring(j,j+1)==".")	{char46_flag = 0; }
	}
	if 	((str_email.substring(0,1)=="@")||(str_email.substring(0,1)=="."))	{
		email_flag = 1;
	}
	else if ((str_email.substring(len_email-1,len_email)=="@")||(str_email.substring(len_email-1,len_email)=="."))	{
		email_flag = 1;
	}

	if ((email_flag == 1)||(char64_flag ==1)||(char64_counter>1)||(char46_flag==1))	{
		alert("Your email doesn't appear to be valid.  Please use the format name@company.com");
		theForm.EMAIL.focus();
		return(false);
	}
	//End Email validation
	return(true);
}


