<?php
$FORM = &$_SESSION[$controller->defaultForm];
$week_start = isset($tpl['option_arr']['o_week_start']) && in_array((int) $tpl['option_arr']['o_week_start'], range(0,6)) ? (int) $tpl['option_arr']['o_week_start'] : 0;
$jqDateFormat = pjUtil::jqDateFormat($tpl['option_arr']['o_date_format']);
?>
<div class="col-xs-12 erSelectorSearchWrapper">
	<form action="#" method="post" class="collapse form-horizontal pjErForm pjErFormAvailability erSelectorFilterForm" id="pjErFormAvailability" data-basket="<?php echo (int) $numberOfItemsInBasket; ?>">
		<input type="hidden" name="filter" value="<?php echo $filter; ?>" />
		<div class="pjErFormCalendarGroup">
			<div class="form-group">
				<div class="row">
					<label for="" class="control-label col-md-5 col-sm-6 col-xs-12"><?php __('rental_start'); ?></label>
													
					<div class="col-md-5 col-sm-6 col-xs-12">
						<div class="row erItemRow">
							<div class="col-xs-5 pjErCalendarInner">
								<input type="text" name="date_from" readonly="readonly" class="form-control pjErField pjErFieldDate pjErFieldDateFrom erSelectorDatepick" data-fday="<?php echo $week_start; ?>" data-dformat="<?php echo $jqDateFormat; ?>" data-iso="<?php echo $FORM['date_from']; ?>" value="<?php echo pjUtil::formatDate($FORM['date_from'], 'Y-m-d', $tpl['option_arr']['o_date_format']); ?>"/>
					
								<a href="#" class="pjErBtn pjErBtnCalendarTrigger pjErBtnCalendarTriggerFrom">
									<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
								</a>
							</div><!-- /.col-xs-6 pjErCalendarInner -->
							<div class="pjErItemTime">
								<?php
								$hasDayLimit = isset($tpl['day_limit']);
								if ($hasDayLimit)
								{
									$cache_day_limit = $tpl['day_limit'];
								}
								$_GET['start'] = 1;
								$_GET['change'] = 'date';
								if (isset($tpl['day_limit_start']) && !$hasDayLimit)
								{
									$tpl['day_limit'] = $tpl['day_limit_start'];
								}
								if (isset($tpl['day_limit'], $tpl['day_limit']['start']) && !empty($tpl['day_limit']['start']))
								{
									list($_GET['hour'], ) = explode(":", $tpl['day_limit']['start']);
								}
								include PJ_VIEWS_PATH . 'pjFrontEnd/pjActionGetTime.php';
								?>
							</div>						
						</div><!-- /.row -->
					</div><!-- /.col-md-5 col-sm-6 col-xs-12 -->
				</div><!-- /.row -->
			</div><!-- /.form-group -->
			
			<div class="form-group">
				<div class="row">
					<label for="" class="control-label col-md-5 col-sm-6 col-xs-12"><?php __('rental_end'); ?></label>
													
					<div class="col-md-5 col-sm-6 col-xs-12">
						<div class="row erItemRow">
							<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pjErCalendarInner">
								<input type="text" name="date_to" class="form-control pjErField pjErFieldDate pjErFieldDateTo erSelectorDatepick" readonly="readonly" data-fday="<?php echo $week_start; ?>" data-dformat="<?php echo $jqDateFormat; ?>" data-iso="<?php echo $FORM['date_to']; ?>" value="<?php echo pjUtil::formatDate($FORM['date_to'], 'Y-m-d', $tpl['option_arr']['o_date_format']); ?>"/>
					
								<a href="#" class="pjErBtn pjErBtnCalendarTrigger pjErBtnCalendarTriggerTo">
									<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
								</a>
							</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-6 pjErCalendarInner -->
							<div class="pjErItemTime">
								<?php
								$_GET['start'] = 0;
								$_GET['change'] = 'date';
								if (isset($tpl['day_limit_end']) && !$hasDayLimit)
								{
									$tpl['day_limit'] = $tpl['day_limit_end'];
								}
								if (isset($tpl['day_limit'], $tpl['day_limit']['end']) && !empty($tpl['day_limit']['start']))
								{
									list($_GET['hour'], ) = explode(":", $tpl['day_limit']['start']);
								}
								include PJ_VIEWS_PATH . 'pjFrontEnd/pjActionGetTime.php';
								?>
							</div>
						</div><!-- /.row -->
					</div><!-- /.col-md-5 col-sm-6 col-xs-12 -->
				</div><!-- /.row -->
			</div><!-- /.form-group -->
		</div><!-- /.pjErFormCalendarGroup -->

		<div class="form-group pjErFormActions">
			<button class="btn btn-default pjErBtn pjErBtnPrimary erSelectorButton"><?php __('button_check_availability'); ?></button>
			<button class="btn btn-link pjErBtn pjErBtnLink erSelectorClearDateTime" data-type="<?php echo $filter; ?>" data-basket="<?php echo (int) $numberOfItemsInBasket; ?>"><?php __('selected_clear'); ?></button>
		</div><!-- /.form-group pjErFormActions -->
	</form><!-- /.form-horizontal pjErForm pjErFormAvailability -->
</div><!-- /.col-xs-12 -->
<?php
# Clean up day limit
unset($_GET['start']);
unset($_GET['change']);
if (isset($_GET['hour']))
{
	unset($_GET['hour']);
}
if ($hasDayLimit && isset($cache_day_limit))
{
	$tpl['day_limit'] = $cache_day_limit;
	unset($cache_day_limit);
}
if (!$hasDayLimit && isset($tpl['day_limit']))
{
	unset($tpl['day_limit']);
}
?>