<?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
//for debug payment method
$debug = false;

if ($debug == true) {
	//2020-10-28
	//1)hided Delivery self javascript function

	//javascript pv2 is the subtotal of indivual price
	//javascript http calculate general details
	//if total price <800 and delevery method is 運費
	//plus $48 delivery price

	//select cart item from database
	//there are two display cart

	//end

	//first data is generate by session
	//second is display by javascript
	//data is stored in database cart

}

$colddelivery = true;
?>
			//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>結賬.</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;">訂單詳細信息</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">產品描述</div>
            <div class="col-md-2 text-center">單價</div>
            <div class="col-md-2 text-center">數量</div>
            <div class="col-md-2 text-right">小計</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!="運費:")
		  {
				document.getElementById("deliveryfee").innerHTML=1;
				document.getElementById("deliveryfee1").innerHTML=1;

				// document.getElementById('subtotal').innerHTML=parseFloat(document.getElementById('total').innerHTML)+48;
				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;

				//hide delivery at 2021-02-03
				document.getElementById("deliveryfee").innerHTML=0;
				document.getElementById('subtotal').innerHTML=parseFloat(document.getElementById('total').innerHTML)+0;
			  }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)
			  {
			  	//hide delivery at 2021-02-03
				// document.getElementById("deliveryfee1").innerHTML=48;
				// document.getElementById('subtotal1').innerHTML=parseFloat(document.getElementById('discount_sub_total').innerHTML)+48;
				document.getElementById("deliveryfee1").innerHTML=0;
				document.getElementById('subtotal1').innerHTML=parseFloat(document.getElementById('discount_sub_total').innerHTML)+0;

			  }else{
				document.getElementById("deliveryfee1").innerHTML=0;
				document.getElementById('subtotal1').innerHTML=parseFloat(document.getElementById('discount_sub_total').innerHTML)+0;
			  }
		  }
      }else{
		  alert("非法輸入.");
	  }
    }
  }
xmlhttp1.open("GET","includes/amount.php?id="+id+"&value="+value+"&username=<?php echo $_SESSION["username"] ?>",true);

//set no cache for responsive action of shopping cart at 2020-08-18

xmlhttp1.setRequestHeader('cache-control', 'no-cache, must-revalidate, post-check=0, pre-check=0');
xmlhttp1.setRequestHeader('cache-control', 'max-age=0');
xmlhttp1.setRequestHeader('expires', '0');
xmlhttp1.setRequestHeader('expires', 'Tue, 01 Jan 1980 1:00:00 GMT');
xmlhttp1.setRequestHeader('pragma', 'no-cache');

//end set no cache for responsive action of shopping cart

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'>移除&nbsp;&nbsp;</a>
		</div>";
		echo "</div>";
		$subtotal = $subtotal + $price;
		$_SESSION["subtotal"] = $subtotal;
	}

	$_SESSION["Tsubtotal"] = $_SESSION["subtotal"];
	if ($_SESSION["subtotal"] <= 800) {
		//change delivery to 0 at 2021-02-03, this is the intial fee for delivery

		// $_SESSION["subtotal"] = $_SESSION["subtotal"] + 48;
		$_SESSION["subtotal"] = $_SESSION["subtotal"] + 0;

		// $_SESSION["delivery_fee"] = 1;
		//changed control delivery fee to 0 at 2021-02-03
		$_SESSION["delivery_fee"] = 1;
	} else {
		//$_SESSION["delivery_fee"] = 0; //change to delivery fee 1 at 2021-02-03
		$_SESSION["delivery_fee"] = 1;
	}

	//added plastic bag fee
	// $_SESSION["subtotal"] = $_SESSION["subtotal"] + 1;
	//end added plastic bag fee

	if ($debug == true) {

		echo 'subtotal of all item and priced added';
		echo '<br>';
		echo '$_SESSION["subtotal"]';
		echo '<br>';
		echo $_SESSION["subtotal"];
		echo '<br>';

		echo '$_SESSION["Tsubtotal"]';
		echo '<br>';
		echo $_SESSION["Tsubtotal"];
		echo '<br>';

		echo '$_SESSION["delivery_fee"]';
		echo '<br>';
		echo $_SESSION["delivery_fee"];
		echo '<br>';

	} //if($debug==true){

	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'>移除&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;  delete delivery fee 2020-10-27

	} else {
		$_SESSION["original_delivery_fee"] = 0;
	}

	//added to control add plastic delivery fee at 2021-02-03
	if ($_SESSION["delivery_fee"] == 0) {

		//added plastic bag fee  2020-10-28
		$_SESSION["subtotal"] = $_SESSION["subtotal"] + 1;
		//end added plastic bag fee
	}
	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='你已成功使用優惠編號'+coupon_name+', 並可享有'+document.getElementById("coupon_discount").innerHTML;
		alert(message+'%折扣優惠。\n* 溫馨提示: 如需使用優惠編號，減價貨品將按原價計算，並不適用於折後價格。');

		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!="運費:"){
			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;
				document.getElementById('subtotal1').innerHTML=discount_sub_total;
			}else{
				document.getElementById('subtotal1').innerHTML=discount_sub_total;
			}
		}
      }else{
	    alert("贈卷代碼不正確。");
	  }
    }
  }
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>贈券代碼:</h2>
            <div class="input-group">
            <input id="code" name="code" class="form-control" placeholder="請輸入贈券代碼">
            <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)" />使用贈券</button>
            </div>
            </div>
            <input id="discount_rate" style="display:none" name="discount_rate" value="1" />

            <h2>訂單詳細信息：</h2>
			<strong>客戶名字</strong>
            <input class="form-control" id="pcfname" placeholder="" type="text" name="customer_Fname" value="<?php echo $_SESSION["first_name"]; ?>" required>

			<strong>客戶姓氏</strong>
            <input class="form-control" id="pclname" placeholder="" type="text" name="customer_Lname" value="<?php echo $_SESSION["last_name"]; ?>" required>


            <strong>客戶電郵地址</strong>
            <input class="form-control" style="text-align: center;" id="pcemail" placeholder="" type="email" name="customer_email" value="<?php echo $_SESSION["email"]; ?>" required>

            <strong>客戶電話號碼</strong>
            <input class="form-control" id="pcphone" placeholder="" type="text" name="customer_phone" value="<?php echo $_SESSION["phone"]; ?>" required>

            <strong>帳單地址</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>公司名稱</strong>
            <input class="form-control" placeholder="" type="text" name="company_name" value="*選擇性" required>

            <h2>運送詳細信息：</h2>
            <button type="button" onclick="p()" />與上述相同</button><br><br>


			<strong>收件人名字</strong>
            <input class="form-control" id="prfname" placeholder="" type="text" name="recipient_Fname"  required>

			<strong>收件人姓氏</strong>
            <input class="form-control" id="prlname" placeholder="" type="text" name="recipient_Lname"  required>

            <strong>收件人電郵地址</strong>
            <input class="form-control" style="text-align: center;" id="premail" placeholder="" name="email" value="*選擇性" required>

            <strong>收件人電話號碼</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_tc1.jpg');
					document.getElementById('delivery_methods_2').setAttribute('src','../img/Selfpickup_tc2.jpg');
					document.getElementById('Delivery_methods').setAttribute('value','自取');

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

					document.getElementById('delivery1').innerHTML="<strong>取貨日期</strong>";
					document.getElementById('datepicker').setAttribute('placeholder','請選擇取貨日期');
					document.getElementById('delivery2').inneHTML="*請選擇上門自取日期。 我們會在收到你的訂單後盡快確認交貨日期。";
					document.getElementById('delivery3').inneHTML="請與我們的職員預約取貨時間, 辨公時間為星期一至五，早上10時正正至下午6時正 (午飯時段為下午1時至2時) 。星期日及公眾假期不設上門自取服務。";

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

					if(document.getElementById('delivery5').innerHTML!="膠袋費:"){
							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="膠袋費:";
					document.getElementById('delivery6').innerHTML="膠袋費:";
					}
				}else{
					document.getElementById('delivery_methods_1').setAttribute('src','../img/delivery_tc2.jpg');
					document.getElementById('delivery_methods_2').setAttribute('src','../img/Selfpickup_tc1.jpg');
					document.getElementById('Delivery_methods').setAttribute('value','順豐冷凍送遞服務');
					// document.getElementById('Delivery_methods').setAttribute('value','送遞服務');

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

					document.getElementById('delivery1').innerHTML="<strong>收貨日期</strong>";
					document.getElementById('datepicker').setAttribute('placeholder','請選擇運送日期');
					document.getElementById('delivery2').innerHTML="*請選擇你的目標送貨日期。 我們會在收到你的訂單後盡快確認交貨日期。<br>星期日及公眾假期不設送貨服務。";
					document.getElementById('delivery3').innerHTML="*Sayvour 採用順豐的冷凍送遞服務運送禮品。我們盡量會將禮品於指定時間內送達，但由於路面交通情況不穩，可能會有延誤情況出現。若我們不能在指定時間為閣下安排送貨，會盡快通知。";

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

					if(document.getElementById('delivery5').innerHTML!="運費:"){
						if(parseFloat(document.getElementById('total').innerHTML)<=800)
						{
							//hide delivery charge 48 at 2021-02-03
							// document.getElementById('deliveryfee').innerHTML="48";
							// document.getElementById('subtotal').innerHTML=parseFloat(document.getElementById('total').innerHTML)+48;
							document.getElementById('deliveryfee').innerHTML="0";
							document.getElementById('subtotal').innerHTML=parseFloat(document.getElementById('total').innerHTML)+0;
						}else{
							document.getElementById('deliveryfee').innerHTML="0";
							document.getElementById('subtotal').innerHTML=parseFloat(document.getElementById('total').innerHTML);
						}
						if(parseFloat(document.getElementById('discount_sub_total').innerHTML)<=800)
						{
							//hide delivery charge 48 at 2021-02-03
							// document.getElementById('deliveryfee1').innerHTML="48";
							// document.getElementById('subtotal1').innerHTML=parseFloat(document.getElementById('discount_sub_total').innerHTML)+48;
							document.getElementById('deliveryfee1').innerHTML="0";
							document.getElementById('subtotal1').innerHTML=parseFloat(document.getElementById('discount_sub_total').innerHTML)+0;
						}else{
							document.getElementById('deliveryfee1').innerHTML="0";
							document.getElementById('subtotal1').innerHTML=parseFloat(document.getElementById('discount_sub_total').innerHTML);
						}

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

            <strong>取貨方式</strong>
            <input style="" id="Delivery_methods" type="text" name="delivery_methods" value="順豐冷凍送遞服務" required>

            <br>
            <br>
					<?php if ($colddelivery == false) {
	//for disable delivery method at 2020-08-10
	?>
					<img id="delivery_methods_1" src="../img/delivery_tc2.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_tc2.jpg" width="210px" height="50px" onClick="Delivery('delivery')" />
            <?php } //if($colddelivery==true){?>
			<img id="delivery_methods_2" src="../img/Selfpickup_tc1.jpg" width="210px" height="50x" onClick="Delivery('self')" />
			<p style="color:rgba(230,149,148,1.00)">*疫情期間，順豐冷凍部不設單件送遞服務，只可安排Lalamove 送貨，運費按不同地區報價，亦可選擇到門市自取。詳情如下：<br><br>
            門市地址: <br>
            銅鑼灣軒尼詩道402-406號 德興大廈6樓 608A室 (銅鑼灣港鐵站Times Square 出口，向天樂里方向步行約5分鐘)<br><br>
            疫情期間開放時間：<br>
            星期一至五，2-6pm<br><br>
            聯絡電話：2951 0005
        	</p>


            <div id="delivery0">

            <strong>郵寄地址</strong>
            <textarea class="form-control" id="praddress" rows="2" name="address" wrap='physical' required></textarea>
            </div>

            <div id="delivery1">
            <strong>收貨日期</strong>
            </div>

            <div id="delivery2">
            <p>*請選擇你的目標送貨日期。 我們會在收到你的訂單後盡快確認交貨日期。<br>
            星期日及公眾假期不設送貨服務。</p>
            </div>

			<input class="form-control" placeholder="請選擇運送日期" type="text" name="delivery_date" id="datepicker" required readonly = "readonly" ></input>


            <div id="delivery3">
            <p>*Sayvour 採用順豐的冷凍送遞服務運送禮品。我們盡量會將禮品於指定時間內送達，但由於路面交通情況不穩，可能會有延誤情況出現。若我們不能在指定時間為閣下安排送貨，會盡快通知。</p>

            </div>

            <div id="delivery4">
            <strong>收貨時間</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>備註</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">訂單摘要</h2>
<?php
echo '
    <div id="aaaa">
      	<div class="row">
        	<div class="col-xs-4 col-sm-7" style="text-align:right">
   				 <div class="">小計:</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">運費:</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) {
	//hide dilivery fee at 2021-02-03
	// echo 48;
	echo 0;
} 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>總計:</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="">原價小計:</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>折扣(%):</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>折扣價格:</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>折後小計:</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">運費:</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>總計</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">
我同意 <a class="" >Sayvour’s 條款</a> 和 <a class="">條件</a>
</label>
</div>

<div class="ng-scope" ng-if="!isUserLoggedIn">
<label style="font-weight: 400;font-size: 14px;">
<input type="checkbox" name="save_marketing" >
我希望訂閱 Sayvour 的宣傳資訊
</label>
</div>

</div>

<script>
function payment(type){
	if(type=='paypal'){
		document.getElementById('paypal_img').setAttribute('src','../img/pic4a.jpg');
		document.getElementById('bank_img').setAttribute('src','../img/pic2b.jpg');
		document.getElementById('payment_method').setAttribute('value','paypal');
	}else{
		document.getElementById('bank_img').setAttribute('src','../img/pic2a.jpg');
		document.getElementById('paypal_img').setAttribute('src','../img/pic4b.jpg');
		document.getElementById('payment_method').setAttribute('value','bank');
	}
}
</script>
<h2 align="middle">付款方式</h2>
<p style="color:rgba(107,180,211,1.00)">請選擇</p>

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

<img id="bank_img" src="../img/pic2a.jpg" width="260px" height="60px" onClick="payment('bank')" />
<p style="color:rgba(107,180,211,1.00)">若閣下以銀行入數，請把款項存入下面的銀行帳號</p>
<p style="color:rgba(107,180,211,1.00)">(只適用於港幣) </p>
<p style="color:rgba(230,149,148,1.00)">帳戶名稱：Patisserie Sayvour Limited</p>
<p style="color:rgba(230,149,148,1.00)">銀行名稱：香港上海匯豐銀行</p>
<p style="color:rgba(230,149,148,1.00)">帳戶號碼：023-462187-838</p>
<p style="color:rgba(230,149,148,1.00)">銀行國際代碼：HSBCHKHHHKH</p>
<p style="color:rgba(230,149,148,1.00)">銀行地址：香港中區皇后大道中1號</p>
<br>
<img id="paypal_img" src="../img/pic4b.jpg" width="260px" height="60px" onClick="payment('paypal')" />
<p style="color:rgba(107,180,211,1.00)">一般買家用信用卡付款。</p>
<p style="color:rgba(107,180,211,1.00)">擁有PayPal帳戶，可以帳戶支付。</p>
<br>

<script>
function SubmitAAA(subtotal,subtotal1){
	// if(parseFloat(subtotal1)<180){
		//hided 180 delivery fee at 2021-02-03
	// 	alert("每宗網上交易的最低訂購額為HK$180。請選購更多產品以完成交易。謝謝。");
	// 	return false;
	// }
	if(document.getElementById("checkbox").checked==false)
	{
		alert("抱歉，你必須同意網站條款和條件。");
		return false;
	}
}
</script>

<input id="paypal" class="btn btn-place-order" type="submit" value="付款">
<input  class="btn btn-place-order" onclick="window.location.href='e-shop.php'" value="繼續購物!!">



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


  </body>
</html>