<?php
/**
 * Avalanche for Magento 1.8+
 * Designed by Fast Division (http://fastdivision.com)
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the EULA
 * that is bundled with this package in the file license.txt.
 * It is also available through the world-wide-web at this URL:
 * http://fastdivision.com/legal/license.txt
 *
 * @author     Fast Division
 * @version    1.5.0
 * @copyright  Copyright 2013 Fast Division
 * @license    http://fastdivision.com/legal/license.txt
 */
?>
<div class="grid_12 white-box">

<h1 style="margin:0"><?php echo $this->__('Review Order') ?></h1>

<div class="multiple-checkout">
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <form action="<?php echo $this->getPostActionUrl() ?>" method="post" onsubmit="return showLoader();" class="clearfix">
        <div class="clearfix">
            <div class="box">
                <?php $_address=$this->getBillingAddress() ?>
                <div class="box-title">
                    <h3><?php echo $this->__('Billing Address') ?> <span class="separator">|</span> <a href="<?php echo $this->getEditBillingAddressUrl($_address) ?>"><?php echo $this->__('Change') ?></a></h3>
                </div>
                <div class="box-content">
                    <address>
                        <?php echo $_address->format('html') ?>
                    </address>
                </div>
            </div>
            <div class="box">
                <div class="box-title">
                    <h3><?php echo $this->__('Payment Method') ?> <span class="separator">|</span> <a href="<?php echo $this->getEditBillingUrl() ?>"><?php echo $this->__('Change') ?></a></h3>
                </div>
                <div class="box-content">
                    <input type="hidden" name="payment[cc_number]" value="<?php echo $this->htmlEscape($this->getPayment()->getCcNumber())?>" />
                    <input type="hidden" name="payment[cc_cid]" value="<?php echo $this->htmlEscape($this->getPayment()->getCcCid())?>" />
                    <?php echo $this->getPaymentHtml() ?>
                </div>
            </div>
         </div>
        <?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
        <div class="clearfix">
        <?php foreach ($this->getShippingAddresses() as $_index => $_address): ?>
            <h3><?php echo $this->__('Shipping Address %s of %s', ($_index+1), $this->getShippingAddressCount()) ?></h3>
            <div class="white-box-inner clearfix">
                <div class="grid_3 alpha omega">
                    <div class="box">
                        <div class="box-title">
                            <h4><?php echo $this->__('Shipping To') ?> <span class="separator">|</span> <a href="<?php echo $this->getEditShippingAddressUrl($_address) ?>"><?php echo $this->__('Change') ?></a></h4>
                        </div>
                        <div class="box-content">
                            <address>
                                <?php echo $_address->format('html') ?>
                            </address>
                        </div>
                    </div>
                    <div class="box">
                        <div class="box-title">
                            <h4><?php echo $this->__('Shipping Method') ?> <span class="separator">|</span> <a href="<?php echo $this->getEditShippingUrl() ?>"><?php echo $this->__('Change') ?></a></h4>
                        </div>
                        <div class="box-content">
                            <?php if($_rate=$this->getShippingAddressRate($_address)): ?>
                            <p>
                            <?php echo $_rate->getCarrierTitle() ?> - <?php echo $_rate->getMethodTitle() ?>
                            <?php $_excl = $this->getShippingPriceExclTax($_address); ?>
                            <?php $_incl = $this->getShippingPriceInclTax($_address); ?>
                            <?php echo $_excl; ?>
                            <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                                (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
                            <?php endif; ?>
                            </p>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <div class="grid_8 omega">
                    <h4><?php echo $this->__('Items') ?> <span class="separator">|</span> <a href="<?php echo $this->getAddressesEditUrl() ?>"><?php echo $this->__('Edit Items') ?></a></h4>
                    <table class="data-table" id="overview-table-<?php echo $_address->getId() ?>">
                        <col />
                        <col width="1" />
                        <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                        <col width="1" />
                        <?php endif; ?>
                        <col width="1" />
                        <col width="1" />
                        <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                        <col width="1" />
                        <?php endif; ?>
                        <thead>
                            <tr>
                                <th rowspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Product Name') ?></th>
                                <th colspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Price') ?></th>
                                <th rowspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Qty') ?></th>
                                <th colspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Subtotal') ?></th>
                            </tr>
                            <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                            <tr>
                                <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                                <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                                <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                                <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                            </tr>
                            <?php endif; ?>
                        </thead>
                        <tfoot>
                            <?php echo $this->renderTotals($this->getShippingAddressTotals($_address)); ?>
                        </tfoot>
                        <tbody>
                        <?php foreach ($this->getShippingAddressItems($_address) as $_item): ?>
                            <?php echo $this->getRowItemHtml($_item); ?>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                    <script type="text/javascript">decorateTable('overview-table-<?php echo $_address->getId() ?>')</script>
                </div>
            </div>
            <?php if($this->getShippingAddressCount()!=$_index+1): ?>
                <div class="divider"></div>
            <?php endif; ?>
        <?php endforeach; ?>
        </div>
        <?php if ($this->getQuote()->hasVirtualItems()): ?>
        <div class="col2-set">
            <h2 class="legend"><?php echo $this->__('Other Items in Your Order') ?></h2>
            <div class="col-1 col-narrow"></div>
            <div class="col-2 col-wide">
                <h3><?php echo $this->__('Items') ?> <span class="separator">|</span> <a href="<?php echo $this->getVirtualProductEditUrl() ?>"><?php echo $this->__('Edit Items') ?></a></h3>
                <?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
                <table class="data-table" id="virtual-overview-table">
                    <col />
                    <col width="1" />
                    <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                    <col width="1" />
                    <?php endif; ?>
                    <col width="1" />
                    <col width="1" />
                    <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                    <col width="70" />
                    <?php endif; ?>
                    <thead>
                        <tr>
                            <th rowspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Product Name') ?></th>
                            <th colspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Price') ?></th>
                            <th rowspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Qty') ?></th>
                            <th colspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Subtotal') ?></th>
                        </tr>
                        <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                        <tr>
                            <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                            <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                            <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                            <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                        </tr>
                        <?php endif; ?>
                    </thead>
                    <tfoot>
                        <?php echo $this->renderTotals($this->getBillinAddressTotals()); ?>
                    </tfoot>
                    <tbody>
                    <?php foreach ($this->getVirtualItems() as $_item): ?>
                        <?php echo $this->getRowItemHtml($_item); ?>
                    <?php endforeach; ?>
                    </tbody>
                    </table>
                    <script type="text/javascript">decorateTable('virtual-overview-table')</script>
                </div>
        </div>
        <?php endif; ?>

           <?php echo $this->getChildHtml('items_after'); ?>

            <div id="checkout-review-submit" class="clearfix">
                <?php echo $this->getChildHtml('agreements') ?>
            </div>

            <div class="box-action box-multishipping clearfix">
                <p class="back-link"><a href="<?php echo $this->getBackUrl() ?>"><small>&laquo; </small><?php echo $this->__('Back to Billing Information') ?></a></p>
                <button type="submit" title="<?php echo $this->__('Complete Order') ?>" class="action-button" id="review-button"><span><?php echo $this->__('Complete Order') ?></span></button>
            </div>
        </form>
        <script type="text/javascript">
        //<![CDATA[
            var submitted = false;

            function showLoader()
            {
                if (submitted) {
                    return false;
                }
                if ($('checkout-agreements')) {
                    var checkboxes = $$('#checkout-agreements input');
                    for (var i=0, l=checkboxes.length; i<l; i++) {
                        if (!checkboxes[i].checked) {
                            alert("<?php echo $this->__('Please agree to all Terms and Conditions before placing the orders.')?>");
                            return false;
                        }
                    }
                }

                submitted = true;
                var step='review';
                Element.show(step+'-please-wait');
                $(step+'-buttons-container').setStyle({opacity:.5});
                $(step+'-buttons-container').descendants().each(function(s) {
                      s.disabled = true;
                });
                return true;
            }
        //]]>
        </script>
</div>
</div>