<?php include_once dirname(__FILE__) . '/elements/header_menu.php'; ?>
<div class="crBox">
	<div class="crBoxTop">
		<div class="crBoxTopLeft"></div>
		<div class="crBoxTopRight"></div>
	</div>
	<div class="crBoxMiddle">


		<?php
		$get = $controller->_get->raw();
		$rental_hours = $_SESSION[$controller->default_product][$controller->default_order]['rental_hours'];
		$hours = $rental_hours % 24;
		$days = 0;
		if ($hours == 0) {
			$days = $rental_hours / 24;
		} else {
			$days = floor($rental_hours / 24);
		}

		$isMinHourRestricted = 0;
		if ((int) $tpl['option_arr']['o_min_hour'] > 0) {
			switch ($tpl['option_arr']['o_booking_periods']) {
				case 'perday':
					if ($days < (int) $tpl['option_arr']['o_min_hour']) {
						$isMinHourRestricted = 1;
					}
					break;
				default:
					if ($rental_hours < (int) $tpl['option_arr']['o_min_hour']) {
						$isMinHourRestricted = 2;
					}
					break;
			}
		}
		if ($isMinHourRestricted !== 0) {
			switch ($isMinHourRestricted) {
				case 1:
		?>
					<div class="row">
						<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
							<div class="crNotice alert alert-warning"><?php echo str_replace('{X}', $tpl['option_arr']['o_min_hour'], __('front_2_min_days', true)); ?></div>
							<input type="button" class="btn btn-default text-uppercase pjCrBtntDefault" id="crBtnWhen" value="<?php __('btnBack'); ?>" />
						</div>
					</div>
				<?php
					break;
				case 2:
				?>
					<div class="row">
						<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
							<div class="crNotice alert alert-warning"><?php echo str_replace('{X}', $tpl['option_arr']['o_min_hour'], __('front_2_min_hours', true)); ?></div>
							<input type="button" class="btn btn-default text-uppercase pjCrBtntDefault" id="crBtnWhen" value="<?php __('btnBack'); ?>" />
						</div>
					</div>
			<?php
					break;
			}
		} else {
			?>
			<div class="crTabsSmallScreen">
				<label><?php __('front_2_filter_by'); ?>:</label>
				<div class="styled-select-car">
					<select name="crTabsSelect" id="crTabsSelect" class="crSelect crTabsSelect crLocation">
						<option<?php echo !isset($get['type_id']) || (isset($get['type_id']) && $get['type_id'] == 'all') ? ' selected="selected"' : NULL; ?> rel="all"><?php __('front_2_all'); ?></option>
							<?php
							foreach ($tpl['type_arr'] as $k => $v) {
							?><option<?php echo isset($get['type_id']) && $get['type_id'] == $v['id'] ? ' selected="selected"' : NULL; ?> rel="<?php echo $v['id']; ?>"><?php echo pjSanitize::clean($v['name']); ?></option><?php } ?>
					</select>
				</div><!-- /.form-group -->
			</div>


			<div class="crSortHolder">
				<label><?php __('front_2_sort_by'); ?>: </label>
				<div class="styled-select-car">
					<select name="sort" id="crSort" class="crSelect crSort crTabsSelect crLocation">
						<option value="price" rel="total_price|asc" <?php echo isset($get['col_name']) &&  $get['col_name'] == 'total_price' && isset($get['direction']) &&  $get['direction'] == 'asc' ? 'selected="selected"' : '' ?>><?php echo __('front_2_sort_price_asc') ?>
						<option value="price" rel="total_price|desc" <?php echo isset($get['col_name']) &&  $get['col_name'] == 'total_price' && isset($get['direction']) &&  $get['direction'] == 'desc' ? 'selected="selected"' : '' ?>><?php echo __('front_2_sort_price_desc') ?>
						<option value="luggage" rel="luggages|asc" <?php echo isset($get['col_name']) &&  $get['col_name'] == 'luggages' && isset($get['direction']) &&  $get['direction'] == 'asc' ? 'selected="selected"' : '' ?>><?php echo __('front_2_sort_luggage_asc') ?>
						<option value="luggage" rel="luggages|desc" <?php echo isset($get['col_name']) &&  $get['col_name'] == 'luggages' && isset($get['direction']) &&  $get['direction'] == 'desc' ? 'selected="selected"' : '' ?>><?php echo __('front_2_sort_luggage_desc') ?>
					</select>
				</div>
			</div><!-- /.form-group -->

			<button class="btn btn-default text-capitalize pjCrBtnPannelTrigger visible-xs-block"><?php __('front_3_booking'); ?></button>
			<br class="visible-xs-inline" />
			<div class="crClear" style="height:20px;">&nbsp;</div>					
			<!-- <div class="panel-heading">
					<h1 class="panel-title"><?php  //__('front_3_booking'); ?></h1>
				</div> -->
			<div class="cr3YourBooking cr2ChooseCar">
				<div class="crBoxWTop"><?php __('front_3_booking'); ?></div>
				<div class="crBooking">
					<div class="crStep"><?php __('front_3_when'); ?> <a href="<?php echo $_SERVER['PHP_SELF']; ?>" id="crBtnWhen"><?php __('front_3_change'); ?></a>
					</div>
					<table class="crTableXtra" style="width: 100%">
						<tbody>
							<tr>
								<td class="crGray crALeft" ><?php __('front_3_pickup'); ?>:</td>
								<td><?php echo stripslashes($tpl['pickup_location']['name']); ?></td>
							</tr>
							<tr>
								<td>&nbsp;</td>
								<td>
								<?php
								$dt_from = $_SESSION[$controller->default_product][$controller->default_order]['date_from'] . " " . $_SESSION[$controller->default_product][$controller->default_order]['hour_from'] . ":" . $_SESSION[$controller->default_product][$controller->default_order]['minutes_from'] . ":00";
								echo date($tpl['option_arr']['o_date_format'], strtotime($dt_from)) . ', ' . date($tpl['option_arr']['o_time_format'], strtotime($dt_from));
								?></td>
							</tr>
							<tr style="line-height:3px;">
								<td colspan="2">&nbsp;</td>
							</tr>
							<tr>
								<td class="crGray crALeft"><?php __('front_3_return'); ?>:</td>
								<td><?php echo isset($tpl['return_location']['name']) ? stripslashes($tpl['return_location']['name']) : stripslashes($tpl['pickup_location']['name']); ?></td>
							</tr>
							<tr>
								<td>&nbsp;</td>
								<td><?php
								$dt_to = $_SESSION[$controller->default_product][$controller->default_order]['date_to'] . " " . $_SESSION[$controller->default_product][$controller->default_order]['hour_to'] . ":" . $_SESSION[$controller->default_product][$controller->default_order]['minutes_to'] . ":00";
								echo date($tpl['option_arr']['o_date_format'], strtotime($dt_to)) . ', ' . date($tpl['option_arr']['o_time_format'], strtotime($dt_to));
								?></td>
							</tr>
							<tr style="line-height:3px;">
								<td colspan="2">&nbsp;</td>
							</tr>

							<?php
								$rental_hours = $_SESSION[$controller->default_product][$controller->default_order]['rental_hours'];
								$hours = $rental_hours %24;
								$days = 0;
								if($hours == 0 ){
									$days = $rental_hours / 24;
								}
								else {
									$days = floor($rental_hours / 24);
								}

							?>
							<tr>
								<td class="crGray crALeft"><?php __('front_3_rental_duration'); ?>:</td>
								<td><?php echo $days > 0 ? ($days == 1 ? $days ." ". __('front_label_day',true) : $days ." ". __('front_3_days',true) ) : ''?><?php echo $days > 0 && $hours > 0 ? ' ' :'';?><?php echo $hours > 0 ?  $hours." ".__('front_3_hours',true) : ''?></td>
							</tr>

						</tbody>
					</table>
				</div>
			</div>
				
		

			<div class="crTypeOuter">
			<?php
			if (count($tpl['arr']) > 0)
			{
				foreach ($tpl['arr'] as $type)
				{
					?>
					<div class="crType">
						<img src="<?php echo is_file(PJ_INSTALL_PATH . $type['thumb_path']) ? PJ_INSTALL_URL . $type['thumb_path'] : PJ_INSTALL_URL . PJ_IMG_PATH . "frontend/dummy_2.png"; ?>" alt="" class="crTypeImg" />
						<div class="crTypeArea">
							<div class="crTypeContent">
								<div class="crTypeTitle"><strong><?php echo stripslashes($type['name']); ?></strong></div>
								<div class="crTypeTitle"><?php __('front_2_example'); ?>: <?php echo stripslashes(@$type['example']['make'] . " " . @$type['example']['model']); ?></div>
								<div class="crAttributeBar">
									<span class="crAttribute crAttribute-passengers" title="<?php __('front_2_passengers'); ?>"><?php echo $type['passengers']; ?></span>
									<span class="crAttribute crAttribute-luggages" title="<?php __('front_2_luggage'); ?>"><?php echo $type['luggages']; ?></span>
									<span class="crAttribute crAttribute-doors" title="<?php __('front_2_doors'); ?>"><?php echo $type['doors']; ?></span>
									<span class="crAttribute crAttribute-transmission" title="<?php __('front_2_transmission'); ?>"><?php echo strtoupper($type['transmission'][0]); ?></span>
								</div>

								<div class="crTypeRightSmallScreen">
									<?php
									if ($type['cnt_available'] > 0 && $type['total_price'] > 0)
									{
										?>
										<div class="crTypePrice">
											<p><?php __('front_2_best'); ?>:</p> <span class="crPrice"><strong><?php echo pjUtil::formatCurrencySign(number_format(floatval($type['total_price']), 2), $tpl['option_arr']['o_currency'], " "); ?></strong></span>
										</div>
										<?php
									}
									?>
									<div class="crPriceBtn">
										<?php
										if ($type['cnt_available'] > 0 && $type['total_price'] > 0)
										{
											?><button type="button" value="<?php echo $type['id']; ?>" class="crBtn crBtnDefault2 crBtnContinue"><?php __('front_btn_continue'); ?></button><?php
										}
										else
										{
											?><div class="crTypePrice"><span><?php echo __('front_2_not', true, false);?></span></div><a href="#" class="crChangeDates"><?php __('front_change_dates', false, true)?></a><?php
										}
										?>
									</div>
								</div>
								<div class="crClear" >&nbsp;</div>

							</div>
							<div class="crClear" >&nbsp;</div>
							<div class="crTypeDesc"><?php echo stripslashes(nl2br($type['description'])); ?></div>


						</div>

						<div class="crTypeRight">

							<?php
							if ($type['cnt_available'] > 0 && $type['total_price'] > 0)
							{
								?>
								<div class="crTypePrice">
									<p><?php __('front_2_best'); ?>:</p> <span class="crPrice"><strong><?php echo pjUtil::formatCurrencySign(number_format(floatval($type['total_price']), 2), $tpl['option_arr']['o_currency'], " "); ?></strong></span>
								</div>
								<?php
							}
							?>

							<div class="crPriceBtn">
								<?php
								if ($type['cnt_available'] > 0 && $type['total_price'] > 0)
								{
									?><button type="button" value="<?php echo $type['id']; ?>" class="crBtn crBtnDefault2 crBtnContinue"><?php __('front_btn_continue'); ?></button><?php
								} else
								{
									?><div class="crTypePrice"><span><?php echo __('front_2_not', true, false);?></span></div><a href="#" class="crChangeDates"><?php __('front_change_dates', false, true)?></a><?php
								}
								?>
							</div>
						</div>

						<div class="crTypeAreaSmallScreen">
							<div class="crTypeTitle"><strong><?php echo stripslashes($type['name']); ?></strong></div>
							<div class="crTypeTitle"><?php __('front_2_example'); ?>: <?php echo stripslashes(@$type['example']['make'] . " " . @$type['example']['model']); ?></div>
							<div class="crClear" >&nbsp;</div>
							<div class="crAttributeBar">
								<span class="crAttribute crAttribute-passengers" title="<?php __('front_2_passengers'); ?>"><?php echo $type['passengers']; ?></span>
								<span class="crAttribute crAttribute-luggages" title="<?php __('front_2_luggage'); ?>"><?php echo $type['luggages']; ?></span>
								<span class="crAttribute crAttribute-doors" title="<?php __('front_2_doors'); ?>"><?php echo $type['doors']; ?></span>
								<span class="crAttribute crAttribute-transmission" title="<?php __('front_2_transmission'); ?>"><?php echo strtoupper($type['transmission'][0]); ?></span>
							</div>
							<div class="crClear" >&nbsp;</div>
							<div class="crTypeDesc"><?php echo stripslashes(nl2br($type['description'])); ?></div>
							<div class="crTypeRightSmallScreen">

								<?php
								if ($type['cnt_available'] > 0 && $type['total_price'] > 0)
								{
									?>
									<div class="crTypePrice">
										<p><?php __('front_2_best'); ?>:</p> <span class="crPrice"><strong><?php echo pjUtil::formatCurrencySign(number_format(floatval($type['total_price']), 2), $tpl['option_arr']['o_currency'], " "); ?></strong></span>
									</div>
									<?php
								}
								?>

								<div class="crPriceBtn">
									<?php

									if ($type['cnt_available'] > 0)
									{
										?><button type="button" value="<?php echo $type['id']; ?>" class="crBtn crBtnDefault2 crBtnContinue"><?php __('front_btn_continue'); ?></button><?php
									}
									else
									{
										?><div class="crTypePrice"><span><?php echo __('front_2_not', true, false);?></span></div><a href="#" class="crChangeDates"><?php __('front_change_dates', false, true)?></a><?php
									}
									?>
								</div>
							</div>
						</div>
					</div>
					<?php
				}
			} else {
				?><p style="padding: 10px"><?php __('front_2_empty'); ?></p><?php
			}
			?>
		</div>
			
		<?php
		}
		?>

	</div>
	<div class="crBoxBottom">
		<div class="crBoxBottomLeft"></div>
		<div class="crBoxBottomRight"></div>
	</div>
</div>