<?php if (!defined('IN_CONTEXT')) die('access violation error!'); ?>
<script type="text/javascript" language="javascript">
<!--
    function cartupdated(response) {
        var o_result = _eval_json(response);
        if (!o_result) {
            return on_failure(response);
        }
        
        if (o_result.result == "ERROR") {
            $("#cartupdating_stat").html(o_result.errmsg);
            return false;
        } else if (o_result.result == "OK") {
            $("#cartupdating_stat").html("<?php _e('OK, refreshing...'); ?>");
            reloadPage();
        } else {
            return on_failure(response);
        }
    }
    
    function cartupdatefailed(response) {
        $("#cartupdating_stat").html("<?php _e('Request failed!'); ?>");
        return false;
    }
    
    function updateprodnum(p_id) {
        $("#cartupdating_stat").css({"display":"block"});
        $("#cartupdating_stat").html("<?php _e('Updating shopping cart...'); ?>");
        var p_num = document.getElementById("prod_num_" + p_id).value;
        _ajax_request("mod_cart", "updateprodnum", 
            { p_id: p_id, p_num: p_num }, cartupdated, cartupdatefailed);
    }
    
    function removeprod(p_id) {
        $("#cartupdating_stat").css({"display":"block"});
        $("#cartupdating_stat").html("<?php _e('Updating shopping cart...'); ?>");
        _ajax_request("mod_cart", "delfromcart", 
                    { p_id: p_id }, cartupdated, cartupdatefailed);
    }
//-->
</script>
<div id="myPannel">
	<div class="title">
    	<div class="l">
        	<div class="r">
            	<?php _e('My Shopping Cart'); ?>
            </div>
        </div>
    </div>
  <div class="kkair">
  	<div class="order">
     	<a href="index.php?<?php echo Html::xuriquery('mod_order', 'ordernow'); ?>" class="bt"><?php _e('Order now!'); ?></a>
    </div>
  </div>
    
     <?php
        if (sizeof($products) > 0) {
            $row_idx = 0;
            foreach ($products as $product) {
                $product->loadRelatedObjects(REL_PARENT, array('ProductCategory'));
     ?>
     
<table width="80%" border="0" cellpadding="0" cellspacing="0" class="list row_style_<?php echo $row_idx; ?>">
  <tr>
    <td>
        <a href="index.php?<?php echo Html::xuriquery('mod_product', 'view', array('p_id' => $product->id)); ?>" title="<?php echo $product->name; ?>"><?php echo $product->name; ?></a>
        <br />
        <?php _e('Category'); ?>: <a href="index.php?<?php echo Html::xuriquery('mod_product', 'prdlist', array('cap_id' => $product->masters['ProductCategory']->id)); ?>"><?php echo $product->masters['ProductCategory']->name; ?></a>
    </td>
    <td>
		<?php _e('Quantity'); ?><?php echo Html::input('text', 'prod_num_'.$product->id, $_COOKIE['n_prd'][$product->id], 'size="4"'); ?>
    </td>
    <td>
        <span><a href="#" onclick="updateprodnum('<?php echo $product->id; ?>');">&raquo; <?php _e('Update quantity'); ?></a></span>
        <br />
        <span><a href="#" onclick="removeprod('<?php echo $product->id; ?>');">&raquo; <?php _e('Remove'); ?></a></span>
    </td>
  </tr>
</table>

     
    <?php
                $row_idx = 1 - $row_idx;
            }
        } else {
	?>
<div><?php _e('No Records!'); ?></div>
        <?php } ?>
</div>
