{% extends "base.html" %}

{% block head %}
  <script type="text/javascript">
    $(document).ready(function(){
    	
    		if (!$.isNumeric($( "#id_patient" )))
		$( "#id_patient" ).val($.cookie("patient"));
    	
      {%if not object%}
        var today = new Date();
        var dd = today.getDate();
        var mm = today.getMonth()+1;//January is 0!
        var yyyy = today.getFullYear();
        if(dd<10){dd='0'+dd}
        if(mm<10){mm='0'+mm}
        $("#id_date").val(yyyy+'-'+mm+'-'+dd);
      {%endif%}
      $("#id_date").datepicker();
    });
  </script>
{% endblock %}

{% block title %}
  Follow-up Form
{% endblock %}

{% block content %}

  {% if object %}
    {{object.patient}} {{object.patient.medical_records}} 
    <h2>Update follow-up</h2>
  {% else %}
    {{patient}} {{patient.medical_records}}
    <h2>Create follow-up</h2>
  {% endif %}

  {% if form.errors %}
    <em>Please correct the following error{{ form.errors|pluralize }}:</em>
  {% endif %}

  <form action="." class="cssform" method="POST" name="followForm">{% csrf_token %}
    <p>{{form.patient.label_tag}}<input type="text" readonly="true" name="patient" id="id_patient"
      {% if object %}
        value = {{object.patient.id}}
      {% else %}
        value = {{patient.id}}
      {% endif %}
      />{{form.patient.errors}}</p>
    <p>{{form.date.label_tag}}{{form.date}}{{form.date.errors}}</p>
    <p>{{form.memo.label_tag}}{{form.memo}}{{form.memo.errors}}</p>
    <input type="submit" /> <input type="reset" />
  </form>
  
<!--
This is a lifesaver when debugging!
<p> {{ form.error_dict }} </p>
-->

  {% if object %}
    <a href='/patient/detail/{{object.patient.id}}/'>Return to patient</a>
  {% else %}
    <a href='/patient/detail/{{patient.id}}/'>Return to patient</a>
  {% endif %}

{% endblock %}