<div id="post-list">
    <div class="sidebar">
      <%= render :partial => "search" %>
      <% if CONFIG["can_see_ads"].call(@current_user) %>
        <%= CONFIG["ad_code_index_side"] %>
      <% end %>
      <div style="margin-bottom: 1em;" id="mode-box">
        <h5><%= t('.mode') %></h5>
        <form onsubmit="return false;" action="">
          <div>
            <select name="mode" id="mode" onchange="PostModeMenu.change()" onkeyup="PostModeMenu.change()" style="width: 13em;">
              <option value="view"><%= t('.view_posts') %></option>
              <option value="reparent"><%= t('.reparent') %></option>
              <option value="dupe"><%= t('.flag_duplicate') %></option>
              <option value="edit"><%= t('.edit_posts') %></option>
<!--              <option value="rating-s">Rate Safe</option>
              <option value="rating-q">Rate Questionable</option>
              <option value="rating-e">Rate Explicit</option>
              <% if @current_user.is_privileged_or_higher? %>
                <option value="lock-rating">Lock Rating</option>
                <option value="lock-note">Lock Notes</option>
              <% end %>-->
              <option value="flag"><%= t('.flag_post') %></option>
              <option value="apply-tag-script"><%= t('.apply_tag_script') %></option>
            </select>
          </div>
        </form>
      </div>

      <%= render :partial => "tag_script" %>
      <%= render :partial => 'blacklists' %>

      <div>
        <h5><%= t('.services') %></h5>
        <ul>
          <li> <%= link_to t('.use_all_services'), similar_link_params(:services => 'all') %>
          <% CONFIG["image_service_list"].map do |service, server| %>
          <li>
            <span class="service-link<%= " service-active" if @services.find { |s| s == service }%>">
              <%= tag('img', class: 'service-icon', id: 'list', src: get_service_icon(service)) %>
              <%= link_to service, similar_link_params(:services => service) %>
              <% if @errors and @errors[server] %>
                (<%= t('.down') %>)
                <!-- <%= @errors[server][:message] %> -->
              <% end %>
            </span>
          <% end %>
        </ul>
      </div>
      <div>
        <h5><%= t('.options') %></h5>
        <ul>
          <li><%= link_to (params[:forcegray] ? t('.mode_color') : t('.mode_gray')), similar_link_params(:forcegray => (params[:forcegray] ? 0 : 1)) %>
          <% unless params[:threshold] %>
          <li><%= link_to t('.show_more'), similar_link_params(:threshold => 0) %></li>
          <% end %>
          <% if params[:url] %>
          <li>
          <%= link_to t('.upload'), :controller => "post", :action => "upload",
                  :url => (params[:full_url] or params[:url]),
                  :tags => params[:tags],
                  :rating => params[:rating],
                  :parent => params[:parent]
          %>
          </li>
          <% end %>
        </ul>
      </div>
    </div>
    <% if @initial %>
      <div id="duplicate">
        <%= t('.duplicate.info_guide_html', :guide => link_to(t('.duplicate.guide'), :controller => '/wiki', :action => :show, :title => 'duplicate')) %>
        <ul>
        <li>
          <%= t('.duplicate.info_reparent_html', :reparent => link_to_function(t('.duplicate.reparent'), "$('mode').value = 'reparent'; PostModeMenu.change();")) %>
        </li>
        <li>
          <%= t('.duplicate.info_mark_duplicate_html', :mark_duplicate => link_to_function(t('.duplicate.mark_duplicate'), "$('mode').value = 'dupe'; PostModeMenu.change();")) %>
        </li>
        <li>
          <%= form_tag url_for(:action => "destroy", :name=>"destroy"), :id => "destroy"  do %>
            <%= hidden_field_tag "id", params[:id], :id=>"destroy_id" %>
            <%= hidden_field_tag "reason", "duplicate" %>
            <%= t('.duplicate.info_delete_html', :delete => link_to_function(t('.duplicate.delete'), "$('destroy').submit()")) %>
          <% end %>
        </li>
        </ul>
        <div id="blacklisted-notice" style="display: none;">
          <%= t('.duplicate.info_blacklist_html', :blacklist => content_tag(:b, t('.duplicate.blacklist'))) %>
        </div>
      </div>
    <% end %>
    <div class="content">
      <div id="quick-edit" style="display: none; margin-bottom: 1em;">
        <h4><%= t('.edit_tags') %></h4>
        <%= form_tag(:action => "update") do %>
          <%= hidden_field_tag "id", "" %>
          <%= hidden_field_tag "post[old_tags]", "" %>
          <%= text_area_tag "post[tags]", "", :size => "60x2", :id => "post_tags" %>
          <%= submit_tag t('.update') %>
          <%= tag(:input, :type => 'button', :value => t('buttons.cancel'), :class => "cancel") %>
        <% end %>
      </div>

      <% unless @initial %>
      <%= form_tag({:controller => "post", :action => "similar"}, :multipart => true, :id => "similar-form") do %>
        <% similar_link_params(:search_id => nil).each do |key, value| %>
          <%= hidden_field_tag(key, value) if !value.nil? %>
        <% end %>

        <table class="form">
          <tfoot>
            <tr>
              <td colspan="2"><%= submit_tag t('buttons.search'), :tabindex => 3, :accesskey => "s" %></td>
            </tr>
          </tfoot>
          <tbody>
            <tr>
              <th>
                <label for="url"><%= t('.source') %></label>
              </th>
              <td>
                <input id="url" name="url" size="50" type="text" tabindex="1" value="<%= h(params[:url]) %>">
              </td>
            </tr>
            <tr>
              <th width="20%"><label for="post_file"><%= t('.file') %></label></th>
              <td width="80%"><input id="file" name="file" size="50" tabindex="2" type="file"></td>
            </tr>
          </tbody>
        </table>
      <% end %>
      <% end %>

      <% if not @posts.nil? %>
      <%= render :partial => "posts", :locals => {:posts => @posts} %>
      <% end %>

      <div id="paginator"></div>

      <% if params[:full_url] %>
      <img src="<%= params[:full_url] %>"/>
      <% end %>
    </div>
</div>
<% content_for :post_cookie_javascripts do %>
<script type="text/javascript">
  <% unless @initial %>
  $("url").focus();
  <% end %>

  <% if params[:id] %>
  // for post_mode_menu.js:click
  id=<%= params[:id] %>;
  <% end %>

  post_quick_edit = new PostQuickEdit('#quick-edit');

  PostModeMenu.init()

  var form = $("similar-form");
  if(form && SimilarWithThumbnailing)
    new SimilarWithThumbnailing(form);
</script>
<% end %>

<%= render :partial => "footer" %>
