<?php

include_once("../includes/core/initNoSession.php");

?>

<!doctype html>
<html lang="en">

<head>

	<script>
		function p() {
			document.getElementById("prfname").value = document.getElementById("pcfname").value;
			document.getElementById("prlname").value = document.getElementById("pclname").value;
			document.getElementById("prphone").value = document.getElementById("pcphone").value;
			document.getElementById("premail").value = document.getElementById("pcemail").value;
			document.getElementById("praddress").value = document.getElementById("pcaddress").value;
		}

		function b() {
			document.getElementById("brfname").value = document.getElementById("bcfname").value;
			document.getElementById("brlname").value = document.getElementById("bclname").value;
			document.getElementById("brphone").value = document.getElementById("bcphone").value;
			document.getElementById("bremail").value = document.getElementById("bcemail").value;
			document.getElementById("braddress").value = document.getElementById("bcaddress").value;
		}
	</script>


	<style>
		@media (min-width: 200px) {
			.form-control-quantity {
				width: 100%;

			}

			.checkout-container {
				padding: 0px 0px;
			}
		}

		@media (min-width: 600px) {
			.form-control-quantity {
				width: 100%;

			}


			.checkout-products {
				padding-top: 10px;
				padding-bottom: 10px;
				border-top: 1xp solid #99EEF8;

			}

			.checkout-container {
				padding: 5% 5%;
			}
		}

		@media (min-width: 990px) and (max-width: 1799px) {
			.form-control-quantity {
				width: 84px;

			}


			.checkout-products {
				padding-top: 10px;
				padding-bottom: 10px;
				display: -webkit-inline-box;
				border-top: 1xp solid #99EEF8;

			}


			.checkout-container {
				padding: 0% 15%;
			}
		}

		@media (min-width: 1800px) {
			.form-control-quantity {
				width: 84px;

			}

			.checkout-products {
				padding-top: 10px;
				padding-bottom: 10px;
				display: -webkit-inline-box;
				border-top: 1xp solid #99EEF8;

			}

			.checkout-container {
				padding: 0px 25%;
			}
		}

		.checkout-tablebottom {
			border: 1px solid #e0e0e0;
			padding: 20px;
			padding-bottom: 20px;

		}

		.checkout-instructions {
			border: 1px solid #e0e0e0;
			border-bottom: 0px;
			padding: 20px;
		}

		.checkout-li {
			border-bottom: 1px solid #e0e0e0;
			padding-bottom: 15px;
			display: list-item;
			list-style-type: none;
			padding-bottom: 35px;
		}


		.prod-thumbnail {
			padding: 0px;
			width: 100%;

		}

		.row {
			margin-bottom: 10px
		}

		.prod-title-variation {
			padding-left: 10px;
		}

		.checkout-img-info {
			padding: 0px;
			padding-left: 15px;
			text-align: left;

		}

		.checkout-prod-info {
			padding: 0px;
			text-align: center;

		}

		.checkout-img {
			padding: 0px;
		}

		.form-control {
			padding: 4px 40px;
		}

		.checkout-Customer-Info .form-control {
			padding: 4px 5px;
			margin-bottom: 10px
		}

		.checkout-prod-info-r {
			text-align: right;
			font-size: 20px;
			padding: 10px 0px;

		}

		.sign-ro-login {
			padding: 10px 10px;
			background: #99EEF8;
			border-radius: 5px;
			margin-bottom: 10px;
		}

		.place-order {
			margin-top: 20px;

		}

		.btn-place-order {
			margin-top: 10px;
		}
	</style>

</head>

<body>
	<script type="text/javascript">

			<?php 

			$colddelivery=false;
			?>
			//hide delivery method at 2020-08-10
			// two parts change
			// one add select javascipt method
			//second hide delivery button

			<?php 

			if($colddelivery==false){
			?>
			 window.onload = function() {
    				// alert("ready");
    				Delivery('self');
			 };
			 <?php 

			}//if($colddelivery==false){
			?>
			 //hide delivery method at 2020-08-10
	</script>
	<!-- head -->
	<div class="checkout-container">
		<h2><strong>Check Out</strong></h2>
		<!-- End head -->

		<!-- part1 -->
		<div class="checkout-instructions " style="height:70px;">
			<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
				<h1 style=" margin:5px 5px;">Order Details</h1>
			</div>
		</div>
		<!-- End part1  -->

		<!-- part2 subject-->

		<div class="checkout-instructions col-lg-12 col-md-12 col-sm-12 col-xs-12">

			<div class="checkout-tabletop checkout-cart-items">
				<div class="checkout-li hidden-sm hidden-xs">
					<div class="col-md-6">Product Description</div>
					<div class="col-md-2 text-center">Unit Price</div>
					<div class="col-md-2 text-center">Quantity</div>
					<div class="col-md-2 text-right">Sub-total</div>
				</div>

				<!--End part2 subject-->

				<!-- part3 cart-items-->

				<script>
					function amount(id, value, price, original_price) {
						var xmlhttp1;
						xmlhttp1 = new XMLHttpRequest();
						xmlhttp1.onreadystatechange = function() {
							if (xmlhttp1.readyState == 4 && xmlhttp1.status == 200) {
								if (xmlhttp1.responseText > 0) {
									document.getElementsByName("pv" + id)[0].value = xmlhttp1.responseText;
									document.getElementsByName("pv" + id)[1].value = xmlhttp1.responseText;

									document.getElementById("pv1" + id).innerHTML = xmlhttp1.responseText;
									document.getElementById("pv2" + id).innerHTML = xmlhttp1.responseText * price;

									var newamount = xmlhttp1.responseText - parseFloat(document.getElementById("pv3" + id).innerHTML);

									document.getElementById("pv3" + id).innerHTML = xmlhttp1.responseText;
									document.getElementById("pv4" + id).innerHTML = xmlhttp1.responseText * original_price;

									document.getElementById("total").innerHTML = (parseFloat(document.getElementById("total").innerHTML) + newamount * price);
									document.getElementById("total1").innerHTML = (parseFloat(document.getElementById("total1").innerHTML) + newamount * original_price);
									document.getElementById("discount_sub_total").innerHTML =
										Math.round(
											(
												parseFloat(document.getElementById("total1").innerHTML) * parseFloat(document.getElementById("discount_rate").value)
											) *
											10) / 10;

									document.getElementById("discounted_amount").innerHTML =
										Math.round(
											(
												parseFloat(document.getElementById("total1").innerHTML) - (parseFloat(document.getElementById("discount_sub_total").innerHTML))
											) *
											10) / 10;

									if (document.getElementById('delivery5').innerHTML != "Delivery Fee:") {
										document.getElementById("deliveryfee").innerHTML = 1;
										document.getElementById("deliveryfee1").innerHTML = 1;

										document.getElementById('subtotal').innerHTML = parseFloat(document.getElementById('total').innerHTML) + 1;
										document.getElementById('subtotal1').innerHTML = parseFloat(document.getElementById('discount_sub_total').innerHTML) + 1;
									} else {
										if (parseFloat(document.getElementById("total").innerHTML) <= 800) {
											document.getElementById("deliveryfee").innerHTML = 48;
											document.getElementById('subtotal').innerHTML = parseFloat(document.getElementById('total').innerHTML) + 48;
										} else {
											document.getElementById("deliveryfee").innerHTML = 0;
											document.getElementById('subtotal').innerHTML = parseFloat(document.getElementById('total').innerHTML) + 0;
										}
										if (parseFloat(document.getElementById("discount_sub_total").innerHTML) <= 800) {
											document.getElementById("deliveryfee1").innerHTML = 48;
											document.getElementById('subtotal1').innerHTML = parseFloat(document.getElementById('discount_sub_total').innerHTML) + 48;
										} else {
											document.getElementById("deliveryfee1").innerHTML = 0;
											document.getElementById('subtotal1').innerHTML = parseFloat(document.getElementById('discount_sub_total').innerHTML) + 0;
										}
									}
								} else {
									alert("Input invalid.");
								}
							}
						}
						xmlhttp1.open("GET", "includes/amount.php?id=" + id + "&value=" + value + "&username=<?php echo $_SESSION["username"] ?>", true);
						xmlhttp1.send();
					}
				</script>

				<div class='cart-products'>
					<?php
					$subtotal = 0;
					$original_subtotal = 0;

					//Be aware of the ordering since it effect $cartTime which will be uses to create token,
					//you might need to find other salt or loop compare the `time` to ensure it is the right salt (e.g. $cartTime = strtotime($cartTime) > strtotime($row['time'] ? $cartTime : $row['time']); )
					$query = "select * from cart where username='" . mysqlSecurity($conn, $_SESSION['username']) . "' ORDER BY `time` DESC";
					$result = mysqli_query($conn, $query);
					if (mysqli_num_rows($result) > 0) {
						echo "<div id='aaa'>";

						while ($row = mysqli_fetch_assoc($result)) {
							$cartRecord = $row["record"];
							$cartTime = $row["time"];
							echo "<div class='checkout-products'>";
							echo "<div class='checkout-prod-info prod-meta col-md-6' ng-class=" . '"' . "{ 'col-md-4': showPromotions, 'col-md-6': !showPromotions }" . '"' . ">";
							echo "<a href='' target='_blank' class='product-link'>";
							echo "<div class='checkout-img col-lg-2 col-md-2 col-sm-12 col-xs-12'>";
							echo "<img class='prod-thumbnail' src='" . $row["image"] . "'>";
							echo "</div>";
							echo "</a>";
							echo "<div class='checkout-img-info col-lg-10 col-md-10 col-sm-12 col-xs-12'>";
							echo $row['product_name'];
							echo "<div ng-repeat='field in item.variation.fields' class='ng-scope'>";
							echo "<span class='variation ng-binding' id='pv1" . $row["id"] . "'>" . $row["amount"] . "</span><span class='variation ng-binding'>XHK$" . $row["price"] . " </spam>";
							echo "</div>";
							echo "</div>";
							echo "</div>";
							echo "<div style=' padding-top:10px; font-size:20px;' class='checkout-prod-info col-md-2 text-center-md  hidden-sm hidden-xs'>HK$" . $row["price"] . "</div>";

							echo "<!-- button -->";
							echo "<div class='checkout-prod-info col-md-2 text-center' style='padding-top:5px'>";
							echo "<div class='info-input-group'>";
							echo "<div class='input-group-btn'>";
							echo "<input type='submit' value='-' class='btn btn-default btn-checkout' onClick='amount(\"" . $row["id"] . "\",\"-\"," . $row["price"] . "," . $row["original_price"] . ")' />";
							echo "</div>";
							echo "<input name='pv" . $row["id"] . "' type='number' step='1' min='1' class='form-inline form-control-quantity ' value='" . $row["amount"] . "' onChange='amount(" . $row["id"] . ",this.value," . $row["price"] . "," . $row["original_price"] . ")'>";
							echo "<div class='input-group-btn'>";
							echo "<input type='submit' value='+' class='btn btn-default btn-checkout' onClick='
		amount(" . $row["id"] . ",\"%2b\"," . $row["price"] . "," . $row["original_price"] . ")' />";
							echo "</div>";
							echo "</div>";
							echo "</div>";
							echo "<!--End  button -->";

							$price = $row["price"] * $row["amount"];

							echo "
		<div class='checkout-prod-info-r col-md-2 text-right'>
		HK$
		<span id='pv2" . $row["id"] . "'>" . $price . "</span>
		<br>
		<a style='font-size:15px' href='includes/add_cart.php?check=delete&name=" . $row["product_name"] . "&from=checkout'>remove&nbsp;&nbsp;</a>
		</div>";
							echo "</div>";
							$subtotal = $subtotal + $price;
							$_SESSION["subtotal"] = $subtotal;
						}
						$_SESSION["Tsubtotal"] = $_SESSION["subtotal"];
						if ($_SESSION["subtotal"] <= 800) {
							$_SESSION["subtotal"] = $_SESSION["subtotal"] + 48;
							$_SESSION["delivery_fee"] = 1;
						} else {
							$_SESSION["delivery_fee"] = 0;
						}

						echo "</div>";
					} else {
						echo "none";
					}

					$query = "select * from cart where username='" . mysqlSecurity($conn, $_SESSION['username']) . "'";
					$result = mysqli_query($conn, $query);
					if (mysqli_num_rows($result) > 0) {
						echo "<div id='bbb' style='display:none'>";
						while ($row = mysqli_fetch_assoc($result)) {
							echo "<div class='checkout-products'>";
							echo "<div class='checkout-prod-info prod-meta col-md-6' ng-class=" . '"' . "{ 'col-md-4': showPromotions, 'col-md-6': !showPromotions }" . '"' . ">";
							echo "<a href='' target='_blank' class='product-link'>";
							echo "<div class='checkout-img col-lg-2 col-md-2 col-sm-12 col-xs-12'>";
							echo "<img class='prod-thumbnail' src='" . $row["image"] . "'>";
							echo "</div>";
							echo "</a>";
							echo "<div class='checkout-img-info col-lg-10 col-md-10 col-sm-12 col-xs-12'>";
							echo $row['product_name'];
							echo "<div ng-repeat='field in item.variation.fields' class='ng-scope'>";
							echo "<span class='variation ng-binding' id='pv3" . $row["id"] . "'>" . $row["amount"] . "</span><span class='variation ng-binding'>XHK$" . $row["original_price"] . " </spam>";
							echo "</div>";
							echo "</div>";
							echo "</div>";
							echo "<div style=' padding-top:10px; font-size:20px;' class='checkout-prod-info col-md-2 text-center-md  hidden-sm hidden-xs'>HK$" . $row["original_price"] . "</div>";

							echo "<!-- button -->";
							echo "<div class='checkout-prod-info col-md-2 text-center' style='padding-top:5px'>";
							echo "<div class='info-input-group'>";
							echo "<div class='input-group-btn'>";
							echo "<input type='submit' value='-' class='btn btn-default btn-checkout' onClick='amount(\"" . $row["id"] . "\",\"-\"," . $row["price"] . "," . $row["original_price"] . ")' />";
							echo "</div>";
							echo "<input name='pv" . $row["id"] . "' type='number' step='1' min='1' class='form-inline form-control-quantity ' value='" . $row["amount"] . "' onChange='amount(" . $row["id"] . ",this.value," . $row["price"] . "," . $row["original_price"] . ")'>";
							echo "<div class='input-group-btn'>";
							echo "<input type='submit' value='+' class='btn btn-default btn-checkout' onClick='amount(" . $row["id"] . ",\"%2b\"," . $row["price"] . "," . $row["original_price"] . ")' />";
							echo "</div>";
							echo "</div>";
							echo "</div>";
							echo "<!--End  button -->";

							$price = $row["original_price"] * $row["amount"];

							echo "
		<div class='checkout-prod-info-r col-md-2 text-right'>
		HK$
		<span id='pv4" . $row["id"] . "'>" . $price . "</span>
		<br>
		<a style='font-size:15px' href='includes/add_cart.php?check=delete&name=" . $row["product_name"] . "&from=checkout'>remove&nbsp;&nbsp;</a>
		</div>";
							echo "</div>";
							$original_subtotal = $original_subtotal + $price;
							$_SESSION["original_subtotal"] = $original_subtotal;
						}
						$_SESSION["Toriginal_subtotal"] = $_SESSION["original_subtotal"];
						if ($_SESSION["original_subtotal"] <= 800) {
							$_SESSION["original_subtotal"] = $_SESSION["original_subtotal"] + 48;
							$_SESSION["original_delivery_fee"] = 1;
						} else {
							$_SESSION["original_delivery_fee"] = 0;
						}
						echo "</div>";
					} else {
						echo "none";
					}
					?>
				</div>
			</div>
		</div>

		<!-- End part3 cart-items-->

		<!-- part4 Coupon Customer Info Place Order-->
		<div class="checkout-tablebottom col-lg-12 col-md-12 col-sm-12 col-xs-12">
			<!-- part4.1 Coupon-->

			<!-- Nav tabs -->
			<!-- End part4.1 Coupon-->

			<!-- Tab panes -->
			<script>
				var currentEnv = [];
				currentEnv.lang = location.href.match(/\/en\/|\/zh\//);
				currentEnv.lang = currentEnv.lang[0].replace(/\//g, '');

				function coupon(code) {
					var xmlhttp;
					xmlhttp = new XMLHttpRequest();
					xmlhttp.onreadystatechange = function() {
						if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
							if (xmlhttp.responseText !== '') {
								document.getElementById("aaaa").style.display = "none";
								document.getElementById("bbbb").style.display = "";
								document.getElementById("aaa").style.display = "none";
								document.getElementById("bbb").style.display = "";

								var respone = JSON.parse(xmlhttp.responseText);
								var discount_rate = respone['discount_rate'],
									coupon_name = respone[window.currentEnv.lang + '_name'];

								document.getElementById("discount_rate").setAttribute("value", discount_rate);

								document.getElementById("coupon_discount").innerHTML = 100 - (discount_rate * 100);

								var message = 'You have applied the coupon code ' + coupon_name + ' successfully and will be able to enjoy ' + document.getElementById("coupon_discount").innerHTML;
								alert(message + '% discount off your selected products.\n* Remarks: If you want to use the coupon code, discounted items shall be calculated on their original prices instead of their discounted ones.');

								document.getElementById("discounted_amount").innerHTML = Math.round((document.getElementById("total1").innerHTML - parseFloat(document.getElementById("total1").innerHTML) * discount_rate) * 10) / 10;

								var discount_sub_total = Math.round(parseFloat(document.getElementById("total1").innerHTML) * discount_rate * 10) / 10;
								document.getElementById("discount_sub_total").innerHTML = discount_sub_total;

								if (document.getElementById('delivery5').innerHTML != "Delivery Fee:") {
									document.getElementById('subtotal1').innerHTML = discount_sub_total + 1;
								} else {
									if (discount_sub_total <= 800) {
										document.getElementById('subtotal1').innerHTML = discount_sub_total + 48;
										document.getElementById('deliveryfee1').innerHTML = 48;
									} else {
										document.getElementById('subtotal1').innerHTML = discount_sub_total;
									}
								}
							} else {
								alert("This Coupon Code is invalid.");
							}
						}

					}
					xmlhttp.open("GET", "includes/check_coupon.php?code=" + code, true);
					xmlhttp.send();
				}
			</script>
			<form method="post" name="paypal_form" id="paypal_form" action="e-shop.php?page=10" onsubmit="return SubmitAAA(document.getElementById('subtotal').innerHTML,document.getElementById('discount_sub_total').innerHTML)">
				<div class="place-order col-lg-6 col-md-6 col-sm-12 col-xs-12" style="margin-top:0;    padding-left: 15px;padding-top: 5px;
">
					<input type="hidden" name="token" value="<?php echo Token::gen_PerForm($cartTime); ?>">
					<h2>Coupon Code:</h2>
					<div class="input-group">
						<input id="code" name="code" class="form-control" placeholder="Please enter Coupon Code">
						<div class="input-group-addon" style="padding:0; background-color:rgba(227,105,10,1.00);">
							<button type="button" style="border:0; background-color:rgba(227,105,10,1.00); color:white; width:100%; height:100%" onClick="coupon(document.getElementById('code').value)" />Apply Coupon</button>
						</div>
					</div>
					<input id="discount_rate" style="display:none" name="discount_rate" value="1" />

					<h2>Customer Info:</h2>
					<strong>Customer's First Name</strong>
					<input class="form-control" id="pcfname" placeholder="" type="text" name="customer_Fname" value="<?php echo $_SESSION["first_name"]; ?>" required>

					<strong>Customer's Last Name</strong>
					<input class="form-control" id="pclname" placeholder="" type="text" name="customer_Lname" value="<?php echo $_SESSION["last_name"]; ?>" required>


					<strong>Customer's Email</strong>
					<input class="form-control" style="text-align: center;" id="pcemail" placeholder="" type="email" name="customer_email" value="<?php echo $_SESSION["email"]; ?>" required>

					<strong>Customer's Phone</strong>
					<input class="form-control" id="pcphone" placeholder="" type="text" name="customer_phone" value="<?php echo $_SESSION["phone"]; ?>" required>

					<strong>Billing Address</strong>
					<textarea class="form-control" id="pcaddress" rows="2" name="customer_address" wrap='physical' required><?php

																																																									$address = preg_replace("<br>", '/\r\n/', ($_SESSION["address"]));
																																																									echo $_SESSION["address"]; ?></textarea>


					<strong>Company Name</strong>
					<input class="form-control" placeholder="" type="text" name="company_name" value="*Optional" required>

					<h2>Delivery Details:</h2>
					<button type="button" onclick="p()" />Same as Above</button><br><br>


					<strong>Recipient's First Name</strong>
					<input class="form-control" id="prfname" placeholder="" type="text" name="recipient_Fname" required>

					<strong>Recipient's Last Name</strong>
					<input class="form-control" id="prlname" placeholder="" type="text" name="recipient_Lname" required>

					<strong>Recipient's Email</strong>
					<input class="form-control" style="text-align: center;" id="premail" placeholder="" name="email" value="*Optional" required>

					<strong>Recipient's phone</strong>
					<input class="form-control" id="prphone" placeholder="" type="text" name="phone" required>

					<script>
						function Delivery(type) {
							if (type == 'self') {
								document.getElementById('delivery_methods_1').setAttribute('src', '../img/delivery_en1.jpg');
								document.getElementById('delivery_methods_2').setAttribute('src', '../img/Selfpickup_en2.jpg');
								document.getElementById('Delivery_methods').setAttribute('value', 'self');

								document.getElementById('delivery0').style.display = "none";
								document.getElementById('praddress').value = 'self pick-up';
								document.getElementById('praddress').setAttribute('value', 'self pick up');

								document.getElementById('delivery1').innerHTML = "<strong>Pick Up Date</strong>";
								document.getElementById('datepicker').setAttribute('placeholder', 'Please select pick up date');
								document.getElementById('delivery2').innerHTML = "*Please select your targeted self-pickup date. We will confirm the exact date after receiving your order very soon.";
								document.getElementById('delivery3').innerHTML = "Please contact us to make an appointment for the pickup during office hour (Monday – Friday: 10:00am -6:00pm, lunch hour: 1:00pm – 2:00pm).";

								document.getElementById('delivery4').style.display = "none";

								if (document.getElementById('delivery5').innerHTML != "Plastic Bag Charge:") {
									document.getElementById('deliveryfee').innerHTML = "1";
									document.getElementById('subtotal').innerHTML = parseFloat(document.getElementById('total').innerHTML) + 1;
									document.getElementById('deliveryfee1').innerHTML = "1";
									document.getElementById('subtotal1').innerHTML = parseFloat(document.getElementById('discount_sub_total').innerHTML) + 1;

									document.getElementById('delivery5').innerHTML = "Plastic Bag Charge:";
									document.getElementById('delivery6').innerHTML = "Plastic Bag Charge:";
								}
							} else {
								document.getElementById('delivery_methods_1').setAttribute('src', '../img/delivery_en2.jpg');
								document.getElementById('delivery_methods_2').setAttribute('src', '../img/Selfpickup_en1.jpg');
								document.getElementById('Delivery_methods').setAttribute('value', 'SF Express Refrigerated Delivery Service');

								document.getElementById('delivery0').style.display = "";
								document.getElementById('praddress').value = '';
								document.getElementById('praddress').setAttribute('value', '');

								document.getElementById('delivery1').innerHTML = "<strong>Delivery Date</strong>";
								document.getElementById('datepicker').setAttribute('placeholder', 'Please select delivery date');
								document.getElementById('delivery2').innerHTML = "*Please select your targeted delivery date. We will confirm the exact date after receiving your order very soon.<br>Kindly note that delivery service is not available on Sundays and public holidays.";
								document.getElementById('delivery3').innerHTML = "*Please note that the delivery service is handled by SF Express. We will try our best to deliver the goods to you within the scheduled time slot but delay may happen sometimes due to traffic situation. We will try our best to contact you directly if we will not be able to arrange the delivery on your targeted delivery time.";

								document.getElementById('delivery4').style.display = "";

								if (document.getElementById('delivery5').innerHTML != "Delivery Fee:") {
									if (parseFloat(document.getElementById('total').innerHTML) <= 800) {
										document.getElementById('deliveryfee').innerHTML = "48";
										document.getElementById('subtotal').innerHTML = parseFloat(document.getElementById('total').innerHTML) + 48;
									} else {
										document.getElementById('deliveryfee').innerHTML = "0";
										document.getElementById('subtotal').innerHTML = parseFloat(document.getElementById('total').innerHTML);
									}
									if (parseFloat(document.getElementById('discount_sub_total').innerHTML) <= 800) {
										document.getElementById('deliveryfee1').innerHTML = "48";
										document.getElementById('subtotal1').innerHTML = parseFloat(document.getElementById('discount_sub_total').innerHTML) + 48;
									} else {
										document.getElementById('deliveryfee1').innerHTML = "0";
										document.getElementById('subtotal1').innerHTML = parseFloat(document.getElementById('discount_sub_total').innerHTML);
									}

									document.getElementById('delivery5').innerHTML = "Delivery Fee:";
									document.getElementById('delivery6').innerHTML = "Delivery Fee:";
								}
							}
						}
					</script>

					<strong>Delivery Methods</strong>
					<input style="display:none" id="Delivery_methods" type="text" name="delivery_methods" value="SF Express Refrigerated Delivery Service" required>
					<br>
					<?php if($colddelivery==false){
						//for disable delivery method at 2020-08-10
						?>
					<img id="delivery_methods_1" src="../img/delivery_en2.jpg" width="210px" height="50px" style="display: none" />
				<?php  }//if($colddelivery==false){?>
					<?php if($colddelivery==true){
						//for disable delivery method at 2020-08-10
						?>
					<img id="delivery_methods_1" src="../img/delivery_en2.jpg" width="210px" height="50px" onClick="Delivery('delivery')" />
					<?php  }//if($colddelivery==true){?>
					<img id="delivery_methods_2" src="../img/Selfpickup_en1.jpg" width="210px" height="50x" onClick="Delivery('self')" />

					<div id="delivery0">
						<strong>Delivery Address</strong>
						<textarea class="form-control" id="praddress" rows="2" name="address" wrap='physical' required></textarea>
					</div>

					<div id="delivery1">
						<strong>Delivery Date</strong>
					</div>

					<div id="delivery2">
						<p>*Please select your targeted delivery date. We will confirm the exact date after receiving your order very soon.<br>Kindly note that delivery service is not available on Sundays and public holidays.</p>
					</div>

					<input class="form-control" placeholder="Please select delivery date" type="text" name="delivery_date" id="datepicker" required readonly="readonly"></input>

					<div id="delivery3">
						<p>*Please note that the delivery service is handled by SF Express. We will try our best to deliver the goods to you within the scheduled time slot but delay may happen sometimes due to traffic situation.We will try our best to contact you directly if we will not be able to arrange the delivery on your targeted delivery time.</p>
					</div>

					<div id="delivery4">
						<strong>Delivery Time Slot</strong>

						<select class="form-control" name="delivery_time">
							<option value="09:00 - 15:00">9:00AM - 3:00PM</option>
							<option value="13:00 - 19:00">1:00PM - 7:00PM</option>
						</select>
					</div>

					<strong>Remarks</strong>
					<textarea class="form-control" rows="4" name="remarks" placeholder="" wrap='physical'></textarea>
				</div>



				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12" style="margin-top:0;padding-right:15px;padding-top: 5px;">
					<h2 align="right">Order Summary</h2>
					<?php
					echo '
    <div id="aaaa">
      	<div class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div class="">Sub-total:</div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <span>HK$</span><span id="total" class="" >';
					echo $_SESSION["Tsubtotal"];
					echo '</span>
 			</div>
        </div>
        
      	<div class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div id="delivery5">Delivery Fee:</div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <span>HK$</span><span id="deliveryfee">';
					if ($_SESSION["delivery_fee"] == 1) {
						echo 48;
					} else {
						echo 0;
					}
					echo '</span>
 			</div>
        </div>
              
      	<div class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div class=""><strong>Total:</strong></div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <span>HK$</span><strong><span id="subtotal">';
					echo $_SESSION["subtotal"];
					echo '</span></strong>
 			</div>
        </div> 
	</div>
';

					echo '
    <div id="bbbb" style="display:none">
      	<div class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div class="">Total Original Price:</div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <span>HK$</span><span id="total1">';
					echo $_SESSION["Toriginal_subtotal"];
					echo '</span>
 			</div>
        </div>
        
      	<div id="discount" class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div>Coupon Discount:</div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <div><span id="coupon_discount"></span>%</div>
 			</div>
        </div>   
        
        <div id="discount1" class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div>Discounted Amount:</div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <span>HK$</span><span id="discounted_amount" class="" ></span>
 			</div>
        </div>   
        
        <div id="discount2" class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div>Sub-total:</div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <span>HK$</span><span id="discount_sub_total" class="" >';
					echo $_SESSION["Toriginal_subtotal"];
					echo '</span>
 			</div>
        </div>   

        
      	<div class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div id="delivery6">Delivery Fee:</div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <span>HK$</span><span id="deliveryfee1">';
					if ($_SESSION["original_delivery_fee"] == 1) {
						echo 48;
					} else {
						echo 0;
					}
					echo '</span>
 			</div>
        </div>
              
      	<div class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right"> 
   				 <div class=""><strong>Total:</strong></div>
  			</div>
        	<div class="col-xs-8 col-sm-5" style="text-align:right">
   				 <span>HK$</span><strong><span id="subtotal1">';
					echo $_SESSION["original_subtotal"];
					echo '</span></strong>
 			</div>
        </div> 
	</div>
';

					?>

					<div label="" data-field-name="terms" class="text-right">
						<div class="">
							<label style="font-weight: 400;font-size: 14px;">
								<input id="checkbox" type="checkbox" name="order_terms">
								I agree to <a class="">Sayvour’s Terms</a> and <a class="">Conditions</a>
							</label>
						</div>

						<div class="ng-scope" ng-if="!isUserLoggedIn">
							<label style="font-weight: 400;font-size: 14px;">
								<input type="checkbox" name="save_marketing">
								I wish to subscribe to Sayvour’s promotional materials
							</label>
						</div>

					</div>

					<script>
						function payment(type) {
							if (type == 'paypal') {
								document.getElementById('paypal_img').setAttribute('src', '../img/pic3a.jpg');
								document.getElementById('bank_img').setAttribute('src', '../img/pic1b.jpg');
								document.getElementById('payment_method').setAttribute('value', 'paypal');
							} else {
								document.getElementById('bank_img').setAttribute('src', '../img/pic1a.jpg');
								document.getElementById('paypal_img').setAttribute('src', '../img/pic3b.jpg');
								document.getElementById('payment_method').setAttribute('value', 'bank');
							}
						}
					</script>

					<h2 align="middle">Payment Method</h2>
					<p style="color:rgba(107,180,211,1.00)">Please select</p>

					<input id="payment_method" style="display:none" name="payment_method" value="bank" />

					<img id="bank_img" src="../img/pic1a.jpg" width="260px" height="60px" onClick="payment('bank')" />
					<p style="color:rgba(107,180,211,1.00)">If you want to pay through bank transfer, please deposit the payment to following account:</p>
					<p style="color:rgba(107,180,211,1.00)">(Only available in Hong Kong Dollars)</p>
					<p style="color:rgba(230,149,148,1.00)">Company Name: Patisserie Sayvour Limited</p>
					<p style="color:rgba(230,149,148,1.00)">Beneficiary's Bank Name: HSBC</p>
					<p style="color:rgba(230,149,148,1.00)">Beneficiary's Account no: 023-462187-838</p>
					<p style="color:rgba(230,149,148,1.00)">SWIFT address: HSBCHKHHHKH</p>
					<p style="color:rgba(230,149,148,1.00)">Bank address: 1 Queen's Road Central, Hong Kong</p>
					<br>
					<img id="paypal_img" src="../img/pic3b.jpg" width="260px" height="60px" onClick="payment('paypal')" />
					<p style="color:rgba(107,180,211,1.00)">PayPal account owner can pay through PayPal account.</p>
					<p style="color:rgba(107,180,211,1.00)">Customers without PayPal account can pay through credit card directly.</p>
					<br>

					<script>
						function SubmitAAA(subtotal, subtotal1) {
							if (parseFloat(subtotal1) < 180) {
								alert("The minimum order amount for each online transaction is HK$180. Please order more in order to complete the transaction. Thank you.");
								return false;
							}
							if (document.getElementById("checkbox").checked == false) {
								alert("Sorry, you must accept terms and conditions.");
								return false;
							}
						}
					</script>

					<input id="paypal" class="btn btn-place-order" type="submit" value="Place Order">
					<input class="btn btn-place-order" onclick="window.location.href='e-shop.php'" value="Continue Shopping!!">



			</form>
		</div>
	</div>
	</div>
	<!-- End part4 Coupon Customer Info Place Order-->


</body>

</html>