//
// This is the javascript validation for the Contact form (contact.php). If all of the
// validation passes then the form is posted using AJAX (not the normal form POST). The response
// is then processed and we either show a <DIV> that has the confirmation message or we display
// a javascript alert popup with the error message returned from the PHP script.
//
function validate_testimony_form() {
  //Form validation
  var bError = false;
  if ($j('#test_first_name').val() == '') { addError('test_first_name'); bError = true; } else { removeErrorClass('test_first_name'); }
  if ($j('#test_last_name').val() == '') { addError('test_last_name'); bError = true; } else { removeErrorClass('test_last_name'); }
  if ($j('#test_state').val() == '') { addError('test_state'); bError = true; } else { removeErrorClass('test_state'); }
  if ($j('#test_comments').val() == '') { addError('test_comments'); bError = true; } else { removeErrorClass('test_comments'); }

  if ($j('#test_security_code').val() == '') { addError('test_security_code'); bError = true; } else { removeErrorClass('test_security_code'); }

  if (bError == true) {
    alert ("Please correct the highlighted fields.");
    return false;
  }
  else {
    return true;
  }
}

function removeErrorClass(control_id) {
  $j('#'+control_id).parent().parent().removeClass('error');
  return true;
}

function addError(control_id) {
  $j('#'+control_id).select().focus();
  $j('#'+control_id).parent().parent().addClass('error');
  return true;
}
