<?php
mt_srand();
$index = mt_rand(1, 9999);
$listing_for = __('listing_for', true);
$yacht_types = __('yacht_types', 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="ylBreadcrumbs">
				<a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjListings&amp;action=pjActionYachts&amp;listing_search=1&amp;for=<?php echo $tpl['arr']['for']; ?>"><?php echo $yacht_types[$tpl['arr']['for']];?></a>
		
				<span class="ylSpacer">&raquo;</span>
		
				<span class="ylCurrent"><?php echo $listing_title;?></span>
			</p><!-- /.breadcrumbs -->
			
			<div class="ylDetails">
				<div class="ylDetailsHead">
					<h1><?php echo $listing_title;?></h1>
				</div><!-- /.ylDetailsHead -->
				<?php
				if(!empty($tpl['gallery_arr']))
				{ 
					?>
					<div class="ylDetailsMedia clearfix">
						<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 -->
					</div><!-- ./ylDetailsMedia -->
					<?php
				} 
				$enum_arr = __('enum_arr', true);
				$opt_speed = $tpl['option_arr']['o_speed'];
				?>
				<div class="ylDetailsInfo">
					<div class="ylDetailsAside">
						<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
								}
							}
							?>
							<?php
							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>
						<?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))
						{
							?>
							<h3><?php __('front_contact_details');?></h3>
	
							<ul class="ylList">
								<?php
								echo $ob_contact;
								?>
							</ul>
							<?php
						}
						?>
					</div><!-- /.ylDetailsAside -->
					
					<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>
						
						<?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="ylSection">
								<div class="ylSectionHead">
									<h3><?php __('front_yacht_reservation');?></h3>
								</div><!-- /.ylDetailsSectionHead -->
								<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;?>" class="ylSectionBody">
									<div class="ylReservationNav">
										<div class="ylColSize1">
											<a class="ylNavMonth" href="#" data-id="<?php echo $tpl['arr']['id']?>" data-month="<?php echo $week_arr['prev'] ?>">&lt; <?php __('front_prev');?></a>
										</div><!-- /.ylColSize1 -->
		
										<div class="ylColSize2">
											<?php
											if($selected_week != null)
											{
												echo $months[date('n', $selected_week)] . ' ' . date('Y', $selected_week);
											}else{
												echo $months[date('n')] . ' ' . date('Y');
											}
											?>
										</div><!-- /.ylColSize2 -->
		
										<div class="ylColSize3">
											<a class="ylNavMonth" href="#" data-id="<?php echo $tpl['arr']['id']?>" data-month="<?php echo $week_arr['next'] ?>"><?php __('front_next');?> &gt;</a>
										</div><!-- /.ylColSize3 -->
									</div>
									<ul class="ylBook">
										<?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;
													}
												}
											}
											?>
											<li>
												<div class="ylColSize1">
													<strong><?php echo date($tpl['option_arr']['o_date_format'], $v['monday'])?> - <?php echo date($tpl['option_arr']['o_date_format'], $v['sunday'])?></strong>
				
													<span><?php __('front_week');?> <?php echo $k;?></span>
												</div><!-- /.ylColSize1 -->
				
												<div class="ylColSize2">
													<strong><?php echo $is_avaialble == true ? pjUtil::formatCurrencySign($tpl['price_arr'][$iso_date], $tpl['option_arr']['o_currency'])  : '&nbsp;'?></strong>
				
												</div><!-- /.ylColSize2 -->
				
												<div class="ylColSize3">
													<?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_book_now');?></a>
															<?php
														}else{
															?><em class="ylUnavailable"><?php __('front_not_avaialble');?></em><?php
														}
													}else{
														?><em class="ylReserved"><?php __('front_reserved');?></em><?php
													} 
													?>
												</div><!-- /.ylColSize3 -->
											</li>
											<?php
										} 
										?>
									</ul>
								</div><!-- /.ylSectionBody -->
							</div><!-- /.ylDetailsSection -->
							<?php
						} 
						?>
					</div><!-- /.ylDetailsContent -->
				</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>
<?php include_once ROOT_PATH . PJ_TEMPLATE_PATH . $tpl['option_arr']['o_layout']. '/elements/loadjs.php';?>