<?php 
/* Email to friend */
?>
<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('fields additional-row');
        li_mail.innerHTML = '<p><a href="delete_email" title="<?php echo $this->__('Remove Email') ?>" onclick="remove_recipient('+i+'); return false" class="btn-remove"><?php echo $this->__('Remove Email') ?>"<\/a><\/p>'
        li_mail.innerHTML += '<div class="field"><label for="recipients_name'+i+'" class="required"><em>*<\/em><?php echo $this->__('Name:') ?><\/label><div class="input-box"><input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name'+i+'" /><\/div>';
        li_mail.innerHTML += '<div class="field"><label for="recipients_email'+i+'" class="required"><em>*<\/em><?php echo $this->__('Email Address:') ?><\/label><div class="input-box"><input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email'+i+'" type="text" class="input-text required-entry validate-email" /><\/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="login_page">
    <div class="page-title">
        <h2><?php echo $this->__('Email to a Friend') ?></h2>
    </div>
    <form action="<?php echo $this->getSendUrl() ?>" method="post" id="product_sendtofriend_form">
        <div class="fieldset">
            <?php echo $this->getBlockHtml('formkey')?>
            <h2 class="legend"><?php echo $this->__('Sender:') ?></h2>
            <ul class="form-list" id="sender_options">
                <li class="fields">
                    <div class="field">
                        <label for="sender_name"><?php echo $this->__('Name:') ?><em class="required">*</em></label>
                        <div class="input-box">
                            <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" />
                        </div>
                    </div>
                    <div class="field">
                       <label for="sender_email"><?php echo $this->__('Email:') ?><em class="required">*</em></label>
                       <div class="input-box">
                           <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" />
                       </div>
                    </div>
                </li>
                <li class="wide">
                    <label for="sender_message"><?php echo $this->__('Message:') ?><em class="required">*</em></label>
                    <div class="input-box">
                        <textarea name="sender[message]"  class="input-text required-entry" id="sender_message" cols="3" rows="3"><?php echo $this->htmlEscape($this->getMessage())?></textarea>
                    </div>
                </li>
            </ul>
        </div>
        <div class="fieldset">
            <h2 class="legend"><?php echo $this->__('Recipient:') ?></h2>
            <ul class="form-list" id="recipients_options">
                <li class="fields">
                    <div class="field">
                        <label for="recipients_name"><?php echo $this->__('Name:') ?><em class="required">*</em></label>
                        <div class="input-box">
                            <input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="recipients_email"><?php echo $this->__('Email Address:') ?><em class="required">*</em></label>
                        <div class="input-box">
                            <input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email" type="text" class="input-text required-entry validate-email" />
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        
            <button style="margin-right:5px;float:left;" type="submit" class="button<?php if (!$this->canSend()):?> disabled<?php endif ?>"<?php if (!$this->canSend()):?> disabled="disabled"<?php endif ?>><span><?php echo $this->__('Send Email') ?></span></button>
            <div id="max_recipient_message" style="display:none;">
                <?php if ($this->getMaxRecipients()): ?>
                  <p class="limit"><?php echo $this->__('Maximum %d email addresses allowed.', $this->getMaxRecipients()) ?></p>
                <?php endif; ?>
            </div>
            <?php if (1 < $this->getMaxRecipients()): ?>
                <p id="add_recipient_button">
                    <button type="button" onclick="add_recipient();" class="button"><span><?php echo $this->__('Add Recipient') ?></span></button>
                </p>
            <?php endif; ?>
            <a class="f-left"  href="#" onclick="history.back(); return false;"><small>&laquo; </small><?php echo $this->__('Back') ?></a>
        
    </form>

    <script type="text/javascript">
    //<![CDATA[
        var productSendtofriendForm = new VarienForm('product_sendtofriend_form');
        productSendtofriendForm.submit = function() {
            if(this.validator.validate()) {
                this.form.submit();
            }
        }.bind(productSendtofriendForm);
    //]]>
    </script>
    <br />
</div> <!--login_page-->