{% load styled_forms %}
{% load base_filters %}

{% if form.errors.values %}
<div class="errors">
There were some problems in the form. Please review. Thanks!
{% for error in form.non_field_errors %}
    <p><a href="#">{{ error }}</a></p>
{% endfor %}
{% if form.fieldsets.fieldsets %}
	{% for fieldset in form.fieldsets %}
		{% for field in fieldset %}
			{% if field.errors %}
            {% for error in field.errors %}
            	<p><a href="{{ request.get_full_path }}#{{ field.auto_id }}">{{ field.label }} - {{ error }}</a></p>
            {% endfor %}
			{% endif %}
		{% endfor %}
	{% endfor %}
{% else %}
	{% for field in form %}
		{% if field.errors %}
	          {% for error in field.errors %}
	          	<p><a href="{{ request.get_full_path }}#{{ field.auto_id }}">{{ field.label }} - {{ error }}</a></p>
	          {% endfor %}
		{% endif %}
	{% endfor %}
{% endif %}
</div>
{% endif %}

{% if form.fieldsets.fieldsets %}
	{% for fieldset in form.fieldsets %}
	  {% if fieldset.boundfields %}
	  <fieldset class="{{ fieldset.classes }}">
		{% if fieldset.legend %}
		  <legend>{{ fieldset.legend }}</legend>
		{% endif %}
		{% if fieldset.description %}
		  <p class="section-description">{{ fieldset.description }}</p>
		{% endif %}
		{% for field in fieldset %}
		{% if field.is_hidden %}
		    {{ field }}
		{% else %}
		    <div class="form-field">
		        <div class="{{ field.auto_id }}">
		        	{% if field|is_checkbox %}
		            	<div class="checkbox">
		               		{% if field.errors %}         
		                    <div class="error">
		                        {% for error in field.errors %}
		                        <p>{{ error }}</p>
		                        {% endfor %}
		                    </div>
		                    {% endif %}  
		                    <div class="field">
		                        {{ field }}
		                    </div> 
		                    <div class="label{% if field.field.required %} required{% endif %}">
		                        {{ field.label_tag }}
		                    </div> 
		                    {% if field.help_text %}
		                    <div class="help-text">{{ field.help_text|safe }}</div>   
		                    {% endif %}
		                </div>
		                <div style="clear: both"><!-- IE7 --></div>
		            {% else %}
		                <div class="label{% if field.field.required %} required{% endif %}">
		                    {{ field.label_tag }}
		                </div>
		                {% if field.errors %}
		                <div class="error">
		                    {% for error in field.errors %}
		                    <p>{{ error }}</p>
		                    {% endfor %}
		                </div>
		                {% endif %}
		                <div class="field">
		                    {{ field }}
		                </div>
		                {% if field.help_text %}
		                <div class="help-text">{{ field.help_text|safe }}</div>
		                {% endif %}
		            {% endif %}
		         </div>
		    </div>
		{% endif %}
		{% endfor %}   	
	  </fieldset>
	  {% endif %}
	{% endfor %}
{% else %}
	{% for field in form %}
	{% if field.is_hidden %}
	    {{ field }}
	{% else %}
	    <div class="form-field">
	        <div class="{{ field.auto_id }}{{ field.field.css_classes }}">
	        	{% if field|is_checkbox %}
	            	<div class="checkbox">
	               		{% if field.errors %}         
	                    <div class="error">
	                        {% for error in field.errors %}
	                        <p>{{ error }}</p>
	                        {% endfor %}
	                    </div>
	                    {% endif %}  
	                    <div class="field">
	                        {{ field }}
	                    </div> 
	                    <div class="label{% if field.field.required %} required{% endif %}">
	                        {{ field.label_tag }}
	                    </div> 
	                    {% if field.help_text %}
	                    <div class="help-text">{{ field.help_text|safe }}</div>   
	                    {% endif %}
	                </div>
	                <div style="clear: both"><!-- IE7 --></div>
	            {% else %}
                    {% if field|is_header or field|is_description %}
                        {% if field|is_header %}
                            <div class="section-header">{{ field.label }}</div>
                        {% else %}
                            <div class="section-description">{{ field.label }}</div>
                        {% endif %}
                    {% else %}
                        <div class="label{% if field.field.required %} required{% endif %}">
                            {{ field.label_tag }}
                        </div>
                        {% if field.errors %}
                        <div class="error">
                            {% for error in field.errors %}
                            <p>{{ error }}</p>
                            {% endfor %}
                        </div>
                        {% endif %}
                        <div class="field">
                            {{ field }}
                        </div>
                        {% if field.help_text %}
                        <div class="help-text">{{ field.help_text|safe }}</div>
                        {% endif %}
                    {% endif %}
	            {% endif %}
	         </div>       
	    </div>
	{% endif %}
	{% endfor %}   
{% endif %}
