<div id="error_status"><%= error_messages_for("todo", :object_name => 'action') %></div>

<%= hidden_field( "todo", "id" ) %>
<%= source_view_tag( @source_view ) %>

<label for="<%= dom_id(@todo, 'description') %>">Description</label>
<%= text_field( "todo", "description", "size" => 30, "tabindex" => 8) %>

<label for="<%= dom_id(@todo, 'notes') %>">Notes</label>
<%= text_area( "todo", "notes", "cols" => 29, "rows" => 4, "tabindex" => 9) %>

<div class="project_input">
<label for="<%= dom_id(@todo, 'project_name') %>">Project</label>
<input id="<%= dom_id(@todo, 'project_name') %>" name="project_name" autocomplete="off" tabindex="10" size="30" type="text" value="<%= @todo.project.nil? ? 'None' : @todo.project.name %>" />
<div class="page_name_auto_complete" id="<%= dom_id(@todo, 'project_list') %>" style="display:none"></div>

<script type="text/javascript">
<%= dom_id(@todo, 'project_autocompleter') %> = new Autocompleter.Local('<%= dom_id(@todo, 'project_name') %>', '<%= dom_id(@todo, 'project_list') %>', <%= project_names_for_autocomplete %>, {choices:100,autoSelect:false});
function selectDefaultContext() {
  todoContextNameElement = $('<%= dom_id(@todo, 'context_name') %>');
  defaultContextName = $('todo_context_name').projectDefaultContextsMap[this.value];
  if (defaultContextName && !todoContextNameElement.editedByTracksUser) {
    todoContextNameElement.value = defaultContextName;
  }
}
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "focus", <%= dom_id(@todo, 'project_autocompleter') %>.activate.bind(<%= dom_id(@todo, 'project_autocompleter') %>));
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "click", <%= dom_id(@todo, 'project_autocompleter') %>.activate.bind(<%= dom_id(@todo, 'project_autocompleter') %>));
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "blur", selectDefaultContext.bind($('<%= dom_id(@todo, 'project_name') %>')));
</script>
</div>

<div class="context_input">
<label for="<%= dom_id(@todo, 'context_name') %>">Context</label>
<input id="<%= dom_id(@todo, 'context_name') %>" name="context_name" autocomplete="off" tabindex="11" size="30" type="text" value="<%= @todo.context.name %>" />
<div class="page_name_auto_complete" id="<%= dom_id(@todo, 'context_list') %>" style="display:none"></div>

<script type="text/javascript">
<%= dom_id(@todo, 'context_autocompleter') %> = new Autocompleter.Local('<%= dom_id(@todo, 'context_name') %>', '<%= dom_id(@todo, 'context_list') %>', <%= context_names_for_autocomplete %>, {choices:100,autoSelect:false});
Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "focus", function(){ $('<%= dom_id(@todo, 'context_name') %>').editedByTracksUser = true; });
Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "focus", <%= dom_id(@todo, 'context_autocompleter') %>.activate.bind(<%= dom_id(@todo, 'context_autocompleter') %>));
Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "click", <%= dom_id(@todo, 'context_autocompleter') %>.activate.bind(<%= dom_id(@todo, 'context_autocompleter') %>));
</script>
</div>

<label class="tag_list_label" for="<%= dom_id(@todo, 'tag_list') %>">Tags (separate with commas)</label>
<%= text_field_tag 'tag_list', tag_list_text, :id => dom_id(@todo, 'tag_list'), :size => 30, :tabindex => 12 %> 

<div class="due_input">
<label for="<%= dom_id(@todo, 'due') %>">Due</label>
<%= date_field_tag("todo[due]", dom_id(@todo, 'due'), format_date(@todo.due), "tabindex" => 13) %>
</div>

<div class="show_from_input">
<label for="<%= dom_id(@todo, 'show_from') %>">Show from</label>
<%= date_field_tag("todo[show_from]", dom_id(@todo, 'show_from'), format_date(@todo.show_from), "tabindex" => 14) %>
</div>

<% if controller.controller_name == "project" || @todo.deferred? -%>
  <input type="hidden" name="on_project_page" value="true" />
<% end -%>

<div class="submit_box">
  <div class="widgets">
    <button type="submit" class="positive" id="<%= dom_id(@todo, 'submit') %>" tabindex="15">
        <%=image_tag("accept.png", :alt => "") %>
        Update
    </button>
    <a href="javascript:void(0);" onclick="Element.toggle('<%= dom_id(@todo, 'line') %>');Element.toggle('<%= dom_id(@todo, 'edit') %>');" class="negative">
        <%=image_tag("cancel.png", :alt => "") %>
        Cancel
    </a>
  </div>
</div>
        
<%= calendar_setup( dom_id(@todo, 'due') ) %>
<%= calendar_setup( dom_id(@todo, 'show_from') ) %>
