<header class="row pjErHeader">
<?php
include PJ_VIEWS_PATH . 'pjFrontEnd/elements/header.php';
$filter = 'packages';
include PJ_VIEWS_PATH . 'pjFrontEnd/elements/search.php'; 
?>
</header><!-- /.row pjErHeader -->

<?php
if (isset($tpl['package_arr']) && !empty($tpl['package_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']);
	
	?>
	<div class="panel panel-default pjErBody pjErProductDetails">
		<div class="panel-body pjErProductDetailsInner">
			<div class="row">
				<div class="col-lg-5 col-md-5 col-sm-6 col-xs-12 pjErProductGallery">
					<?php
					$gallery_arr = $tpl['package_arr']['gallery_arr'];
					if (!empty($gallery_arr))
					{
						?>
						<div>
							<div class="pjErProductMainImage">
								<img src="<?php echo PJ_INSTALL_URL . $gallery_arr[0]['medium_path']; ?>" alt="<?php echo pjSanitize::html($gallery_arr[0]['alt']); ?>" class="erSelectorItemPic" />
							</div><!-- /.pjErProductMainImage -->
							
							<ul class="list-inline pjErProductThumbs">
								<?php
								foreach ($gallery_arr as $pic)
								{ 
									if (!empty($pic['small_path']) && is_file(PJ_INSTALL_PATH . $pic['small_path']))
									{
										?>
										<li class="pjErProductThumb">
											<a href="<?php echo pjUtil::getReferer(); ?>" data-src="<?php echo PJ_INSTALL_URL . $pic['medium_path']; ?>" class="thumbnail erSelectorItemThumb">
												<img src="<?php echo PJ_INSTALL_URL . $pic['small_path']; ?>" alt="<?php echo pjSanitize::html($pic['alt']); ?>" />
											</a>
										</li><!-- /.pjErProductThumb -->
										<?php
									}
								} 
								?>
							</ul><!-- /.list-inline pjErProductThumbs -->
								
						</div><br/>
						<?php
					}else{
						?>
						<div class="pjErProductMainImage">
							<img src="<?php echo PJ_INSTALL_URL . PJ_IMG_PATH . 'frontend/er-noimg.png'; ?>" alt="<?php echo pjSanitize::html($tpl['package_arr']['title']); ?>" class="erSelectorItemPic" />
						</div><!-- /.pjErProductMainImage -->
						<?php
					} 
					?>
				</div><!-- /.col-lg-5 col-md-5 col-sm-6 col-xs-12 pjErProductGallery -->
	
				<div class="col-lg-7 col-md-7 col-sm-6 col-xs-12">
					<header class="pjErProductHead">
						<p class="pjErProductTitle"><?php echo pjSanitize::html($tpl['package_arr']['title']); ?></p><!-- /.pjErProductTitle -->
					</header><!-- /.pjErProductHead -->
	
					<div class="pjErProductBody">
						<p><?php echo nl2br(pjSanitize::html($tpl['package_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="package_id" value="<?php echo $tpl['package_arr']['id']; ?>" />
								<div class="form-group">
									<label for="" class="control-label col-lg-4 col-md-4 col-sm-12 col-xs-12"><?php __('number_packages'); ?></label>
									<?php
									$key = 'package_' . $tpl['package_arr']['id'];
									$cnt = NULL;
									if (isset($CART[$key]))
									{
										$cnt = $CART[$key];
									}
									?>
									<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
										<div class="row">
											<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
												<select name="cnt" class="form-control erFormField">
												<?php
												foreach (range(1, $tpl['package_arr']['cnt']) as $i)
												{
													?><option value="<?php echo $i; ?>"<?php echo $i != $cnt ? NULL : ' selected="selected"'; ?>><?php echo $i; ?></option><?php
												}
												?>
												</select>
											</div><!-- /.col-lg-6 col-md-6 col-sm-6 col-xs-6 -->
										</div><!-- /.row -->
									</div><!-- /.col-lg-8 col-md-8 col-sm-12 col-xs-12 -->
								</div><!-- /.form-group -->
							
								<div class="pjErFormCalendarGroup">
									<div class="form-group">
										<label for="" class="control-label col-lg-4 col-md-4 col-sm-12 col-xs-12"><?php __('rental_start'); ?></label>
									
										<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
											<div class="row erItemRow">
												<div class="col-lg-5 col-md-5 col-sm-5 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-lg-6 col-md-6 col-sm-6 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-lg-8 col-md-8 col-sm-12 col-xs-12 -->
									</div><!-- /.form-group -->
									<?php
									$first_working_date = $tpl['first_working_date']; 
									?>
									<div class="form-group">
										<label for="" class="control-label col-lg-4 col-md-4 col-sm-12 col-xs-12"><?php __('rental_end'); ?></label>
									
										<div class="col-lg-8 col-md-8 col-sm-12 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 !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-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-lg-8 col-md-8 col-sm-12 col-xs-12 -->
									</div><!-- /.form-group -->
								</div><!-- /.pjErFormCalendarGroup -->
							
								<div class="form-group pjErFormActions">
									<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
										<a href="<?php echo pjUtil::getReferer(); ?>#!/Packages" class="btn btn-default btn-block pjErBtn pjErBtnSecondary erSelectorPackages"><?php __('button_back'); ?></a>
									</div><!-- /.col-lg-4 col-md-4 col-sm-12 col-xs-12 -->
	
									<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
										<button type="submit" class="btn btn-default btn-block pjErBtn pjErBtnPrimary"><?php __('button_check_availability'); ?></button>
									</div><!-- /.col-lg-8 col-md-8 col-sm-12 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-lg-7 col-md-7 col-sm-6 col-xs-12 -->
			</div><!-- /.row -->
		</div><!-- /.panel-body pjErProductDetailsInner -->
	</div><!-- /.panel panel-default pjErBody pjErProductDetails -->
	<?php
} else {
	__('e_package_not_found');
}
?>