<?php
$listing_for = __('listing_for', true); 
?>
<div class="jumbotron">
	<div class="container">
		<h1><?php __('ws_reservations');?></h1>

		<p><?php __('ws_reservations_desc');?></p>
	</div><!-- /.container -->
</div><!-- /.jumbotron -->

<div class="section section-contact">
	<div class="container">
		<?php
		if($tpl['status'] == '200')
		{ 
			
			if (@$_GET['controller'] == 'pjWebsite' && @$_GET['action'] == 'pjActionReserve')
			{
				$back = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF'] .'?controller=pjWebsite&amp;action=pjActionView&amp;id=' . $_GET['id'] . (isset($_GET['iframe']) ? '&amp;iframe' : NULL);
			}
			$listing_title = pjSanitize::html(stripslashes($tpl['arr']['title']));
			if ($tpl['option_arr']['o_website_seo'] == 'No')
			{
				$url = $_SERVER['SCRIPT_NAME'] . '?controller=pjWebsite&amp;action=pjActionView&amp;id=' . $tpl['arr']['id'] .(isset($_GET['iframe']) ? '&amp;iframe' : NULL);
			} else {
				$path = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
				$path = $path == '/' ? '' : $path;
				$url = $path .'/'. $controller->friendlyURL($tpl['arr']['title']) . "-". $tpl['arr']['id'] . ".html";
			}
			$image = '';
			if(!empty($tpl['arr']['image']))
			{
				if(is_file(PJ_INSTALL_PATH . $tpl['arr']['medium']))
				{
					$image = PJ_INSTALL_URL . $tpl['arr']['medium'];
				}
			}
			?>
			<div class="row">
				<div class="col-sm-4">
					<div class="selected-yacht">
						<a href="<?php echo $url;?>" class="btn btn-primary"><span class="glyphicon glyphicon-menu-left"></span> <?php __('ws_btn_back');?></a>
	
						<h3><?php __('ws_selected_yacht');?></h3>
	
						<div class="selected-yacht-image">
							<img src="<?php echo $image;?>" alt="">
						</div><!-- /.selected-yacht-image -->
	
						<ul>
							<li>
								<?php echo $listing_title;?>
							</li>
	
							<li>
								<span>
									<?php __('ws_selected_period');?>
	
									<em><?php __('ws_week');?> <?php echo date('W', $_GET['week']);?> <br> <?php echo date($tpl['option_arr']['o_date_format'], $_GET['week']);?> - <?php echo date($tpl['option_arr']['o_date_format'], ($_GET['week'] + (6 * 60 * 60 * 24)));?></em>
								</span>
	
								<strong><?php echo pjUtil::formatCurrencySign(number_format($tpl['price_arr']['subtotal'], 2), $tpl['option_arr']['o_currency']);?></strong>
							</li>
	
							<li>
								<span><?php __('ws_sub_total');?></span>
	
								<strong><?php echo pjUtil::formatCurrencySign(number_format($tpl['price_arr']['subtotal'], 2), $tpl['option_arr']['o_currency']);?></strong>
							</li>
	
							<li>
								<span><?php __('ws_tax');?></span>
	
								<strong><?php echo pjUtil::formatCurrencySign(number_format($tpl['price_arr']['tax'], 2), $tpl['option_arr']['o_currency']);?></strong>
							</li>
	
							<li>
								<span><?php __('ws_total');?></span>
	
								<strong class="selected-yacht-total"><?php echo pjUtil::formatCurrencySign(number_format($tpl['price_arr']['total'], 2), $tpl['option_arr']['o_currency']);?></strong>
							</li>
	
							<li>
								<span><?php __('ws_deposit');?></span>
	
								<strong><?php echo pjUtil::formatCurrencySign(number_format($tpl['price_arr']['deposit'], 2), $tpl['option_arr']['o_currency']);?></strong>
							</li>
						</ul>
					</div>
				</div><!-- /.col-sm-3 -->
	
				<div class="col-sm-8">
					<div class="form form-reservation">
						<form action="<?php echo  $tpl['option_arr']['o_website_seo'] == 'Yes' ? PJ_INSTALL_URL.'reservation.html' : $_SERVER['PHP_SELF'] . '?controller=pjListings&amp;action=pjActionReserve';?>" method="post" id="frmYLReserve" name="frmYLReserve">
							<input type="hidden" name="reserve" value="1" />
							<input type="hidden" name="listing_id" value="<?php echo $tpl['arr']['id'];?>" />
							<input type="hidden" name="week_start" value="<?php echo date('Y-m-d', $_GET['week']);?>" />
							<input type="hidden" name="sub_total" value="<?php echo $tpl['price_arr']['subtotal'];?>" />
							<input type="hidden" name="tax" value="<?php echo $tpl['price_arr']['tax'];?>" />
							<input type="hidden" name="total" value="<?php echo $tpl['price_arr']['total'];?>" />
							<input type="hidden" name="deposit" value="<?php echo $tpl['price_arr']['deposit'];?>" />
							
							<?php
							ob_start();
							if (in_array((int) $tpl['option_arr']['o_bf_include_title'], array(2,3)))
							{ 
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_title');?>:</label>
									<div class="form-control-select">
										<select name="c_title" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_title'] === 3 ? ' required' : null;?>" data-err="<?php __('front_title_required');?>">
											<option value="">-- <?php __('front_choose');?> --</option>
											<?php
											foreach(__('personal_titles', true) as $k => $v) 
											{
												?><option value="<?php echo $k;?>"<?php echo isset($_POST['c_title']) ? ($_POST['c_title'] == $k ? ' selected="selected"' : null) : null;?>><?php  echo $v;?></option><?php
											}
											?>
										</select>
									</div>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_name'], array(2,3)))
							{ 
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_name');?>:</label>
									<input type="text" name="c_name" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_name'] === 3 ? ' required' : NULL; ?>" data-err="<?php __('front_name_required');?>" value="<?php echo pjSanitize::html(@$FORM['c_name']); ?>">
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_email'], array(2,3)))
							{
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_email');?>:</label>
									<input type="text" name="c_email" class="form-control email<?php echo (int) $tpl['option_arr']['o_bf_include_email'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_email']); ?>" data-err="<?php __('front_email_required');?>" data-email="<?php __('front_email_invalid');?>">
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_phone'], array(2,3)))
							{
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_phone');?>:</label>
									<input type="text" name="c_phone" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_phone'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_phone']); ?>" data-err="<?php __('front_phone_required');?>">
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_company'], array(2,3)))
							{
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_company');?>:</label>
									<input type="text" name="c_company" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_company'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_company']); ?>" data-err="<?php __('front_company_required');?>">
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_address'], array(2,3)))
							{
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_address');?>:</label>
									<input type="text" name="c_address" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_address'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_address']); ?>" data-err="<?php __('front_address_required');?>">
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_country'], array(2,3)))
							{
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_country');?>:</label>
									<div class="form-control-select">
										<select name="c_country" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_country'] === 3 ? ' required' : NULL; ?>" data-err="<?php __('front_country_required');?>">
											<option value="">-- <?php __('front_choose');?> --</option>
											<?php
											foreach($tpl['country_arr'] as $k => $v) 
											{
												?><option value="<?php echo $v['id'];?>"<?php echo isset($FORM['c_country']) ? ($FORM['c_country'] == $v['id'] ? ' selected="selected"' : null) : null;?>><?php  echo $v['name'];?></option><?php
											}
											?>
										</select>
									</div>
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_state'], array(2,3)))
							{
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_state');?>:</label>
									<input type="text" name="c_state" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_state'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_state']); ?>" data-err="<?php __('front_state_required');?>">
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_city'], array(2,3)))
							{
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_city');?>:</label>
									<input type="text" name="c_city" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_city'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_city']); ?>" data-err="<?php __('front_city_required');?>">
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_zip'], array(2,3)))
							{
								?>
								<div class="col-sm-6">
									<label class="control-label"><?php __('front_zip');?>:</label>
									<input type="text" name="c_zip" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_zip'] === 3 ? ' required' : NULL; ?>" value="<?php echo pjSanitize::html(@$FORM['c_zip']); ?>" data-err="<?php __('front_zip_required');?>">
									<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
								</div><!-- /.col-sm-6 -->
								<?php
								$number_of_cols++;
							}
							if($number_of_cols == 2 || $number_of_cols == 1)
							{
								$ob_fields = ob_get_contents();
								ob_end_clean();
								?>
								<div class="row"><?php echo $ob_fields; ?></div>
								<?php
								ob_start();
								$number_of_cols = 0;
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_notes'], array(2,3)))
							{
								?>
								<div class="row">
									<div class="col-sm-12">
										<label class="control-label"><?php __('front_notes');?>:</label>
										<textarea name="c_notes" class="form-control<?php echo (int) $tpl['option_arr']['o_bf_include_notes'] === 3 ? ' required' : NULL; ?>" rows="6" data-err="<?php __('front_notes_required');?>"><?php echo pjSanitize::html(@$FORM['c_notes']); ?></textarea>
										<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
									</div><!-- /.col-sm-6 -->
								</div>
								<?php
							}
							if ($tpl['option_arr']['o_payment_disable'] == 'No')
							{
								$rand = rand(1, 99999);
								?>
								<div class="row">
									<div class="col-sm-6">
										<label class="control-label"><?php __('front_payment_method');?>:</label>
										<div class="form-control-select">
											<select id="ylPaymentMethod" name="payment_method" class="form-control required" data-err="<?php __('front_payment_method_required');?>">
									    		<option value="">-- <?php __('front_choose'); ?> --</option>
									    		<?php
												foreach (__('payment_methods', true) as $k => $v)
												{
													if ($tpl['option_arr']['o_allow_'.$k] == 'No')
													{
														continue;
													}
													?><option value="<?php echo $k; ?>"<?php echo @$FORM['payment_method'] != $k ? NULL : ' selected="selected"'; ?>><?php echo $v; ?></option><?php
												}
												?>
									    	</select>
									    </div>
									    <div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
									</div><!-- /.col-sm-6 -->
									<div class="col-sm-6 ylBankWrap" style="display: <?php echo @$FORM['payment_method'] != 'bank' ? 'none' : NULL; ?>">
										<label class="control-label">Bank account:</label>
										<input type="text" name="back_account" class="form-control" value="<?php echo pjSanitize::html(nl2br($tpl['option_arr']['o_bank_account'])); ?>" disabled="disabled">
									</div><!-- /.col-sm-6 -->
								</div>
								
								<div class="row">
									<div class="col-sm-6 ylCcWrap" style="display: <?php echo @$FORM['payment_method'] != 'creditcard' ? 'none' : NULL; ?>">
										<label class="control-label"><?php __('front_cc_type');?>:</label>
										<div class="form-control-select">
											<select name="cc_type" class="form-control required" data-err="<?php __('front_cc_type_required');?>">
									    		<option value="">-- <?php __('front_choose'); ?>-- </option>
									    		<?php
												foreach (__('cc_types', true) as $k => $v)
												{
													?><option value="<?php echo $k; ?>"<?php echo @$FORM['cc_type'] != $k ? NULL : ' selected="selected"'; ?>><?php echo $v; ?></option><?php
												}
												?>
									    	</select>
									    </div>
									    <div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
									</div><!-- /.col-sm-6 -->
									<div class="col-sm-6 ylCcWrap" style="display: <?php echo @$FORM['payment_method'] != 'creditcard' ? 'none' : NULL; ?>">
										<label class="control-label"><?php __('front_cc_num');?>:</label>
										<input type="text" name="cc_num" class="form-control required" value="<?php echo pjSanitize::html(@$FORM['cc_num']); ?>"  autocomplete="off" data-err="<?php __('front_cc_num_required');?>"/>
										<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
									</div><!-- /.col-sm-6 -->
								</div>
								<div class="row">
									<div class="col-sm-6 ylCcWrap" style="display: <?php echo @$FORM['payment_method'] != 'creditcard' ? 'none' : NULL; ?>">
										<label class="control-label"><?php __('front_cc_sec');?>:</label>
										<input type="text" name="cc_code" class="form-control required" value="<?php echo pjSanitize::html(@$FORM['cc_code']); ?>"  autocomplete="off" data-err="<?php __('front_cc_code_required');?>"/>
										<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
									</div><!-- /.col-sm-6 -->
									<div class="col-sm-6 ylCcWrap" style="display: <?php echo @$FORM['payment_method'] != 'creditcard' ? 'none' : NULL; ?>">
										<label class="control-label"><?php __('front_cc_exp');?>:</label>
										<?php
										$time = pjTime::factory()
											->attr('name', 'cc_exp_month')
											->attr('id', 'cc_exp_month_' . $rand)
											->attr('class', 'form-control ylCCField required')
											->prop('format', 'F');
										if (isset($FORM['cc_exp_month']) && !is_null($FORM['cc_exp_month']))
										{
											$time->prop('selected', $FORM['cc_exp_month']);
										}
										?>
										<div class="row">
											<div class="col-sm-6">
												<div class="form-control-select">
													<?php
													echo $time->month();
													?>
												</div>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
											<?php
											$time = pjTime::factory()
												->attr('name', 'cc_exp_year')
												->attr('id', 'cc_exp_year_' . $rand)
												->attr('class', 'form-control ylCCField required')
												->prop('left', 0)
												->prop('right', 10);
											if (isset($FORM['cc_exp_year']) && !is_null($FORM['cc_exp_year']))
											{
												$time->prop('selected', $FORM['cc_exp_year']);
											}
											?>
											<div class="col-sm-6">
												<div class="form-control-select">
													<?php
													echo $time->year();
													?>
												</div>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div>
										</div>
									</div><!-- /.col-sm-6 -->
								</div><!-- /.row -->
								<?php 
							}
							if (in_array((int) $tpl['option_arr']['o_bf_include_captcha'], array(3)))
							{
								?>
								<div class="row">
									<div class="col-sm-12">
										<label class="control-label"><?php __('front_captcha');?>:</label>
										
										<div class="row">
											<div class="col-sm-3">
												<input type="text" name="captcha" class="form-control ylCaptchaField required" maxlength="6" data-folder="<?php echo PJ_INSTALL_FOLDER;?>" autocomplete="off" data-err="<?php __('front_captcha_required');?>" data-captcha="<?php __('front_captcha_incorrect');?>"/>
												<div class="help-block with-errors"><ul class="list-unstyled"></ul></div>
											</div><!-- /.col-sm-8 -->
		
											<div class="col-sm-3">
												<img id="ylCaptchaImage" src="<?php echo PJ_INSTALL_FOLDER; ?>index.php?controller=pjFront&amp;action=pjActionCaptcha&amp;rand=<?php echo rand(1, 999999); ?>" alt="Captcha" style="vertical-align:top;"/>
											</div><!-- /.col-sm-4 -->
										</div><!-- /.row -->
									</div><!-- /.col-sm-6 -->
								</div>
								<?php
							} 
							?>
								
							<div class="buttons">
								<a class="btn btn-primary" href="<?php echo $back;?>"><?php __('front_button_cancel');?></a>		
	
								<button class="btn btn-secondary" type="submit"><?php __('front_button_continue');?></button>		
							</div><!-- /.buttons -->
							
							<div class="row" style="display: none;">
								<div class="col-sm-6">
									<br/>
									<span class="ylFormMessage text-info"><?php __('front_booking_processing');?></span>
								</div>
							</div>
							<div class="row" style="display: none;">
								<div class="col-sm-6">
									<br/>
									<span class="ylFormError text-danger"><?php __('front_booking_not_saved');?></span>
								</div>
							</div>
						</form>
						
						<div id="ylReserveMessage" class="ylPaymentForm"></div>
					</div><!-- /.form -->
				</div><!-- /.col-sm-9 -->
			</div><!-- /.row -->
			<?php
		}else{
			$listing_statuses = __('listing_statuses', true);
			echo $listing_statuses[$tpl['status']];
		} 
		?>
	</div><!-- /.container -->
</div><!-- /.main -->