<!doctype html>
<html class="no-js" lang="zxx">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Sudila Printers - Kurunegala Sri Lanka</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicons -->
<!-- <link rel="shortcut icon" href="images/favicon.ico"> -->

<!-- Google font (font-family: 'Roboto', sans-serif; Poppins ; Satisfy) -->
<link type="text/css" href="css/font_opensans.css" rel="stylesheet">
<link type="text/css" href="css/font_poppins.css" rel="stylesheet">
<link type="text/css" href="css/font_roboto.css" rel="stylesheet">
<!-- Stylesheets -->
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="css/plugins.css">
<link type="text/css" rel="stylesheet" href="css/style.css">
<!-- Cusom css -->
<link type="text/css" rel="stylesheet" href="css/custom.css">
<link href="css/jquery.toast.min.css" rel="stylesheet" type="text/css">
<!-- Modernizer js -->
<script type="text/javascript" src="js/vendor/modernizr-3.5.0.min.js"></script>
<style type="text/css">
.del_meth {
	margin: 0 10px 0 5px;
}
.select__option {height: 35px;}
</style>
</head>
<body>
<!-- Main wrapper -->
<div class="wrapper" id="wrapper"> 
  <!-- Header -->
  <?php include 'common/header.php'; ?>
  <!-- //Header --> 
  <!-- Start Bradcaump area -->
  <div class="ht__bradcaump__area bg-image--4">
    <div class="container">
      <div class="row">
        <div class="col-lg-12">
          <div class="bradcaump__inner text-center">
            <h2 class="bradcaump-title">My Cart</h2>
            <nav class="bradcaump-content"> <a class="breadcrumb_item" href="index">Home</a> <span class="brd-separetor">/</span> <span class="breadcrumb_item active">My Cart</span> </nav>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- End Bradcaump area --> 
        <!-- cart-main-area start -->
        <div class="cart-main-area section-padding--xlg bg--white">
            <div class="container">
                <div class="row">
                    <div class="col-md-12 col-sm-12 ol-lg-12">             
						<div class="table-content wnro__table table-responsive" id="shop_tbl"></div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-5">
					<div class="cartbox__total__area product-add-to-cart"><a href="bookstore-sudila-printers-sri-lanka"> CONTINUE SHOPPING </a></div>
					</div>
                    <div class="col-lg-7 price-total" style="display:none">
                        <div class="cartbox__total__area">
                            <div class="cartbox-total">
                                <ul class="cart__total__list">
									<li><span><b>Select Delivery Method <br>Total Weight: <span id="tot_wgt">0</span>g</b></span>
									<span class="cart__total__tk">
									  <?php
									  $sqldel = "SELECT * FROM delivery_methods WHERE view_cart = 1 AND enable_method = 1 ORDER BY order_id ASC";
									  $sqld = mysqli_query($conn, $sqldel);
									  while($rowd = mysqli_fetch_array($sqld)) {
										  echo '<input type="radio" id="'.$rowd['method_id'].'" name="del_type" value="'.$rowd['id'].'"><span class="del_meth">'.$rowd['method_type'].'</span>';
									  }
									  /*<!--<input type="radio" id="postal" name="del_type" value=1><span class="del_meth">Postal</span>-->
									  <input type="radio" id="courier" name="del_type" value=2><span class="del_meth">Courier Service</span>
									  <!--<input type="radio" id="cash_on" name="del_type" value=4><span class="del_meth">Cash On Delivery</span>-->
									  <input type="radio" id="ems" name="del_type" value=3><span class="del_meth">EMS</span>*/
									  ?>
									  <span id="txt_error" style="display:none" class="help-block"><br>*Please Select Your Delivery Method
									  </span>
									  <span id="txt_error2" style="display:none"class="help-block" ><br>*You Cannot Select Postal Method. Maximum Total Weight is 20kg</span>
									</span></li>
                                    <li id="country_list" style="display:none"><span>Select Country</span> <span class="cart__total__tk">
										<select class="select__option" id="country">
											<option value=""></option>
											<?php $sql_ct = mysqli_query($conn, "SELECT country FROM ems_charges WHERE max_kg>0 ORDER BY country");while($row_ct = mysqli_fetch_array($sql_ct)) { ?>
												<option><?php echo $row_ct['country']; ?></option>
											<?php } ?>
										</select>
										<span id="txt_error3" style="display:none" class="help-block"><br>*Please Select Your Country</span>
										<span id="txt_error4" style="display:none" class="help-block"><br>*Maximum Total Weight is <span id="max_kg"></span>kg</span>
									</span></li>
                                    <li><span><b>Sub Total</b></span> <span class="cart__total__tk"><b>LKR <span id="sub_tot">0</span></b></span></li>
                                    <li><span><b>Total Discount</b></span> <span class="cart__total__tk"><b>LKR <span id="dis_tot">0</span></b></span></li>
                                    <li id="del_chg" style="display:none"><span><b>Delivery Charges</b></span> <span class="cart__total__tk"><b>LKR <span id="del_amount">0</span></b></span></li>
                                </ul>
                            </div>
                            <div class="cart__total__amount">
                                <span>Grand Total</span>
                                <span>LKR <span id="g_tot">0</span><input type="hidden" readonly id="net_amount" readonly></span>
                            </div>
							<div class="mt--30 product-add-to-cart chkt text-center"><a id="btn_checkout" href="javascript:void(0);"> PROCEED TO CHECKOUT</a></div>
                        </div>
                    </div>
                </div>
            </div>  
        </div>
        <!-- cart-main-area end --> 
  <!-- Footer Area -->
  <?php include 'common/footer.php'; ?>
  <!-- //Footer Area --> 
</div>
<div id="pre_loader"></div>
<!-- //Main wrapper -->
<!-- JS Files --> 
<script type="text/javascript" src="js/vendor/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/popper.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/plugins.js"></script>
<script type="text/javascript" src="js/active.js"></script>
<script type="text/javascript" src="js/add-to-cart.js"></script>
<script type="text/javascript" src="js/jquery.toast.js"></script>
<script type="text/javascript">
$(document).ready(function () {
	//localStorage.clear();
	//localStorage.removeItem('delvry_type_b');
	//localStorage.removeItem('country_b');

	load_cart_table();
	get_tot_weight();
	
	var del_type = localStorage['delvry_type_b'];
	var country = localStorage['country_b'];
	//alert(country+', '+del_type);
	
	if (del_type == '1') { // Postal
		$('#del_chg').show();
		$("#postal_chk").prop("checked", true);
		$("#country_list").hide();
		$('#country').val('');
		get_delivery_fee('1');
	
	} else if(del_type == '2') { // Courier
		$('#del_chg').show();
		$("#cour_chk").prop("checked", true);
		$("#country_list").hide();
		$('#country').val('');
		get_delivery_fee('2');
	
	} else if(del_type == '3') { // EMS
		$('#del_chg').show();
		$("#ems_chk").prop("checked", true);
		$("#country_list").show();
		$('#country').val(country);
		get_delivery_fee('3', country);
	
	} else if(del_type == '4') { // Cash on Delivery
		$('#del_chg').show();
		$("#cash_on").prop("checked", true);
		$("#country_list").hide();
		$('#country').val('');
		get_delivery_fee('4');
	
	} else {
		$('#del_chg').hide();
		$('#del_amount').text('');
		$('#g_tot').text($('#net_amount').val());		
	}
});
	
$("#btn_checkout").click(function() {
	var del_type = $("input[name='del_type']:checked").val();
	if(del_type === '1' || del_type === '2' || del_type === '3' || del_type === '4') {
		if(del_type === '3') {
			if($('#country').val() === '') {
				$('#txt_error3').fadeIn();
			
			} else {
				localStorage['country_b'] = $('#country').val();
				localStorage['delvry_type_b'] = del_type;
				window.location.href = 'checkout';
			}
		
		} else {
			localStorage['country_b'] = $('#country').val();
			localStorage['delvry_type_b'] = del_type;
			window.location.href = 'checkout';
		}
	
	} else {
		$('#txt_error').fadeIn();
	}
});
	
$("input[name='del_type']").on('change', function() {
	$('#del_chg').show('medium');
	$('#txt_error').fadeOut();
	$('#txt_error4').fadeOut();
	$('#country').val('');
	var del_type = $(this).val();
	
	if(del_type === '3') {
		$('#txt_error2').fadeOut();
		$("#pre_loader").fadeIn();
		$("#country_list").show('medium');
		
		setTimeout(function() {
			$('#del_amount').text(parseFloat(0).toFixed(2));
			$('#g_tot').text(parseFloat($('#net_amount').val()).toFixed(2));
		}, 500);
		$("#pre_loader").fadeOut();
		
	} else {
		get_delivery_fee(del_type);
		$("#country_list").hide('medium');
		$('#txt_error3').fadeOut();
	}
});
	
function get_tot_weight() {
	$.post("connection/my_cart_conn", {'get_tot_weight': "data"}, function( data ) {
		$('#tot_wgt').text(data.tot_weight);
		if(data.tot_weight <= 20000) {
			$('#txt_error2').fadeOut();
		}
	}, "json");
}
	
function get_delivery_fee(del_type, country) {
	$("#pre_loader").fadeIn();
	$.post( "connection/my_cart_conn", {'get_delivery_fee': "data", type:del_type, country:country }, function( data ) {
		if(data.msgType === 1) {
			var del_fee = parseFloat(data.del_fee).toFixed(2);
			var max_weight = data.max_weight;
			var tot_weight = data.tot_weight;
			$('#del_amount').text(del_fee);
			$('#tot_wgt').text(tot_weight);
			
			if(del_type === '2' || del_type === '4') {
				$('#txt_error2').fadeOut();
				setTimeout(function() {
					var tot = $('#net_amount').val();
					var g_tot = parseFloat(del_fee) + parseFloat(tot);
					$('#g_tot').text(parseFloat(g_tot).toFixed(2));
				}, 500);
				$("#pre_loader").fadeOut();
				
			} else {
				if(tot_weight > max_weight) {
					$("#pre_loader").fadeOut();
					$("input[name='del_type']").prop("checked", false);
					$('#del_amount').text(parseFloat(0).toFixed(2));
					$('#g_tot').text(parseFloat($('#net_amount').val()).toFixed(2));

					if(del_type === '1') {
						$('#txt_error2').fadeIn();
					
					} else {
						$('#txt_error4').fadeIn();
						
						$("#max_kg").text(max_weight/1000);
					}
				
				} else {
					$("input[name=del_type][value=" + del_type + "]").prop('checked', true);
					$('#txt_error').fadeOut();
					$('#txt_error4').fadeOut();
					setTimeout(function() {
						var tot = $('#net_amount').val();
						var g_tot = parseFloat(del_fee) + parseFloat(tot);
						$('#g_tot').text(parseFloat(g_tot).toFixed(2));
						$("#pre_loader").fadeOut();
					}, 500);
				}
			}
		
		} else {
			setTimeout(function() {
				$('#del_amount').text(parseFloat(0).toFixed(2));
				$('#g_tot').text(parseFloat($('#net_amount').val()).toFixed(2));
			}, 500);
			$("#pre_loader").fadeOut();
		}
	}, "json");
}
	
$("#country").change(function(){
	var country = $(this).val();
	$('#txt_error3').fadeOut();
	$('#txt_error4').fadeOut();
	get_delivery_fee('3', country);
});

</script>
</body>
</html>