<?php
mt_srand();
$index = mt_rand(1, 9999);
$listing_for = __('listing_for', true);
?>
<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 ylBtnBack"><?php __('front_back_to_yachts');?></a>
			</p><!-- /.ylButtons -->
			<div class="ylDetails">
				<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 -->
					<div class="ylDetailsMediaAside">
						<h1><?php echo $listing_title;?></h1>
						<?php
						if($tpl['arr']['for'] == 'sale' && !empty($tpl['arr']['listing_price']))
						{ 
							?>
							<p class="ylPrice">
								<small><?php __('front_price');?>:</small>
								<strong><?php echo pjUtil::formatCurrencySign($tpl['arr']['listing_price'], $tpl['option_arr']['o_currency']);?></strong>
							</p>
							<?php
						}
						if($tpl['arr']['for'] == 'rent')
						{
							if($tpl['arr']['min_price'] != '' || $tpl['arr']['max_price'] != '')
							{
								if($tpl['arr']['min_price'] == $tpl['arr']['max_price'])
								{
									$price = pjUtil::formatCurrencySign(number_format($tpl['arr']['min_price'], 0, '.', ','), $tpl['option_arr']['o_currency']);
								}else{
									$price = pjUtil::formatCurrencySign(number_format($tpl['arr']['min_price'], 0, '.', ','), $tpl['option_arr']['o_currency']) . ' - ' . pjUtil::formatCurrencySign(number_format($tpl['arr']['max_price'], 0, '.', ','), $tpl['option_arr']['o_currency']);
								}
								?>
								<p class="ylPrice">
									<small><?php __('front_price');?>:</small>
									<strong><?php echo $price;?></strong> <?php __('front_per_week');?>
								</p>
								<?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>
								<span><?php __('front_name');?></span>
								<strong><?php echo pjSanitize::html($owner_name);?></strong> 
							</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>
								<span><?php __('front_email');?></span>
								<strong><?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>'; ?></strong>
							</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>
								<span><?php __('front_phone');?></span>
								<strong><?php echo pjSanitize::html($owner_phone);?></strong> 
							</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>
								<span><?php __('front_fax');?></span>
								<strong><?php echo pjSanitize::html($owner_fax);?></strong> 
							</li>
							<?php
						}
						$ob_contact = ob_get_contents();
						ob_end_clean();
						
						?>
					</div><!-- /.ylDetailsMediaAside -->
				</div><!-- ./ylDetailsMedia -->
				
				<div class="ylDetailsSection">
					<div class="ylColSize1">
						<ul class="ylList">
							<li>
								<span><?php __('front_reference_id');?></span>
								<strong><?php echo pjSanitize::html($tpl['arr']['listing_refid']);?></strong> 
							</li>
							<li>
								<span><?php __('front_manufacturer');?></span>
								<strong><?php echo pjSanitize::html($tpl['arr']['manufacturer']);?></strong> 
							</li>
							<?php
							if(!empty($tpl['arr']['listing_model']))
							{ 
								?>
								<li>
									<span><?php __('front_model');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_model']);?></strong> 
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_year']))
							{
								?>
								<li>
									<span><?php __('front_registration_year');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_year']);?></strong> 
								</li>
								<?php
							}
							?>
						</ul>
					</div><!-- ./ylColSize1 -->
					<div class="ylColSize2">
						<ul class="ylList">
							<?php
							$feature_types = __('feature_types', true);
							foreach($feature_types as $k => $v)
							{
								if(!empty($tpl['arr']['feature_' . $k]))
								{
									?>
									<li>
										<span><?php echo $v;?></span>
										<strong><?php echo pjSanitize::html($tpl['arr']['feature_' . $k]);?></strong> 
									</li>
									<?php
								}
							} 
							?>
						</ul>
					</div><!-- ./ylColSize2 -->
					<div class="ylColSize3">
						<ul class="ylList">
							<?php
							$enum_arr = __('enum_arr', true);
							$opt_speed = $tpl['option_arr']['o_speed'];
							if(!empty($tpl['arr']['listing_length']))
							{
								?>
								<li>
									<span><?php __('front_length');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_length']);?> <?php echo $enum_arr[$tpl['option_arr']['o_length']];?></strong> 
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_loa']))
							{
								?>
								<li>
									<span><?php __('front_loa');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_loa']);?></strong> 
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_beam']))
							{
								?>
								<li>
									<span><?php __('front_beam');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_beam']);?> <?php echo $enum_arr[$tpl['option_arr']['o_length']];?></strong> 
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_power']))
							{
								?>
								<li>
									<span><?php __('front_horsepower');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_power']);?> <?php echo $enum_arr[$tpl['option_arr']['o_power']];?></strong> 
								</li>
								<?php
							}
							?>
						</ul>
					</div><!-- ./ylColSize3 -->
					<div class="ylColSize3">
						<ul class="ylList">
							<?php
							if(!empty($tpl['arr']['listing_engine_model']))
							{
								?>
								<li>
									<span><?php __('front_engine_model');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_engine_model']);?></strong> 
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_engine_hours']))
							{
								?>
								<li>
									<span><?php __('front_engine_hours');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_engine_hours']);?> <?php __('front_hours');?></strong> 
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_cruising_speed']))
							{
								?>
								<li>
									<span><?php __('front_cruising_speed');?></span>
									 <strong><?php echo pjSanitize::html($tpl['arr']['listing_cruising_speed']);?> <?php echo $enum_arr[$opt_speed];?></strong> 
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_max_speed']))
							{
								?>
								<li>
									<span><?php __('front_max_speed');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_max_speed']);?> <?php echo $enum_arr[$opt_speed];?></strong> 
								</li>
								<?php
							}
							if(!empty($tpl['arr']['listing_fuel_tank']))
							{
								?>
								<li>
									<span><?php __('front_fuel_tank');?></span>
									<strong><?php echo pjSanitize::html($tpl['arr']['listing_fuel_tank']);?> <?php echo $enum_arr[$tpl['option_arr']['o_fuel']];?></strong> 
								</li>
								<?php
							} 
							?>
						</ul>
					</div><!-- ./ylColSize3 -->
				</div><!-- ./ylDetailsSection -->
				
				<div class="ylDetailsInfo">
					<div class="ylDetailsContent">
						<h3><?php __('front_yacth_description');?></h3>
						<div class="ylDetailsDesc">
							<?php echo stripslashes($tpl['arr']['description']);?>
						</div>
					</div><!-- /.ylDetailsContent -->
					<div class="ylDetailsAside">
						<?php
						if(!empty($tpl['listing_extra_arr']))
						{	 
							?>
							<h3><?php __('front_feature_set');?></h3>
							<p><?php echo join(', ', $tpl['listing_extra_arr']);?></p>
							<?php
						} 
						?>
					</div><!-- /.ylDetailsAside -->
				</div><!-- ./ylDetailsInfo -->
				<?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="ylDetailsSection">
						<h2><?php __('front_yacht_reservation');?></h2>
						
						<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>
						<br/>
						<div id="ylReservationTable_<?php echo $index;?>" class="ylReservationTableHolder">
							<table class="ylReservationTable">
								<thead>
									<tr>
										<th class="ylTableLeft">
											<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="3">
											<?php
											if($selected_week != null)
											{
												echo $months[date('n', $selected_week)] . ' ' . date('Y', $selected_week);
											}else{
												echo $months[date('n')] . ' ' . date('Y');
											}
											?>
										</th>
										<th class="ylTableRight">
											<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;
										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;
												}
											}
										}
										?>
										<tr class="<?php echo $is_reserved == true ? 'ylReserved' : ($is_avaialble == true ? 'ylAvailable' : '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>
														<?php
													}else{
														?><em><?php __('front_not_avaialble');?></em><?php
													}
												}else{
													?><em><?php __('front_reserved');?></em><?php
												} 
												?>
											</td>
											<td>
												<?php
												if($is_reserved == false)
												{ 
													if($is_avaialble == true)
													{
														?>
														<a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjListings&amp;action=pjActionReserve&amp;id=<?php echo $tpl['arr']['id']?>" data-week="<?php echo $v['monday'];?>" class="ylBtn ylBtnTertiary ylBtnReserve"><?php __('front_make_a_reservation');?></a>
														<?php
													}else{
														?>&nbsp;<?php
													}
												}else{
													?>&nbsp;<?php
												} 
												?>
											</td>
										</tr>
										<?php
									} 
									?>
								</tbody>
							</table>
						</div><!-- ./ylReservationTableHolder -->
					</div><!-- /.ylDetailsSection -->
					<?php
				} 
				?>
				<div class="ylDetailsInfo">
					<div class="ylDetailsMediaAside">
						<?php
							if($tpl['arr']['owner_show'] == 'T' && !empty($ob_contact))
							{
								?>
								<h4><?php __('front_contact_details');?>:</h4>
						
								<ul class="ylList ylContactList">
									<?php
									echo $ob_contact;
									?>
								</ul>
								<?php
							}
						?>
					</div><!-- /.ylDetailsMediaAside -->
				</div><!-- /.ylDetailsInfo -->
			</div><!-- /.ylDetails -->
			<?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';?>