<script type="text/javascript">
    
$(function(){  
        //attach autocomplete  
        $('input#id_has_position').autocomplete({  
  		   appendTo: "#search-panel-dialog",
           //define callback to format results  
           source: function(req, add){  
                //pass request to server  
                $.getJSON(ajax_position_lookup, req, function(data) {  
                    //create array for response objects  
                    var suggestions = [];  
                    $.each(data['result'], function(i, val){  
                      suggestions.push(val[0]);  
                });  
                //pass array to callback  
                add(suggestions);  
            });  
          },  
        });  
        
        $('input#id_has_argument').autocomplete({  
  		   appendTo: "#search-panel-dialog",
           //define callback to format results  
           source: function(req, add){  
                //pass request to server  
                $.getJSON(ajax_argument_lookup, req, function(data) {  
                    //create array for response objects  
                    var suggestions = [];  
                    $.each(data['result'], function(i, val){  
                      suggestions.push(val[0]);  
                });  
                //pass array to callback  
                add(suggestions);  
            });  
          },  
        });
        
    $('#filter-form-tabs').tabs();
        
}); 
    
</script>

<form class="filter-form" method="post"> {% csrf_token %}
<div id="filter-form-tabs">
    <ul>
       <li><a href="#lemma-filters">Hasło</a></li>
       <li><a href="#schema-filters">Schematy</a></li>
       <li><a href="#frame-filters">Ramy</a></li>
    </ul>
    <div id="lemma-filters">
      {% if not form.lemma.is_hidden %}
        <p class="fieldWrapper">
          {{ form.lemma.errors }}
          {{ form.lemma.label_tag }}: {{ form.lemma }}
        </p>
      {% endif %}
      {% if not form.pos.is_hidden %}
        <p class="fieldWrapper">
          {{ form.pos.errors }}
          {{ form.pos.label_tag }}: {{ form.pos }}
        </p>
      {% endif %}
      {% if not form.contains_phraseology.is_hidden %}
        <p class="fieldWrapper">
          {{ form.contains_phraseology.errors }}
          {{ form.contains_phraseology.label_tag }}: {{ form.contains_phraseology }}
        </p>
      {% endif %}
      {% if not form.owner.is_hidden or not form.phraseologist.is_hidden or not form.semanticist.is_hidden %}
        <hr class="filtersSeparator">
      {% endif %}
      {% if not form.owner.is_hidden %}
        <p class="fieldWrapper">
          {{ form.owner.errors }}
          {{ form.owner.label_tag }}: {{ form.owner }}
        </p>
      {% endif %}
      {% if not form.phraseologist.is_hidden %}
        <p class="fieldWrapper">
          {{ form.phraseologist.errors }}
          {{ form.phraseologist.label_tag }}: {{ form.phraseologist }}
        </p>
      {% endif %}
      {% if not form.semanticist.is_hidden %}
        <p class="fieldWrapper">
          {{ form.semanticist.errors }}
          {{ form.semanticist.label_tag }}: {{ form.semanticist }}
        </p>
      {% endif %}
      {% if not form.vocabulary.is_hidden or not form.status.is_hidden or not form.has_message_from.is_hidden %}
        <hr class="filtersSeparator">
      {% endif %}
      {% if not form.vocabulary.is_hidden %}
        <p class="fieldWrapper">
          {{ form.vocabulary.errors }}
          {{ form.vocabulary.label_tag }}: {{ form.vocabulary }}
        </p>
      {% endif %}
      {% if not form.status.is_hidden %}
        <p class="fieldWrapper">
          {{ form.status.errors }}
          {{ form.status.label_tag }}: {{ form.status }}
        </p>
      {% endif %}
      {% if not form.has_message_from.is_hidden %}
        <p class="fieldWrapper">
          {{ form.has_message_from.errors }}
          {{ form.has_message_from.label_tag }}: {{ form.has_message_from }}
        </p>
      {% endif %}
      {% if not form.example_source.is_hidden or not form.approver.is_hidden %}
        <hr class="filtersSeparator">
      {% endif %}
      {% if not form.example_source.is_hidden %}
        <p class="fieldWrapper">
          {{ form.example_source.errors }}
          {{ form.example_source.label_tag }}: {{ form.example_source }}
        </p>
      {% endif %}
      {% if not form.approver.is_hidden %}
        <p class="fieldWrapper">
          {{ form.approver.errors }}
          {{ form.approver.label_tag }}: {{ form.approver }}
        </p>
      {% endif %}
	</div>
	<div id="schema-filters">
	  {% if not form.schema_opinion.is_hidden %}
        <p class="fieldWrapper">
          {{ form.schema_opinion.errors }}
          {{ form.schema_opinion.label_tag }}: {{ form.schema_opinion }}
        </p>
      {% endif %}
	  {% if not form.schema_type.is_hidden %}
        <p class="fieldWrapper">
          {{ form.schema_type.errors }}
          {{ form.schema_type.label_tag }}: {{ form.schema_type }}
        </p>
      {% endif %}
      {% if not form.reflex.is_hidden %}
        <p class="fieldWrapper">
          {{ form.reflex.errors }}
          {{ form.reflex.label_tag }}: {{ form.reflex }}
        </p>
      {% endif %}
      {% if not form.negativity.is_hidden %}
        <p class="fieldWrapper">
          {{ form.negativity.errors }}
          {{ form.negativity.label_tag }}: {{ form.negativity }}
        </p>
      {% endif %}
      {% if not form.predicativity.is_hidden %}
        <p class="fieldWrapper">
          {{ form.predicativity.errors }}
          {{ form.predicativity.label_tag }}: {{ form.predicativity }}
        </p>
      {% endif %}
      {% if not form.aspect.is_hidden %}
        <p class="fieldWrapper">
          {{ form.aspect.errors }}
          {{ form.aspect.label_tag }}: {{ form.aspect }}
        </p>
      {% endif %}
      {% if not form.has_argument.is_hidden %}
        <p class="fieldWrapper">
          {{ form.has_argument.errors }}
          {{ form.has_argument.label_tag }}: {{ form.has_argument }}
        </p>
      {% endif %}
      {% if not form.has_position.is_hidden %}
        <p class="fieldWrapper">
          {{ form.has_position.errors }}
          {{ form.has_position.label_tag }}: {{ form.has_position }}
        </p>
      {% endif %}
      {% if not form.filter_frames.is_hidden %}
        <p class="fieldWrapper">
          {{ form.filter_frames.errors }}
          {{ form.filter_frames.label_tag }}: {{ form.filter_frames }}
        </p>
      {% endif %}
	</div>
	<div id="frame-filters">
      {% if not form.frame_opinion.is_hidden %}
        <p class="fieldWrapper">
          {{ form.frame_opinion.errors }}
          {{ form.frame_opinion.label_tag }}: {{ form.frame_opinion }}
        </p>
      {% endif %}
      <hr class="filtersSeparator">
      <div id="sem-arguments">
        <p>Argumenty semantyczne: 
          <button type="button" onclick="addSemArgFilter(this)">Dodaj</button>
          <button type="button" onclick="addArgAlternative(this)">Lub</button>
        </p>
		{% for arg_form in sem_args_forms %}
		  <div id="sem-argument">
		    {% include 'sem_arg_form.html' with form=arg_form only %}
		  </div>
		{% endfor %}
      </div>
	</div>
  </div>
  {% for hidden in form.hidden_fields %}
    {{ hidden }}
  {% endfor %}
  {{ form.non_field_errors }}
  <p class="lexeme-save">
    <button type="submit" id="filter-form-submit">
      Filtruj
    </button>
    <button type="button" id="filter-form-reset">
      Cofnij Filtrowanie
    </button>
    <button type="reset" id="filter-form-cancel">
      Anuluj
    </button>
  </p>
  
</form>
