<?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
 * @package     default_iphone
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/* @var $this Mage_Wishlist_Block_Customer_Wishlist */
?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<div class="my-wishlist">
    <div class="page-title title-buttons">
        <?php if ($this->helper('wishlist')->isRssAllow() && $this->hasWishlistItems()): ?>
            <a href="<?php echo $this->helper('wishlist')->getRssUrl(); ?>" class="link-rss"><?php echo $this->__('RSS Feed') ?></a>
        <?php endif; ?>
        <h1><?php echo $this->__('My Wishlist') ?></h1>
    </div>
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <?php if ($this->hasWishlistItems()): ?>
    <form id="wishlist-view-form" action="<?php echo $this->getUrl('*/*/update') ?>" method="post">
        <fieldset>
            <?php echo $this->getBlockHtml('formkey')?>
            <table class="data-table" id="wishlist-table">
            <col width="1" />
            <col width="1" />
            <col width="1" />
            <col width="1" />
                <thead>
                    <tr>
                        <th><?php echo $this->__('Product') ?></th>
                        <th class="a-center"><span class="nobr"><?php echo $this->__('Added On') ?></span></th>
                        <th class="a-center"><span class="nobr"><?php echo $this->__('Add to Cart') ?></span></th>
                    </tr>
                </thead>
                <tbody>
                <?php foreach ($this->getWishlistItems() as $item): ?>
                    <tr>
                        <td>
                            <a class="product-image" href="<?php echo $this->getProductUrl($item) ?>" title="<?php echo $this->escapeHtml($item->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($item, 'small_image')->resize(113, 113); ?>" width="113" height="113" alt="<?php echo $this->escapeHtml($item->getName()) ?>" /></a>
                            <h2 class="product-name"><a href="<?php echo $this->getProductUrl($item) ?>"><?php echo $this->escapeHtml($item->getName()) ?></a></h2>
                            <?php echo $this->getPriceHtml($item) ?>
                        </td>
                        <td>
                            <span class="nobr"><?php echo $this->getFormatedDate($item->getAddedAt()) ?></span>
                        </td>
                        <td class="a-center">
                        <?php if ($item->canHaveQty()): ?>
                            <p><input type="text" class="input-text qty" name="qty[<?php echo $item->getId() ?>]" value="<?php echo $this->getAddToCartQty($item) * 1 ?>" /></p>
                        <?php endif; ?>
                        <?php if($item->isSaleable()): ?>
                            <button type="button" title="<?php echo $this->__('Add to Cart') ?>" onclick="addWItemToCart(<?php echo $item->getId(); ?>)" class="button btn-cart"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                        <?php else: ?>
                            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                            <p><a href="<?php echo $this->getItemConfigureUrl($item) ?>"><?php echo $this->__('Edit') ?></a></p>
                            <a href="<?php echo $this->getItemRemoveUrl($item) ?>" title="<?php echo $this->__('Remove Item') ?>" onclick="return confirmRemoveWishlistItem();" class="btn-remove2"><?php echo $this->__('Remove item')?></a>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <span><?php echo $this->__('Comment:') ?></span>
                            <textarea name="description[<?php echo $item->getWishlistItemId() ?>]" rows="3" cols="5" onfocus="focusComment(this)" onblur="focusComment(this)" title="<?php echo $this->__('Comment') ?>"><?php echo $this->getCommentValue($item); ?></textarea>
                        </td>
                    </tr>
                <?php endforeach ?>
                </tbody>
            </table>
            <script type="text/javascript">decorateTable('wishlist-table')</script>
            <div class="buttons-set buttons-set2">
                <button type="submit" onclick="this.name='save_and_share'" title="<?php echo $this->__('Share Wishlist') ?>" class="button btn-share"><span><span><?php echo $this->__('Share Wishlist') ?></span></span></button>
                <?php if($this->isSaleable()):?>
                    <button type="button" title="<?php echo $this->__('Add All to Cart') ?>" onclick="addAllWItemsToCart()" class="button btn-add"><span><span><?php echo $this->__('Add All to Cart') ?></span></span></button>
                <?php endif;?>
                <button type="submit" onclick="this.name='do'" title="<?php echo $this->__('Update Wishlist') ?>" class="button btn-update"><span><span><?php echo $this->__('Update Wishlist') ?></span></span></button>
            </div>
        </fieldset>
    </form>
    <?php else: ?>
        <p><?php echo $this->__('You have no items in your wishlist.') ?></p>
    <?php endif ?>
    <script type="text/javascript">
    //<![CDATA[
    function confirmRemoveWishlistItem() {
        return confirm('<?php echo $this->__('Are you sure you want to remove this product from your wishlist?') ?>');
    }

    function focusComment(obj) {
        if( obj.value == '<?php echo $this->helper('wishlist')->defaultCommentString() ?>' ) {
            obj.value = '';
        } else if( obj.value == '' ) {
            obj.value = '<?php echo $this->helper('wishlist')->defaultCommentString() ?>';
        }
    }

    function addWItemToCart(itemId) {
        var url = '<?php echo $this->getItemAddToCartUrl('%item%') ?>';
        url = url.gsub('%item%', itemId);
        var form = $('wishlist-view-form');
        if (form) {
            var input = form['qty[' + itemId + ']'];
            if (input) {
                var separator = (url.indexOf('?') >= 0) ? '&' : '?';
                url += separator + input.name + '=' + encodeURIComponent(input.value);
            }
        }
        setLocation(url);
    }

    function addAllWItemsToCart() {
        var url = '<?php echo $this->getUrl('*/*/allcart') ?>';
        var separator = (url.indexOf('?') >= 0) ? '&' : '?';
        $$('#wishlist-view-form .qty').each(
            function (input, index) {
                url += separator + input.name + '=' + encodeURIComponent(input.value);
                separator = '&';
            }
        );
        setLocation(url);
    }
    //]]>
    </script>
</div>
<div class="buttons-set">
    <p class="back-link"><a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
</div>
<?php endif ?>
