<?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="my-wishlist">
	<h1><?php echo $this->__('My Wishlist') ?></h1>

	<div class="white-box-inner">
		<div class="page-messages">
  	  		<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
		</div>
	    <?php if ($this->hasWishlistItems()): ?>
	    <form id="wishlist-view-form" action="<?php echo $this->getUrl('*/*/update') ?>" method="post">
	        <fieldset>
	            <?php echo $this->getBlockHtml('formkey')?>
	            <table id="wishlist-table" width="100%">
	                <tbody>
	                <?php foreach ($this->getWishlistItems() as $item): ?>
	                    <?php
	                        $product = $item->getProduct();
	                        $isVisibleProduct = $product->isVisibleInSiteVisibility();
	                    ?>
	                    <tr>
							<td>
								<a class="product-image" href="<?php echo $this->getProductUrl($item) ?>" title="<?php echo $this->htmlEscape($product->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(113, 113); ?>" width="113" height="113" alt="<?php echo $this->htmlEscape($product->getName()) ?>" /></a>
							</td>
	                        <td>
	                            <a href="<?php echo $this->getProductUrl($item) ?>"><?php echo $this->htmlEscape($product->getName()) ?></a>
	                            <span class="price"><?php echo $this->getPriceHtml($product) ?></span>
								<textarea name="description[<?php echo $item->getWishlistItemId() ?>]" rows="3" cols="32" onfocus="focusComment(this)" onblur="focusComment(this)" style="margin-top: 6px" title="<?php echo $this->__('Comment') ?>"><?php echo $this->getCommentValue($item); ?></textarea><br><br>
	                        </td>
	                        <td style="width: 90px" class="a-center">
	                        <?php if ($item->canHaveQty() && $isVisibleProduct): ?>
	                            <input type="text" class="input-text qty" style="margin: 0 0 8px 0; text-align: center; width: 30px" name="qty[<?php echo $item->getId() ?>]" value="<?php echo $this->getAddToCartQty($item) * 1 ?>" /><br>
	                        <?php endif; ?>
	                        <?php if ($product->isSaleable()): ?>
	                            <?php if ($isVisibleProduct): ?>
	                            <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><br>
	                            <?php endif ?>
								<a href="<?php echo $this->getItemRemoveUrl($item) ?>" title="<?php echo $this->__('Remove') ?>" onclick="return confirmRemoveWishlistItem();" class="remove-link"><?php echo $this->__('Remove')?></a>
	                        <?php else: ?>
	                            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
	                        <?php endif; ?>
	                        </td>
	                    </tr>
	                <?php endforeach ?>
	                </tbody>
	            </table>
	            <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 light-button"><span><span><?php echo $this->__('Share Wishlist') ?></span></span></button>&nbsp;&nbsp;
	                <?php if($this->isSaleable()):?>
	                    <button type="button" title="<?php echo $this->__('Add All to Cart') ?>" onclick="addAllWItemsToCart()" class="button btn-add light-button"><span><span><?php echo $this->__('Add All to Cart') ?></span></span></button>&nbsp;&nbsp;
	                <?php endif;?>
	                <button type="submit" title="<?php echo $this->__('Update Wishlist') ?>" onclick="this.name='do'" class="button btn-update light-button"><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 ?>
	</div>
    <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>
