<?php 
include_once PJ_VIEWS_PATH . 'pjFront/elements/menu.php'; 
$extra_per = __('extra_per',true); 
?>
<div class="crBox">
	<div class="crBoxTop">
		<div class="crBoxTopLeft"></div>
		<div class="crBoxTopRight"></div>
	</div>
	<div class="crBoxMiddle">
		<div class="cr3YourBooking">
			<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 echo date($tpl['option_arr']['o_datetime_format'], strtotime(pjUtil::formatDate($_SESSION[$controller->default_product][$controller->default_order]['date_from'], $tpl['option_arr']['o_date_format']) . " " . $_SESSION[$controller->default_product][$controller->default_order]['hour_from'] . ":" . $_SESSION[$controller->default_product][$controller->default_order]['minutes_from'] . ":00")); ?></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 echo date($tpl['option_arr']['o_datetime_format'], strtotime(pjUtil::formatDate($_SESSION[$controller->default_product][$controller->default_order]['date_to'], $tpl['option_arr']['o_date_format']) . " " . $_SESSION[$controller->default_product][$controller->default_order]['hour_to'] . ":" . $_SESSION[$controller->default_product][$controller->default_order]['minutes_to'] . ":00")); ?></td>
						</tr>
						<tr style="line-height:3px;">
							<td colspan="2">&nbsp;</td>
						</tr>	
						<?php if($tpl['type_arr']['rent_type'] == 'day') { ?>
						<?php
							$days = $_SESSION[$controller->default_product][$controller->default_order]['rental_days'];
						?>
							<tr>
								<td class="crGray crALeft"><?php __('front_3_rental'); ?>:</td>
								<td><?php echo $days == 1 ? $days ." ". __('front_label_day',true) : $days ." ". __('front_3_days',true); ?></td>
							</tr>
						<?php } else { ?>
						<?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 $rental_duration = $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>
						<?php } ?>
					</tbody>
				</table>
			</div>
			<div class="crBooking">
				<div class="crStep"><?php __('front_3_choise'); ?> <a href="<?php echo $_SERVER['PHP_SELF']; ?>" id="crBtnChoise"><?php __('front_3_change'); ?></a></div>
				<div class="cr3imgBox">
					<img src="<?php echo is_file(@$tpl['type_arr']['thumb_path']) ? PJ_INSTALL_URL . $tpl['type_arr']['thumb_path'] : PJ_INSTALL_URL . PJ_IMG_PATH . 'frontend/dummy_1.png'; ?>" alt="" class="cr3Img" />
				</div>
				<div class="cr3Items">
					<p class=""><?php echo stripslashes(@$tpl['type_arr']['name']); ?></p>
					<p class="crGray">(<?php __('front_3_example'); ?>: <?php echo stripslashes(@$tpl['type_arr']['example']['make'] . " " . @$tpl['type_arr']['example']['model']); ?>)</p>
					
				</div>
				<div class="cr3Term">
					<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>" id="crBtnConditions"><?php __('front_3_conditions'); ?></a></p>
				</div>
				
			</div>
		</div>
		
		<div class="cr3Extras">
		
			<div class="cr3ExtraLoader"></div>
			
			<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="crFormExtras">
			<div class="crBoxWTop" style="margin-bottom:15px"><?php __('front_3_extras'); ?></div>
			<?php
			$extraCost = 0;
			
			foreach ($tpl['arr'] as $extra)
			{
				?>
				<div class="crExtra">
					<div class="crExtraName" >
						<?php echo stripslashes($extra['name']); ?> 
						
					</div>
					<div class="crExtraQty">
						x
						<select  name="extra_quantity[<?php echo $extra['extra_id']; ?>]" id="extra_quantity_<?php echo $extra['extra_id']; ?>" class="crSelectSmall" rel="<?php echo $extra['extra_id']; ?>" rev="<?php echo (isset($_SESSION[$controller->default_product][$controller->default_order]) && isset($_SESSION[$controller->default_product][$controller->default_order]['extras']) && array_key_exists($extra['extra_id'], $_SESSION[$controller->default_product][$controller->default_order]['extras'])) ? 1: 0 ?>"id="crTabsSelect" class="crSelectSmall ">
							<?php for ($i=1; $i<= 10;$i++){ ?>
								<?php 
									$selected = '';
									if (isset($_SESSION[$controller->default_product]) && isset($_SESSION[$controller->default_product][$controller->default_order]) && isset($_SESSION[$controller->default_product][$controller->default_order]['extras']) && array_key_exists($extra['extra_id'], $_SESSION[$controller->default_product][$controller->default_order]['extras'])  )
									{
										if(isset($_SESSION[$controller->default_product][$controller->default_order]['extras'][$extra['extra_id']]['extra_quantity']) && $_SESSION[$controller->default_product][$controller->default_order]['extras'][$extra['extra_id']]['extra_quantity'] == $i){
											$selected = 'selected="selected"';
										}
										
									}
								?>
								<option value="<?php echo $i ?>" <?php echo $selected ?> ><?php echo $i ;?></option>
							<?php } ?>
						</select>
					</div>
					<div class="crExtraPrice">
					<?php
					if (isset($_SESSION[$controller->default_product][$controller->default_order]) && isset($_SESSION[$controller->default_product][$controller->default_order]['extras']) && array_key_exists($extra['extra_id'], $_SESSION[$controller->default_product][$controller->default_order]['extras']))
					{
						?><button type="button" value="<?php echo $extra['extra_id']; ?>" class="crBtn crBtnRemove"><?php __('front_btn_remove'); ?></button><?php
						switch ($extra['per'])
						{
							case 'day':
								$extraCost += $extra['price'] * $_SESSION[$controller->default_product][$controller->default_order]['rental_days']* $_SESSION[$controller->default_product][$controller->default_order]['extras'][$extra['extra_id']]['extra_quantity'];
								break;
							case 'booking':
								$extraCost += $extra['price'] * $_SESSION[$controller->default_product][$controller->default_order]['extras'][$extra['extra_id']]['extra_quantity'];;
								break;
						}
					} else {
						?><button type="button" value="<?php echo $extra['extra_id']; ?>" class="crBtn crBtnAdd"><?php __('front_btn_add'); ?></button><?php
					}
					?>
						<div class="extraPriceValue">
							<strong><?php echo pjUtil::formatCurrencySign(number_format(floatval($extra['price']), 2), $tpl['option_arr']['o_currency'], " "); ?></strong>&nbsp;<?php echo strtolower(@$extra_per[$extra['per']]); ?>
						</div>	
					</div>
				</div>
				<?php
			}
			$rental_fee_detail = array(); 
			?>
			</form>
			<table class="crExtraTable" cellspacing="0" cellpadding="0">
				<tbody>
					<tr>
						<td class="crKey"><span><?php __('front_3_rental_duration'); ?></span><br/><?php echo join(" + ", $rental_fee_detail);?></td>
						<td class="crValue">
							<?php echo $rental_duration = $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>
					<tr style="display:<?php echo in_array($tpl['option_arr']['o_booking_periods'], array('both', 'perday')) ? 'table-row' : 'none';?>">
						<td class="crKey"><span><?php __('front_3_price_per_day'); ?></span><br/><?php echo $tpl['cart']['price_per_day_detail']; ?></td>
						<td class="crValue">
							<?php echo $rental_fee_detail[] = pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['price_per_day']), 2), $tpl['option_arr']['o_currency'], " ");?>
						</td>
					</tr>
					<tr style="display:<?php echo in_array($tpl['option_arr']['o_booking_periods'], array('both', 'perhour')) ? 'table-row' : 'none';?>">
						<td class="crKey"><span><?php __('front_3_price_per_hour'); ?></span><br/><?php echo $tpl['cart']['price_per_hour_detail']; ?></td>
						<td class="crValue">
							<?php echo $rental_fee_detail[] = pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['price_per_hour']), 2), $tpl['option_arr']['o_currency'], " ");?>
						</td>
					</tr>
					<tr><td colspan="2" class="crLine"></td></tr>
					<tr>
						<td class="crKey"><span><?php __('front_3_price'); ?></span><br/><?php echo join(" + ", $rental_fee_detail);?></td>
						<td class="crValue">
							<?php echo pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['car_rental_fee']), 2), $tpl['option_arr']['o_currency'], " ");?>
						</td>
					</tr>
					<tr>
						<td class="crKey"><span><?php __('front_3_extra_price'); ?></span></td>
						<td class="crValue">
							<?php echo pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['extra_price']), 2), $tpl['option_arr']['o_currency'], " ");?>
						</td>
					</tr>
					<?php
					if ($tpl['option_arr']['o_insurance_payment'] > 0)
					{
						$insurance_types = __('insurance_type_arr', true, false);
						?>
						<tr>
							<td class="crKey"><span><?php __('front_3_insurance'); ?></span><br/>
								<?php
								switch ($tpl['option_arr']['o_insurance_payment_type']) {
									case 'perday':
										echo pjUtil::formatCurrencySign($tpl['option_arr']['o_insurance_payment'], $tpl['option_arr']['o_currency']) . ' ' . strtolower($insurance_types['perday']);
									;
									break;
									case 'percent':
										echo $tpl['option_arr']['o_insurance_payment'] . '% ' . __('front_label_of', true, false) . ' ' . pjUtil::formatCurrencySign($sum, $tpl['option_arr']['o_currency']);
									;
									break;
									case 'perbooking':
										echo pjUtil::formatCurrencySign($tpl['option_arr']['o_insurance_payment'], $tpl['option_arr']['o_currency']) . ' ' . strtolower($insurance_types['perbooking']);
									;
									break;
								} 
								?>
							</td>
							<td class="crValue">
								<?php echo pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['insurance']), 2), $tpl['option_arr']['o_currency'], " ");?>
							</td>
						</tr>
						<tr><td colspan="2" class="crLine"></td></tr>
						<?php
					} 
					?>
					<tr>
						<td class="crKey crKeyBold"><span><?php __('front_3_sub_total'); ?></span></td>
						<td class="crValue crKeyBold">
							<?php echo pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['sub_total']), 2), $tpl['option_arr']['o_currency'], " ");?>
						</td>
					</tr>
					<tr><td colspan="2" class="crLine"></td></tr>
					<?php
					if ($tpl['option_arr']['o_tax_payment'] > 0)
					{
						?>
						<tr>
							<td class="crKey"><span><?php __('front_3_tax'); ?></span><br/>
								<?php
								if($tpl['option_arr']['o_tax_type'] == '1')
								{
									echo $tpl['option_arr']['o_tax_payment'] . '% ' . __('front_label_of', true, false) . ' ' . pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['sub_total']), 2), $tpl['option_arr']['o_currency'], " ");
								} 
								?>
							</td>
							<td class="crValue">
								<?php echo pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['tax']), 2), $tpl['option_arr']['o_currency'], " ");?>
							</td>
						</tr>
						<?php
					}
					?>
					
					<tr>
						<td class="crKey crKeyBold crRed"><?php __('front_3_total_price'); ?></td>
						<td class="crValue crKeyBold">
							<?php echo pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['total_price']), 2), $tpl['option_arr']['o_currency'], " ");?>
						</td>
					</tr>
					<tr><td colspan="2" class="crLine"></td></tr>
					<tr>
						<td class="crKey">
							<span><?php __('front_3_required_deposit'); ?></span><br/>
							<?php
							echo $tpl['option_arr']['o_deposit_payment'] . '% ' . __('front_label_of', true, false) . ' ' . pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['total_price']), 2), $tpl['option_arr']['o_currency']); 
							?>
						</td>
						<td class="crValue crKeyBold">
							<?php echo pjUtil::formatCurrencySign(number_format(floatval($tpl['cart']['required_deposit']), 2), $tpl['option_arr']['o_currency'], " ");?>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="cr3Continue">
				<input type="button" value="<?php __('front_btn_continue'); ?>" id="crBtnCheckout" class="crBtn crBtnDefault crBtnCheckout" />
			</div>
		
		</div>
	</div>
	<div class="crBoxBottom">
		<div class="crBoxBottomLeft"></div>
		<div class="crBoxBottomRight"></div>
	</div>
</div>