<h2><%= l(:label_search) %></h2>
<%= form_tag({}, :method => :get, :id => 'search-form', :class => 'form-box') do %>
  <div>

    <p>
      <%= text_field_tag 'q', @question, :size => 60, :id => 'search-input' %>
      <%= search_scope_type_input(@scope_select, @project) %>
      <span id="search_projects_select" style="<%= 'display:none' if @scope_select != 'project' %>"><%= project_select_tag %></span>
      <%= hidden_field_tag 'all_words', '', :id => nil %>
      <label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label>
      <%#= hidden_field_tag 'titles_only', '', :id => nil %>
      <!--<label><%#= check_box_tag 'titles_only', 1, @titles_only %> <%#= l(:label_search_titles_only) %></label>-->
      <span onclick="EASY.utils.toggleDivAndChangeOpen('options-content', this);" class="tooltip-left icon icon-settings">
    <span class="tooltip"><%= l(:button_advanced_search) %></span></span>
    </p>

    <p id="search-types">
      <% @object_types.each do |t| %>
        <label class="inline"><%= check_box_tag t, 1, @scope.include?(t) %> <%= link_to type_label(t), "#" %></label>
      <% end %>
    </p>


      <div id="options-content" style="display:none;">
        <%= hidden_field_tag('open_issues', false) %>
        <p><label><%= check_box_tag 'open_issues', true, @open_issues %> <%= l(:label_search_open_issues_only) %></label></p>
        <p>
          <label class="inline"><%= radio_button_tag 'attachments', '0', @search_attachments == '0' %> <%= l(:label_search_attachments_no) %></label>
          <label class="inline"><%= radio_button_tag 'attachments', '1', @search_attachments == '1' %> <%= l(:label_search_attachments_yes) %></label>
          <label class="inline"><%= radio_button_tag 'attachments', 'only', @search_attachments == 'only' %> <%= l(:label_search_attachments_only) %></label>
        </p>
        <%= call_hook(:view_search_index_advance_options_bottom, {scope: @scope, params: params} )%>
      </div>


    <%= hidden_field_tag 'options', '', :id => 'show-options' %>

  </div>
  <div class="form-actions"><%= submit_tag l(:button_submit), :class => 'button-positive' %></div>
<% end %>

<% if @results %>
  <h3><%= l(:label_result_plural) %> (<%= @result_count %>)</h3>
  <div id="search-results-counts">
    <%= render_results_by_type(@result_count_by_type) unless @scope.size == 1 %>
  </div>
  <dl id="search-results">
    <% @results.each do |e| %>
      <dt class="">
        <%= link_to highlight_tokens(e.event_title.truncate(255), @tokens), e.event_url %>
        <%= content_tag('span', ', ' + l(:label_project) + ': ' + e.project.to_s) unless @project == e.project %>
      </dt>
        <%= content_tag :dd, highlight_tokens(e.event_description, @tokens), :class => 'description' -%>
        <%= content_tag :dd, additional_search_results(e, @tokens).html_safe, :class => 'additional-results' -%>
        <%= content_tag :dd, "<strong>#{e.class.human_attribute_name(e.searchable_options[:date_column])}</strong>".html_safe + ': ' +   format_time(e.event_datetime) -%>
    <% end %>
  </dl>
<% end %>

<% if @result_pages %>
  <span class="pagination"><%= pagination_links_full @result_pages, @result_count, :per_page_links => false %></span>
<% end %>

<% html_title(l(:label_search)) -%>

<%= javascript_tag do %>
  $("#search-types a").click(function(e){
  e.preventDefault();
  $("#search-types input[type=checkbox]").prop('checked', false);
  $(this).siblings("input[type=checkbox]").prop('checked', true);
  if ($("#search-input").val() != "") {
  $("#search-form").submit();
  }
  });

  $("#search-form").submit(function(){
  $("#show-options").val($("#options-content").is(":visible") ? '1' : '0');
  });

  <% if params[:options] == '1' %>
        EASY.utils.toggleDivAndChangeOpen('options-content', '.collapsible legend');
  <% end %>
<% end %>


<% content_for :header_tags do %>
  <script type="text/javascript">
    function selectSearchRange(select) {
      if (select.value == 'project') {
        $("#scope").prop('disabled', false);
        $("#search_projects_select").show();
      } else {
        $("#scope").prop('disabled', true);
        $("#search_projects_select").hide();
      }
    }

    $(document).ready(function(){
      // To prevent selection project for type: all and subprojects
      selectSearchRange($("select[name='scope_type'] option:selected")[0]);
    });
  </script>
<% end -%>
