function TestEmail(src)
{
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9._-]+\.)+[a-zA-Z0-9._-]{2,4}$/;
  return regex.test(src);
}

function DuplicateEmail()
{
var EmailCheck = '<%=Request("StatusID")%>'

	if (EmailCheck == 1)
	{
	  alert('     You have entered an email address that has already been used to set up an account.\n\nIf you believe you have received this messsage in error, please contact support@scrma.com.');
   	  AccountForm.txtEmail.focus();
   	  AccountForm.txtEmail.select();
	}
}

function EmailAlert(FieldName)
  {
    alert("This field must be a valid email address like (name@company.com).");
    FieldName.focus()
  }
function ERAddressAlert(FieldName)
  {
    alert("All of the address fields must be completed in order to submit the account.");
    FieldName.focus()
  }
function EmptyAlert(FieldName, FieldName2)
  {
    alert(FieldName2 + " is a required field.  It must be completed before you can register.");
    FieldName.focus()
  }

function ValidateRegistrationForm(theForm)
{
var okstatus = true
  if (theForm.txtFirstName.value == "")
  {
    EmptyAlert(theForm.txtFirstName, "First Name");
    var okstatus = false;
  }
if (okstatus == true)
{
  if (theForm.txtFirstName.value == "")
  {
    EmptyAlert(theForm.txtFirstName, "First Name");
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.txtLastName.value == "")
  {
    EmptyAlert(theForm.txtLastName, "Last Name");
    var okstatus = false;
  }
}
if (okstatus == true)
{
  var checkOK = "0123456789";
  var checkStr = theForm.txtExt.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 digit characters in the Ext field.");
    theForm.txtExt.focus();
    theForm.txtExt.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
 if (!TestEmail(theForm.txtEmail.value))
  {
	EmailAlert(theForm.txtEmail);
	var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.txtEmail.value == "")
  {
    EmptyAlert(theForm.txtEmail, "Email Address");
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.txtEmail.value != theForm.txtEmail2.value)
  {
    alert("Both email address fields much match!");
    theForm.txtEmail.focus();
    theForm.txtEmail.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.txtCompanyName.value == "")
  {
    EmptyAlert(theForm.txtCompanyName, "Company Name");
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.CompanyTypeCombo.value == "none")
  {
    EmptyAlert(theForm.CompanyTypeCombo, "Company Type");
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.txtCompanyZip.value.length != 5 && theForm.txtCompanyZip.value != "")
  {
    alert("Please enter 5 characters in the zip code field.");
    theForm.txtCompanyZip.focus();
    theForm.txtCompanyZip.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.txtCompanyZip4.value.length != 4 && theForm.txtCompanyZip4.value != "")
  {
    alert("Please enter 4 characters in the '+4' zip code field.");
    theForm.txtCompanyZip4.focus();
    theForm.txtCompanyZip4.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  var checkOK = "0123456789";
  var checkStr = theForm.txtCompanyZip.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 digit characters in the zip code field.");
    theForm.txtCompanyZip.focus();
    theForm.txtCompanyZip.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  var checkOK = "0123456789";
  var checkStr = theForm.txtCompanyZip4.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 digit characters in the zip code field.");
    theForm.txtCompanyZip4.focus();
    theForm.txtCompanyZip4.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  var checkOK = "0123456789";
  var checkStr = theForm.txtNumberEmployees.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 digit characters in the number of employee field.");
    theForm.txtNumberEmployees.focus();
    theForm.txtNumberEmployees.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.txtPhone.value.length < 10 && theForm.txtPhone.value != "")
  {
    alert("Please enter at least 10 characters in the phone number field.");
    theForm.txtPhone.focus();
    theForm.txtPhone.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.txtPhone.value.length > 14)
  {
    alert("Please enter at most 14 characters in the phone number field.");
    theForm.txtPhone.focus();
    theForm.txtPhone.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.CompanyTypeCombo.value == "OT" && theForm.txtTypeOther.value == "")
  {
    alert("Please enter a company type because you have selected 'Other'.");
    theForm.txtTypeOther.focus();
    theForm.txtTypeOther.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  if (theForm.CompanySystemCombo.value == "OT" && theForm.txtSystemOther.value == "")
  {
    alert("Please enter the name of your company's system because you have selected 'Other'.");
    theForm.txtSystemOther.focus();
    theForm.txtSystemOther.select();
    var okstatus = false;
  }
}
if (okstatus == true)
{
  window.status = "";
  document.RegistrationForm.action="../asp/SubmitAccount.asp";
  document.RegistrationForm.submit();
}
}