function checkCommonFormElements()
{
  $("name-error-text").innerHTML = "";
  $("email-error-text").innerHTML = "";
  
  var error_occurred = false;
  
  if ($("name").value == "")
  {
    $("name-error-text").innerHTML = "Please enter your name.";
	$("name-error-text").show();
    error_occurred = true;
  }
  
	// Email regexp obtained from RFC822::EmailAddress in the app
	var email_regexp = /^[a-z0-9!#$%&*+\/=?^_{|}~'-]+(\.[a-z0-9!#$%&*+\/=?^_{|}~'-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i;

  if (!$("email").value.match(email_regexp))
  {
    $("email-error-text").innerHTML = "Please enter a valid e-mail address.";
	$("email-error-text").show();
    error_occurred = true;
  }
  
  return error_occurred;
}

function checkContactForm()
{
  var error_occurred = checkCommonFormElements();

  $("comment-error-text").innerHTML = "";  
  if ($("comment").value == "")
  {
    $("comment-error-text").innerHTML = "Please enter a comment.";
    error_occurred = true;
  }
  
  return !error_occurred;  
}

function checkBusinessForm()
{
  try {
    var error_occurred = checkCommonFormElements();
  
    var contact_time_selected = false;
    $$("#business_contact_form input[type='checkbox']").each(function(check_box) {
      contact_time_selected = contact_time_selected || check_box.checked;
    });
    if(!contact_time_selected) {
      $("contact-time-error-text").innerHTML = "Please select at least one contact time";
      error_occurred = true;
    } else {
      $("contact-time-error-text").innerHTML = "";
    }

    if ($("phone").value == "")
    {
      $("phone-error-text").innerHTML = "Please enter a phone number.";
      error_occurred = true;
    } else {
      $("phone-error-text").innerHTML = "";    
    }
  
    return !error_occurred;  
  } catch(error) {
    $("contact-time-error-text").innerHTML = "Sorry, an unknown error has occurred";
    // Don't let the form submit on errors
    return false;
  }
}

function checkNewsletterForm()
{
  $("street-error-text").innerHTML = "";
  $("city-error-text").innerHTML = "";
   
  var error_occurred = checkCommonFormElements();
  if ($("street").value == "")
  {
    $("street-error-text").innerHTML = "Please enter a street address.";
    error_occurred = true;
  }

  if ($("city").value == "")
  {
    $("city-error-text").innerHTML = "Please enter a city.";
    error_occurred = true;
  }

  return !error_occurred;  
}


