<?php
/**
 * aheadWorks Co.
 *
 * 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://ecommerce.aheadworks.com/LICENSE-M1.txt
 *
 * @category   AW
 * @package    AW_Mobile
 * @copyright  Copyright (c) 2010-2011 aheadWorks Co. (http://www.aheadworks.com)
 * @license    http://ecommerce.aheadworks.com/LICENSE-M1.txt
 */
?>
<?php if(!$this->getDontDisplayContainer()): ?>
<script type="text/javascript">
<!--
if(!window.toogleVisibilityOnObjects) {
    var toogleVisibilityOnObjects = function(source, objects) {
        if($(source) && $(source).checked) {
            objects.each(function(item){
                $(item).show();
                $$('#' + item + ' .input-text').each(function(item) {
                    item.removeClassName('validation-passed');
                });
            });


        } else {
            objects.each(function(item){
                $(item).hide();
                $$('#' + item + ' .input-text').each(function(sitem) {
                    sitem.addClassName('validation-passed');
                });

                 $$('#' + item + ' .giftmessage-area').each(function(sitem) {
                    sitem.value = '';
                });
            });

        }

    }
}
if(!window.toogleRequired) {
    var toogleRequired = function (source, objects)
    {
        if(!$(source).value.blank()) {
            objects.each(function(item) {
               $(item).addClassName('required-entry');
            });
        } else {
            objects.each(function(item) {
                if(shippingMethod && shippingMethod.validator) {
                   shippingMethod.validator.reset(item);
                }
                $(item).removeClassName('required-entry');
            });

        }
    }
}
if(window.shipping) {

shipping.onSave = function(evt){
    new Ajax.Updater('onepage-checkout-shipping-method-additional-load', '<?php echo $this->getAdditionalUrl(); ?>', {onSuccess: function() {
          this.nextStep(evt);
    }.bind(this), evalScripts:true});
}.bindAsEventListener(shipping);

billing.onSave = function(evt){
    new Ajax.Updater('onepage-checkout-shipping-method-additional-load', '<?php echo $this->getAdditionalUrl(); ?>', {onSuccess: function() {
          this.nextStep(evt);
    }.bind(this), evalScripts:true});
}.bindAsEventListener(billing);

}
//-->
</script>
<?php endif ?>
<?php if (true): ?>

<div class="giftmessages">
<?php switch ($this->getType()): ?>
<?php case 'onepage_checkout': ?>
    <div class="inner-box">
        <span class="gift-header"><?php echo $this->__('Do you have any gift items in your order?'); ?></span>
        <div class="clear"></div>
        <div class="a-left input-checkbox">
            <input type="checkbox" name="allow_gift_messages" id="allow_gift_messages" value="1" onclick="toogleVisibilityOnObjects(this, ['allow-gift-message-container']);" <?php if($this->getItemsHasMesssages() || $this->getEntityHasMessage()): ?>checked="checked"<?php endif ?> />
            <label for="allow_gift_messages"><?php echo $this->__('Check this checkbox if you want to add gift messages.') ?></label>
        </div>
        <div class="clear"></div>
    </div>
    <div class="gift-box" id="allow-gift-message-container">
        <div class="scroll-box">
            <?php if (Mage::helper('giftmessage/message')->isMessagesAvailable('quote', $this->getEntity())): ?>
            <span class="gift-header"><?php echo $this->__('Enter a gift message for entire order.'); ?></span>
            <p><?php echo $this->__('You can leave a box blank if you don\'t wish to add a gift message for whole order.') ?></p>
            <fieldset class="group-select">
                <input type="hidden" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][type]"  value="quote" />
                <ul class="no-padding">
                    <li>
                        <div class="">
                            <label for="gift-message-whole-from"><?php echo $this->__('From') ?></label><br />
                            <input type="text" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][from]" id="gift-message-whole-from" title="<?php echo $this->__('From') ?>"  value="<?php echo $this->getEscaped($this->getMessage()->getSender(), $this->getDefaultFrom()) ?>" class="input-text validation-passed" />
                        </div>
                        <div class="">
                            <label for="gift-message-whole-to"><?php echo $this->__('To') ?></label><br />
                            <input type="text" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][to]" id="gift-message-whole-to" title="<?php echo $this->__('To') ?>" value="<?php echo $this->getEscaped($this->getMessage()->getRecipient(), $this->getDefaultTo()) ?>" class="input-text validation-passed" />
                        </div>
                    </li>
                    <li>
                        <label for="gift-message-whole-message"><?php echo $this->__('Message') ?></label>
                        <br/>
                        <textarea id="gift-message-whole-message" onchange="toogleRequired('gift-message-whole-message', ['gift-message-whole-from','gift-message-whole-to'])" class="input-text validation-passed giftmessage-area" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][message]" title="<?php echo $this->__('Message') ?>" rows="5" cols="40"><?php echo $this->getEscaped($this->getMessage()->getMessage()) ?></textarea>
                    </li>
                </ul>
                    <script type="text/javascript">
                        toogleRequired('gift-message-whole-message', ['gift-message-whole-from','gift-message-whole-to']);
                    </script>
             </fieldset>
             <?php endif; ?>
             <?php if($this->isItemsAvailable()): ?>
             <span class="gift-header"><?php echo $this->__('Enter a gift message for each item in your order.'); ?></span><div class="clear"></div>
             <p><?php echo $this->__('You can leave a box blank if you don\'t wish to add a gift message for the item.') ?></p>
             <?php foreach($this->getItems() as $_index=>$_item): ?>
             <?php $_product=$_item->getProduct() ?>
               <div class="left">
                    <img width="75" class="product-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>"  alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /><br />
                    <span class="numeration"><?php echo $this->__('Item %d of %d', $_index+1, $this->countItems()) ?></span>
               </div>
               <div class="left">
                    <h5 class="giftmessage-product-info"><?php echo $this->htmlEscape($_product->getName()) ?></h5>
                    <fieldset class="group-select">
                        <input type="hidden" name="giftmessage[<?php echo $_item->getId() ?>][type]" value="quote_item"/>
                        <ul class="no-padding">
                            <li>
                                <div class="">
                                    <label for="gift-message-<?php echo $_item->getId() ?>-from"><?php echo $this->__('From') ?></label><br />
                                    <input type="text" name="giftmessage[<?php echo $_item->getId() ?>][from]" id="gift-message-<?php echo $_item->getId() ?>-from" title="<?php echo $this->__('From') ?>" value="<?php echo $this->getEscaped($this->getMessage($_item)->getSender(), $this->getDefaultFrom()) ?>" class="input-text validation-passed" />
                                </div>
                                <div class="">
                                    <label for="gift-message-<?php echo $_item->getId() ?>-to"><?php echo $this->__('To') ?></label><br />
                                    <input type="text" name="giftmessage[<?php echo $_item->getId() ?>][to]" id="gift-message-<?php echo $_item->getId() ?>-to" title="<?php echo $this->__('To') ?>" value="<?php echo $this->getEscaped($this->getMessage($_item)->getRecipient(), $this->getDefaultTo()) ?>" class="input-text validation-passed" />
                                </div>
                            </li>
                            <li>
                                <label for="gift-message-<?php echo $_item->getId() ?>-message"><?php echo $this->__('Message') ?></label>
                                <br/>
                                <textarea id="gift-message-<?php echo $_item->getId() ?>-message" onchange="toogleRequired('gift-message-<?php echo $_item->getId() ?>-message', ['gift-message-<?php echo $_item->getId() ?>-from','gift-message-<?php echo $_item->getId() ?>-to'])" class="input-text validation-passed  giftmessage-area" name="giftmessage[<?php echo $_item->getId() ?>][message]" title="<?php echo $this->__('Message') ?>" rows="5" cols="40"><?php echo $this->getEscaped($this->getMessage($_item)->getMessage()) ?></textarea>
                            </li>
                        </ul>
                            <script type="text/javascript">
                                toogleRequired('gift-message-<?php echo $_item->getId() ?>-message', ['gift-message-<?php echo $_item->getId() ?>-from','gift-message-<?php echo $_item->getId() ?>-to']);
                            </script>
                    </fieldset>
             </div>
             <div class="clear"></div>
             <?php endforeach; ?>
             <?php endif; ?>
        </div>
    </div>
    <script type="text/javascript">
        toogleVisibilityOnObjects('allow_gift_messages', ['allow-gift-message-container']);
    </script>
    <?php break; ?>
    <?php case 'multishipping_adress_checkbox': ?>

    <?php break; ?>
    <?php case 'multishipping_adress': ?>
     <br />
    <div class="inner-box">
        <span class="gift-header"><?php echo $this->__('Gift Messages'); ?></span>
        <div class="clear"></div>
        <div class="a-left input-checkbox">
            <input type="checkbox" name="allow_gift_messages_<?php echo $this->getEntity()->getId() ?>" id="allow_gift_messages_<?php echo $this->getEntity()->getId() ?>" value="1" onclick="toogleVisibilityOnObjects(this, ['allow-gift-message-container-<?php echo $this->getEntity()->getId() ?>']);" <?php if($this->getItemsHasMesssages() || $this->getEntityHasMessage()): ?>checked="checked"<?php endif ?> />
            <label for="allow_gift_messages_<?php echo $this->getEntity()->getId() ?>"><?php echo $this->__('Check this checkbox if you want to add gift messages to your items.') ?></label>
        </div>
        <div class="clear"></div>
    </div>
    <div id="allow-gift-message-container-<?php echo $this->getEntity()->getId() ?>">
        <?php if (Mage::helper('giftmessage/message')->isMessagesAvailable('quote', $this->getEntity())): ?>
        <span class="gift-header"><?php echo $this->__('Enter a gift message for this address.'); ?></span>
        <p><?php echo $this->__('You can leave a box blank if you don\'t wish to add a gift message for this address.') ?></p>
        <fieldset class="group-select no-border no-padding">
        <input type="hidden" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][type]" value="quote_address" />
            <ul class="no-padding">
             <li>
                <div class="">
                    <label for="gift-message-<?php echo $this->getEntity()->getId() ?>-from"><?php echo $this->__('From') ?></label><br />
                    <input type="text" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][from]" id="gift-message-<?php echo $this->getEntity()->getId() ?>-from" title="<?php echo $this->__('From') ?>" value="<?php echo $this->getEscaped($this->getMessage()->getSender(), $this->getDefaultFrom()) ?>" class="input-text validation-passed" />
                </div>
                <div class="">
                    <label for="gift-message-<?php echo $this->getEntity()->getId() ?>-to"><?php echo $this->__('To') ?></label><br />
                    <input type="text" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][to]" id="gift-message-<?php echo $this->getEntity()->getId() ?>-to" title="<?php echo $this->__('To') ?>" value="<?php echo $this->getEscaped($this->getMessage()->getRecipient(), $this->getDefaultTo()) ?>" class="input-text validation-passed" />
                </div>
            </li>
            <li>
                <label for="gift-message-<?php echo $this->getEntity()->getId() ?>-message"><?php echo $this->__('Message') ?></label>
                <br />
                <textarea id="gift-message-<?php echo $this->getEntity()->getId() ?>-message" onchange="toogleRequired('gift-message-<?php echo $this->getEntity()->getId() ?>-message', ['gift-message-<?php echo $this->getEntity()->getId() ?>-from','gift-message-<?php echo $this->getEntity()->getId() ?>-to'])" class="input-text validation-passed giftmessage-area" name="giftmessage[<?php echo $this->getEntity()->getId() ?>][message]" title="<?php echo $this->__('Message') ?>" rows="5" cols="40"><?php echo $this->getEscaped($this->getMessage()->getMessage()) ?></textarea>
            </li>
            </ul>
            <script type="text/javascript">
                var shippingMethod = new VarienForm('shipping_method_form');
                toogleRequired('gift-message-<?php echo $this->getEntity()->getId() ?>-message', ['gift-message-<?php echo $this->getEntity()->getId() ?>-from','gift-message-<?php echo $this->getEntity()->getId() ?>-to']);
            </script>
         </fieldset>
         <?php endif; ?>
         <?php if($this->isItemsAvailable()): ?>
         <span class="gift-header"><?php echo $this->__('Enter a gift message for each item in your order.'); ?></span><div class="clear"></div>
         <p><?php echo $this->__('You can leave a box blank if you don\'t wish to add a gift message for the item.') ?></p>
         <?php foreach($this->getItems() as $_index=>$_item): ?>
         <?php $_product=$_item->getProduct() ?>
           <div class="left">
                <img width="75" class="product-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(75); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /><br />
                <span class="numeration"><?php echo $this->__('Item %d of %d', $_index+1, $this->countItems()) ?></span>
           </div>
           <div class="left">
                <h5 class="giftmessage-product-info"><?php echo $this->htmlEscape($_product->getName()) ?></h5>
                <fieldset class="group-select no-padding no-border">
                    <input type="hidden" name="giftmessage[<?php echo $_item->getId() ?>][type]" value="quote_address_item"/>
                    <input type="hidden" name="giftmessage[<?php echo $_item->getId() ?>][address]" value="<?php echo $this->getEntity()->getId()?>" />
                    <ul class="no-padding">
                        <li>
                            <div class="">
                                <label for="gift-message-<?php echo $_item->getId() ?>-from"><?php echo $this->__('From') ?></label><br />
                                <input type="text" name="giftmessage[<?php echo $_item->getId() ?>][from]" id="gift-message-<?php echo $_item->getId() ?>-from" title="<?php echo $this->__('From') ?>"  value="<?php echo $this->getEscaped($this->getMessage($_item)->getSender(), $this->getDefaultFrom()) ?>" class="input-text validation-passed" />
                            </div>
                            <div class="">
                                <label for="gift-message-<?php echo $_item->getId() ?>-to"><?php echo $this->__('To') ?></label><br />
                                <input type="text" name="giftmessage[<?php echo $_item->getId() ?>][to]" id="gift-message-<?php echo $_item->getId() ?>-to" title="<?php echo $this->__('To') ?>" value="<?php echo $this->getEscaped($this->getMessage($_item)->getRecipient(), $this->getDefaultTo()) ?>" class="input-text validation-passed" />
                            </div>
                        </li>
                        <li>
                            <label for="gift-message-<?php echo $_item->getId() ?>-message"><?php echo $this->__('Message') ?></label>
                            <br />
                            <textarea id="gift-message-<?php echo $_item->getId() ?>-message" onchange="toogleRequired('gift-message-<?php echo $_item->getId() ?>-message', ['gift-message-<?php echo $_item->getId() ?>-from','gift-message-<?php echo $_item->getId() ?>-to'])" class="input-text validation-passed  giftmessage-area" name="giftmessage[<?php echo $_item->getId() ?>][message]" title="<?php echo $this->__('Message') ?>" rows="5" cols="40"><?php echo $this->getEscaped($this->getMessage($_item)->getMessage()) ?></textarea>
                        </li>
                    </ul>
                        <script type="text/javascript">
                            toogleRequired('gift-message-<?php echo $_item->getId() ?>-message', ['gift-message-<?php echo $_item->getId() ?>-from','gift-message-<?php echo $_item->getId() ?>-to']);
                        </script>
                </fieldset>
         </div>
         <div class="clear"></div>
         <?php endforeach; ?>
         <?php endif; ?>
    </div>
    <script type="text/javascript">
        toogleVisibilityOnObjects('allow_gift_messages_<?php echo $this->getEntity()->getId() ?>', ['allow-gift-message-container-<?php echo $this->getEntity()->getId() ?>']);
    </script>
    <?php break; ?>
<?php endswitch ?>
</div>
<?php endif; ?>
