<!-- BEGIN [% component.name %] -->
[% # INCLUDE dumper.tt dump = data.as_tree %]

    <script type="text/javascript">
        jQuery( function() {
            $("#is_valid_date_min").Watermark("min");
            $("#is_valid_date_hour").Watermark("hr");
            $("#is_valid_date_day").Watermark("dd");
            $("#is_valid_date_month").Watermark("mm");
            $("#is_valid_date_year").Watermark("yyyy");
        } );
    </script>

    [% BLOCK validate_date; IF c.cfg('use_cgi_ajax') %]
        onChange="do_ajax(
			['is_valid_date_day','is_valid_date_month','is_valid_date_year',
				'is_valid_date_hour','is_valid_date_min' ],
            ['bad_datetime']
		); return true;"
    [% END; END %]

	<table class="indent">
        <tr>
            <td class="label">Referrer:</td>
			<td class="search_bar">
				<input style="width: 150px" type="text" name="_referrer"
					id="referrer_name" value="[% data.referrer_department.referrer.name %]" />
				<input type="hidden" name="referrer_code" id="referrer_id" />
                [% IF error_referrer_code %]
                    [% error_referrer_code %]
                [% ELSE %]
                    [ <a href="[% app_url %]/config/clinicians">new</a> ]
                [% END %]
            </td>
        </tr>
        <tr>
            <td class="label">Specimen:</td>
            <td class="content">
                <input class="field" type="text" name="specimen_code" id="is_valid_specimen"
					value="[% request_data.specimen_map.item(data.id).sample_code.join(', ') %]"
                [% IF c.cfg('use_cgi_ajax') %]
                    onChange="do_ajax(['is_valid_specimen'], ['bad_specimen']); return true;"
                [% END %] [% site.html.on_focus %] />[% error_specimen_code %]
                <span class="ajax_error"><em id="bad_specimen"></em></span>
			</td>
        </tr>

		<tr>
            <td class="label">Taken:</td>
			<td class="content">
                [% specimen_date = request_data.has_optional.request_specimen_detail
                        ? data.request_specimen_detail.specimen_date : undef;
                    # INCLUDE dumper.tt dump = specimen_date %]
                <input type="text" name="day" size="2" id="is_valid_date_day"
					   value="[% specimen_date.strftime('%d') %]"
					[% PROCESS validate_date %] maxlength="2" class="[% class %]"
					   [% site.html.on_focus %] />

				<input type="text" name="month" size="2" id="is_valid_date_month"
					   value="[% specimen_date.strftime('%m') %]"
					[% PROCESS validate_date %] maxlength="2" class="[% class %]"
					   [% site.html.on_focus %] />

				<input type="text" name="year" size="4" id="is_valid_date_year"
					   value="[% specimen_date.strftime('%Y') %]"
					[% PROCESS validate_date %] maxlength="4" class="[% class %]"
					   [% site.html.on_focus %] />
				<b>@</b>
				<input type="text" name="hour" size="2" id="is_valid_date_hour"
					   value="[% specimen_date.strftime('%H') %]"
					[% PROCESS validate_date %] maxlength="2" class="[% class %]"
					   [% site.html.on_focus %] />
				<input type="text" name="minute" size="2" id="is_valid_date_min"
					   value="[% specimen_date.strftime('%M') %]"
					[% PROCESS validate_date %] maxlength="2" class="[% class %]"
					   [% site.html.on_focus %] />
				[% UNLESS error_day || error_year # set if date invalid %]
					<span class="ajax_error"><em id="bad_datetime"></em></span>
				[% END %]
                [% error_day || error_year # set if date invalid %]
            </td>
        </tr>

		[%
			IF request_data.has_optional.clinical_trial;
				trial_id = data.request_trial.trial_id;
				trial_number = get_trial_number(patient.id, data.request_trial.trial_id);
			END;
            IF trials.size;
		%]
            <tr>
                <td class="label">Trial/study:</td>
                <td class="content">
                    <select name="trial_id" id="trial_id" [% site.html.on_focus %]>
                        <option value="">&nbsp;</option>
                        [% FOREACH trial IN trials %]
                        <option value="[% trial.id %]"
                                [% 'selected' IF trial.id == trial_id %]>
                            [% trial.trial_name %]
                        </option>
                        [% END %]
                    </select>
                    [% error_trial_id %]
                </td>
            </tr>
            <tr>
                <td class="label">Trial no:</td>
                <td class="content">
                    <input class="field" type="text" name="trial_number"
                        value="[% trial_number %]" />
                    [% error_trial_number %]
                </td>
            </tr>
		[% END %]

		[%
			IF request_data.has_optional.external_ref;
				external_ref = data.request_external_ref.external_reference;
			END;
		%]
        <tr>
            <td class="label">External ref:</td>
            <td class="content">
				<input class="field" type="text" name="external_reference"
					value="[% external_ref %]" />
                [% error_external_reference %]
			</td>
        </tr>
	</table>
<!-- END [% component.name %] -->
