{% extends "forms/base.html" %}
{% load styled_forms %}
{% load forms_tags %}

{% block title %}{% firstof MODULE_FORMS_LABEL 'Forms' %} Add{% endblock %}

{% block body %}

<div class="t">
    {% forms_nav request.user %}

    <h1>{% firstof MODULE_FORMS_LABEL 'Forms' %} Add</h1>

	<div class="form-builder-wrap">
    	<form action="." method="post">{% csrf_token %}
    	<div class="forms">
            {{ form|styled_form }}
            <fieldset id='pricing-options'>
                <legend>Pricing Options</legend>
                {{ formset.management_form }}
                {{ formset|styled_form_set }}
            </fieldset>
            <input type="submit" value="Add {% firstof MODULE_FORMS_LABEL 'Form' %}" />
		</div>
        </form>
    </div>

</div>
{% endblock %}

{% block extra_body %}
{{ block.super }}
<script type="text/javascript" src="{{ STATIC_URL }}js/slug.js"></script>
<script type="text/javascript">
    $(document).ready(function(){

        var custom_payment = $('#id_custom_payment');

        /* Take Payment CHANGE Handler */
        custom_payment.change(function(){
            pricings = $(this).attr('checked');
            if(pricings){
                $('#pricing-options').show();
                $('.id_payment_methods').show();
                $('.id_recurring_payment').show();
            }else{
                $('#pricing-options').hide();
                $('.id_payment_methods').hide();
                $('.id_recurring_payment').hide();
            }
        });

        /* Presetting Payment Display */
        if (custom_payment.attr('checked')){
            $('#pricing-options').show();
            $('.id_payment_methods').show();
            $('.id_recurring_payment').show();
        } else {
            $('#pricing-options').hide();
            $('.id_payment_methods').hide();
            $('.id_recurring_payment').hide();
        }
        
        var recurring_payment = $('#id_recurring_payment');
        recurring_payment.change(function(){
            rp = $(this).attr('checked');
            if(rp=='checked') {
                $('.recurring-payment').closest('div.form-field').show();
            }else{
                $('.recurring-payment').closest('div.form-field').hide();
            }
        });
        
        /*Presenting recurring payment display */
        if (recurring_payment.attr('checked')){
            $('.recurring-payment').closest('div.form-field').show();
        } else {
            $('.recurring-payment').closest('div.form-field').hide();
	    }

    });

    var slugit = new Slugify({
        input_element : 'input#id_title',
        slug_element : 'input#id_slug',
        submit_element : 'input[type="submit"]',
        help: false,
        limit : 150
    });
</script>
{% endblock %}
