<?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="page-head">
    <h3><?php echo $this->__('Write Your Own Review') ?></h3>
</div>
<h4><?php echo $this->__("You're reviewing: %s", $this->htmlEscape($this->getProductInfo()->getName())) ?></h4>
<form action="<?php echo $this->getAction() ?>" method="post" id="review-form">
<div>
    <?php if( $this->getRatings() && $this->getRatings()->getSize()): ?>
    <strong><?php echo $this->__('How do you rate this product?') ?><span class="required">*</span></strong><br />
    <span id="input-message-box"></span>
    <table class="data-table product-review-box field-row" id="product-review-table" cellspacing="0">
        <thead>
            <tr>
                <th>&nbsp;</th>
                <th><?php echo $this->__('1 star') ?></th>
                <th><?php echo $this->__('2 stars') ?></th>
                <th><?php echo $this->__('3 stars') ?></th>
                <th><?php echo $this->__('4 stars') ?></th>
                <th><?php echo $this->__('5 stars') ?></th>
            </tr>
        </thead>
        <tbody>
        <?php $_oddIterator = 1; ?>
        <?php foreach ($this->getRatings() as $_rating): ?>
            <tr class="odd<?php if($_oddIterator == $this->getRatings()->getSize()): $_oddIterator = 0; ?> last<?php endif; ?>">
                <td class="label"><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></td>
            <?php $_iterator = 1; ?>
            <?php foreach ($_rating->getOptions() as $_option): ?>
                <!--<td <?php if($_iterator == 5): ?>class="last"<?php endif; ?> style="width:60px;"><input type="radio" <?php if($_iterator == 5): $_iterator=0; ?>class="validate-one-required-by-name"<?php endif; ?> name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>"/></td>-->
                <td<?php if($_iterator == 5): ?> class="last"<?php endif; ?> style="width:60px;"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" /></td>
            <?php $_iterator++ ?>
            <?php endforeach; ?>
            </tr>
        <?php $_oddIterator ++; ?>
        <?php endforeach; ?>
        </tbody>
    </table>
    <input type="hidden" name="validate_rating" class="validate-rating" value="" />
    <script type="text/javascript">decorateTable('product-review-table')</script>
    <?php endif; ?>
        <?php // do not remove div - some problem whith validator in IE ?>
        <div>
        <label for="nickname_field"><?php echo $this->__('Nickname') ?><span class="required">*</span></label><br />
        <input class="input-text required-entry" name="nickname" id="nickname_field" style="width: 450px;" type="text" value="<?php echo $this->htmlEscape($data->getNickname()) ?>" />
        </div>

        <div>
        <label for="summary_field"><?php echo $this->__('Summary of Your Review') ?><span class="required">*</span></label><br />
        <input name="title" class="input-text  required-entry" id="summary_field" style="width: 450px;" type="text" value="<?php echo $this->htmlEscape($data->getTitle()) ?>" />
        </div>

        <div>
        <label for="review_field"><?php echo $this->__('Review') ?><span class="required">*</span></label><br />
        <textarea class="required-entry" name="detail" id="review_field" cols="53" rows="10" style="width: 450px;"><?php echo $this->htmlEscape($data->getDetail()) ?></textarea>
        </div>

    <div class="button-set">
        <button class="form-button right" type="submit"><span><?php echo $this->__('Submit Review') ?></span></button>
    </div>
</div>
</form>
<script type="text/javascript">
    var dataForm = new VarienForm('review-form');

    Validation.addAllThese(
    [
           ['validate-rating', '<?php echo $this->__('Please select one of each of the ratings above') ?>', function(v) {
                var trs = $('product-review-table').select('tr');
                var inputs;
                var error = 1;

                for( var j=0; j < trs.length; j++ ) {
                    var tr = trs[j];
                    if( j > 0 ) {
                        inputs = tr.select('input');

                        for( i in inputs ) {
                            if( inputs[i].checked == true ) {
                                error = 0;
                            }
                        }

                        if( error == 1 ) {
                            return false;
                        } else {
                            error = 1;
                        }
                    }
                }
                return true;
            }]
    ]
    );
</script>
