<%
	projects = Project.all.map{|project| [project.name, project.id]}
	project_id = session[controller_name].try( :[], :project_id)
	period = session[controller_name].try( :[], :period)
	groupid = session[controller_name].try( :[], :group_id)
%>
<%= form_tag({}, method: :get, id: 'query_form') do %>
	<%= hidden_field_tag "searchlist", controller_name %>
	<fieldset>
		<label><%= l(:label_date_range) %></label>
		<%= radio_button_tag 'period_type', '1', !@free_period,
			:onclick => '$("#from,#to").attr("disabled", true);$("#period").removeAttr("disabled");' %>
		<%= select_tag 'period', options_for_period_select(period),
			:onchange => '$("#query_form").submit(); return false;',
			:onfocus => '$("period_type_1").checked = true;',
			:disabled => @free_period %>
		<%= radio_button_tag 'period_type', '2', @free_period,
			:onclick => '$("#from,#to").removeAttr("disabled");$("#period").attr("disabled", true);' %>
		<span onclick="$('period_type_2').checked = true;">
			<%= l(:label_date_from_to, :start => ( date_field_tag('from', @from, {:id => 'from', :size => 10,
				:disabled => !@free_period}) + calendar_for('from')),
				:end => ( date_field_tag('to', @to, {:id => 'to', :size => 10, :disabled => !@free_period}) + calendar_for('to'))).html_safe %>
		</span>
		<label style="padding-left: 5px;"><%= l(:label_project_plural) %></label>
		<%=h select_tag('project_id', options_for_select( [["",""]] + projects, :selected => project_id), :style => "width:125px;")  %></td>
		<label style="padding-left: 5px;"><%=l(:label_group_plural)%></label>
		<%=h select_tag('group_id', options_for_select( [["",""]] + (@groups.collect {|p| [p.name, p.id ]}), :selected => groupid), :style => "width:125px;") %>&nbsp
		<%= submit_tag l(:button_apply), :class => 'button-small', :name => 'submit' %>
		<%= link_to l(:button_clear), {tab: controller_name, clear: true}, :class => 'icon icon-reload' %>
	</fieldset>
<% end %>