<link rel="stylesheet" type="text/css" href="catalog/template/beststoreitems/css/cart.css">
<script type="text/javascript" src="catalog/javascript/livequery.js"></script>
<script type="text/javascript" src="catalog/javascript/cart_number.js"></script>
<script language="javascript">

	function remove_all_alter()
	{
		return confirm("Do you confirm to remove all items from your shopping cart?");
	}
	function remove_one()
	{
//		return confirm("Do you confirm to remove this item from your shopping cart?");
	}
	function caculate(id,value)
	{

	switch(id){
		case 0: // country
		{
			$("#country_id").val(value);
			break;
		}
		case 1: // shipping
		{
			$("#shipping_method_id").val(value);
			break;
		}
	}

	var subtotal_usd=$("#subtotal_usd").val();
	var subtotal_discount=$("#subtotal_discount").val();
	var country_id = $("#country_id").val();
	var shipping_method_id = $("#shipping_method_id").val();

		$.ajax({
			type: "post",
			url: "index.php?controller=cart&action=calculate&subtotal_usd="+subtotal_usd+"&subtotal_discount="+subtotal_discount+"&country_id="+country_id+"&shipping_method_id="+shipping_method_id,
			success: function(data){
				var result_data=data.split('|');
				var country_cost_html='+ '+result_data[0]+'';
				var grand_total_html='<font color="red">'+result_data[1]+'</font>';
				$("#country_cost").html(country_cost_html);
				$("#grand_total").html(grand_total_html);
				$("#shipping_cost_id").val(result_data[2]);
			}
		});
	}

    function checkout_review()
    {
    	var country_id = $("#country_id").val();
	    var shipping_method_id = $("#shipping_method_id").val();
//	    alert(country_id); // alert(shipping_method_id);
	   if ((country_id==0) || (country_id==null) || (country_id==undefined) || (country_id=='')) {
	    	alert('Please choose your shipping country!');
	    	return false;
	    }
 		 if ((shipping_method_id==0) || (shipping_method_id==null) || (shipping_method_id==undefined) || (shipping_method_id=='')) {
	    	alert('Please choose shipping method!');
	    	return false;
	    }

       return true;
    }

	function add_to_wish_list(product_id)
	{
	 window.location.href="https://www.beststoreitems.com/index.php?controller=my_wishlist&action=addtowishlist&product_id="+product_id;
	}

	//select//
	$(document).ready(function(){
	 $('.son_ul').hide();
	 $('.select_box span').hover(function(){
		  $(this).parent().find('ul.son_ul').show(0);
		  $(this).parent().find('li').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});
		  $(this).parent().hover(function(){},
								 function(){
									 $(this).parent().find("ul.son_ul").hide(0);
									 }
								 );
		  },function(){}
		  );
	 $('ul.son_ul li').click(function(){
		  $(this).parents('.select_box').find('span').html($(this).html());
		  $(this).parents('.select_box').find('ul').hide(0);
		  });
	 }
	 );

	 $(document).ready(function(){
	 $('.son_ul_2').hide();
	 $('.select_box_2 span').hover(function(){
		  $(this).parent().find('ul.son_ul_2').show(0);
		  $(this).parent().find('li').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});
		  $(this).parent().hover(function(){},
								 function(){
									 $(this).parent().find("ul.son_ul_2").hide(0);
									 }
								 );
		  },function(){}
		  );
	 $('ul.son_ul_2 li').click(function(){
		  $(this).parents('.select_box_2').find('span').html($(this).html());
		  $(this).parents('.select_box_2').find('ul').hide(0);
		  });
	 }
	 )

//Remove
$(function(){
	$(".crt-product_right .link-remove").click(function() {
		$(this).parents('#shopping-cart-table tr').addClass('active')
		$(this).parents('#shopping-cart-table tr').siblings('tr').removeClass('active')})
	});
	$('.no').livequery('click', function(){
		$('.cart_product_line').removeClass('active');
	});
	$('.yes').livequery('click', function(){
		var product_key=$(this).parents('div.remove_confirm').attr('data-produt-key');
		var shipping_cost=$("#shipping_cost_id").val();
    var k = $(this).attr('data-index');
    k = parseInt(k);
    $.ajax({
        type:'GET',
        url: 'index.php?controller=cart&action=ajax_removeproduct&product_key='+product_key+'&shipping_cost='+shipping_cost,
        dataType: 'json',
        success: function(json) {
            if(json.errcode == 1) {
              window.location.reload();
            }
            // var json = eval("(" + jsonData + ")");
            $('#subtotal_value_id').text(json.sub_total);
            $('#grandtotal_value_id').text(json.calculate);
            $('#grand_total font').text(json.calculate);

	          $('#remove_tr_'+k).remove();
            reloadCartHeader();
        }
    });
	});

//Wishlist
$(function(){
	$(".crt-product_right .link-wishlist").click(function() {

		// $(this).parents('#shopping-cart-table tr').addClass('current')
		// $(this).parents('#shopping-cart-table tr').siblings('tr').removeClass('current')
      var productKey = $(this).parents('.cart_product_line').attr('data-product-key');
      var js_options_array = productKey.split(':');
      var js_options=js_options_array[1];
      <?php if(!$customer_logged){ ?>
        $('#bg_tip,.wishlist_confirm').show();
        return false;
      <?php } ?>
      var product_id = js_options_array[0];
      var quantity = $(this).parents('.cart_product_line').find('input.qty').val();
      console.log(quantity);
      $.ajax({
          type:'GET',
          url: 'index.php?controller=product&action=ajax_addtowishlist&product_id='+product_id+'&quantity='+quantity+'&options='+js_options,
          dataType: 'json',
          success: function(json) {
            //alert(js_options);
            $('#bg_tip,.wishlist_confirm').show();
            $('#wishlist_count').text(json['wishlist_count']);
          }
        });
       return false;
  })

	$('.continue_shopping,#wishlist-close-btn').click(function(){
		$('.cart_product_line').removeClass('current');
		$('#bg_tip,.wishlist_confirm').hide()
	});
});

</script>
<div class="main container">
    <div class="row" id="cart">
    	<!--left-->
        <div class="col-md-24">
        <?php if (!empty($products)) { ?>
        <div class="top-part">
            <div class="page-title clearfix">
                <h1>Shopping Cart</h1>
                <div class="pay_methods">
                    <span title="SSL Secure" class="pay_method pay_ssl">SSL Secure</span>
                    <span title="VISA" class="pay_method pay_visa">VISA</span>
                    <span class="pay_method pay_master" title="MasterCard">MasterCard</span>
                    <span title="American Express" class="pay_method pay_american">American Express</span>
                    <span title="Western Union" class="pay_method pay_wu">Western Union</span>
                </div>
            </div>
            <div style="display:none"></div>
        </div>
        <table width="100%">
        <tr>
        <td align="left" style="padding:10px 0 0;">
        <div class="heading" style="text-align:right;">
            <form onsubmit="return remove_all_alter();" action="index.php?controller=cart&action=removeAll" method="post" enctype="multipart/form-data">
                <input type="image" style="width:112px;height:28px;" src="https://www.beststoreitems.com/catalog/template/beststoreitems/image/remove-all.gif">
            </form>
        </div>

        <form action="<?php echo $cart; ?>" name="cartform" method="post" enctype="multipart/form-data">

          <?php if ($error_outofstock) { ?>
          <div class="warning"><?php echo $error_outofstock; ?></div>
          <?php } ?>

          <table class="a" id="shopping-cart-table">
            <tr class="highlight2">
              <th class="c" colspan="2">Item</th>
              <th class="e" width="100" style="text-align:center;">Item Number</th>
              <th class="g" nowrap="nowrap" style="text-align:center;">Price</th>
              <th class="f" style="text-align:center;">Quantity</th>
              <th class="g" style="text-align:center;">Total</th>
              <th class="b">Options</th>
              </tr>

            <?php
              foreach ($products as $k=>$product) {
            ?>
            <tr class="highlight1 cart_product_line" id="remove_tr_<?php echo $k+1; ?>" data-product-key="<?php echo $product['product_key']; ?>">
              <td class="i" colspan="2">
                    <div class="crt-product clearfix">
                    <a class="crt-product_img" href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></a>
                    <div class="crt-product_right">
                        <h2 class="product-name">
                        	<a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
                        	  <?php if ($product['quantity']>$product['stock']) { ?> <label style="color:red;">* * *</label> <?php } ?>
                        </h2>
                        <div>
                          <?php foreach ($product['option'] as $option) { ?>
                          	<small style="color:#FF0000; font-size:13px;">- <?php echo $option['name']; ?>: <?php echo $option['value']; ?></small><br />
                          <?php } ?>
                        </div>
                    </div>
            		</div>
              </td>
              <td class="k" align="center"  style="vertical-align:middle;text-align:center;"><div class="crt-product_item"><?php echo $product['product_id']; ?></div></td>
              <td align="left">
              		<div class="crt-product_price">
                    	<span class="cart-price">
                          <span class="price">
                              <span class="price_old"><?php echo $product['price']; ?></span><br />

                              <?php if($product['price']!=$product['discount_price']){ ?>
                              <span class="price_new"><?php echo $product['discount_price']; ?></span>
                              <?php } ?>
                          </span>
                    	</span>
                    </div>
              </td>
              <td class="l"  style="vertical-align:middle; text-align:center;">
                  <div class="crt-product_qty">
                  	<div class="input-group qty-group">
                    	<button id="" class="itemjian btn minus btn-gray" type="button">-</button><input type="text" class="input-text qty form-control" kitorder="0" warecode="" qty="" value="<?php echo $product['quantity']; ?>" id="" name="quantity[<?php echo $product['product_key']; ?>]"><button id="" class="itemjia btn plus btn-gray" type="button">+</button>
                    	<!--<span class="input-group-btn"><button type="button" class="btn itemjian btn-gray" id="">-</button></span>
                    	<input type="text" id="quantity[<?php echo $product['product_key']; ?>]" name="quantity[<?php echo $product['product_key']; ?>]" value="<?php echo $product['quantity']; ?>" qty="<?php echo $product['quantity']; ?>" class="input-text form-control qty"/>
                    	<span class="input-group-btn"><button type="button" class="btn itemjia btn-gray" id="">+</button></span>-->
                    </div>
                  </div>
              </td>
              <td class="m"  style="vertical-align:middle; text-align:center">
              	<div class="crt-product_subtotal">
                    <span class="cart-price">
                        <span class="price"><?php echo $product['total']; ?></span>
                    </span>
                </div>
              </td>
              <td class="h last"  style="vertical-align:middle; text-align:center">
                <div class="crt-product_right">
                    <div class="crt-product_actions">
                    <input type="CheckBox" name="product_id[<?php echo $product['key']; ?>]" style="visibility:hidden; display:none;"/>
                        <a class="icon_link remove-product-link link-wishlist" title="Add to wish list"><!-- onclick="return add_to_wish_list(<?php echo $product['product_id']; ?>)"-->
                            <span class="icon"><i class="icon-heart"></i></span>
                        </a>
                        <a class="icon_link remove-product-link link-remove" title="Remove" onclick="javascript:remove_one('<?php echo $product['key']; ?>');">
                        <span class="icon"><i class="glyphicon glyphicon-trash"></i></span>
                        </a>
                    </div>
                </div>
                <!--remove-->
                <div class="remove_confirm" id="remove-<?php echo $k+1; ?>" data-produt-key='<?php echo $product['product_key']; ?>'>
                	<p>Remove from your cart?</p>
                    <p class="btn_wrap">
                        <a id="remove_yes_<?php echo $k+1; ?>" data-index="<?php echo $k+1; ?>" class="yes">Yes</a> &nbsp;
                        <a class="no">No</a>
                    </p>
                    <i class="icon-remove-top bg"></i>
                    <i class="icon-remove-top"></i>
                </div>
                <!--remove end-->
                </td>
              </tr>
            <?php } ?>
          </table>

            <div class="n cart-collaterals">
              <table id="shopping-cart-totals-table">
                <tr>
                  <td valign="middle" style="padding-right:15px;">
                    <span class="hidden-btn">Click to update the quantity.</span>
                    <img id="updateCartQtyBtn" src="https://www.beststoreitems.com/catalog/template/beststoreitems/image/update.png" alt="Click to update the quantity" style="display:inline-block; margin:0 0 0 2px; vertical-align:bottom;" />
                  </td>
                  <td align="right" class="crt-product_price"><?php echo $text_subtotal; ?> <font id="subtotal_value_id" color=""><?php echo $subtotal; ?></font></td>
                  </tr>
                <?php if(isset($vip_info)){?>
                <tr>
                  <td><a href="index.php?controller=knowledge_base&knowledge_id=6" target="_blank" style="font-size:14px; padding-right:10px; text-decoration:underline;">What is our vip policy?</a></td>
                  <td align="right" class="crt-product_price"><?php echo $vip_info['vip_rank'];?>: <font color="">- <?php echo $vip_info['discount'];?>% off</font></td>
                  </tr>
                <?php }?>
                <tr>
                  <td colspan="2">
                    <span style="">Ship To:</span>
                    <div class="selectBox selectBox1">
                      <ul>
                        <li class="select_box">
                          <span> <?php if(!empty($country_icon)){ echo '<img src="../icon/country/'.$country_icon.'">'; }?><?php echo $country_name; ?></span>
                          <ul class="son_ul">
                            <table style="display:block;">
                              <tbody>
                                <tr>
                                  <td class="tLt"></td>
                                  <td class="tMid"></td>
                                  <td class="tRi"></td>
                                  </tr>
                                <tr>
                                  <td class="mLt"></td>
                                  <td>
                                    <input type="hidden" id="country_id" name="country_id" value="<?php echo $country_id; ?>">
                                    <div class="son_ul_div">
                                      <?php foreach ($countries as $country) { ?>
                                      <li onclick="caculate(0,<?php echo $country['country_id'];?>)"><img src="../icon/country/<?php echo $country['icon']; ?>"><?php echo $country['name']; ?></li>
                                      <?php }?>
                                      </div>
                                    </td>
                                  <td class="mRi"></td>
                                  </tr>
                                <tr>
                                  <td class="bLt"></td>
                                  <td class="bMid"></td>
                                  <td class="bRi"></td>
                                  </tr>
                                </tbody>
                              </table>
                            </ul>
                          </li>
                        </ul>
                      </div>
                    <p id="country_cost">+ <?php echo $country_cost; ?></p></td>
                  </tr>
                <tr>
                  <td align="right" colspan="2">
                    <span>Shipping Method:</span>
                    <div class="selectBox selectBox2">
                      <ul>
                        <li class="select_box select_box_2">
                          <span><?php echo $ship_method_name; ?></span>
                          <ul class="son_ul son_ul_2">
                            <table style="display:block;">
                              <tbody>
                                <tr>
                                  <td class="tLt"></td>
                                  <td class="tMid"></td>
                                  <td class="tRi"></td>
                                  </tr>
                                <tr>
                                  <td class="mLt"></td>
                                  <td>
                                    <input type="hidden" id="shipping_method_id" name="shipping_method_id" value="<?php echo $shipping_method_id; ?>">
                                    <div class="son_ul_div">
                                      <?php foreach ($shipping_methods as $shipping_method) { ?>

                                      <li onclick="caculate(1,<?php echo $shipping_method['ship_id'];?>)"><?php echo $shipping_method['name']; ?> + <b><?php echo $shipping_method['ship_fee']; ?></b></li>
                                      <?php }?>
                                      </div>
                                    </td>
                                  <td class="mRi"></td>
                                  </tr>
                                <tr>
                                  <td class="bLt"></td>
                                  <td class="bMid"></td>
                                  <td class="bRi"></td>
                                  </tr>
                                </tbody>
                              </table>
                            </ul>
                          </li>
                        </ul>
                      </div>
                    </td>
                  </tr>
                <tr>
                  <td align="right" colspan="2">
                      <div class="grand-total">
                        <div class="grand_totals">
                       	 <?php echo 'Grand Total: '; ?><span id="grand_total"><span id="grandtotal_value_id" class="price"><?php echo $grand_total; ?></span></span>
                        </div>
                      </div>
                    </td>
                  </tr>
                <tr><td colspan="2"><input type="hidden" id="shipping_cost_id" value="<?php echo $shipping_cost?>" /></td></tr>
                </table>
            </div>

           <div class="buttons" align="right">
        		<!--p style="color:blue; font-weigh:bold; font-size:14px;">Note: Flat Rate Shipping: 10 - 20 business days  (Not include the Processing Time), Express Shipping: 3 - 7 business days  (Not include the Processing Time)</p-->
                <div class="buttons_box clearfix"><a href="/" title="Continue Shopping" class="btn_button btn_gray">Continue Shopping</a>
                    <button type="submit" name="checkout" class="btn_button btn_orange" onclick="return checkout_review();" value="" /><i class="icon_safety"></i>Proceed to Checkout</button>
                    <!--div class="or_text">OR</div>
                    <input class="btn_paypal" type="button" value="" onclick="javascript:location.href='index.php?controller=paypal_express&action=checkout'" />
                    </div-->
               </div>
               <input type="hidden" name="subtotal_usd" id="subtotal_usd" value="<?php echo $subtotal_usd; ?>">
               <input type="hidden" name="subtotal_discount" id="subtotal_discount" value="<?php echo $subtotal_discount; ?>">
           </div>
        </form>
        </td>
        </tr>
        </table>
        <?php }else{ ?>
        <div id="error"><?php echo $text_error; ?></div>
        <div class="buttons">
          <table>
            <tr>
              <td align="right"><input type="button" style="background:url(catalog/template/beststoreitems/image/continue.gif); width:130px; height:28px; cursor:pointer; border:0;" value="" onclick="location='<?php echo $continue; ?>'" /></td>
            </tr>
          </table>
        </div>
         <?php } ?>
         </div>
         <!--left end-->
     </div>

     <!--Wishlist-->
    <div class="bg_tip" id="bg_tip"></div>
    <div class="wishlist_confirm" style="display:none;">
    	<div class="wishlis-container">
        <?php if($customer_logged) { ?>
            <div class="atc-inner">
            	<div class="atc-inner-box">
                  <div class="atc-caption">
                      <i class="icon_success"></i>
                      New item added to wishlist
                  </div>
    <div class="atc-message-success"><em id="wishlist_count">2</em> total items in your wishlist</div>
                  <p class="btn_wrap">
                      <a class="continue_shopping btn btn-dark-gray" href="javascript:void(0);">Continue Shopping</a>
                      <a class="btn btn-primary" href="/index.php?controller=my_wishlist">View Wishlist</a>
                  </p>
                  <i class="icon-remove-top bg"></i>
                  <i class="icon-remove-top"></i>
              </div>
              </div>
          <?php }else{ ?>
    			<div class="atc-inner atc-inner-login">
                	<div class="atc-inner-box">
                    <h2>Sign In</h2>
                    <a href="javascript:void(0);" class="atc-close" id="wishlist-close-btn"></a>
                    <div class="clearfix">
                        <form enctype="multipart/form-data" method="post" action="index.php?controller=account_login" id="xsignIn">
                            <div id="login-form-part">
                                <ul>
                                    <li class="form-group">
                                        <input placeholder="Email Address" size="25" id="loginName" maxlength="128" name="email" value="" tabindex="1" class="input-text form-control">
                                    </li>
                                    <li class="form-group">
                                        <input type="password" placeholder="Password" size="25" id="loginPassword" name="password" maxlength="100" value="" tabindex="2" class="input-text form-control">
                                    </li>
                                </ul>
                                <div class="form-group forgetpw"><a id="forgotPwId" href="https://www.beststoreitems.com/index.php?controller=account_forgotten">Forgot password?</a></div>
                                <div class="buttonWrap">
                                    <input type="submit" onclick="return login_checkinput();" value="Sign &nbsp;in" id="submitName" class="btn btn-primary">
                                </div>
                          </div>
                        </form>
                    </div>
                </div>
          <?php } ?>
          </div>
    </div>
    <!--Wishlist-->
	</div>
</div>
<script type="text/javascript" src="catalog/javascript/select_product.js"></script>
