{% load i18n %}
{% load sph_extras %}
{% load sphboard_extras %}
  {% if bbcodewysiwyg %}
    <link rel="stylesheet" href="{{ STATIC_URL }}sphene/sphboard/styles/editor.css" />
    <script type="text/javascript" src="{{ STATIC_URL }}sphene/sphboard/js/editor.js"></script>
  {% endif %}
  <script language="JavaScript" type="text/javascript" src="{{ STATIC_URL }}sphene/community/xmlhttp.js"></script>
  <script language="JavaScript" type="text/javascript">
  <!--
   function doPreview() {
     {% if bbcodewysiwyg %}
       doCheck();
     {% endif %}
     var markup = "";
     if(document.postform.markup) {
       markup = "&markup=" + encodeURIComponent( document.postform.markup.value );
     }
     showResponseInElement( 'previewarea', '{% trans "Loading Preview ..." %}', "type=preview" + markup + "&body=" + encodeURIComponent( document.postform.body.value )+ '&csrfmiddlewaretoken=' + encodeURIComponent( document.postform.csrfmiddlewaretoken.value ) );
   }
  //-->
  </script>

<div id="previewarea" class="board_previewarea"></div>
<form enctype="multipart/form-data" method="post" action='{{ form_action|default:"." }}' name="postform" {% if bbcodewysiwyg %}onsubmit="doCheck()" {% endif %}>{% csrf_token %}
  <input type="hidden" name="category" value="{{ category.id }}" />
  {% if thread %}
    <input type="hidden" name="thread" value="{{ thread.id }}" />
  {% endif %}
  {% if post %}
    <input type="hidden" name="post_id" value="{{ post.id }}" />
  {% endif %}
  <table class="sphboard form">
    {{ form }}
    {% if bbcodewysiwyg %}
    <script type="text/javascript">
      var editor_static = "{{ STATIC_URL }}sphene/sphboard";
    </script>
    <script type="text/javascript" src="{{ STATIC_URL }}sphene/sphboard/js/inline.js"></script>
    {% endif %}
  </table>
  </script>
    {% if user.is_authenticated %}
          {% if thread.has_monitor or category.has_monitor %}
            <small>{% trans "You are already receiving email notifications for this thread or category." %}</small>
          {% else %}
            <input type="checkbox" name="addmonitor" value="1" id="addmonitor_id" {% if user|sphboard_default_notify_me %}checked="checked"{% endif %} /> <label for="addmonitor_id">{% trans "Notify me by email on new posts in this thread." %}</label>
          {% endif %}
          <br/><br/>
    {% endif %}

  {% if pollform %}
  <input type="checkbox" name="createpoll" value="1" onchange="javascript:document.getElementById( 'poll' ).style.display = (this.checked ? 'block' : 'none' )" id="createpoll_id"{% if createpoll %} checked="checked"{% endif %} /> <label for="createpoll_id">{% trans "Add a poll to this thread" %}</label><br/><br/>

  <div id="poll" style="display: none">
    <table class="sphboard form">
      <tr>
        <th colspan="2">{% trans "Poll" %}</th>
      </tr>
      {{ pollform }}
    </table>
  </div>
  <script language="JavaScript">
  <!--
    document.getElementById( 'poll' ).style.display = (document.postform.createpoll.checked ? 'block' : 'none');
  //-->
  </script>
  {% endif %}
  {{ post_attachment_formset.management_form }}
  {% if post_attachment_formset.forms %}
      <table class="sphboard form attachment">
          <tr>
              <th colspan="2">{% trans "Upload Attachment" %}</th>
          </tr>
          {% for form in post_attachment_formset.forms %}
              <tr>
                  <td>
                      {{ form.as_p }}
                  </td>
              </tr>
          {% endfor %}
          <tr>
              <td colspan="2"><input type="submit" name="cmd_addfile" value="{% trans "Upload File" %}" style="width: auto;" /></td>
          </tr>
      </table>
  {% endif %}

  <input type="submit" value="{% trans "Post" %}" /> * <input type="button" value="{% trans "Preview" %}" onclick="javascript:doPreview()" />

</form>
