<?php
mt_srand();
$index = mt_rand(1, 9999);
$listing_for = __('listing_for', true);
?>
<br/>
<div id="ylContainer_<?php echo $index;?>" class="ylContainer">
	<?php include_once ROOT_PATH . PJ_TEMPLATE_PATH . $tpl['option_arr']['o_layout']. '/elements/header.php';?>
	<div class="ylMain">
		<?php
		if($tpl['status'] == '200')
		{
			if (@$_GET['controller'] == 'pjListings' && @$_GET['action'] == 'pjActionView')
			{
				$back = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF'] .'?controller=pjListings&amp;action=pjActionYachts'. (isset($_GET['iframe']) ? '&amp;iframe' : NULL);
				if(strpos($back, 'pjActionReserve') > 0)
				{
					$back = $_SERVER['PHP_SELF'] .'?controller=pjListings&amp;action=pjActionYachts'. (isset($_GET['iframe']) ? '&amp;iframe' : NULL);
				}
			}
			$listing_title = pjSanitize::html(stripslashes($tpl['arr']['title']));
			?>
			<p class="ylButtons">
				<a href="<?php echo $back;?>" class="ylBtn ylBtnSecondary">&lt; <?php __('front_back_to_yachts');?></a>
			</p><!-- /.ylButtons -->
			<div class="ylDetails">
				<div class="ylDetailsHead">
					<h1><?php echo $listing_title;?></h1>
				</div><!-- /.ylDetailsHead -->
				<div class="ylDetailsMedia clearfix">
					<div class="ylDetailsMediaContent">
						<?php
						if(!empty($tpl['gallery_arr']))
						{
							?>
							<div class="ylDetailsImage">
								<img id="ylDetailsImage_<?php echo $index;?>" src="<?php echo PJ_INSTALL_URL . $tpl['gallery_arr'][0]['medium_path']?>" alt="">
							</div><!-- /.ylDetailsImage -->
							<div class="ylDetailsThumbs">
								<ul>
									<?php
									foreach ($tpl['gallery_arr'] as $k => $v)
									{
										?>
										<li>
											<a class="ylGalleryThumbs" href="<?php echo PJ_INSTALL_URL . $v['medium_path'];?>">
												<span></span>
												<img src="<?php echo PJ_INSTALL_URL . $v['small_path'];?>" alt="" width="90" height="68">
											</a>
										</li>
										<?php
									} 
									?>
								</ul>
							</div><!-- /.ylDetailsThumbs -->
							<?php
						} 
						?>
					</div><!-- /.ylDetailsMediaContent -->
					<?php
					if(isset($tpl['price_arr']))
					{ 
						$selected_week = isset($_SESSION[$controller->defaultStore]['week']) ? $_SESSION[$controller->defaultStore]['week'] : null;
						if($selected_week != null)
						{
							$week_arr = pjUtil::getWeeksOfMonth(date('Y', $selected_week), date('n', $selected_week), $tpl['option_arr']['o_week_start']);
						}else{
							$week_arr = pjUtil::getWeeksOfMonth(date('Y'), date('n'), $tpl['option_arr']['o_week_start']);
						}
						$months = __('months', true);
						?>
						<div class="ylDetailsMediaAside">
							<h2><?php __('front_yacht_reservation');?></h2>
						</div><!-- /.ylDetailsMediaAside -->
						<form id="frmBooking_<?php echo $index;?>" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" name="frmBooking" method="get">
							<input type="hidden" value="pjListings" name="controller">
							<input type="hidden" value="pjActionReserve" name="action">
							<input type="hidden" value="<?php echo $tpl['arr']['id'];?>" name="id">
							<input type="hidden" value="" id="ylWeek_<?php echo $index;?>" name="week">
						</form>
						<div id="ylReservationTable_<?php echo $index;?>">
							<table class="ylReservationTable">
								<thead>
									<tr>
										<th>
											<a class="ylNavMonth" href="#" data-id="<?php echo $tpl['arr']['id']?>" data-month="<?php echo $week_arr['prev'] ?>">&lt; <?php __('front_prev');?></a>
										</th>
										<th colspan="2">
											<?php
											if($selected_week != null)
											{
												echo $months[date('n', $selected_week)] . ' ' . date('Y', $selected_week);
											}else{
												echo $months[date('n')] . ' ' . date('Y');
											}
											?>
										</th>
										<th>
											<a class="ylNavMonth" href="#" data-id="<?php echo $tpl['arr']['id']?>" data-month="<?php echo $week_arr['next'] ?>"><?php __('front_next');?> &gt;</a>
										</th>
									</tr>
								</thead>
								<tbody>
									<?php
									foreach($week_arr as $k => $v)
									{
										if($k == 'next' || $k == 'prev')
										{
											continue;
										}
										$iso_date = date('Y-m-d', $v['monday']);
										$is_reserved = false;
										$is_avaialble = false;
										$active_class = '';
										if(in_array($iso_date, $tpl['booking_arr']))
										{
											$is_reserved = true;
										}else{
											if(isset($tpl['price_arr'][$iso_date]))
											{
												if($iso_date >= date('Y-m-d'))
												{
													$is_avaialble = true;
												}
											}
										}
										if($selected_week == $v['monday'])
										{
											$active_class = ' ylActiveRow';
										}
										?>
										<tr class="<?php echo $is_reserved == true ? 'ylReserved' : ($is_avaialble == true ? 'ylAvailable' . $active_class : 'ylUnavailable');?>" data-week = "<?php echo $v['monday'];?>">
											<td>
												<span><?php __('front_week');?> <?php echo $k;?></span>
											</td>
											<td>
												<span><?php echo date($tpl['option_arr']['o_date_format'], $v['monday'])?> - <?php echo date($tpl['option_arr']['o_date_format'], $v['sunday'])?></span>
											</td>
											<td>
												<strong><?php echo $is_avaialble == true ? pjUtil::formatCurrencySign($tpl['price_arr'][$iso_date], $tpl['option_arr']['o_currency'])  : '&nbsp;'?></strong>
											</td>
											<td>
												<?php
												if($is_reserved == false)
												{ 
													if($is_avaialble == true)
													{
														?>
														<em><?php __('front_free');?></em>
														&nbsp;
														&nbsp;
														<img src="<?php echo PJ_INSTALL_URL . PJ_TEMPLATE_PATH . $tpl['option_arr']['o_layout'] . '/img/check.png';?>" alt="" width="12" height="12" class="ylChecked">
														<?php
													}else{
														?><em><?php __('front_not_avaialble');?></em><?php
													}
												}else{
													?><em><?php __('front_reserved');?></em><?php
												} 
												?>
											</td>
										</tr>
										<?php
									} 
									?>
								</tbody>
								<tfoot>
									<tr>
										<td colspan="4">
											<a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjListings&amp;action=pjActionReserve&amp;id=<?php echo $tpl['arr']['id']?>" class="ylBtn ylBtnTertiary ylBtnReserve"><?php __('front_make_a_reservation');?></a>
										</td>
									</tr>
								</tfoot>
							</table>
						</div>
						<?php 
					} 
					?>
				</div><!-- /.ylDetailsMedia -->
			</div><!-- /.ylDetails -->
			<br/>
			<div class="ylDetailsInfo">
				<div class="ylDetailsContent">
					<?php
					if(!empty($tpl['listing_extra_arr']))
					{	 
						?>
						<h3><?php __('front_feature_set');?></h3>
						<p><?php echo join(', ', $tpl['listing_extra_arr']);?></p>
						<?php
					} 
					?>
					<h3><?php __('front_yacth_description');?></h3>
					<div class="ylDetailsDesc">
						<?php echo stripslashes($tpl['arr']['description']);?>
					</div>
				</div><!-- /.ylDetailsContent -->
				<div class="ylDetailsAside">
					<div class="ylBox">
						<h3><?php __('front_general_specifications');?></h3>
						<ul class="ylList">
							<li>
								<strong><?php __('front_reference_id');?></strong> 
								<span><?php echo pjSanitize::html($tpl['arr']['listing_refid']);?></span>
							</li>
							<li>
								<strong><?php __('front_manufacturer');?></strong> 
								<span><?php echo pjSanitize::html($tpl['arr']['manufacturer']);?></span>
							</li>
							<?php
							if(!empty($tpl['arr']['listing_model']))
							{ 
								?>
								<li>
									<strong><?php __('front_model');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_model']);?></span>
								</li>
								<?php
							}
							if($tpl['arr']['for'] == 'sale' && !empty($tpl['arr']['listing_price']))
							{
								?>
								<li>
									<strong><?php __('front_price');?></strong> 
									<span><?php echo pjUtil::formatCurrencySign($tpl['arr']['listing_price'], $tpl['option_arr']['o_currency']);?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_year']))
							{
								?>
								<li>
									<strong><?php __('front_registration_year');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_year']);?></span>
								</li>
								<?php
							}
							$feature_types = __('feature_types', true);
							foreach($feature_types as $k => $v)
							{
								if(!empty($tpl['arr']['feature_' . $k]))
								{
									?>
									<li>
										<strong><?php echo $v;?></strong> 
										<span><?php echo pjSanitize::html($tpl['arr']['feature_' . $k]);?></span>
									</li>
									<?php
								}
							}
							?>
						</ul>
					</div><!-- /.ylBox -->
					<div class="ylBox">
						<h3><?php __('front_technical_specifications')?></h3>
						<ul class="ylList">
							<?php
							$enum_arr = __('enum_arr', true);
							$opt_speed = $tpl['option_arr']['o_speed'];
							if($opt_speed == 'km/h')
							{
								$opt_speed = 'kmph';
							}
							if(!empty($tpl['arr']['listing_length']))
							{
								?>
								<li>
									<strong><?php __('front_length');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_length']);?> <?php echo $enum_arr[$tpl['option_arr']['o_length']];?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_loa']))
							{
								?>
								<li>
									<strong><?php __('front_loa');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_loa']);?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_beam']))
							{
								?>
								<li>
									<strong><?php __('front_beam');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_beam']);?> <?php echo $enum_arr[$tpl['option_arr']['o_length']];?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_power']))
							{
								?>
								<li>
									<strong><?php __('front_horsepower');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_power']);?> <?php echo $enum_arr[$tpl['option_arr']['o_power']];?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_engine_model']))
							{
								?>
								<li>
									<strong><?php __('front_engine_model');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_engine_model']);?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_engine_hours']))
							{
								?>
								<li>
									<strong><?php __('front_engine_hours');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_engine_hours']);?> <?php __('front_hours');?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_cruising_speed']))
							{
								?>
								<li>
									<strong><?php __('front_cruising_speed');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_cruising_speed']);?> <?php echo $enum_arr[$opt_speed];?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_max_speed']))
							{
								?>
								<li>
									<strong><?php __('front_max_speed');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_max_speed']);?> <?php echo $enum_arr[$opt_speed];?></span>
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_fuel_tank']))
							{
								?>
								<li>
									<strong><?php __('front_fuel_tank');?></strong> 
									<span><?php echo pjSanitize::html($tpl['arr']['listing_fuel_tank']);?> <?php echo $enum_arr[$tpl['option_arr']['o_fuel']];?></span>
								</li>
								<?php
							}
							?>
						</ul>
					</div><!-- /.ylBox -->
					<?php 
					ob_start();
					$owner_name = !empty($tpl['arr']['owner_name']) ? $tpl['arr']['owner_name'] : (!empty($tpl['arr']['name']) ? $tpl['arr']['name'] : null);
					if(!empty($owner_name))
					{
					?>
						<li>
							<strong><?php __('front_name');?></strong>
							<span><?php echo pjSanitize::html($owner_name);?></span> 
						</li>
						<?php
					}
					$owner_email = !empty($tpl['arr']['owner_email']) ? $tpl['arr']['owner_email'] : (!empty($tpl['arr']['email']) ? $tpl['arr']['email'] : null);
					if(!empty($owner_email))
					{ 
						?>
						<li>
							<strong><?php __('front_email');?></strong>
							<span><?php echo !preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i', $owner_email) ? $owner_email : '<a href="mailto:'.$owner_email.'">'.$owner_email.'</a>'; ?></span>
						</li>
						<?php
					}
					$owner_phone = !empty($tpl['arr']['owner_phone']) ? $tpl['arr']['owner_phone'] : (!empty($tpl['arr']['phone']) ? $tpl['arr']['phone'] : null);
					if(!empty($owner_phone))
					{
						?>
						<li>
							<strong><?php __('front_phone');?></strong>
							<span><?php echo pjSanitize::html($owner_phone);?></span> 
						</li>
						<?php
					}
					$owner_fax = !empty($tpl['arr']['owner_fax']) ? $tpl['arr']['owner_fax'] : (!empty($tpl['arr']['fax']) ? $tpl['arr']['fax'] : null);
					if(!empty($owner_fax))
					{
						?>
						<li>
							<strong><?php __('front_fax');?></strong>
							<span><?php echo pjSanitize::html($owner_fax);?></span> 
						</li>
						<?php
					}
					$ob_contact = ob_get_contents();
					ob_end_clean();
					if($tpl['arr']['owner_show'] == 'T' && !empty($ob_contact))
					{
						?>
						<div class="ylBox">
							<h3><?php __('front_contact_details');?>:</h3>
	
							<ul class="ylList">
								<?php
								echo $ob_contact;
								?>
							</ul>
						</div><!-- /.ylBox -->
						<?php
					}
					?>
				</div><!-- ./ylDetailsAside -->
			</div><!-- /.ylDetailsInfo -->
			<?php
		}else{
			$listing_statuses = __('listing_statuses', true);
			?>
			<div class="ylDetails">
				<?php echo $listing_statuses[$tpl['status']];?>
			</div>
			<?php
		} 
		?>
	</div><!-- /.ylMain -->
</div>
<br/><br/>
<?php include_once ROOT_PATH . PJ_TEMPLATE_PATH . $tpl['option_arr']['o_layout']. '/elements/loadjs.php';?>