{% extends "memberships/base-wide.html" %}
{% load base_filters %}
{% load i18n %}
{% load membership_tags %}
{% load styled_forms %}

{% block title %}{% endblock %}
{% block meta_description %}{% endblock %}
{% block meta_keywords %}{% endblock %}
{% block meta_canonical_url %}<link rel="canonical" href="" />{% endblock %}

{% block extra_head %}
{{ block.super }}
<link rel="stylesheet" href="{{ STATIC_URL }}css/jquery-ui/jquery-ui-1.8.2.custom.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/timepicker.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}css/memberships.css">
<style>
    .inline-block{
        display: inline-block;
    }
    div.short-label{
        width: 125px;
    }
    div.float-left{
        float: left;
    }
    div.clear{
        clear: both;
    }
    div.form-field{
        margin: 3px 0;
    }
    div.admin-only-header{
        color: #CC0000;
    }
    div.section-break{
        margin: 2em 0 1em 0;
    }
    div.form-field ul{
        list-style-type: none;
    }
    div.form-field{
        margin-left: 2em;
    }
    div.form-field .error{
        color: #990000;
    }
    div.form-errors{
        margin-left: 0;
        background-color: #ffebe8;
        border: 2px solid #ff8b78;
        margin-bottom: 20px;
        padding: 10px;
        width: 75%;
    }
</style>
{% endblock %}

{% block body %}
<div class="t">
<div class="application-form-wrap">

        <h1>{{ app.name }}</h1>
        {{ app.description|safe }}

       <form action="" method="post">{% csrf_token %}
           
      {% if user_form.errors.values or profile_form.errors.values or demographics_form.errors.values or membership_form.errors.values or captcha_form.errors.values %}
        <div class="form-errors">
            
            There were some problems in the form. Please review. Thanks!
            {% if user_form.errors.values %}
            {% for error in user_form.non_field_errors %}
                <p><a href="#">{{ error }}</a></p>
            {% endfor %}
            {% endif %}
            
            {% if profile_form.errors.values %}
            {% for error in profile_form.non_field_errors %}
                <p><a href="#">{{ error }}</a></p>
            {% endfor %}
            {% endif %}
            
            {% if demographics_form.errors.values %}
            {% for error in demographics_form.non_field_errors %}
                <p><a href="#">{{ error }}</a></p>
            {% endfor %}
            {% endif %}
            
            {% if membership_form.errors.values %}
            {% for error in membership_form.non_field_errors %}
                <p><a href="#">{{ error }}</a></p>
            {% endfor %}
            {% endif %}
            
            {% for field in user_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 %}
            
            {% for field in profile_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 %}
            
            {% for field in demographics_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 %}
            
            {% for field in membership_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 %}
            
            {% for field in captcha_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 %}
    
        </div>
      {% endif %}
           
        {% for field_obj in app_fields %}
            {% render_membership_field request field_obj user_form profile_form demographics_form membership_form %} 
        {% endfor %}

        {% if membership_form.discount_code %}
        <div class="form-field discount-field-wrap">
            <div id="discount-message" class="error">{{ membership_form.discount_code.errors }}</div>
			<div class="required">{% trans "Discount Code" %}</div>
			<div class="field">{{ membership_form.discount_code }}</div>
            <button type="button" id="discount_check">Check Discount</button>
        </div>
        {% endif %}

        {{ captcha_form.as_p }}

        <input class="btn" type="submit" name="submit" value="Submit" />

    </form>
</div>
</div>
{% endblock %}


{% block extra_body %}
    {{ block.super }}
      <script type="text/javascript" 
      src="{{ STATIC_URL }}js/jquery-ui-1.8.2.custom.min.js"></script>
      <script src="{{ STATIC_URL }}js/jquery.time.picker.js" type="text/javascript"></script>
      <script type="text/javascript">
            $(".datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
            $('.timepicker').timePicker({
              show24Hours: false,
              step: 15
            });

        $(document).ready(function(){
            $('#discount_check').click(function(){
                var code = $('#id_discount_code').val();
                var model = 'membershipset';
                var prices = '0';
                
                $.post(
                    '{% url discount.check_discount %}',
                    {
                        'code':code,
                        'prices':prices,
                        'model':model,
                    },
                    function(data, textStatus, jqXHR){
                        json = $.parseJSON(data);
                        //alert(json['message'])
                        $('#discount-message').html(json["message"]);
                    }
                );
            });
        });
      </script>
{% endblock extra_body %}
