<% provide :title, t('.title') %>
<div id="post-add">
  <div id="static_notice" style="display: none;"></div>

  <% if @deleted_posts > 0 %>
    <div id="posts-deleted-notice" class="has-deleted-posts" style="margin-bottom: 1em;">
      <%= t(@deleted_posts == 1 ? '.posts_deleted.notice_singular_html' : '.posts_deleted.notice_plural_html',
            :recently_deleted => link_to(t('.posts_deleted.recently'), :action => :deleted_index, :user_id => @current_user.id))
      %>
      (<%= link_to_function t('.posts_deleted.hide'), 'Post.acknowledge_new_deleted_posts();' %>)
    </div>
  <% end %>

  <% unless @current_user.is_privileged_or_higher? %>
    <div style="margin-bottom: 2em;">
      <h4><%= t('.guidelines.title') %></h4>
      <p><%= t('.guidelines.info') %></p>
      <ul>
        <li>
          <%= t('.guidelines.do_not.tags_html', :tags => %w[furry yaoi guro toon poorly_drawn].map { |t| link_to(t.humanize.downcase, :controller => '/wiki', :action => :show, :title => t) }.to_sentence(:last_word_connector => t('.guidelines.last_word_connector_or')).html_safe) %>
        </li>
        <li>
          <%= t('.guidelines.do_not.with_html', :with => link_to(t('.guidelines.do_not.compression_artifacts'), :controller => '/wiki', :action => :show, :title => 'compression_artifacts')) %>
        </li>
        <li>
          <%= t('.guidelines.do_not.with_html', :with => link_to(t('.guidelines.do_not.obnoxious_watermarks'), :controller => '/wiki', :action => :show, :title => 'watermark')) %>
        </li>
        <li><%= link_to t('.guidelines.group'), help_path("post_relationships") %></li>
        <li><%= t('.guidelines.more_html', :more_link => link_to(t('.guidelines.more_link'), help_path("tags"))) %></li>
      </ul>
      <p><%= t('.guidelines.limit', :n =>  pluralize(CONFIG["member_post_limit"] - Post.where(:user_id => @current_user.id).where("created_at > ?", 1.day.ago).count, "post")) %></p>
    </div>
  <% end %>

  <%= form_tag({:controller => "post", :action => "create"}, :level => :member, :multipart => true, :id => "edit-form") do %>
    <div id="posts">
      <% if params[:url] %>
        <%= tag :img, :src => params['url'], :alt => params['url'], :title => 'Preview', :id => 'image' %>
        <p id="scale"></p>
        <script type="text/javascript">
        document.observe("dom:loaded", function() {
          if ($("image").height > 400) {
            var width = $("image").width
            var height = $("image").height
            var ratio = 400.0 / height
            $("image").width = width * ratio
            $("image").height = height * ratio
            $("scale").innerHTML = "Scaled " + parseInt(100 * ratio) + "%"
          }
        })
        </script>
      <% end %>

      <table class="form">
        <tfoot>
          <tr>
            <td></td>
            <td>
              <%= submit_tag t('.form.upload'), :tabindex => 8, :accesskey => "s", :class => "submit", :style => "margin: 0;" %>
              <%= submit_tag t('buttons.cancel'), :tabindex => 8, :accesskey => "s", :class => "cancel", :style => "display: none; vertical-align: bottom; margin: 0;" %>
              <div id="progress" class="upload-progress-bar" style="display: none;">
                <div class="upload-progress-bar-fill"></div>
              </div>
              <span style="display: none;" id="post-exists"><%= t('.already_exists') %>: <a href="#" id="post-exists-link"></a></span>
              <span style="display: none;" id="post-upload-error"></span>
            </td>
          </tr>
        </tfoot>
        <tbody>
          <tr>
            <th width="15%"><label for="post_file"><%= t('.form.file') %></label></th>
            <td width="85%"><%= file_field "post", "file", :size => 50, :tabindex => 1 %><span class="similar-results" style="display: none;"></span></td>
          </tr>
          <tr>
            <th>
              <label for="post_source"><%= t('.form.source._') %></label>
              <% unless @current_user.is_privileged_or_higher? %>
                <p><%= t('.form.source.info') %></p>
              <% end %>
            </th>
            <td>
              <%= text_field "post", "source", :value => (params["url"] || params["ref"]), :size => 50, :tabindex => 2 %>
              <% if CONFIG["enable_artists"] %>
                <%= link_to t(".form.find_artist"), "#", :class => "js-related-tags--autoload", :data => { :toggle => "related-tags", :type => "artist-url" } %>
              <% end %>
            </td>
          </tr>
          <tr>
            <th>
              <label for="post_tags"><%= t('.form.tags._') %></label>
              <% unless @current_user.is_privileged_or_higher? %>
                <p><%= t('.form.tags.info') %> (<%= link_to t('.form.help'), help_path("tags"), :target => "_blank" %>)</p>
              <% end %>
            </th>
            <td>
              <%= text_area "post", "tags", :value => params[:tags], :size => "60x2", :tabindex => 3 %>
              <%= link_to t(".form.find_related.tags"), "#", :data => { :toggle => "related-tags", :type => "all" } %> |
              <%= link_to t(".form.find_related.artists"), "#", :data => { :toggle => "related-tags", :type => "artist" } %> |
              <%= link_to t(".form.find_related.characters"), "#", :data => { :toggle => "related-tags", :type => "char" } %> |
              <%= link_to t(".form.find_related.copyrights"), "#", :data => { :toggle => "related-tags", :type => "copyright" } %> |
              <%= link_to t(".form.find_related.circles"), "#", :data => { :toggle => "related-tags", :type => "circle" } %>
            </td>
          </tr>
          <tr>
            <th><label for="post_parent_id"><%= t('.form.parent') %></label></th>
            <td><%= text_field "post", "parent_id", :value => params["parent"], :size => 5, :tabindex => 4 %></td>
          </tr>
          <tr>
            <th>
              <label for="post_rating_questionable"><%= t('.form.rating._') %></label>
              <% unless @current_user.is_privileged_or_higher? %>
                <p><%= t('.form.rating.info') %> (<%= link_to t('.form.help'), help_path("ratings"), :target => "_blank" %>)</p>
              <% end %>
            </th>
            <td>
              <label>
                <%= radio_button_tag "post[rating]", "Explicit", params[:rating] == "e", :id => "post_rating_explicit", :tabindex => 5 %>
                <%= t('ratings.e') %>
              </label>

              <label>
                <%= radio_button_tag "post[rating]", "Questionable", params[:rating].blank? || (params[:rating] == "q"), :id => "post_rating_questionable", :tabindex => 6 %>
                <%= t('ratings.q') %>
              </label>

              <label>
                <%= radio_button_tag "post[rating]", "Safe", params[:rating] == "s", :id => "post_rating_safe", :tabindex => 7 %>
                <%= t('ratings.s') %>
              </label>
            </td>
          </tr>
          <% if @current_user.is_contributor_or_higher? %>
            <tr>
              <th><label for="anonymous"><%= t('.anonymous') %></label></th>
              <td><%= check_box_tag 'anonymous', '1' %></td>
            </tr>
          <% end %>
        </tbody>
      </table>

      <div id="related"><em><%= t('.form.find_related.none') %></em></div>
    </div>
  <% end %>

</div>

<script type="text/javascript">
  Post.observe_text_area("post_tags")
  if (Cookie.get("upload-disclaimer") == "1") {
    $("upload-disclaimer").hide()
  }

  /* Set up PostUploadForm in dom:loaded, to make sure the login handler can attach to
   * the form first. */
  document.observe("dom:loaded", function() {
    var form = $("edit-form");
    form.down("#post_file").on("change", function(e) { form.down("#post_tags").focus(); });

    if(form)
    {
      new PostUploadForm(form, $("progress"));
      new UploadSimilarSearch(form.down("#post_file"), form.down(".similar-results"));
    }
  }.bindAsEventListener());
</script>

<script type="text/javascript">
  new TagCompletionBox($("post_tags"));
  if(TagCompletion)
    TagCompletion.observe_tag_changes_on_submit($("edit-form"), $("post_tags"), null);
</script>

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