<!-- 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, isBundle) {
    
    if(isBundle) {
        var confirmMsg = "<?php echo $this->lang('Are you sure that you wish to remove the item from your cart? <br>Note: The associated domain will also be removed.');?>";
    } else {
        var confirmMsg = "<?php echo $this->lang('Are you sure that you wish to remove the item from your cart?');?>";
    }

    // Set the cart ID globally & show popup
    cartItem = itemID;
    bundleCartItem = isBundle;
    Ext.Msg.show({
       title: itemName,
       msg: confirmMsg,
       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, bundleCartItem:bundleCartItem }
	});
    }
}

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'
    }

    if ( $('#toggle_addon_text_' + productId).html() == '+' ) {
        $('#toggle_addon_text_' + productId).html('-');
    } else {
        $('#toggle_addon_text_' + productId).html('+');
    }
    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 /><span id="toggle_addon_text_<?php echo $item['cartItemId'];?>">+</span> <?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"> <?php if(!isset($item['hidden']['delete'])){?><a onclick="confirmCartDelete('<?php echo $item['safeGroupName'];?> / <?php echo $item['safeName'];?>', '<?php echo $item['cartItemId'];?>', '<?php if(isset($item['bundledDomainId'])) { echo $item['bundledDomainId'];}?>');" style="color:#900; cursor: pointer;"><?php echo $this->lang('Remove');?></a> <?php } ?><?php if(@$this->acceptCoupons) { ?><?php if(!isset($item['hidden']['delete'])){?>|<?php }?> <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']) && $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 } ?>
            <?php echo $this->lang('Subtotal'); ?>: <strong><?php echo $this->cartTotal['price'];?></strong>
          <?php if($this->cartTotal['recurringItems'] != false) { ?>
                <br><?php echo $this->lang('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>