<?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) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_Send
 */
?>
<script type="text/javascript">
/*<![CDATA[*/
    i=0;
    var recipCount  = 1;
    var maxRecip    = <?php echo $this->getMaxRecipients() ?>;
    function remove_recipient(i){
        $('recipients_name'+i).up(2).remove();
        recipCount--;
        if(recipCount<maxRecip && maxRecip != 0) {
            $('add_recipient_button').show();
            $('max_recipient_message').hide();
        }
        return false;
    }

    function add_recipient(){
        ul = $('recipients_options');
        var li_mail = Element.extend(document.createElement("LI"));
        li_mail.addClassName('addElement');
        li_mail.innerHTML = '<div align="right"><a href="delete_email" onclick="remove_recipient('+i+');return false"><img src="<?php echo $this->getSkinUrl('images/list_remove_btn.gif') ?>" alt="<?php echo $this->__('Remove Email') ?>" /><\/a><\/div>'
        li_mail.innerHTML += '<div class="left"><label for="recipients_name"><?php echo $this->__('Name:') ?> <span class="required">*<\/span><\/label><br /><div style="width:250px"><input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name'+i+'" style="width:250px;" /><\/div><br /><br /><\/div>';
        li_mail.innerHTML += '<div class="right"><label for="recipients_email"><?php echo $this->__('Email Address:') ?><span class="required">*<\/span><\/label><br /><div style="width:250px"><input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email'+i+'" type="text" class="input-text required-entry validate-email" style="width:250px;" /><\/div><\/div>';
        i++;
        recipCount++;
        if(recipCount>=maxRecip && maxRecip != 0) {
            $('add_recipient_button').hide();
            $('max_recipient_message').show();
        }

        ul.appendChild(li_mail);
    }
/*]]>*/
</script>

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-head">
    <h3><?php echo $this->__('Email to a Friend') ?></h3>
</div>
<form action="<?php echo $this->getUrl('catalog/product/sendmail',array('id'=>$this->getProductId())) ?>" method="post" id="product_sendtofriend_form">
<div class="col-1 login-box">
    <div class="col-1 registered-users">
        <div class="content ">
            <div>
                <h4><?php echo $this->__('Sender:') ?></h4>
                 <ul class="form-list" id="sender_options">
                       <li>
                            <div class="left">
                                <label for="sender_name"><?php echo $this->__('Name:') ?> <span class="required">*</span></label><br />
                                <div style="width:250px"><input name="sender[name]" value="<?php echo $this->htmlEscape($this->getUserName()) ?>" title="<?php echo $this->__('Name') ?>" id="sender_name" type="text" class="input-text required-entry" style="width:250px;" /></div>
                            </div>
                            <div class="right">
                               <label for="sender_email"><?php echo $this->__('Email:') ?> <span class="required">*</span></label><br/>
                               <div style="width:250px"><input name="sender[email]" value="<?php echo $this->htmlEscape($this->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" id="sender_email" type="text" class="input-text required-entry validate-email" style="width:250px;" /></div>
                            </div>
                        </li>
                        <li>
                            <label for="sender_message"><?php echo $this->__('Message:') ?></label><br/>
                            <textarea name="sender[message]" cols="3" rows="3" class="input-text" id="sender_message" style="width:100%; height:100px"></textarea>
                        </li>

                 </ul>
            </div>

            <div>
                <div>
                   <br />
                   <h4><?php echo $this->__('Recipient:') ?></h4>
                    <ul class="form-list" id="recipients_options">
                            <li>
                                <div class="left">
                                    <label for="recipients_name"><?php echo $this->__('Name:') ?> <span class="required">*</span></label><br/>
                                    <div style="width:250px"><input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name" style="width:250px;" /></div><br /><br />
                                </div>
                                <div class="right">
                                    <label for="recipients_email"><?php echo $this->__('Email Address:') ?> <span class="required">*</span></label><br />
                                    <div style="width:250px"><input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email" type="text" class="input-text required-entry validate-email" style="width:250px;" /></div>
                                </div>
                            </li>
                    </ul>
                    <div id="max_recipient_message" style="display:none">
                    <?php if ($this->getMaxRecipients()): ?>
                      <?php echo $this->__('Maximum %d email addresses allowed.', $this->getMaxRecipients()) ?>
                    <?php endif; ?>
                    </div>
                    <?php if (1 < $this->getMaxRecipients()): ?>
                        <div id="add_recipient_button">
                            <button class="form-button" onclick="add_recipient();" type="button"><span><?php echo $this->__('Add Recipient') ?></span></button>
                        </div>
                    <?php endif; ?>
               </div>
            </div>
            <div style="clear:both"></div>

        </div>

        <div class="button-set">
            <button class="form-button right" type="submit"><span><?php echo $this->__('Send email') ?></span></button>
        </div>
    </div>
</div>
</form>
<script type="text/javascript">
    var productSendtofriendForm = new VarienForm('product_sendtofriend_form');
    productSendtofriendForm.submit = function() {
        if(this.validator.validate()) {
            this.form.submit();
        }
    }.bind(productSendtofriendForm);
</script>
