<% if @saved -%>
  TracksPages.page_notify('notice', "<%=@status_message%>", 5);
  RecurringTodosPage.toggle_overlay();
  add_recurring_todo_to_active_container();
  replace_form_with_empty_form();
  TracksPages.set_page_badge(<%= @down_count %>);
<% else -%>
  TracksPages.show_errors(html_for_error_messages());
<% end -%>

function replace_form_with_empty_form() {
  $('div.recurring_container').html(html_for_empty_form());
}

function add_recurring_todo_to_active_container() {
    $('#recurring_todos_container').append(html_for_recurring_todo());
    $('#<%= dom_id(@recurring_todo)%>').effect('highlight', {}, 2000 );
    $('#recurring-todos-empty-nd').hide();
}

function html_for_recurring_todo() {
  return "<%= @saved ? escape_javascript(render(:partial => @recurring_todo)) : "" %>";
}

function html_for_empty_form() {
  return "<%= @saved ? escape_javascript(render(:partial => 'recurring_todo_form')) : "" %>";
}

function html_for_error_messages() {
  return "<%= escape_javascript(error_messages_for('recurring_todo')) %>";
}