$(document).ready(function() {
  var options = {
      beforeSubmit:  validateForm,  // pre-submit callback
      success:       showResponse  // post-submit callback
  };

  $('#form-form-update-details').ajaxForm(options);

});

function showResponse() {
  $('#form-errors').css("display", "none");
  $('#form-update-detail').css("display", "none");
  $('#form-sent').css("display", "block");
  $.scrollTo(0);
}

function validateForm() {
  var requiredFields = [ "memberStatus", "strYearJoined", "strContact", "strTitle", "strPhone", "strPhoneW", "strEmail", "strCellphone",
                         "strAddress", "strCity", "strProvince", "strPostalCode", "strIdNumber", "strReferredBy" ];

  var errors = false;

  $.each(
    requiredFields,
    function( intIndex, objValue )
    {
      // test to ensure there is data in these fields
      if (! $('#' + objValue).val() )
      {
        $('#' + objValue).addClass("form-field-error");
        errors = true;
      }
    }
  );

  if (errors)
  {
    $('#form-errors').css("display", "block");
    $.scrollTo('#form-errors');

    return false;
  }
  else
  {
    return true;
  }

}