<header class="row pjErHeader">
<?php
include PJ_VIEWS_PATH . 'pjFrontEnd/elements/header.php';
$filter = 'items';
include PJ_VIEWS_PATH . 'pjFrontEnd/elements/search.php'; 
?>
</header><!-- /.row pjErHeader -->
<?php
if (isset($tpl['item_arr']) && !empty($tpl['item_arr']))
{ 
	$CART = $controller->cart->getAll();
	$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']);
	$isReady2Buy = !empty($FORM['date_from']) && !empty($FORM['date_to']) && !empty($_GET['date_from']) && !empty($_GET['date_to']);
	
	$src = PJ_INSTALL_URL . PJ_IMG_PATH . 'frontend/er-noimg.png';
	if (!empty($tpl['item_arr']['pic']) && is_file($tpl['item_arr']['pic']))
	{
		$src = PJ_INSTALL_URL . $tpl['item_arr']['pic'];
	}
	?>
	<div class="panel panel-default pjErBody pjErProductDetails">
		<div class="panel-body pjErProductDetailsInner">
			<div class="row">
				<div class="col-md-5 col-sm-6 col-xs-12 pjErProductGallery">
					<div class="pjErProductMainImage">
						<img src="<?php echo $src; ?>" alt="<?php echo pjSanitize::html($tpl['item_arr']['title']); ?>" class="erSelectorItemPic" />
					</div><!-- /.pjErProductMainImage -->
					<?php
					if (isset($tpl['item_arr']['small_path']) && !empty($tpl['item_arr']['small_path']))
					{ 
						?>
						<ul class="list-inline pjErProductThumbs">
							<?php
							foreach ($tpl['item_arr']['small_path'] as $k => $image)
							{ 
								if (!empty($image) && is_file(PJ_INSTALL_PATH . $image))
								{
									?>
									<li class="pjErProductThumb">
										<a href="<?php echo pjUtil::getReferer(); ?>" data-src="<?php echo PJ_INSTALL_URL . $tpl['item_arr']['medium_path'][$k]; ?>" class="thumbnail erSelectorItemThumb">
											<img src="<?php echo PJ_INSTALL_URL . $image; ?>" alt="<?php echo pjSanitize::html(@$tpl['item_arr']['alt'][$k]); ?>" />
										</a>
									</li><!-- /.pjErProductThumb -->
									<?php
								}
							} 
							?>
						</ul><!-- /.list-inline pjErProductThumbs -->
						<?php
					} 
					?>
				</div><!-- /.col-md-5 col-sm-6 col-xs-12 pjErProductGallery -->
	
				<div class="col-md-7 col-sm-6 col-xs-12">
					<header class="pjErProductHead">
						<p class="pjErProductTitle"><?php echo pjSanitize::html($tpl['item_arr']['title']); ?></p><!-- /.pjErProductTitle -->
						<p><?php echo pjSanitize::html($tpl['item_arr']['category_name']); ?></p>
					</header><!-- /.pjErProductHead -->
	
					<div class="pjErProductBody">
						<p><?php echo pjSanitize::html($tpl['item_arr']['description']); ?></p>
					</div><!-- /.pjErProductBody -->
	
					<footer class="pjErProductFoot">
						<div class="row">
							<form action="" method="post" class="form-horizontal pjErForm pjErFormAvailability erBefore erSelectorAvailabilityForm" style="display: <?php echo $isReady2Buy ? 'none' : NULL; ?>" data-basket="<?php echo (int) $numberOfItemsInBasket; ?>">
								<input type="hidden" name="item_id" value="<?php echo $tpl['item_arr']['id']; ?>" />
								<div class="form-group">
									<label for="" class="control-label col-md-4 col-xs-12"><?php __('number_items'); ?></label>
									<?php
									$key = 'item_' . $tpl['item_arr']['id'];
									$cnt = NULL;
									if (isset($CART[$key]))
									{
										$cnt = $CART[$key];
									}
									?>
									<div class="col-md-8 col-xs-12">
										<div class="row">
											<div class="col-xs-6">
												<select name="cnt" class="form-control erFormField">
												<?php
												$max_cnt = pjUtil::getMaxCount($tpl['item_arr']['cnt'], $tpl['item_arr']['min_from'], $tpl['item_arr']['min_to']);
												$max_cnt = $max_cnt - (int)$tpl['item_arr']['booked_qty'];
												foreach (range(1, $max_cnt) as $i)
												{
													?><option value="<?php echo $i; ?>"<?php echo $i != $cnt ? NULL : ' selected="selected"'; ?>><?php echo $i; ?></option><?php
												}
												?>
												</select>
											</div><!-- /.col-xs-6 -->
										</div><!-- /.row -->
									</div><!-- /.col-md-8 col-xs-12 -->
								</div><!-- /.form-group -->
							
								<div class="pjErFormCalendarGroup">
									<div class="form-group">
										<label for="" class="control-label col-md-4 col-xs-12"><?php __('rental_start'); ?></label>
									
										<div class="col-md-8 col-xs-12">
											<div class="row erItemRow">
												<div class="col-xs-5 pjErCalendarInner">
													<?php
													$from_date = !empty($FORM['date_from']) ? $FORM['date_from'] : $tpl['first_working_date'];
													?>
													<input type="text" name="date_from" class="form-control pjErField pjErFieldDate pjErFieldDateFrom erSelectorDatepick" readonly="readonly" data-fday="<?php echo $week_start; ?>" data-dformat="<?php echo $jqDateFormat; ?>" data-iso="<?php echo $from_date; ?>" data-today="<?php echo $from_date == date('Y-m-d') ? 'true' : 'false'; ?>" value="<?php echo pjUtil::formatDate(!empty($FORM['date_from']) ? $FORM['date_from'] : $tpl['first_working_date'], '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']);
													$_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-8 col-xs-12 -->
									</div><!-- /.form-group -->
									<?php
									$first_working_date = $tpl['first_working_date']; 
									if($tpl['item_arr']['rent_by_day'] == 1)
									{
										$first_working_date = date('Y-m-d', strtotime($tpl['first_working_date']) + 24*60*60);
										$rent_by_day = true;
									}
									?>
									<div class="form-group">
										<label for="" class="control-label col-md-4 col-xs-12"><?php __('rental_end'); ?></label>
									
										<div class="col-md-8 col-xs-12">
											<div class="row erItemRow">
												<div class="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 !empty($FORM['date_to']) ? $FORM['date_to'] : $first_working_date; ?>" value="<?php echo pjUtil::formatDate(!empty($FORM['date_to']) ? $FORM['date_to'] : $first_working_date, '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-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-8 col-xs-12 -->
									</div><!-- /.form-group -->
								</div><!-- /.pjErFormCalendarGroup -->
							
								<div class="form-group pjErFormActions">
									<div class="col-md-4 col-xs-12">
										<a href="<?php echo pjUtil::getReferer(); ?>#!/Items" class="btn btn-default btn-block pjErBtn pjErBtnSecondary erSelectorItems"><?php __('button_back'); ?></a>
									</div><!-- /.col-md-4 col-xs-12 -->
	
									<div class="col-md-8 col-xs-12">
										<button type="submit" class="btn btn-default btn-block pjErBtn pjErBtnPrimary"><?php __('button_check_availability'); ?></button>
									</div><!-- /.col-md-8 col-xs-12 -->
								</div><!-- /.form-group pjErFormActions -->
							</form><!-- /.form-horizontal pjErForm pjErFormAvailability -->
							<div class="erSelectorAvailabilityBox" style="display: <?php echo $isReady2Buy ? NULL : 'none'; ?>"></div>
						</div><!-- /.row -->
					</footer><!-- /.pjErProductFoot -->
				</div><!-- /.col-md-7 col-sm-6 col-xs-12 -->
			</div><!-- /.row -->
		</div><!-- /.panel-body pjErProductDetailsInner -->
	</div><!-- /.panel panel-default pjErBody pjErProductDetails -->
	<?php
}else{
	__('e_item_not_found');
} 
?>