%= error_messages_for 'period' %>
<% if @period.new_record? %>
<%= select 'period', 'party_id', (@period.party ? [] : [['', '']]) + @parties.map{|party| [party.name, party.id]}, {}, :onchange => "form.action = '#{url_for :action => :new}'; form.submit();" %>
<% else %>
:
<%= hidden_field 'period', 'party_id' %><%=detour_to h(@period.party.name), :controller => @period.party.type.name.downcase.pluralize, :action => :edit, :id => @period.party%>
<% end %>
<% if @period.party %>
<%=image_detour_to(@period.party.icon, "#{l(@period.party.to_sym)} #{@period.party.name}", :controller => @period.party.controller, :action => :edit, :id => @period.party) %>
<% end %>
<%=detour_to l(:new_group), :controller => 'groups', :action => :new %>
: <% if @period.new_record? %> <%= @period.party.periods.last ? @period.party.periods.last.position + 1 : 1 %>
<% else %> <%= @period.position %> <% end %> <% end %>
<% if @period.party && @period.new_record? %>
<% minimum_date = @period.party.periods.last ? @period.party.periods.last.end_on + 1 : Date.today %>
<% maximum_date = Date.today + 5*365 %>
<% else %>
<% minimum_date = @period.higher_item ? @period.higher_item.end_on + 1 : Date.today %>
<% maximum_date = @period.lower_item ? @period.lower_item.start_on - 1 : Date.today + 5*365 %>
<% end %>
<%= text_field 'period', 'start_on', :size => 10, :value => @period.start_on ? @period.start_on.strftime('%Y-%m-%d') : nil %>
<%= text_field 'period', 'end_on', :size => 10, :value => @period.end_on ? @period.end_on.strftime('%Y-%m-%d') : nil %>