function ajax_validate(t) {
  $$('.form_error').each(function(el) { el.update().hide() });
  if(t.responseJSON) {
    if(!t.responseJSON.ok) {
      Object.keys(t.responseJSON.errors).each(function(field) {
        if($('error_for_' + field)) {
          $('error_for_' + field).update(t.responseJSON.errors[field]).show();
        }
      });
    } else if(t.responseJSON.redirect)
      document.location.href = t.responseJSON.redirect;
  }
}