<?php
	$company = $site->getCompanyDetails();
	$companyCountry = $company->country;
	$analytics_ga4 = (string)$company->analytics_ga4;
	$analytics_gtm = (string)$company->analytics_gtm;
	$meta_pixel = (string)$company->meta_pixel;
	$cart_total = $site->getCartTotal();
	$gateway_id = (string)$company->gateway_id;

	if (isset($company->tips->present->value)) {
		$tips_enabled = in_array('fe', (array)$company->tips->present->value) ? 1 : 0;
	} else {
		$tips_enabled = 0;
	}

	$using_paypal_checkout = $site->usingPaypalCheckout();

	//ticket guardian values
	$tg_supported_currencies = array('USD', 'CAD', 'GBP', 'AUD', 'MXN', 'JPY', 'BRL', 'EUR');
	$tg_display_currency = 0;
	$tg_enabled = 0;

	$site_base_currency = strtoupper($company->currency_base);

	if (in_array($site_base_currency, $tg_supported_currencies) && $company->ticketguardian) {
		$tg_display_currency = $site_base_currency;
	}

	$tg_disallowed_gateways = array('stripe_connect', 'tmt', 'first_atlantic_commerce', 'opayo','square');
	$tg_limit = ($cart_total >= '25' && $cart_total <= '2500') ? 1 : 0;

	$tg_enabled = (!in_array($gateway_id, $tg_disallowed_gateways)
		&& ($tg_display_currency !== 0)
		&& ($site->getGateway())
		&& in_array($site_base_currency, $tg_supported_currencies)
		&& $tg_limit) ? 1 : 0;
?>
<?php if (!REZGO_WORDPRESS) { ?>
<script type="text/javascript" src="<?php echo $site->path; ?>/js/jquery.form.js"></script>
<script type="text/javascript" src="<?php echo $site->path; ?>/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="<?php echo $site->path; ?>/js/jquery.selectboxes.js"></script>
<script type="text/javascript" src="/js/ie8.polyfils.min.js"></script>
<?php } ?>

<script>
	var overall_total = '0';
	var split_total = new Array();
	var tg_booking_prices = new Array();
	var tg_booking_prices_total = 0;

	function getCookie(cname) {
		var name = cname + "=";
		var decodedCookie = decodeURIComponent(document.cookie);
		var ca = decodedCookie.split(';');
		for(var i = 0; i <ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0) == ' ') {
				c = c.substring(1);
			}
			if (c.indexOf(name) == 0) {
				return c.substring(name.length, c.length);
			}
		}
		return "";
	}
</script>

        <div id="rezgo-order-wrp" class="container-fluid rezgo-container" role="main">
            <div class="jumbotron rezgo-booking">

                <form id="rezgo-payment-form" role="form" method="post" target="rezgo_content_frame">
                    <div id="rezgo-book-step-two">
						<div id="rezgo-book-step-two-anchor"></div>

						<div id="rezgo-book-step-two-crumb" class="row">
							<ol class="breadcrumb rezgo-breadcrumb">
								<?php 
									// check for cart token, add to order link to preserve cart data 
									$cart_token = sanitize_text_field($site->cart_token); 
									$order_url = $site->base . '/order/' . $cart_token; 
								?>
									<li id="rezgo-book-step-two-your-order" class="rezgo-breadcrumb-order"><a class="link" href="<?php echo esc_url($order_url); ?>"><span class="default">Order</span><span class="custom"></span></a></li>
									<li id="rezgo-book-step-two-info" class="rezgo-breadcrumb-info"><a class="link" href="<?php echo esc_url($site->base); ?>/book"><span class="default">Guest Information</span><span class="custom"></span></a></li>
									<li id="rezgo-book-step-two-billing" class="rezgo-breadcrumb-billing active"><span class="default">Payment</span><span class="custom"></span></li>
									<li id="rezgo-book-step-two-confirmation" class="rezgo-breadcrumb-confirmation"><span class="default">Confirmation</span><span class="custom"></span></li>
							</ol>
						</div>
						<input type="hidden" name="cart_token" value="<?php echo esc_attr($cart_token); ?>">
							
					<?php $cart = $site->getCart(1); // get the cart, remove any dead entries ?>

					<div id="rezgo-order-error-message" style="display:none;">
						<!-- Top level error message -->
						<span class="message"></span>
						<a href="#" id="rezgo-error-dismiss" class="btn"><span><i class="fas fa-times"></i></span></i></a>
					</div>

					<script>
						jQuery(function($) {
							if ( getCookie('cart_status') ) {
								$.ajax({
									type: 'POST',
									url: '<?php echo admin_url('admin-ajax.php'); ?>' + '?action=rezgo&method=book_ajax',
									data: { rezgoAction: 'get_cart_status', dateFormat: '<?php echo $company->date_format; ?>'},
									success: function(response){
										$('#rezgo-order-error-message').show();
										$('#rezgo-order-error-message .message').html(response);
									},
									error: function(error){
										console.log(error);
									}
								});
							}

							// dismiss error when user navigates away or manually closes it
							function dismissError(){
								$.ajax({
									type: 'POST',
									url: '<?php echo admin_url('admin-ajax.php'); ?>' + '?action=rezgo&method=book_ajax',
									data: { rezgoAction: 'reset_cart_status'},
									success: function(data){
										// console.log('reset cart status session');
									},
									error: function(error){
										console.log(error);
									}
								});
							}

							$('#rezgo-error-dismiss').click(function(e){
								dismissError();
								e.preventDefault();
								$('#rezgo-order-error-message').fadeOut();
							});

							setTimeout(() => {
								dismissError();
							}, 3000);

							window.onbeforeunload = dismissError();
						});
					</script>
						
					<?php if (!$cart) { ?>

						<div class="rezgo-order-empty-cart-wrp">
							<div class="rezgo-form-group cart_empty">
								<p class="lead">	
									<span class="d-none d-sm-inline-block">There are</span><span>&nbsp;<span class="d-none d-sm-inline-block">n</span><span class="d-sm-none">N</span>o items</span><span class="d-none d-sm-inline-block">&nbsp;in your order.</span>
								</p>
							</div>

							<div class="row" id="rezgo-booking-btn">
								<div class="col-md-4 col-12 rezgo-btn-wrp">
									<span class="btn-check"></span>
									<a id="rezgo-order-book-more-btn" href="<?php echo esc_attr($site->base); ?>" class="btn rezgo-btn-default btn-lg btn-block">
										<span>Book More</span>
									</a>
								</div>
							</div>
						</div>

					<?php } else { ?>

						<div class="flex-container confirm-page-container">

							<div class="checkout-container">
							<?php
								$complete_booking_total = 0;
								$lead_passenger = $site->getLeadPassenger(); // get lead passenger details
								$billing_address = (int)$company->billing_address;
								$billing_country_required = in_array($gateway_id, ['tmt','square']);
								$form_display = $site->getFormDisplay() ?? $site->getFormDisplay(); // get primary form addons
								$gf_form_display = $site->getGroupFormDisplay() ?? $site->getGroupFormDisplay(); // get group form addons
								$booking_dates = array();
								$booking_items = array();

								$item_total = array();
								$item_booking_total = array();
								$non_package_items = array();
								$cart_package_uids = array();
								$package_sub_total = array();
								$total_deposit_set = array();
								$package_overall_total = array();
								$package_deposit_value = array();
								$package_form_display = array();
								$package_gf_form_display = array();
								$pf_form_total = array();
								$gf_form_total = array(); 

								foreach ($cart as $item) {
									if ($site->exists($item->package)) {
										$cart_package_uids[] .= $item->cart_package_uid; 
									} else {
										$non_package_items[] = $item; 
									}
								} unset($item);

								$unique_package_uids = array_unique($cart_package_uids);
								$cart_count = (int)count($unique_package_uids) + (int)count($non_package_items);
								$cart_subtotal_analytics = 0;
								$cart_discount = array();
							?>
							
							<?php 
							$c = 0; // start cart loop for each booking in the order
							$index = 0;
							$item_count = 1;
							$overall_taxes = 0;
							$total_value;
                            $deposit_full_total_value;
                            $mixed_deposit_total;

							foreach($cart as $item) {
                                	$site->readItem($item); 
									$currency_base = $item->currency_base; 
                                	$overall_taxes += (float)$item->tax_calc;
									$cart_subtotal_analytics += ($item->package ? $item->package_item_after_discount : $item->sub_total);
									?>
								
									<?php if(DEBUG) { ?>
										<div class="row">
											<pre style="max-height:100px; overflow-y:auto; margin:15px 0"><?php var_dump($item); ?></pre>
										</div>
									<?php } ?>

								<?php if((int) $item->availability >= (int) $item->pax_count) { ?>
                                    <?php $c++; // only increment if it's still available ?>

										<?php 
											if(in_array((string) $item->date_selection, DATE_TYPES)) {
												$booking_date = date("Y-m-d", (int)$item->booking_date);
											} else {
												$booking_date = 'open'; // for open availability
											}

											if ($gateway_id == 'tmt'){
												if(!in_array((string) $item->date_selection, DATE_TYPES)){
													$tmt_date = ($item->expiry && ($item->expiry < strtotime('+30 days'))) ? $item->expiry : strtotime('+30 days', time());
												} else {
													$tmt_date = $item->booking_date;
												}
												array_push($booking_dates, (string)$tmt_date);
												array_push($booking_items, (string)$item->item .' - '. $item->option);
											}
										?>

										<?php if($c==1){ ?> <h3 id="rezgo-review-order-header" class="text-info">1. Review Order</h3> <?php } ?>

										<?php	
										if ($site->exists($item->package_item_total)){
											$first = (int)$item->package_item_index === 1 ? 1 : '';
											$last = (int)$item->package_item_index === (int)$item->package_item_total ? 1 : ''; 
											$package_id = (int)$item->package; 
											$cart_package_uid = (int)$item->cart_package_uid; 
											$package = $site->getTours('t=com&q='.$item->package);
											$package_sub_total[$cart_package_uid] = 0;
											$package_overall_total[$cart_package_uid] = 0;
											$package_deposit_value[$cart_package_uid] = 0;
											$item_total[$cart_package_uid][$index] = 0;
											$mixed_deposit_total[$cart_package_uid] = 0;
											$item_deposit_total[$cart_package_uid] = 0;
										?>

											<?php if ($first){ ?>
												<div class="rezgo-booking-info">
													<h3 class="rezgo-booking-of rezgo-booking-title">
														<div class="rezgo-sub-title">
															<span>Booking <?php echo esc_html($item_count); ?> of <?php echo esc_html($cart_count); ?></span>
														</div>
													</h3>
													<h3 class="rezgo-package-title">
														<?php $package_url = $site->base.'/details/'.$item->package.'/'.$site->seoEncode($item->package_name); ?>
														<a class="no-click" href="<?php echo esc_url($package_url); ?>">
															<i class="fad fa-layer-group fa-lg"></i> 
														<span><?php echo esc_html($item->package_name); ?></span>
														</a>
													</h3>
												</div>
											<?php } // if ($first) ?>

											<div class="package-icon-container">
												<i class="fad fa-circle"></i>
											</div>

											<div id="rezgo-book-step-two-item-<?php echo esc_attr($item->uid); ?>" class="rezgo-form-group rezgo-booking-info single-package-order-item">

												<h3 class="rezgo-item-title"><?php echo esc_html($item->item); ?> &mdash; <?php echo esc_html($item->option); ?></h3>
												<div class="">
													<table class="rezgo-table-list" border="0" cellspacing="0" cellpadding="2">
														<?php if(in_array((string) $item->date_selection, DATE_TYPES)) { ?>
															<label>
																<span>Date: </span>
																<span class="lead"><?php echo esc_html(date((string) $company->date_format, (int) $item->booking_date)); ?></span>
															</label>
															<?php if ($site->exists($item->time)){ ?>
																<label>&nbsp; at <?php echo (string) esc_html($item->time); ?></label>
															<?php } ?> 
														<?php } else { ?>
															<label><span class="lead"> Open Availability </span></label>
														<?php } ?>

														<?php if($item->duration != '') { ?>
															&nbsp;- <label class="rezgo-duration"><span class="lead">(Duration: <?php echo esc_html($item->duration); ?>)</span></label> 
														<?php } ?>


														<?php if($item->discount_rules->rule) {
															echo '<br><label class="rezgo-booking-discount">
															<span class="rezgo-discount-span">Discount:</span> ';
															$discount_string = '';
															foreach($item->discount_rules->rule as $discount) {	
																$discount_string .= ($discount_string) ? ', '.$discount : $discount;
															}
															echo '<span class="rezgo-promo-code-desc">'.esc_html($discount_string).'</span>
															</label>';
														} ?>
													</table>
												</div>

												<?php 
													// collect all form displays to display on the last table
													if (isset($form_display[$c-1])) $package_form_display[$cart_package_uid][] = $form_display[$c-1]; 
													if (isset($gf_form_display[$c-1])) $package_gf_form_display[$cart_package_uid][] = $gf_form_display[$c-1]; 

													// add up item totals
													$package_sub_total[$cart_package_uid] += $item->sub_total; 
													$package_overall_total[$cart_package_uid] += $item->overall_total; 
													$package_deposit_value[$cart_package_uid] += $item->deposit_value;

													//add up line items
													$package_line_items[$cart_package_uid.$item->uid.$index][] = $site->getTourLineItems();
												?>

												<div class="rezgo-form-group rezgo-cart-table-wrp rezgo-table-container">
													<div class="col-12 col-wrapper">
														<table class="table table-responsive rezgo-billing-cart" id="<?php echo esc_attr($item->uid); ?>" data-book-id="<?php echo esc_attr($c); ?>" data-cart-package-uid="<?php echo esc_attr($item->cart_package_uid); ?>">
															<tr class="rezgo-tr-head">
																<td class="text-start rezgo-billing-type"><label>Type</label></td>
																<td class="text-start rezgo-billing-qty"><label class="d-none d-sm-inline-block">Qty.</label></td>
																<td class="text-start rezgo-billing-cost"><label>Cost</label></td>
																<td class="text-end rezgo-billing-total"><label>Total</label></td>
															</tr>

															<?php 
																// gather package price points
																foreach ($package[0]->prices->price as $package_price_point) { 
																	$package_price_id = (int) $package_price_point->id; ?>

																	<span id="package-label-<?php echo esc_attr($package_id.'-'.$cart_package_uid.'-main-'.$package_price_id); ?>" class="d-none"><?php echo (string)$package_price_point->label; ?></span>

																	<script>
																		jQuery(function($){	
																			// replace subsequent labels in package items with package price labels
																			setTimeout(() => {
																				$('.package-label-<?php echo esc_html($package_id.'-'.$cart_package_uid.'-sub-'.$package_price_id); ?>').text($('#package-label-<?php echo esc_html($package_id.'-'.$cart_package_uid.'-main-'.$package_price_id); ?>').text());
																			}, 150);
																		});
																	</script>

															<?php } ?>

															<?php 
																$price_label_count = 0;
																foreach($site->getTourPrices($item) as $price) { ?>

																<?php if($item->{$price->name.'_num'}) { ?>

																	<?php $price_name = $cart_package_uid.'_'.$price->name; ?>
																	
																	<tr class="rezgo-tr-pax">
																		<td class="text-start package-label-<?php echo esc_attr($package_id.'-'.$cart_package_uid.'-sub-'.$price->id); ?>"><?php echo esc_html($price->label); ?></td>
																		<td class="text-start" ><?php echo esc_html($item->{$price->name.'_num'}); ?></td>
																		<td class="text-start package-pax-price">
																		<?php
																			$initial_price = isset($price->price) ? (float) $price->price : 0;
																			$strike_price = isset($price->strike) ? (float) $price->strike : 0;
																			$discount_price = isset($price->base) ? (float) $price->base : 0;
																			if ($price->discount) $cart_discount[$item_count] += (float) ($price->discount * $price->count);
																		?>
																		<?php if ( ($site->exists($price->strike)) && (isset($price->base) && $site->exists($price->base)) )  { ?>
																			<?php $show_this = max($strike_price, $discount_price); ?>

																			<span class="discount">
																				<?php echo esc_html($site->formatCurrency($show_this)); ?>
																			</span>

																	<?php } else if($site->exists($price->strike)) { ?>

																			<!-- show only if strike price is higher -->
																			<?php if ($strike_price >= $initial_price) { ?>
																				<span class="discount">
																					<span class="rezgo-strike-price">
																						<?php echo esc_html($site->formatCurrency($strike_price)); ?>
																					</span>
																				</span>
																			<?php } ?>

																	<?php } else if(isset($price->base) && $site->exists($price->base)) { ?>

																		<span class="discount">
																			<?php echo esc_html($site->formatCurrency($price->base)); ?>
																		</span>

																	<?php } ?>
																		<?php echo esc_html($site->formatCurrency($price->price)); ?>
																		</td>		
																		<td class="text-end package-pax-total">
																			<span>
																				<?php echo esc_html($site->formatCurrency($price->total)); ?>
																			</span>
																		</td>
																	</tr>
																	<?php if(isset($price->vat) && $price->vat > 0) { ?>
																	<tr class="rezgo-tr-vat">
																		<td colspan="4" class="text-start">
																			&nbsp;&nbsp;&nbsp;&nbsp;Includes <?php echo esc_html($price->vat_label . ' (' . $price->vat . '%)'); ?>
																		</td>
																	</tr>
																<?php } ?>		
																	<?php if(!$site->exists($item->deposit)) { 
																		$item_total[$cart_package_uid][$index] += $price->total;
																	} else {
																		if ($item->deposit_full_enabled) {
																			$item_total[$cart_package_uid][$index] = (float)$item->deposit_full;
																		} else {
																			$item_total[$cart_package_uid][$index] = (float)$item->deposit_value;
																		}
																	} ?>

																<?php $price_label_count++;
																} ?>
															<?php } // end foreach($site->getTourPrices($item) as $price) 
															?>

															<?php //$line_items = $site->getTourLineItems(); ?>

															<?php 

															foreach ($package_line_items[$cart_package_uid.$item->uid.$index] as $k => $v) {

																// remove booking fee and package discount
																foreach ($v as $line_item) {
																	$omit = array('');
																	if (!in_array( (string)$line_item->label, $omit)){
																		$line_items[$cart_package_uid]['item_'.$index][] = $line_item;
																	} else {
																		$consolidated_line_items[$cart_package_uid][] = $line_item;
																	}
																}
															}

															?>
										
															<?php 	
																$pax_totals = array(
																	'adult_num' => 'price_adult', 
																	'child_num' => 'price_child', 
																	'senior_num' => 'price_senior', 
																	'price4_num' => 'price4', 
																	'price5_num' => 'price5', 
																	'price6_num' => 'price6', 
																	'price7_num' => 'price7', 
																	'price8_num' => 'price8', 
																	'price9_num' => 'price9'
																);
															?>
															<?php if (isset($line_items[$cart_package_uid]['item_' . $index])) { ?>
																<?php foreach($line_items[$cart_package_uid]['item_' . $index] as $line) { ?>
																<?php $label_add = ''; ?>

																	<?php

																	if($site->exists($line->percent) || $site->exists($line->multi)) {
																		$label_add = ' (';

																		if($site->exists($line->percent)) {
																			$label_add .= $line->percent.'%';
																		}

																		if($site->exists($line->multi)) {

																			if(!$site->exists($line->percent)) {
																				$label_add .= $site->formatCurrency($line->multi);
																			}

																				if($site->exists($line->meta)) {

																					$line_pax = 0;
																					foreach ($pax_totals as $p_num => $p_rate) {

																						if ( (int) $item->{$p_num} > 0 && ((float) $item->date->{$p_rate} > (float) $line->meta)) {
																							$line_pax += (int) $item->{$p_num};
																						}
																					}
																					$label_add .= ' x ' . $line_pax;
																				} else {
																					$label_add .= ' x ' . $item->pax;
																				}
																		}

																		$label_add .= ')';
																	}
																
																	?>

																<tr class="rezgo-tr-subtotal">
																	<td colspan="3" class="text-end">
																	<?php if ($line->source == 'bundle') { ?>
																		<strong class="rezgo-line-bundle push-right"></i>&nbsp;<?php echo esc_html($line->label); ?><?php echo esc_html($label_add); ?> (Bundle)</strong></span>
																	 <?php } else { ?>
                                                                        <span class="push-right"><strong><?php echo esc_html($line->label); ?><?php echo esc_html($label_add); ?></strong>
																			<?php if($line->vat) { ?>
																				<br>
																				<span class="rezgo-line-vat">
																					Includes <?php echo esc_html((string)$line->vat->label . ' (' . (float)$line->vat->amount . '%)'); ?>
																				</span>
																			<?php } ?>
																		</span>
                                                                    <?php } ?>
																	</td>
																	<td class="text-end"><?php echo esc_html($site->formatCurrency($line->amount)); ?></td>
																</tr> 

																<?php if (!$site->exists($item->deposit)) {
																	$item_total[$cart_package_uid][$index] += $line->amount;
																} else {
																	if ($item->deposit_full_enabled) {
																		$item_total[$cart_package_uid][$index] = (float)$item->deposit_full;
																	} else {
																		$item_total[$cart_package_uid][$index] = (float)$item->deposit_value;
																	}
																} ?>

																<?php } unset($line); //foreach($line_items as $line) ?>	
															<?php } ?>

															<tbody id="line_item_box_<?php echo esc_attr($c); ?>" class="rezgo-line-item-box" data-line-uid="<?php echo esc_attr($item->uid); ?>" data-book-id="<?php echo esc_attr($c); ?>">
															</tbody><!-- line items -->
															<input type="hidden" id="rezgo-pickup-line-<?php echo esc_attr($c); ?>" value="" />

															<tbody id="fee_box_<?php echo esc_attr($c); ?>" class="rezgo-fee-box">
															</tbody><!-- extra fees -->

															<tbody id="line_item_box_<?php echo esc_attr($c); ?>" class="rezgo-form-display-box" data-line-uid="<?php echo esc_attr($item->uid); ?>" data-book-id="<?php echo esc_attr($c); ?>">

															<?php 
																$pf_form_total[$c] = 0;
																
																if ($package_form_display[$cart_package_uid]) {

																$package_form_display = $package_form_display[$cart_package_uid];

																foreach ($package_form_display as $package_primary_forms){
																	if ($package_primary_forms->primary_forms->form ) {
																		foreach ($package_primary_forms->primary_forms->form as $form){
																			
																			if (((float)$form->price != 0 && $form->value == 'on') || ($form->status == 'on')) { ?>
																				<tr class="rezgo-tr-form-display">
																					<td colspan="3" class="text-end rezgo-line-item">
																						<strong class="push-right">
																							<?php echo '1 <i class="far fa-times" style="position:relative; top:1px;"></i>'; ?>
																							<?php echo esc_html($form->title); ?>
																							<?php echo $form->select_price_option ? esc_html('('.$form->select_price_option.')') : ''; ?>
																						</strong>
																						<?php if ($form->vat) { ?> 
																						<br>
																						<span class="rezgo-line-vat">
																							Includes <?php echo esc_html((string)$form->vat->label . ' (' . (float)$form->vat->amount . '%)'); ?>
																						</span>
																					<?php } ?>
																					</td>

																					<td class="text-end">
																						<span class="rezgo-form-display-total_<?php echo esc_attr($c); ?>" rel="<?php echo esc_attr($form->price); ?>"><?php echo esc_html($site->formatCurrency($form->price)); ?></span>
																					</td>
																				</tr>
																			<?php $pf_form_total[$c] += $form->price; ?>

																			<?php if(!$site->exists($item->deposit)) { 
																				$item_total[$cart_package_uid][$index] += $form->price;
																			} ?>
																			<?php $cart_subtotal_analytics += $form->price; ?>

															<?php 			}
																		}
																	}
																}
															} ?>

															<?php 
																$gf_form_total[$c] = 0;
																if (isset($package_gf_form_display[$cart_package_uid])) {
															
																$gf_array = $gf_vat = array();
																$package_gf_form_display = $package_gf_form_display[$cart_package_uid];

																foreach ($package_gf_form_display as $package_gf_forms) {
																	foreach ($package_gf_forms as $form){
																		if (((float)$form->price != 0 && $form->value == 'on') || ($form->status == 'on')) {
																			$gf_array[] = (string) $form->title . '|||' . (string) $form->price. '|||' . (string) $form->select_price_option;
																			if ($form->vat) {
																				$gf_vat[(string) $form->title] = (string)$form->vat->label . '|||' . (float)$form->vat->amount;
																			}
																		}
																	}
																}

																$gf_line = array_count_values($gf_array);
																	foreach ($gf_line as $k => $count) {
																		$result = explode('|||', $k);
																		$title = $result[0];
																		$price = $result[1]; 
																		$select_price_option = $result[2]; ?>

																		<tr class="rezgo-tr-form-display">
																			<td colspan="3" class="text-end rezgo-line-item">
																				<strong class="push-right">
																					<?php echo esc_html($count) .' <i class="far fa-times" style="position:relative; top:1px;"></i>'; ?>
																					<?php echo esc_html($title); ?>
																					<?php echo $select_price_option ? esc_html('('.$select_price_option.')') : ''; ?>
																					<?php $price = $price * $count; ?>
																				</strong>
																				<?php if (isset($gf_vat[$title])) { 
																					$gf_vat_values = explode('|||', $gf_vat[$title]);
																					$vat_label = $gf_vat_values[0];
																					$vat_amount = $gf_vat_values[1]; ?> 
																					<br>
																					<span class="rezgo-line-vat">
																						Includes <?php echo esc_html($vat_label . ' (' . $vat_amount . '%)'); ?>
																					</span>
																				<?php } ?>
																			</td>
																			<td class="text-end">
																				<span class="rezgo-form-display-total_<?php echo esc_attr($c); ?>" rel="<?php echo esc_attr($price); ?>"><?php echo esc_html($site->formatCurrency($price)); ?></span>
																			</td> 
																		</tr>
																		<?php $gf_form_total[$c] += $price; ?>

																		<?php if(!$site->exists($item->deposit)) { 
																			$item_total[$cart_package_uid][$index] += $price;
																		} ?>

																		<?php $cart_subtotal_analytics += $price; ?>
																	<?php } ?>
															<?php } ?>
															
															</tbody><!-- form_display items -->

															<tbody class="rezgo-form-summary-box" data-line-uid="<?php echo esc_attr($item->uid); ?>" data-book-id="<?php echo esc_attr($c); ?>">

																<tr class="rezgo-tr-subtotal package-item-total">
																	<td colspan="3" class="text-end">
																		<span class="push-right"><strong>Item Total</strong></span>
																	</td>
																<td class="text-end">

																<?php 
																	if (!isset($item_booking_total[$cart_package_uid])) {
																		$item_booking_total = [$cart_package_uid => ($item->overall_total + $pf_form_total[$c] + $gf_form_total[$c])]; 
																	} else {
																		$item_booking_total[$cart_package_uid] += ($item->overall_total + $pf_form_total[$c] + $gf_form_total[$c]);
																	}
																	$total_value[$c] = $item->overall_total + $pf_form_total[$c] + $gf_form_total[$c]; 
																	$cart_subtotal_analytics += ($pf_form_total[$c] + $gf_form_total[$c]);
																	$total_value[$c] = ($total_value[$c] < 0 ) ? 0 : $total_value[$c]; 	
																?>

																		<span class="rezgo-item-total" id="total_value_<?php echo esc_attr($c); ?>" rel="<?php echo esc_attr($total_value[$c]); ?>">
																			<?php echo esc_html($site->formatCurrency($total_value[$c])); ?>
																		</span>
																		<input type="hidden" id="total_extras_<?php echo esc_attr($c); ?>" value="" />
																	</td>
																</tr>

															<?php if($site->exists($item->deposit)) { ?>

																<?php if ($item->deposit_full_enabled) { 
																		$deposit_full_total_value[$c] = $item->deposit_full + $pf_form_total[$c] + $gf_form_total[$c]; 
																		$item_deposit_total[$cart_package_uid] += $deposit_full_total_value[$c];
																		$mixed_deposit_total[$cart_package_uid] += $deposit_full_total_value[$c];
																		$complete_booking_total += $deposit_full_total_value[$c];
																	} else { 
																		$complete_booking_total += $item->deposit_value;
																		$mixed_deposit_total[$cart_package_uid] += $item->deposit_value;
																		$item_deposit_total[$cart_package_uid] += $item->deposit_value;
																		$total_deposit_set = array($cart_package_uid => 1); ?>

																<tr class="rezgo-tr-subtotal package-item-total">
																	<td colspan="3" class="text-end">
																		<span class="push-right"><strong>Item Deposit Total</strong></span>
																	</td>
																	<td class="text-end">
																		<span class="rezgo-item-deposit" id="deposit_value_<?php echo esc_attr($c); ?>" rel="<?php echo esc_attr($item->deposit_value); ?>">
																			<?php echo esc_html($site->formatCurrency($item->deposit_value)); ?>
																		</span>
																	</td>
																</tr>

                                                            	<?php } // if ($item->deposit_full_enabled) ?>
									
															<?php } else { ?>

                               
							   									<?php 
																	$complete_booking_total += (float) $total_value[$c]; 
																	$mixed_deposit_total[$cart_package_uid] += (float) $total_value[$c]; 
																?>

															<?php } ?>

															</tbody><!-- summary total items -->
															
															<tbody class="rezgo-gc-box" style="display:none">
																<tr class="rezgo-tr-gift-card">
																	<td colspan="3" class="text-end">
																		<span class="push-right"><strong>Gift Card</strong></span>
																	</td>
																	<td class="text-end">
																		<strong><span>-</span> <span class="cur"></span><span class="rezgo-gc-min"></strong></span>
																	</td>
																</tr>
															</tbody>

															<?php if ($last){ ?>
																
																<td colspan="3" class="rezgo-td-grouped-line-item text-end"></td>
																<td class="rezgo-td-grouped-line text-end"><i class="fad fa-horizontal-rule"></i></td>

																	<tr class="rezgo-tr-package-subtotal tr-package-total" data-package-id="<?php echo esc_attr($c); ?>">
																		<td colspan="3" class="text-end"><span class="push-right"><strong>Package Total</strong></span></td>
																		<td class="text-end"><span class="rezgo-package-total" id="rezgo_package_total_<?php echo esc_attr($cart_package_uid); ?>" rel="<?php echo esc_attr($item_booking_total[$cart_package_uid]); ?>"></span><strong><?php echo esc_html($site->formatCurrency($item_booking_total[$cart_package_uid])); ?></strong></td>
																	</tr>

																<?php //if((int)$total_deposit_set[$cart_package_uid] === (int)$item->package_item_total) { ?>

																<?php if (isset($total_deposit_set[$cart_package_uid])) { ?>
																	<?php if ( ((int)$total_deposit_set[$cart_package_uid] === (int)$item->package_item_total) || 
																			((int)$total_deposit_set[$cart_package_uid] > 0 && ((int)$total_deposit_set[$cart_package_uid] < (int)$item->package_item_total))   
																		) { 
																			$mixed_deposit = ((int)$total_deposit_set[$cart_package_uid] > 0 && ((int)$total_deposit_set[$cart_package_uid] < (int)$item->package_item_total)) ? 1 : 0;
                                                                   		 	$deposit_wording = $mixed_deposit ? 'Required to Pay Now' : 'Amount to Pay Now';
																			$deposit_package_total = $mixed_deposit ? $mixed_deposit_total[$cart_package_uid] : $item_deposit_total[$cart_package_uid];
																		?>

																		<tr class="rezgo-tr-deposit rezgo-tr-package-deposit_<?php echo esc_attr($cart_package_uid); ?>">
																			<td colspan="3" class="text-end">
																				<span class="push-right"><strong><?php echo esc_html($deposit_wording); ?></strong></span>
																			</td>
																			<td class="text-end">
																				<span id="rezgo_package_deposit_<?php echo esc_attr($cart_package_uid); ?>" rel="<?php echo esc_attr($deposit_package_total); ?>">	
																					<strong><?php echo esc_html($site->formatCurrency($deposit_package_total)); ?></strong>
																				</span>
																			</td>
																		</tr> 

																	<?php } ?>	
																<?php } ?>	
																
																<tbody class="append-package-gc append-package-gc-<?php echo esc_attr($item->cart_package_uid); ?>" style="display:none;"></tbody>

															<?php } // if ($last) ?>

														</table>
													</div>
												</div>
											</div>

											<?php if ($last) {
												$item_count++;
												echo '<hr class="confirm-billing-item-line">';
											} ?>

										<?php } else { ?>

										<div id="rezgo-book-step-two-item-<?php echo esc_attr($item->uid); ?>" class="rezgo-form-group rezgo-booking-info">
											<h3 class="rezgo-booking-of rezgo-booking-title">
												<div class="rezgo-sub-title">
													<span>Booking <?php echo esc_html($item_count); ?> of <?php echo esc_html($cart_count); ?></span>
												</div>
											</h3>

											<h3 class="rezgo-item-title"><?php echo esc_html($item->item); ?> &mdash; <?php echo esc_html($item->option); ?></h3>	

											<div class="">
												<table class="rezgo-table-list" border="0" cellspacing="0" cellpadding="2">

													<?php if(in_array((string) $item->date_selection, DATE_TYPES)) { ?>
														<label>
															<span>Date: </span>
															<span class="lead"><?php echo esc_html(date((string) $company->date_format, (int) $item->booking_date)); ?></span>
														</label> 
														<?php if ($site->exists($item->time)){ ?>
															<label>&nbsp; at <?php echo (string) esc_html($item->time); ?></label>
														<?php } ?> 
													<?php } else { ?>
														<label><span class="lead"> Open Availability </span></label>
													<?php } ?>

													<?php if($item->duration != '') { ?>
														&nbsp;- <label class="rezgo-duration"><span class="lead">(Duration: <?php echo esc_html($item->duration); ?>)</span></label> 
													<?php } ?>

													<?php if($item->discount_rules->rule) {
														echo '<br><label class="rezgo-booking-discount">
														<span class="rezgo-discount-span">Discount:</span> ';
														$discount_string = '';
														foreach($item->discount_rules->rule as $discount) {	
															$discount_string .= ($discount_string) ? ', '.$discount : $discount;
														}
														echo '<span class="rezgo-promo-code-desc">'.esc_html($discount_string).'</span>
														</label>';
													} ?>

												</table>
											</div>

											<div class="rezgo-form-group rezgo-cart-table-wrp rezgo-table-container">
												<div class="col-12 col-wrapper">
													<table class="table table-responsive rezgo-billing-cart" id="<?php echo esc_attr($item->uid); ?>" data-book-id="<?php echo esc_attr($c); ?>">
														<tr class="rezgo-tr-head">
															<td class="text-start rezgo-billing-type"><label>Type</label></td>
															<td class="text-start rezgo-billing-qty"><label class="d-none d-sm-block">Qty.</label></td>
															<td class="text-start rezgo-billing-cost"><label>Cost</label></td>
															<td class="text-end rezgo-billing-total"><label>Total</label></td>
														</tr>

														<?php foreach($site->getTourPrices($item) as $price) { ?>

															<?php if($item->{$price->name.'_num'}) { ?>
																<tr class="rezgo-tr-pax">
																	<td class="text-start"><?php echo esc_html($price->label); ?></td>
																	<td class="text-start" ><?php echo esc_html($item->{$price->name.'_num'}); ?></td>
																	<td class="text-start">
																		<?php
																			$initial_price = isset($price->price) ? (float) $price->price : 0;
																			$strike_price = isset($price->strike) ? (float) $price->strike : 0;
																			$discount_price = isset($price->base) ? (float) $price->base : 0;
																			if ($price->discount) $cart_discount[$item_count] += (float) ($price->discount * $price->count);
																		?>
																		<?php if ( ($site->exists($price->strike)) && (isset($price->base) && $site->exists($price->base)) )  { ?>
																			<?php $show_this = max($strike_price, $discount_price); ?>

																			<span class="discount">
																				<?php echo esc_html( $site->formatCurrency($show_this)); ?>
																			</span>

																		<?php } else if($site->exists($price->strike)) { ?>

																				<!-- show only if strike price is higher -->
																				<?php if ($strike_price >= $initial_price) { ?>
																					<span class="discount">
																						<span class="rezgo-strike-price">
																							<?php echo esc_html($site->formatCurrency($strike_price)); ?>
																						</span>
																					</span>
																				<?php } ?>

																		<?php } else if(isset($price->base) && $site->exists($price->base)) { ?>

																			<span class="discount">
																				<?php echo esc_html($site->formatCurrency($price->base)); ?>
																			</span>

																		<?php } ?>
																			<?php echo esc_html($site->formatCurrency($price->price)); ?>
																	</td>		
																	<td class="text-end">
																		<span>
																			<?php echo esc_html($site->formatCurrency($price->total)); ?>
																		</span>
																	</td>
																</tr>
																<?php if(isset($price->vat) && $price->vat > 0) { ?>
																	<tr class="rezgo-tr-vat">
																		<td colspan="4" class="text-start">
																			&nbsp;&nbsp;&nbsp;&nbsp;Includes <?php echo esc_html($price->vat_label . ' (' . $price->vat . '%)'); ?>
																		</td>
																	</tr>
																<?php } ?>
															<?php } ?>
														<?php } ?>

														<tr class="rezgo-tr-subtotal">
															<td colspan="3" class="text-end" style="padding-top:15px;"><span class="push-right"><strong>Subtotal</strong></span></td>
                                                            <td class="text-end text-nowrap" style="padding-top:15px;"><span><?php echo esc_html($site->formatCurrency($item->sub_total)); ?></span></td>
														</tr>

														<?php $line_items = $site->getTourLineItems(); ?>
									
														<?php 	
															$pax_totals = array(
																'adult_num' => 'price_adult', 
																'child_num' => 'price_child', 
																'senior_num' => 'price_senior', 
																'price4_num' => 'price4', 
																'price5_num' => 'price5', 
																'price6_num' => 'price6', 
																'price7_num' => 'price7', 
																'price8_num' => 'price8', 
																'price9_num' => 'price9'
															);
														?>

															<?php foreach($line_items as $line) { ?>
																<?php $label_add = ''; ?>

																<?php if($site->exists($line->percent) || $site->exists($line->multi)) {
																		$label_add = ' (';

																	if($site->exists($line->percent)) {
																		$label_add .= $line->percent.'%';
																	}

																		if($site->exists($line->multi)) {
																			if(!$site->exists($line->percent)) {
																				$label_add .= $site->formatCurrency($line->multi);
																			}
																			
																			if($site->exists($line->meta)) {
																				
																				$line_pax = 0;
																				foreach ($pax_totals as $p_num => $p_rate) {
																					
																					if ( (int) $item->{$p_num} > 0 && ((float) $item->date->{$p_rate} > (float) $line->meta)) {
																						$line_pax += (int) $item->{$p_num};
																					}
																					
																				}
																				$label_add .= ' x '.$line_pax;
																				
																			} else {
																				$label_add .= ' x '.$item->pax;
																			}
																		}

																		$label_add .= ')';
																	} 
																		
																	?>

														<tr class="rezgo-tr-subtotal">
															<td colspan="3" class="text-end">
															<?php if ($line->source == 'bundle') { ?>
															<strong class="rezgo-line-bundle push-right"></i>&nbsp;<?php echo esc_html($line->label); ?><?php echo esc_html($label_add); ?> (Bundle)</strong></span>
															 <?php } else { ?>
                                                                        <span class="push-right">
																			<strong><?php echo esc_html($line->label); ?><?php echo esc_html($label_add); ?></strong>
																			<?php if($line->vat) { ?>
																				<br>
																				<span class="rezgo-line-vat">
																					Includes <?php echo esc_html((string)$line->vat->label . ' (' . (float)$line->vat->amount . '%)'); ?>
																				</span>
																			<?php } ?>
																		</span>
                                                                    <?php } ?>
															</td>
                                                            <td class="text-end text-nowrap"><?php echo esc_html($site->formatCurrency($line->amount)); ?></td>
														</tr> 

														<?php } //foreach($line_items as $line) ?>	

														<tbody id="line_item_box_<?php echo esc_attr($c); ?>" class="rezgo-line-item-box" data-line-uid="<?php echo esc_attr($item->uid); ?>" data-book-id="<?php echo esc_attr($c); ?>">
														</tbody><!-- line items -->
														<input type="hidden" id="rezgo-pickup-line-<?php echo esc_attr($c); ?>" value="" />

														<tbody id="fee_box_<?php echo esc_attr($c); ?>" class="rezgo-fee-box">
														</tbody><!-- extra fees -->

														<tbody id="line_item_box_<?php echo esc_attr($c); ?>" class="rezgo-form-display-box" data-line-uid="<?php echo esc_attr($item->uid); ?>" data-book-id="<?php echo esc_attr($c); ?>">

														<?php 
															$pf_form_total[$c] = 0;
															if ($form_display) {

															$primary_forms = $form_display[$c-1]->primary_forms;
															if ($primary_forms->count()){
																foreach ($primary_forms->form as $form){
																	if (((float)$form->price != 0 && $form->value == 'on') || ($form->status == 'on')) { ?>
																		<tr class="rezgo-tr-form-display">
																			<td colspan="3" class="text-end rezgo-line-item">
																				<strong class="push-right">
																					<?php echo '1 <i class="far fa-times" style="position:relative; top:1px;"></i>'; ?>
																					<?php echo esc_html($form->title); ?>
																					<?php echo $form->select_price_option ? esc_html('('.$form->select_price_option.')') : ''; ?>
																				</strong>
																				<?php if ($form->vat) { ?> 
																					<br>
																					<span class="rezgo-line-vat">
																						Includes <?php echo esc_html((string)$form->vat->label . ' (' . (float)$form->vat->amount . '%)'); ?>
																					</span>
																				<?php } ?>
																			</td>

                                                                            <td class="text-end text-nowrap">
																				<span class="rezgo-form-display-total_<?php echo esc_attr($c); ?>" rel="<?php echo esc_attr($form->price); ?>"><?php echo esc_html($site->formatCurrency($form->price)); ?></span>
																			</td>
																		</tr>
																	<?php $pf_form_total[$c] += $form->price; ?>
																	<?php } ?>
																<?php } ?>
															<?php } ?>
														<?php } ?>

														<?php 
															$gf_form_total[$c] = 0;
															if ($gf_form_display) {
                                                                $gf_array = $gf_vat = array();

																if (isset($gf_form_display[$c-1])) {
																	$group_forms = $gf_form_display[$c-1];
																	foreach ($group_forms as $form){
																		if (((float)$form->price != 0 && $form->value == 'on') || ($form->status == 'on')) {
																			$gf_array[] = (string) $form->title . '|||' . (string) $form->price. '|||' . (string) $form->select_price_option;
																			if ($form->vat) {
																				$gf_vat[(string) $form->title] = (string)$form->vat->label . '|||' . (float)$form->vat->amount;
																			}
																		}
																	}

																	$gf_line = array_count_values($gf_array);
																	foreach ($gf_line as $k => $count) {
																		$result = explode('|||', $k);
																		$title = $result[0];
																		$price = $result[1];
																		$select_price_option = $result[2]; ?>

																		<tr class="rezgo-tr-form-display">
																			<td colspan="3" class="text-end rezgo-line-item">
																				<strong class="push-right">
																					<?php echo esc_html($count) .' <i class="far fa-times" style="position:relative; top:1px;"></i>'; ?>
																					<?php echo esc_html($title); ?>
																					<?php echo $select_price_option ? esc_html('('.$select_price_option.')') : ''; ?>
																					<?php $price = $price * $count; ?>
																				</strong>
																				<?php if (isset($gf_vat[$title])) { 
																					$gf_vat_values = explode('|||', $gf_vat[$title]);
																					$vat_label = $gf_vat_values[0];
																					$vat_amount = $gf_vat_values[1]; ?> 
																					<br>
																					<span class="rezgo-line-vat">
																						Includes <?php echo esc_html($vat_label . ' (' . $vat_amount . '%)'); ?>
																					</span>
																				<?php } ?>
																			</td>
                                                                        	<td class="text-end text-nowrap">
																				<span class="rezgo-form-display-total_<?php echo esc_attr($c); ?>" rel="<?php echo esc_attr($price); ?>"><?php echo esc_html($site->formatCurrency($price)); ?></span>
																			</td> 
																		</tr>
																		<?php $gf_form_total[$c] += $price; ?>
																<?php } ?>
															<?php } ?>
														<?php } ?>
														
														</tbody><!-- form_display items -->

														<tbody class="rezgo-form-summary-box" data-line-uid="<?php echo esc_attr($item->uid); ?>" data-book-id="<?php echo esc_attr($c); ?>">

														<tr class="rezgo-tr-total summary-total">
															<td colspan="3" class="text-end">
																<span class="push-right"><strong>Total</strong></span>
															</td>
                                                            <td class="text-end text-nowrap">
																<?php 
																	$total_value[$c] = $item->overall_total + $pf_form_total[$c] + $gf_form_total[$c]; 
																	$total_value[$c] = ($total_value[$c] < 0 ) ? 0 : $total_value[$c]; 
																	$cart_subtotal_analytics += ($pf_form_total[$c] + $gf_form_total[$c]);
																?>
																<span class="rezgo-item-total" id="total_value_<?php echo esc_attr($c); ?>" rel="<?php echo esc_attr($total_value[$c]); ?>">
																	<?php echo esc_html($site->formatCurrency($total_value[$c])); ?>
																</span>
																<input type="hidden" id="total_extras_<?php echo esc_attr($c); ?>" value="" />
															</td>
														</tr>

														<tbody class="rezgo-gc-box" style="display:none">
															<tr class="rezgo-tr-gift-card">
																<td colspan="3" class="text-end">
																	<span class="push-right"><strong>Gift Card</strong></span>
																</td>
																<td class="text-end">
																	<strong><span>-</span> <span class="cur"></span><span class="rezgo-gc-min"></strong></span>
																</td>
															</tr>
														</tbody>

														<?php if($site->exists($item->deposit)) { ?>

															<?php 
																if ($item->deposit_full_enabled) { 
																	$deposit_full_total_value[$c] = $item->deposit_full + $pf_form_total[$c] + $gf_form_total[$c]; 
																	$complete_booking_total += $deposit_full_total_value[$c]; 
																} else { 
																	$complete_booking_total += $item->deposit_value; ?>

																<tr class="rezgo-tr-deposit">
																	<td colspan="3" class="text-end">
																		<span class="push-right"><strong>Deposit to Pay Now</strong></span>
																	</td>
																	<td class="text-end text-nowrap">
																		<strong class="rezgo-item-deposit" id="deposit_value_<?php echo esc_attr($c); ?>" rel="<?php echo esc_attr($item->deposit_value); ?>">
																			<?php echo esc_html($site->formatCurrency($item->deposit_value)); ?>
																		</strong>
																	</td>
																</tr>

															<?php } // if ($item->deposit_full_enabled) ?>

														<?php } else { ?>
								
															<?php $complete_booking_total += (float) $total_value[$c]; ?>

														<?php } ?>

														</tbody><!-- summary total items -->
													</table>
												</div>
											</div>
										</div>

										<hr class="confirm-billing-item-line">

                                    <?php $item_count++;
                                    } // end if ($site->exists($item->package_item_total)) 
                                    ?>

                                <?php } else {
                                    $cart_count--;
                                } // end if((int) $item->availability >= (int) $item->pax_count) 
                                ?>

								<script>
									split_total[<?php echo $c; ?>] = <?php echo $total_value[$c]; ?>;
								</script>

                            <?php $index++;
                            } // end foreach($cart as $item ) 
                            ?>

							<script>
								overall_total = '<?php echo esc_html($complete_booking_total); ?>';
							</script>

							<!-- BOOKING TOTAL -->						
							<div class="rezgo-total-payable-wrp">
								<div class="row">
									<div class="rezgo-total-payable">
										
										<span id="rezgo_table_tips" class="flex-row" style="display:none;"></span>

										<div class="flex-row align-center">
											<h5>Total Due</h5> &nbsp; &nbsp; <span id="total_value" rel="<?php echo esc_attr($complete_booking_total); ?>"><?php echo esc_html($site->formatCurrency($complete_booking_total)); ?></span>
											<br>
											<input type="hidden" id="expected" name="expected" value="<?php echo esc_attr($complete_booking_total); ?>"/>
										</div>
										
									</div>
													
									<div class="clearfix visible-xs"></div>
								</div>
							</div>
							<div id="rezgo-review-order-memo"></div>
							<hr>

							<!-- WAIVER -->
							<?php
								$waiver = 0;
								$waiver_ids = '';
								foreach ($cart as $item) {
									if ((int) $item->waiver === 1 && (int) $item->waiver['type'] === 0) {
										$waiver++;
										$waiver_ids .= $item->uid . ',';
									}
								}
								?>
								<?php if ($waiver >= 1) { ?>
									<div id="rezgo-waiver-use">
										<div id="rezgo-waiver" class="row rezgo-form-group rezgo-booking">
											<div class="col-12">
												<h3 class="text-info"><span>Waiver</span></h3>

												<div class="row">
													<div id="rezgo-waiver-info" class="col-12">
														<div class="msg intro">
															<span>You must read and sign the liability waiver to complete this order.</span>
														</div>

														<div class="msg success" style="display:none">
															<i class="fa fa-check" aria-hidden="true"></i>
															<span>Thank you for signing the waiver.</span>
														</div>

														<div class="msg error" style="display:none">
															<i class="fa fa-times" aria-hidden="true"></i>
															<span>Waiver signature is required.</span>
														</div>
													</div>
													
													<div class="row">
														<div id="rezgo-waiver-read-btn" class="col-xs-5 col-lg-5">
															<span class="btn-check"></span>
															<button id="rezgo-waiver-show" class="btn rezgo-btn-default btn-lg btn-block" type="button" data-ids="<?php echo rtrim(esc_attr($waiver_ids), ','); ?>">
																<span><i class="far fa-edit"></i>&nbsp;<span class="rezgo-read-waiver"><span>read and sign waiver</span></span></span>
															</button>
														</div>

														<div id="rezgo-waiver-signature" class="col-xs-7 col-lg-7">
															<img class="signature" style="display:none">
														</div>
													</div>

													<input id="rezgo-waiver-input" name="waiver" type="text" value="" required />
													<span id="append_initial_inputs"></span>

														<script>
														jQuery(function($) {
															// check for signature in localStorage
															if (localStorage['signature']){
																let signature = localStorage['signature'];

																$('img.signature').attr('src', signature);
																$('img.signature').show();

																$('.msg.intro').hide();
																$('.msg.success').show();

																// check for signature_url in localStorage
																if (localStorage['signature_url']){
																	let signature_url = localStorage['signature_url'];
																	$('#rezgo-waiver-input').val(String(signature_url));
																}
															}
														});
														</script>
												</div>
											</div>
										</div>
										<hr>
									</div>

							<?php } ?>

								<div class="payment-select-container rezgo-form-group">
										<h3 class="text-info" id="payment_info_head">									
											<span> 2. Payment</span>
										</h3>

										<!-- GIFT CARD -->
										<div id="rezgo-gift-card-use">
											<div class="row">
												<div class="col-12">
													<?php require 'gift_card_redeem.php'; ?>
												</div>
											</div>
											<input type="hidden" name="gift_card">
										</div>
										<hr id="rezgo-gift-card-use-hr">

										<div class="rezgo-payment-frame" id="payment_info">
											<p class="select-payment"><span>Select a payment method</span></p>
											<!-- PAYMENT MODULE -->
											<?php require 'payment_module.php'; ?>
											<div id="rezgo-payment-method-memo"></div>
											<hr>
										</div><!-- // #payment_info -->

									</div><!-- // payment-select-container -->

								<?php if ($billing_address) { ?> 
									<!-- BILLING INFO -->
									<div class="rezgo-billing-wrp" style="display:none;">
										<div class="row">
											<div class="col-12">

												<h3 id="rezgo-billing-information-header" class="text-info">
													<span>
														3. Billing Information &nbsp;
													</span>

													<span id="rezgo-copy-pax-span" style="display:none">
														<br class="visible-xs-inline" />
														<input type="checkbox" name="copy_pax" id="rezgo-copy-pax" />
														<span id="rezgo-copy-pax-desc" class="rezgo-memo">Use first guest information</span>
													</span>
												</h3>

												<div class="form-group">
													<label for="tour_address_1" class="control-label">Address</label>

													<div class="rezgo-form-input col-12">
														<input type="text" class="form-control required" id="tour_address_1" name="tour_address_1" placeholder="Address 1" />
													</div>
													<div class="rezgo-form-input col-12">
														<input type="text" class="form-control" id="tour_address_2" name="tour_address_2" placeholder="Address 2 (optional)" />
													</div>
												</div>

												<div class="form-group">
													<div class="rezgo-form-row">
														<div class="col-12 rezgo-form-input">
															<label for="tour_city" class="control-label col-sm-8 col-12 rezgo-form-label">City</label>
															<input type="text" class="form-control required" id="tour_city" name="tour_city" placeholder="City" />
														</div>
													</div>
												</div>

												<div class="form-group">
													<div class="rezgo-form-row">
														<div class="col-12 rezgo-form-input">
															<label for="tour_postal_code" class="control-label col-12 d-xl-block rezgo-form-label">Zip/Postal</label>
															<input type="text" class="form-control required" id="tour_postal_code" name="tour_postal_code" placeholder="Zip/Postal Code" />
														</div>
													</div>
												</div>

												<div class="form-group">
													<div class="rezgo-form-row">
														<div class="col-12 rezgo-form-input">
															<label for="tour_country" class="control-label rezgo-form-label">Country</label>
															<select class="form-select required" name="tour_country" id="tour_country">
																<option value=""></option>
																<?php foreach ($site->getRegionList() as $iso => $name) { ?>
																	<option value="<?php echo esc_attr($iso); ?>" <?php echo (($iso == $companyCountry) ? 'selected' : ''); ?>><?php echo ucwords(esc_html($name)); ?></option>
																<?php } ?>
															</select>
														</div>
													</div>
												</div>

												<div class="form-group">
													<div class="rezgo-form-row">
														<div class="col-12 rezgo-form-input">
															<div class="rezgo-form-row">
																<label for="tour_stateprov" class="control-label col-12 rezgo-form-label">State/Prov</label>
															</div>
															<select class="form-select" id="tour_stateprov" style="display:<?php echo (($companyCountry != 'ca' && $companyCountry != 'us' && $companyCountry != 'au') ? 'none' : ''); ?>;"></select>
															<input id="tour_stateprov_txt" class="form-control" name="tour_stateprov" type="text" value="" style="display:<?php echo (($companyCountry != 'ca' && $companyCountry != 'us' && $companyCountry != 'au') ? '' : 'none'); ?>;" />
														</div>
													</div>
												</div>

												<div class="form-group">
													<div class="rezgo-form-row">
														<div class="col-12 rezgo-form-input">
															<label for="tour_phone_number" class="control-label rezgo-form-label">Phone</label>
															<input type="text" class="form-control required" id="tour_phone_number" name="tour_phone_number" placeholder="Phone" />
														</div>
													</div>
												</div>
											</div>
										</div>

										<hr>
									</div>
								<?php } // if ($billing_address) ?>
                                
                                <input type="hidden" name="validate[language]" id="validate_language" value="">
                                <input type="hidden" name="validate[height]" id="validate_height" value="">
                                <input type="hidden" name="validate[width]" id="validate_width" value="">
                                <input type="hidden" name="validate[tz]" id="validate_tz" value="">
                                <input type="hidden" name="validate[agent]" id="validate_agent" value="">
                                <input type="hidden" name="validate[callback]" id="validate_callback" value="">
                                
                                <script>
									jQuery(function($) {
                                    $('#validate_language').val(navigator.language);
                                    $('#validate_height').val(window.innerHeight);
                                    $('#validate_width').val(window.innerWidth);
                                    $('#validate_tz').val(new Date().getTimezoneOffset());
                                    $('#validate_agent').val(navigator.userAgent);
                                    $('#validate_callback').val(window.location.protocol + '//' + window.location.hostname + '<?php echo esc_html($site->base); ?>' + '/3DS');
									});
                                </script>

							<!-- PAYMENT INFO -->
							<div id="rezgo-payment-wrp">
								<div class="row">
									<div class="col-12">
                                        <div class="rezgo-form-row rezgo-terms-container">
                                            <div class="col-sm-12 rezgo-payment-terms">
                                                <div class="rezgo-form-input">

                                                    <div class="checkbox">
                                                        <label id="rezgo-terms-check">

                                                            <input type="checkbox" class="required" id="agree_terms" name="agree_terms" value="1"/>
                                                            <span>I agree to the </span>
                                                        </label>

                                                        <a data-toggle="collapse" class="rezgo-terms-link" onclick="jQuery('#rezgo-privacy-panel').hide(); jQuery('#rezgo-terms-panel').toggle();">
                                                            <span>Terms and Conditions</span>
                                                        </a>
                                                        and
                                                        <a data-toggle="collapse" class="rezgo-terms-link" onclick="jQuery('#rezgo-terms-panel').hide(); jQuery('#rezgo-privacy-panel').toggle();">
                                                            <span>Privacy Policy</span>
                                                        </a>

                                                        <div id="rezgo-terms-panel" class="collapse rezgo-terms-panel">
                                                            <?php echo wp_kses($site->getPageContent('terms'), ALLOWED_HTML); ?>
                                                        </div>

                                                        <div id="rezgo-privacy-panel" class="collapse rezgo-terms-panel">
                                                            <?php echo wp_kses($site->getPageContent('privacy'), ALLOWED_HTML); ?>
                                                        </div>

                                                    </div>
                                                    
                                                </div>

                                            </div>
                                        </div>
                                        
                                        <?php if ($company->marketing_consent == 1) { ?>
                                            <div class="rezgo-form-row rezgo-terms-container">
                                                <div class="col-sm-12 rezgo-payment-terms">
                                                    <div class="rezgo-form-input">
    
                                                        <div class="checkbox">
                                                            <label id="rezgo-marketing-terms-label">
                                                                <input type="checkbox" id="marketing_consent" name="marketing_consent" value="1"/>
                                                                <span>Please keep me up to date with news from <?php echo esc_html($company->company_name); ?></span>
                                                            </label>
                                                        </div>
                                                    
                                                    </div>
    
                                                </div>
                                            </div>
										<?php } ?>

										<div class="rezgo-form-row">
											<div class="col-sm-12 rezgo-payment-terms">

												<div id="rezgo-book-terms">
													<div class="help-block" id="terms_credit_card" style="display:<?php if(!$site->getPaymentMethods('Credit Cards')) { ?>none<?php } ?> ;">
														<?php if ($site->getGateway()) { ?>
															<?php if ($complete_booking_total > 0) { ?>
																<span class='terms_credit_card_over_zero'>Please note that your credit card will be charged.</span>
																<br>
															<?php } ?>
															<span>If you are satisfied with your entries, please confirm by clicking the 
																<span id="rezgo-book-terms-wording">
																	<span>&quot;Complete Booking&quot;</span>
																</span>
																button.
															</span>
														<?php } else { ?>
															<?php if ($complete_booking_total > 0) { ?>
																<span class='terms_credit_card_over_zero'>Please note that your credit card will not be charged now. Your transaction information will be stored until your payment is processed. Please see the Terms and Conditions for more information.</span>
																<br>
															<?php } ?>
															<span>If you are satisfied with your entries, please click the 
																<span id="rezgo-book-terms-wording">
																	<span>&quot;Complete Booking&quot;</span>
																</span>
																button.
															</span>
														<?php } ?>
													</div>

													<div class="help-block" id="terms_other" style="display:<?php if ($site->getPaymentMethods('Credit Cards')) { ?>none<?php } ?>;">
														<span>If you are satisfied with your entries, please confirm by clicking the 
															<span id="rezgo-book-terms-wording">
																<span>&quot;Complete Booking&quot;</span>
															</span>
															button.
														</span>
													</div>
												</div>

												<div id="rezgo-book-message" class="row" style="display:none;">
													<div id="rezgo-book-message-body" class="col-sm-8 offset-sm-2"></div>
                         							 <div id="rezgo-book-message-wait" class="col-sm-2"><i class="far fa-sync fa-spin fa-3x fa-fw"></i></div>
												</div>
											</div>
                                          
										</div>

									</div>
								</div>
							</div> <!-- payment wrp -->

								<?php if (DEBUG) { ?>
									<div id="debug_container" class="text-center" style="display:none;">
										<p> DEBUG API REQUEST </p>
										<textarea id="api_request_debug" readonly="readonly" rows="10"></textarea>
										<hr>
										<button id="api_send_request" class="btn btn-default" >Send Request</button>
									</div>

									<script>
										jQuery(function($) {
											$('#api_send_request').click(function(e){
												e.preventDefault();
												submit_payment();
											})
										});
									</script>
								<?php } ?>

								<div id="rezgo-book-errors-wrp">
                                    <div id="rezgo-book-errors" class="" style="display:none;">
                                        <span>Some required fields are missing. Please complete the highlighted fields.</span>
                                    </div>
                                </div> <!-- // book errors -->

								<div id="rezgo-complete-booking-memo"></div>
								<div id="rezgo-book-step-two-nav" class="rezgo-booking-nav">
									<div class="col-sm-12 col-12 rezgo-btn-wrp rezgo-complete-btn-wrp">
										<span class="btn-check"></span>
										<button type="submit" class="btn rezgo-btn-book btn-lg btn-block" id="rezgo-complete-payment">
											<span>
												Complete Booking
												<?php if ($complete_booking_total > 0) { ?>
													of <span id="complete_booking_total"><?php echo $site->formatCurrency($complete_booking_total, $company); ?></span>
												<?php } ?>
											</span>
										</button>
									</div>

									<div id="rezgo-bottom-cta">
										<span class="btn-check"></span>
										<button class="btn btn-lg btn-block" type="button" onclick="<?php echo LOCATION_WINDOW; ?>.location.href='<?php echo $site->base; ?>/book';">
											<span>Previous Step</span>
										</button>
									</div>
								</div>
							</div> <!-- checkout container --> 

							<?php if($cart) { ?>
								<!-- FIXED CART -->
								<?php require('fixed_cart.php'); ?>
							<?php } ?> 

							</div> <!-- flex container -->

						</div>
						<?php } // if ($cart) ?>
					</div>
					<?php if(REZGO_CAPTCHA_PUB_KEY) { ?>	
						<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
					<?php } ?>
				</form>

			</div>
		</div>
	</div>
</div>

<?php if (REZGO_CAPTCHA_PUB_KEY) { ?>
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo REZGO_CAPTCHA_PUB_KEY; ?>"></script>
<?php } ?>
<script>
<?php if ($cart) { ?>

	// hide last line
	jQuery('.confirm-billing-item-line').last().hide();

	function grecaptcha_submit() {
		grecaptcha.execute('<?php echo REZGO_CAPTCHA_PUB_KEY; ?>', {action: 'submit'}).then(function(token) {
			jQuery('#recaptchaResponse').val(token);

			jQuery('#rezgo-payment-form').ajaxSubmit({
				url: '<?php echo admin_url('admin-ajax.php'); ?>' + '?action=rezgo&method=book_ajax',
				data: {rezgoAction: 'book'},
				success: delay_response,
				error: function() {
                    var body = 'Sorry, the system has suffered an error that it can not recover from.<br><br>Please try again later.<br />';
					jQuery('#rezgo-book-message-body').html(body);
					jQuery('#rezgo-book-message-body').addClass('alert alert-warning');
				}
			});

		});
		
	}

	function regular_submit() {
		jQuery('#rezgo-payment-form').ajaxSubmit({
			url: '<?php echo admin_url('admin-ajax.php'); ?>' + '?action=rezgo&method=book_ajax',
			data: {rezgoAction: 'book'},
			success: delay_response,
			error: function () {
				var body = 'Sorry, the system has suffered an error that it can not recover from.<br />Please try again later.<br />';
				jQuery('#rezgo-book-message-body').html(body);
				jQuery('#rezgo-book-message-body').addClass('alert alert-warning');
			}
		});
	}

	// Catch form submissions
	jQuery('#rezgo-payment-form').submit(function(evt) {
		evt.preventDefault();

		<?php if (DEBUG) { ?>
			var validate_check = validate_form();
			if (validate_check) {

			grecaptcha.execute('<?php echo REZGO_CAPTCHA_PUB_KEY; ?>', {action: 'submit'}).then(function(token) {
				jQuery('#recaptchaResponse').val(token);
				// show debug window with update request
				jQuery('#rezgo-payment-form').ajaxSubmit({
					url: '<?php echo admin_url('admin-ajax.php'); ?>' + '?action=rezgo&method=book_ajax',
					data: { rezgoAction: 'commit_debug' },
					success: function(data){
						jQuery('#debug_container').show();
						jQuery('#api_request_debug').html(data);
					}
					});
					
				});
				
			} else {
				return error_payment();
			}

		<?php } else { ?>

			submit_payment();

		<?php } ?>
	});

	jQuery('#tour_country').change(function() {
		var country = jQuery(this).val();
		jQuery('#tour_stateprov').removeOption(/.*/);

		switch (country) {
			case 'ca':
				jQuery('#tour_stateprov_txt').hide();
				jQuery('#tour_stateprov').addOption(ca_states, false).show();
				jQuery('#tour_stateprov_txt').val(jQuery('#tour_stateprov').val());
				break;
			case 'us':
				jQuery('#tour_stateprov_txt').hide();
				jQuery('#tour_stateprov').addOption(us_states, false).show();
				jQuery('#tour_stateprov_txt').val(jQuery('#tour_stateprov').val());
				break;
			case 'au':
				jQuery('#tour_stateprov_txt').hide();
				jQuery('#tour_stateprov').addOption(au_states, false).show();
				jQuery('#tour_stateprov_txt').val(jQuery('#tour_stateprov').val());
				break;
			default:
				jQuery('#tour_stateprov').hide();
				jQuery('#tour_stateprov_txt').val('');
				jQuery('#tour_stateprov_txt').show();
				break;
		}
	});

	jQuery('#tour_stateprov').change(function() {
		var state = jQuery(this).val();
		jQuery('#tour_stateprov_txt').val(state);
	});

	<?php if (in_array($companyCountry, array('ca', 'us', 'au'))) { ?>
		jQuery('#tour_stateprov').addOption(<?php echo esc_html($companyCountry); ?>_states, false);
		jQuery('#tour_stateprov_txt').val(jQuery('#tour_stateprov').val());
	<?php } ?>

	if (typeof String.prototype.trim != 'function') {
		// detect native implementation
		String.prototype.trim = function () {
			return this.replace(/^\s+/, '').replace(/\s+$/, '');
		};
	}

	// change the modal dialog box or pass the user to the receipt depending on the response
	function show_response() {
			 
		let currency_base = jQuery('#currency_base').val();
		let order_value = jQuery('#order_value').val();

		function analytics_purchase() {
			<?php if ($analytics_ga4) { ?>
				// gtag purchase
				gtag("event", "purchase", {
					transaction_id: response.order_code,
					value: parseFloat(<?php echo $cart_subtotal_analytics; ?>),
					tax: <?php echo abs($overall_taxes); ?>,
					currency: "<?php echo esc_html($company->currency_base); ?>",
					<?php echo isset($_COOKIE['rezgo_promo']) ? 'coupon: ' .'"'.esc_html($_COOKIE['rezgo_promo'] ?? $site->cart_trigger_code).'"' . ',': ''; ?>
					<?php echo array_sum($cart_discount) > 0 ? 'discount: ' .esc_html((float)array_sum($cart_discount)). ',': ''; ?>
					items: [
						<?php $tag_index = 1;
							foreach ($cart as $ga4_item){ 
							$new_ga4_price = $ga4_item->package ? $ga4_item->package_item_after_discount : $ga4_item->sub_total;
						?>
						{
							item_id: "<?php echo esc_html($ga4_item->uid); ?>",
							item_name: "<?php echo esc_html(htmlentities(trim($ga4_item->item))); ?>",
							item_category: "<?php echo esc_html(htmlentities(trim($ga4_item->option))); ?>",
							<?php echo isset($_COOKIE['rezgo_promo']) ? 'coupon: ' .'"'.esc_html($_COOKIE['rezgo_promo'] ?? $site->cart_trigger_code).'"' . ',': ''; ?>
							<?php echo $cart_discount[$tag_index] > 0 ? 'discount: ' .esc_html((float)$cart_discount[$tag_index]). ',': ''; ?>
							price: Number(parseFloat(<?php echo esc_html((float) ($new_ga4_price / $ga4_item->pax)); ?>).toFixed(2)),
							affiliation: 'Rezgo',
							quantity: <?php echo esc_html($ga4_item->pax); ?>,
							index: <?php echo esc_html($tag_index); ?>,
						},
					<?php $tag_index++; } unset($tag_index); ?>
					]
				});
			<?php } ?>

			<?php if ($analytics_gtm) { ?>
				// tag manager purchase
				window.dataLayer = window.dataLayer || []; // Check the dataLayer is exists and an array
				window.dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
				window.dataLayer.push({
					event: "purchase",
					ecommerce: {
						transaction_id: response.order_code,
						value: parseFloat(<?php echo $cart_subtotal_analytics; ?>),
						tax: <?php echo abs($overall_taxes); ?>,
						currency: "<?php echo esc_html($company->currency_base); ?>",
						<?php echo isset($_COOKIE['rezgo_promo']) ? 'coupon: ' .'"'.esc_html($_COOKIE['rezgo_promo'] ?? $site->cart_trigger_code).'"' . ',': ''; ?>
						<?php echo array_sum($cart_discount) > 0 ? 'discount: ' .esc_html((float)array_sum($cart_discount)). ',': ''; ?>
						items: [
							<?php $tag_index = 1;
								foreach ($cart as $gtm_item){ 
								$new_gtm_price = $gtm_item->package ? $gtm_item->package_item_after_discount : $gtm_item->sub_total;
							?>
							{
								item_id: "<?php echo esc_html($gtm_item->uid); ?>",
								item_name: "<?php echo esc_html(htmlentities(trim($gtm_item->item))); ?>",
								item_category: "<?php echo esc_html(htmlentities(trim($gtm_item->option))); ?>",
								price: Number(parseFloat(<?php echo esc_html((float) ($new_gtm_price / $gtm_item->pax)); ?>).toFixed(2)),
								affiliation: 'Rezgo',
								quantity: <?php echo esc_html($gtm_item->pax); ?>,
								<?php echo isset($_COOKIE['rezgo_promo']) ? 'coupon: ' .'"'.esc_html($_COOKIE['rezgo_promo'] ?? $site->cart_trigger_code).'"' . ',': ''; ?>
								<?php echo $cart_discount[$tag_index] > 0 ? 'discount: ' .esc_html((float)$cart_discount[$tag_index]). ',': ''; ?>
								index: <?php echo esc_html($tag_index); ?>,
							},
							<?php $tag_index++; } unset($tag_index); ?>
						]
						},
						user_data: {
							email: '<?php echo $lead_passenger['email'] ?: ''; ?>',                     
							phone_number: jQuery('#tour_phone_number').val() ? jQuery('#tour_phone_number').val() : '',      
							address: {
								first_name: '<?php echo $lead_passenger['first_name'] ?: ''; ?>',
								last_name:'<?php echo $lead_passenger['last_name'] ?: ''; ?>',
								street:  jQuery('#tour_address_1').val() ? jQuery('#tour_address_1').val() : '',
								city: jQuery('#tour_city').val() ? jQuery('#tour_city').val() : '',
								region: jQuery('#tour_stateprov').val() ? jQuery('#tour_stateprov').val() : '',
								postal_code: jQuery('#tour_postal_code').val() ? jQuery('#tour_postal_code').val() : '',
								country: jQuery('#tour_country').val() ? jQuery('#tour_country').val().toUpperCase() : ''
							}
						}
					});
			<?php } ?>
			
			<?php if ($meta_pixel) { ?>
				fbq('track', 'Purchase', { 
					value: parseFloat(<?php echo $cart_subtotal_analytics; ?>),
					currency: "<?php echo esc_html($company->currency_base); ?>",
					contents: [
						<?php $tag_index = 1;
							foreach ($cart as $pixel_item){ 
							$new_pixel_price = $pixel_item->package ? $pixel_item->package_item_after_discount : $pixel_item->sub_total;
						?>
						{
							"id": "<?php echo esc_html($pixel_item->uid); ?>",
							"name": "<?php echo esc_html(htmlentities(trim($pixel_item->item) . ' - ' . trim($pixel_item->option))); ?>",
							"coupon": "<?php echo isset($_COOKIE['rezgo_promo']) ? esc_html($_COOKIE['rezgo_promo']) : esc_html($site->cart_trigger_code); ?>",
							"price": Number(parseFloat(<?php echo esc_html((float) ($new_pixel_price / $pixel_item->pax)); ?>).toFixed(2)),
							"quantity": <?php echo esc_html($pixel_item->pax); ?>,
						},
						<?php $tag_index++; } unset($tag_index); ?>
						]
					}
				);
			<?php } ?>
		}
	 
		response = response.trim();
		
		let title = '';
		let body = '';

        if(response.indexOf('STOP::') != -1) {  // debug handling

            let split = response.split('<br><br>');

            try {
                response = JSON.parse(split[1]);
            } catch (error) {
                response.status = 999;
            }
            
            if (response.status == 1) {
                 split[1] = '<div class="clearfix">&nbsp;</div>BOOKING COMPLETED WITHOUT ERRORS<div class="clearfix">&nbsp;</div><button type="button" class="btn btn-default" onclick="window.top.location.replace(\'<?php echo esc_js($site->base); ?>/complete/thank-you/' + response.txid + '\');">Continue to Receipt</button><div class="clearfix">&nbsp;</div>';
				 
                analytics_purchase();

            } else if (response.status == '8') {
                // an SCA challenge is required for this transaction
				if(response.direct) {
					// frictionless flow   
					sca_window('direct', null, response.direct, response.pass);
					return false;
				} else {
					// challenge flow
					sca_window('iframe', response.url, response.post, response.pass);
				}
			} else {
				split[1] = '<br /><br />Error Code: ' + response.status + '<br />Error Message: ' + (response.message ?? '') + '<br /> Error Details: ' + (response.error ?? '');
			}
            
            body = 'DEBUG-STOP ENCOUNTERED<br /><br />' + '<textarea id="debug_response">' + split[0] + '</textarea>' + split[1];

        } else {

			console.log(response);
			
            try {
				response = JSON.parse(response);
            } catch (error) {
                response.status = 999;
            }

            if (response.status == '2') {
                title = 'No Availability Left';
                body = 'Sorry, there is not enough availability left for this item on this date.<br />';
            } else if (response.status == '3') {
                title = 'Payment Error';
                body = 'Sorry, your payment could not be completed. Please verify your card details and try again.<br /';
            } else if (response.status == '4') {
                title = 'Booking Error';
                body = 'Sorry, there has been an error with your booking and it can not be completed at this time.<br />';
            } else if (response.status == '5') {
                // this error should only come up in preview mode without a valid payment method set
                title = 'Booking Error';
                body = 'Sorry, you must have a credit card attached to your Rezgo Account in order to complete a booking.<br><br>Please go to "Settings &gt; Rezgo Account" to attach a credit card.<br />';
            } else if (response.status == '6') {
                // this error is returned when expected total does not match actual total
                title = 'Booking Error';
                body = 'Sorry, a price on an item you are booking has changed. Please return to the shopping cart and try again.<br />';
			} else if (response.status == '8') {
				
				// an SCA challenge is required for this transaction
				if(response.direct) {
					// frictionless flow   
					sca_window('direct', null, response.direct, response.pass);
					return false;
				} else {
					// challenge flow
					sca_window('iframe', response.url, response.post, response.pass);
					
					jQuery('#rezgo-complete-payment').val('Complete Booking');
					jQuery('#rezgo-complete-payment').removeAttr('disabled');
				}
				
			} else {
                
                if (response.txid) {
       
                	analytics_purchase();
                    
                    <?php echo LOCATION_WINDOW; ?>.location.replace("<?php echo esc_html($site->base); ?>/complete/thank-you/" + response.txid);
                    return true; // stop the html replace
                    
                } else {
                    
                    title = 'Booking Error';
                    body = 'Sorry, an unknown error has occurred. Our staff have already been notified. Please try again later.<br />';
                    
                }
                
            }
            
        }

		payment_wait(false);
		
		if (body) {
			reset_payment(body);
        }
	}

	// WAIVER
	function receiveMessage(e) {
		// Update the div element to display the message.
		if (e.data.type && e.data.type == 'modal' || e.data.mode == 'order_waiver') {

			var
			waiverInfo = document.getElementById('rezgo-waiver-info'),
			waiverSignature = document.getElementById('rezgo-waiver-signature'),
			waiverInput = document.getElementById('rezgo-waiver-input'),
			waiverIntro = waiverInfo.getElementsByClassName('intro')[0],
			waiverSuccess = waiverInfo.getElementsByClassName('success')[0],
			waiverError = waiverInfo.getElementsByClassName('error')[0],
			signature = waiverSignature.getElementsByClassName('signature')[0];

			signature.src = e.data.sig;

			signature.style.display = 'inline-block';
			waiverIntro.style.display = 'none';
			waiverSuccess.style.display = 'inline-block';
			waiverError.style.display = 'none';
			waiverInput.value = e.data.signature_url;

			jQuery('#rezgo-waiver-wrp').hide();

			<?php echo LOCATION_WINDOW; ?>.jQuery('#rezgo-modal').modal('toggle');

		}
	}
							
	jQuery('#rezgo-waiver-show').click(function(){
		var
		rezgoModalTitle = 'Sign Waiver',
		ids = jQuery(this).data('ids'),
	<?php if (REZGO_WORDPRESS){ ?>
		query = '<?php echo home_url() . esc_html($site->base); ?>?rezgo=1&mode=modal&type=order&sec=1&ids=' + ids + '&title=' + rezgoModalTitle;
	<?php } else { ?>
		query = '/modal?mode=waiver&type=order&sec=1&ids=' + ids;
	<?php } ?>

		<?php echo LOCATION_WINDOW; ?>.jQuery('#rezgo-modal-loader').css({'display':'block'});
		<?php echo LOCATION_WINDOW; ?>.jQuery('#rezgo-modal-iframe').attr('title', rezgoModalTitle);
		<?php echo LOCATION_WINDOW; ?>.jQuery('#rezgo-modal-iframe').attr('src', query).attr('height', '460px');
		<?php echo LOCATION_WINDOW; ?>.jQuery('#rezgo-modal-title').html(rezgoModalTitle);
		<?php echo LOCATION_WINDOW; ?>.rezgoModal.show();
		
		<?php if(REZGO_LITE_CONTAINER) 
		{ ?>
			<?php echo LOCATION_WINDOW; ?>.jQuery('#rezgo-modal').css({'top':0});
		<?php } ?>
	});

	window.addEventListener('message', receiveMessage);
	
	// check if gift card has been applied
	var req = jQuery('#gift-card-number').val()
	gcReq(req);

	jQuery('#rezgo-payment-form').validate({
		rules: {
			tour_email_address: {
				validate_domain: true,
			}
		},
		messages: {
			tour_address_1: {
				required: "Enter your address"
			},
			tour_city: {
				required: "Enter your city"
			},
			tour_postal_code: {
				required: "Enter postal code"
			},
			tour_phone_number: {
				required: "Enter your phone number"
			},
			payment_method: {
				required: "Please select a payment method"
			},
			agree_terms: {
				required: "You must agree to the terms"
			}
		}
	});

	noPaymentMethod = function(total_due){
		if (total_due <= 0) {

			jQuery('#rezgo-gift-card-redeem').hide();
			jQuery('.rezgo-input-radio').not('no-payment').hide();
			jQuery('.rezgo-input-radio.no-payment').show();

			hideSelectPayment();
			setTimeout(() => {
				jQuery("input#no_payment_required").prop("checked", true);
				jQuery('#payment_data').hide();
				jQuery('.payment_method_container').hide();
			}, 350);
			jQuery('.rezgo-billing-wrp').show();

		} else {
			jQuery('#rezgo-gift-card-redeem').show();
			jQuery('.rezgo-input-radio').not('no-payment').show();
			jQuery('.rezgo-input-radio.no-payment').hide();

			setTimeout(() => {
				jQuery("input#no_payment_required").prop("checked", false);
				jQuery('#payment_data').show();
			}, 350);
		}
	}
	noPaymentMethod(<?php echo esc_html($complete_booking_total); ?>);
<?php } // if ($cart) ?>

</script>

<style>#debug_response {width:100%; height:200px;}</style>
<style>#debug_container {width:80%; margin:30px auto;} #debug_container p{margin-bottom: 15px;font-size: 1.5rem; font-weight: 200;}</style>
<style>#api_request_debug {width:100%; height:200px;}</style>