{% extends "corporate_memberships/base.html" %}
{% load corporate_memberships_tags %}
{% load i18n %}

{% block title %}{% trans "Corporate Membership Add" %}{% 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/corporate_memberships.css">
{% endblock %}

{% block body %}
<div class="t">
	{% corpmemb_nav request.user %}
	
     <h1>{{ corp_app.name }}</h1>
    <p>{{ corp_app.description|safe }}</p>


    <form method="post" enctype="multipart/form-data">{% csrf_token %}
	<div class="forms">
	{% if form.errors.values %}
		<div class="errors">
		{% trans "There were some problems in the form. Please review. Thanks!" %}
		
		{% 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 %}
		
		</div>
	{% endif %}

		{% for field_obj in field_objs %}
				
			{% render_corp_field request field_obj form %}
			
		{% endfor %}
		
		<input type="submit" value="Submit" />
	</div>
	
	</form>
  
    
</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
		});
	</script>
        <script type="text/javascript" >
        function find_field(name) {
            labels = $(".forms").find("label");
            label = labels[0];
            i = 0;
            while((label.innerHTML!=name) && (i < labels.length)) {
                i++;
                label = labels[i];
            };
            field = $('.'+$.trim(label.parentNode.parentNode.attributes[0].value));
            return field;
        };
        
        breaks = $.find('div.section-break h2');
        pay_break = $(breaks[0]);
        i = 0;
        while((pay_break.html()!="Payment Details") && (i < breaks.length)) {
            i++;
            pay_break = $(breaks[i]);
        };
        
        membership = find_field("Corporate Membership Type");
        payment = find_field("Payment Method");
        
        mem_options = membership.find('li');
        
        for(var i=0; i < mem_options.length; i++) {
            op = $(mem_options[i]);
            if(parseFloat(op.find('label').html().split('$')[1])==0) {
                op.click(function() {
                    payment.hide();
                    pay_break.hide();
                });
            } else {
                op.click(function() {
                    payment.show();
                    pay_break.show();
                });
            };
        }
    </script>
{% endblock %}
