<!-- Progress Bar -->
<?php echo $this->progressBar;?>


<!-- Main Page -->

<script type="text/javascript">
var cartItem = null;
// Show an ExtJS alert box when deleting a cart item
function confirmCartDelete(itemName, itemID) {

    // Set the cart ID globally & show popup
    cartItem = itemID;
    Ext.Msg.show({
       title: itemName,
       msg: "<?php echo $this->lang('Are you sure that you wish to remove the item from your cart?');?>",
       buttons: Ext.Msg.YESNO,
       fn: processRemoveResult,
       icon: Ext.MessageBox.QUESTION
    });
}
// Callback function for ExtJS delete popup
function processRemoveResult(btn) {

    // Check if we can remove the item
    if(btn == 'yes') {

        // Callback for recieved
        var received = function (response) {
            window.location='order.php?step=3';
	}

	Ext.Ajax.request({
	   url: 'index.php?fuse=admin&action=deleteCartItem',
	   success: received,
	   failure: received,
	   params: { cartItem: cartItem }
	});
    }
}

function showHideAddons(productId) {
    var el = document.getElementById('addons-' + productId);
    if ( el.style.display != 'none' ) {
        el.style.display = 'none';
        el.style.visibility = 'hidden';
    } else {
        el.style.display = 'block';
        el.style.visibility = 'visible'
    }
    return false;
}

// Show popup for Coupon
function applyCoupon(itemID, couponCode) {
    Ext.Msg.prompt('Apply Coupon', '<?php echo $this->lang("Please enter the Coupon Code");?>:', function(btn, text){
    if (btn == 'ok'){
        validateCoupon(text, itemID);
    }
}, null, null, couponCode);
}

// Validate Coupon Code
function validateCoupon(couponCode, itemID) {
    var received = function (response) {
        var data = Ext.util.JSON.decode(response.responseText);
        if(data.error){
            Ext.Msg.show({
               title: '<?php echo $this->lang('Coupon Error');?>',
               msg: data.message,
               buttons: Ext.Msg.OK,
               icon: Ext.MessageBox.WARNING,
               minWidth: '300'
            });
        } else {
            window.location='order.php?step=3';
        }
    }
    Ext.Ajax.request({
       url: 'index.php?fuse=admin&action=validateCoupon',
       success: received,
       failure: received,
       params: { couponCode: couponCode, itemID: itemID }
    });
}
</script>
<form action="order.php?step=4" method="POST">
<h3><?php echo $this->lang("Order Summary");?></h3>
<p class="pagedesc"><?php echo $this->lang("Please review your order and make any neccessary adjustments before proceeding to checkout.");?></p>

<div>
<table class="ts2" cellspacing="0">
  <tr style="background:#E8F3F8;">
    <td><strong><?php echo $this->lang('Product');?></strong></td>
    <td></td>
    <td width="150" align="right"><strong><?php echo $this->lang('Price');?></strong></td>
  </tr>

  <?php if(is_array($this->cartItems)) { ?>
  
    <?php foreach($this->cartItems AS $item) { ?>
      <tr>
        <td><?php echo $item['groupName'];?> / <?php echo $item['name'];?> <?php if(@$item['titleText']) { echo $item['titleText'];}?>
            <?php if(@$item['isDomain']) { ?><br /> <em> <?php echo $item['domainName']; ?> x <?php echo $item['term']; ?> <?php } ?></em>
            <?php if($item['associatedDomain'] != false) { ?><br /> <?php echo $item['associatedDomain'];?> <?php } ?>
            <?php if($item['hasAddons']) {?>
                <a style="cursor: pointer;" onclick="showHideAddons('<?php echo $item['cartItemId'];?>');"><br />+ <?php echo $this->lang('Addons');?></a>
                <div id="addons-<?php echo $item['cartItemId'];?>" style="visibility:hidden; display:none;">
                    <?php foreach($item['addons'] AS $addon) { ?>
                        <?php echo $addon['name']; ?>  - <?php echo$addon['item']; ?><br>
                    <?php } ?>
                </div>
            <?php } ?>
        </td>
        <td align="right"> <a onclick="confirmCartDelete('<?php echo $item['groupName'];?> / <?php echo $item['name'];?>', '<?php echo $item['cartItemId'];?>');" style="color:#900; cursor: pointer;"><?php echo $this->lang('Remove');?></a> <?php if(@$this->acceptCoupons) { ?>| <a onclick="applyCoupon('<?php echo $item['cartItemId'];?>', '<?php echo $item['appliedCoupon'];?>');" style="cursor: pointer;"><?php if(@$item['hasCoupon']) { echo $this->lang('Update Coupon'); } else { echo $this->lang('Apply Coupon'); }?></a><?php } ?></td>
        <td align="right">
            <strong><?php if(@$item['newTotal']) { echo '<span style="text-decoration: line-through;"> '.$item['totalFormatted'] .'</span> <span style="color:red;">'.$item['newTotal'].'</span>'; } else { echo $item['totalFormatted']; }?></strong> <?php if(isset($item['isProRated'])) { echo "*"; } ?>
                    <?php if(@$item['newSetup']) { echo '<br><span style="text-decoration: line-through;"> '.$item['setupFormatted'] .' '.$this->lang('Setup Fee').'</span> <br> <span style="color:red;">'.$item['newSetup'].' '.$this->lang('Setup Fee').'</span>'; } elseif(@$item['setupFormatted']) { echo "<br> ".$item['setupFormatted']." ".$this->lang('Setup Fee'); } ?>
        </td>
      </tr>
    <?php } // end foreach ?>

  <?php } else { ?>
      <tr>
        <td colspan="3"><?php echo $this->lang('Cart is empty');?></td>
      </tr>
  <?php } //endif ?>

  <?php if(is_array($this->cartItems)) { ?>
      <tr>
        <td colspan="3" align="right" style="font-size:14px; border-bottom:0px;">
            <?php if(isset($this->isProRating)) { ?> <div style="font-size:10px"><?php echo $this->lang('* Price is pro-rated to '); echo $this->proRatingTo; echo $this->lang(" of the month. Next bill date will be: "); echo $this->proRateDate;?></div><br><?php } ?>
            Subtotal: <strong><?php echo $this->cartTotal['price'];?></strong>
          <?php if($this->cartTotal['recurringItems'] != false) { ?>
                <br>Then <?php if(count($this->cartTotal['recurringItems']) > 1) { ?> <br> <?php } ?>
                <?php foreach($this->cartTotal['recurringItems'] AS $item) {
                        echo "<b>".$item['amount']."</b> ".$this->lang('every')." ".$item['period']." ".$item['text']."<br>";
                 } //endforeach ?>
          <?php } //endif ?>
                <div style="font-size:10px"><?php echo $this->lang('All prices are excluding any applicable taxes which will be calculated in the next step.');?></div>
                
        </td>
      </tr>
  <?php } //endif ?>
</table>
</div>

<div class="clear"></div>

<div style="margin-bottom:20px;text-align:center;"><input class="submit" type="button" value="<?php echo $this->lang('Continue Shopping');?>" onclick="window.location.href='order.php'" /> &nbsp; <input class="submit" type="submit" value="<?php echo $this->lang('Proceed to Checkout');?>" <?php if($this->cartCount == 0) { echo "disabled";}?> /></div>

</form>