<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:tal="http://xml.zope.org/namespaces/tal"
    xmlns:metal="http://xml.zope.org/namespaces/metal"
    xmlns:i18n="http://xml.zope.org/namespaces/i18n"
    metal:use-macro="here/main_template/macros/master"
    i18n:domain="senaite.health">

<metal:slot fill-slot="head_slot">
    <link rel="stylesheet" type="text/css" media="all" href=""
          tal:attributes="href python:context.absolute_url()+'/bika_widgets/recordswidget.css'" />
</metal:slot>

<body>

    <metal:content-core fill-slot="content-core">
        <form name="treatmenthistory" method="post" action='treatmenthistory'
            tal:attributes="action python:context.absolute_url()+'/treatmenthistory'"
            tal:define="errors python:request.get('errors', {});">

            <metal:widget use-macro="python:context.widget('TreatmentHistory', mode='edit')" />

            <input class="action_button" type="submit"
                i18n:attributes="value" value="save" />
            <input type='hidden' name='submitted' value='1'/>
        </form>

        <script type="text/javascript" tal:attributes="src python:context.absolute_url()+'/bika_widgets/recordswidget.js'"> </script>

        <!-- Simple date range validation -->
        <script type="text/javascript">
            $("input[name^='TreatmentHistory\\.Start'],input[name^='TreatmentHistory\\.End']").live('change',
                function(){
                    if($(this).hasClass('datepicker_nofuture')){
                        var start = $(this).val();
                        var end = $($($($(this).parents('td')[0]).next()).children()[0]).val();
                    } else {
                        var start = $($($($(this).parents('td')[0]).prev()).children()[0]).val();
                        var end = $(this).val();
                    }
                    if (start != '' && end != ''){
                        if (Date.parse(end) < Date.parse(start)) {
                            window.bika.lims.portalMessage('End date must be after start date');
                            $(this).val('');
                        }
                    }
                }
            )
        </script>

    </metal:content-core>

</body>
</html>
