{% load i18n form_tags %}

<form class="form-horizontal" method="POST" action="{{ posturl }}" id="composemail">
  {% csrf_token %}
  {{ form.origmsgid }}
  <div id="compose-container">
    <div id="mailheader">
      {% render_field form.from_ label_width="col-sm-1" %}
      <div class="form-group{% if form.errors.to %} has-error{% endif %}">
	{# handling to field #} 
        <label class="col-sm-1 control-label" for="id_to">{% trans "To" %}</label>
        <div class="col-sm-8">
          <input id="id_to" name="to" class="form-control selectize-contact"
                 value='{% if form.to.value %}{{ form.to.value }}{% endif %}'
                 placeholder="{% trans "Enter one or more addresses." %}">
	  {% if form.to.errors %}
	  {% for error in form.to.errors %}
	  <p class="help-block">{{ error }}</p>
	  {% endfor %}
	  {% endif %}
        </div>

	{# handling cc and bcc buttons #}
        {% if not form.cc.value or not form.bcc.value %}
        <div class="col-sm-2">
	  {% if not form.cc.value %}
          <button id="add_cc" class="btn btn-default btn-xs">
	    <span class="fa fa-plus"></span> {% trans "Cc" %}
	  </button>
	  {% endif %}
	  {% if not form.bcc.value %}
          <button id="add_bcc" class="btn btn-default btn-xs">
	    <span class="fa fa-plus"> {% trans "Bcc" %}</span>
	  </button>
	  {% endif %}
        </div>
       {% endif %}
      </div>

      {# display cc field when required #}
      {% if form.cc.value %}
        {% render_field form.cc label_width="col-sm-1" %}
      {% else %}
        {% render_field form.cc label_width="col-sm-1" hidden=True %}
      {% endif %}

      {# display bcc field when required #}
      {% if form.bcc.value %}
        {% render_field form.bcc label_width="col-sm-1" %}
      {% else %}
        {% render_field form.bcc label_width="col-sm-1" hidden=True %}
      {% endif %}

      {% render_field form.subject label_width="col-sm-1" %}

    </div>

    <div id="body_container">
      {{ form.body }}
    </div>

  </div>
</form>

