<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="page-head">
    <h3><?php echo $this->__('Review Order') ?></h3>
</div>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="multi-address-checkout-box">

    <div class="box">
        <h4 class="legend"><?php echo $this->__('Shipping Information') ?></h4>
        <div class="clear"></div>
        <div class="content col2-set">
            <div class="col-1">
                <div class="head">
                    <h4><?php echo $this->__('Shipping Address') ?> <span class="separator">|</span> <a href="<?php echo $this->getUrl('paypaluk/express/edit') ?>"><?php echo $this->__('Change Shipping Address') ?></a></h4>
                </div>
                <address>
                    <?php echo $this->getShippingAddress()->getFormated(true) ?>
                </address>
            </div>
            <div class="col-2">
                <div class="head">
                    <h4><?php echo $this->__('Shipping Method') ?></h4>
                </div>
                <?php if ($this->isVirtual()): ?>
                    <strong><?php echo $this->__('No shipping method required.') ?></strong>
                <?php else: ?>
                    <?php if (!($_shippingRateGroups = $this->getShippingRates())): ?>
                        <strong><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></strong>
                    <?php else: ?>

                    <form method="post" action="<?php echo $this->getUrl('paypaluk/express/saveShippingMethod') ?>">
                        <select name="shipping_method" id="shipping_method" style="width:250px" onchange="saveShippingMethod(this.value)">
                        <?php if(!$this->getAddressShippingMethod()): ?>
                            <option value=""><?php echo $this->__('Please select a shipping method...') ?></option>
                        <?php endif ?>
                        <?php foreach ($_shippingRateGroups as $code => $_rates): ?>
                            <optgroup label="<?php echo $this->getCarrierName($code) ?>" style="font-style:normal;">
                            <?php foreach ($_rates as $_rate): ?>
                               <?php if ($_rate->getErrorMessage()): ?>
                                    <option value="">
                                        <?php echo $_rate->getErrorMessage() ?>
                                    </option>
                               <?php else: ?>
                                   <option value="<?php echo $_rate->getCode() ?>" <?php if($_rate->getCode()===$this->getAddressShippingMethod()): ?>selected="selected"<?php endif ?> style="margin-left:16px">
                                        <?php echo $_rate->getMethodTitle() ?> -

                                        <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
                                        <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>

                                        <?php echo $_excl; ?>
                                        <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
                                            (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
                                        <?php endif; ?>
                                   </option>
                               <?php endif ?>
                            <?php endforeach; ?>
                            </optgroup>
                        <?php endforeach; ?>
                        </select>
                        <br/><br/>
                        <button id="update_shipping_method" class="form-button" type="submit"><span><?php echo $this->__('Update Shipping Method') ?></span></button>
                    </form>

                    <?php endif; ?>
                <?php endif; ?>

            </div>
        </div>
     </div>

    <div class="box">
        <h4 class="legend"><?php echo $this->__('Billing Information') ?></h4>
        <div class="clear"></div>

        <div class="content">
            <div class="head">
                <h4><?php echo $this->__('Payment Method') ?> <span class="separator">|</span> <a href="<?php echo $this->getUrl('paypaluk/express/edit') ?>"><?php echo $this->__('Change Payment Method') ?></a></h4>
            </div>
            <?php echo $this->__('PayPal Uk Account') ?><br />
            <?php echo $this->getBillingAddress()->getEmail() ?>

        </div>
    </div>

    <div class="head" style="margin-top:-11px">
        <h4><?php echo $this->__('Items in Your Shopping Cart') ?> <span class="separator">|</span> <a href="<?php echo $this->getUrl('checkout/cart') ?>"><?php echo $this->__('Edit Shopping Cart') ?></a></h4>
    </div>

    <div id='details-reload'>
        <?php echo $this->getChildHtml('details') ?>
    </div>
    <script type="text/javascript">decorateTable('details-table')</script>

    <br/>

    <form method="post" action="<?php echo $this->getUrl('paypaluk/express/saveOrder') ?>">
        <p class="a-right">
             <span id="review-please-wait" style="display:none;" class="opc-please-wait">
                <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" class="v-middle" alt=""/> &nbsp; <?php echo $this->__('Submitting order information...') ?> &nbsp;
            </span>
            <span id="review-buttons-container">
                <input type="image" id="review-button" src="<?php echo $this->getSkinUrl('images/btn_place_order.gif') ?>" value="<?php echo $this->__('Place an Order') ?>" onclick="return saveOrder();" />
            </span>
        </p>
    </form>

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

</div>

<script type="text/javascript">
//<![CDATA[
    if ($('update_shipping_method')) {
        $('update_shipping_method') && $('update_shipping_method').hide();
    }
    var submitted = false;

    function saveShippingMethod(value)
    {
        new Ajax.Updater('details-reload', '<?php echo $this->getUrl('paypaluk/express/saveShippingMethod') ?>', {
            parameters: { ajax:true, shipping_method:value },
            onComplete: function(){decorateTable('details-table')}
        });
    }

    function saveOrder()
    {
        if (submitted) {
            return false;
        }
        if ($('shipping_method') && $('shipping_method').value=='') {
            alert('Please select a valid shipping method before submitting the order.');
            return false;
        }
        submitted = true;
        showLoader();
        return true;
    }


    function showLoader()
    {
        Element.show('review-please-wait');
        Element.setStyle('review-buttons-container', {opacity:.5});
    }
//]]>
</script>
