<?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) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="discount-codes box">
    <form id="discount-coupon-form" action="<?php echo $this->getUrl('checkout/cart/couponPost') ?>" method="post">
    <table align="center">
        <tr>
            <td valign="middle"><h4><?php echo $this->__('Discount Codes') ?></h4></td>
            <td valign="middle">
                <input type="hidden" name="remove" id="remove-coupone" value="0"/>
                <?php if(!strlen($this->getCouponCode())): ?>
                <div><input class="input-text" style="width:70px;" id="coupon_code" name="coupon_code" value="<?php echo $this->htmlEscape($this->getCouponCode()) ?>" /></div>
                <?php else: ?>
                <div><input class="input-text" style="width:70px;" id="coupon_code" name="coupon_code" value="<?php echo $this->htmlEscape($this->getCouponCode()) ?>" /></div>
                <?php endif;?>
                <div class="clear"></div>
            </td>
            <td valign="middle">
                <?php if(!strlen($this->getCouponCode())): ?>
                    &nbsp;<button class="form-button-alt" onclick="discountForm.submit(false)" type="button" value="<?php echo $this->__('Apply Coupon') ?>"><span><?php echo $this->__('Apply') ?></span></button>
                <?php else: ?>
                    &nbsp;<button class="form-button-alt" onclick="discountForm.submit(false)" type="button"  value="<?php echo $this->__('Apply Coupon') ?>"><span><?php echo $this->__('Apply') ?></span></button>
                    &nbsp;<button class="form-button-alt" type="button" onclick="discountForm.submit(true)" value="<?php echo $this->__('Cancel Coupon') ?>"><span><?php echo $this->__('Cancel') ?></span></button>
                <?php endif;?>
            </td>
        </tr>
        <tr><td colspan="3" align="center"><?php echo $this->__('Enter your coupon code if you have one.') ?></td></tr>
    </table>
</form>
<script type="text/javascript">
var discountForm = new VarienForm('discount-coupon-form');
discountForm.submit = function (isRemove) {
    if (isRemove) {
        $('coupon_code').removeClassName('required-entry');
        $('remove-coupone').value = "1";
    } else {
        $('coupon_code').addClassName('required-entry');
        $('remove-coupone').value = "0";
    }
    return VarienForm.prototype.submit.bind(discountForm)();
}
</script>
</div>
