<script language="JavaScript" type="text/javascript">
<!--
function uniqSubmit()
{
    now = new Date();
    document.compose.action = document.compose.action + now.getTime();
    document.compose.submit();
}
// -->
</script>

<form method="post" name="compose" enctype="multipart/form-data" action="<?php echo Horde::url('compose.php?uniq=' . uniqid(rand())) ?>">
<?php if ($browser->isBrowser('msie') && (($browser->getMajor() >= 6) || (($browser->getMajor() == 5) && ($browser->getMinor() >= 5)))): ?>
<input type="hidden" name="msie_formdata_is_broken" value="" />
<?php endif; ?>
<input type="hidden" name="actionID" value="" />
<input type="hidden" name="spellcheck" value="" />
<input type="hidden" name="index" value="<?php echo htmlspecialchars(Horde::getFormData('index', '')) ?>" />
<input type="hidden" name="page" value="<?php echo htmlspecialchars(Horde::getFormData('page', '')) ?>" />
<input type="hidden" name="start" value="<?php echo htmlspecialchars(Horde::getFormData('start', '')) ?>" />
<input type="hidden" name="popup" value="<?php echo htmlspecialchars(Horde::getFormData('popup', '')) ?>" />
<input type="hidden" name="thismailbox" value="<?php echo htmlspecialchars(Horde::getFormData('thismailbox', '')) ?>" />
<input type="hidden" name="attachmentAction" value="" />
<input type="hidden" name="reloaded" value="1" />

<table border="0" align="center" cellpadding="0" cellspacing="1">
<tr class="header">
    <td colspan="2" height="25" class="header" width="700">
        <b>&nbsp;<?php echo htmlspecialchars($ACTION_TEXT) ?></b> -
        <?php echo strftime($conf['compose']['date_format']) ?>
    </td>
</tr>

<!-- Buttons Row -->
<tr>
    <td>&nbsp;</td>
    <td>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
    <td class="header" nowrap="nowrap" align="left">
        <input type="button" class="button" onclick="document.compose.actionID.value='<?php echo SEND_MESSAGE ?>'; uniqSubmit();" value="<?php echo _("Send Message") ?>" />
        <?php if ($conf['user']['allow_folders']): ?>
        <input type="button" class="button" onclick="document.compose.actionID.value='<?php echo SAVE_DRAFT ?>'; uniqSubmit();" value="<?php echo _("Save Draft") ?>" />
        <?php endif; ?>
        <input type="button" class="button" onclick="confirmCancel();" value="<?php echo _("Cancel Message") ?>" />
    </td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td class="header" align="right"><?php echo Help::link('imp', 'compose-buttons') ?></td>
<?php else: ?>
    <td class="header">&nbsp;</td>
<?php endif; ?>
</tr>
</table>

    </td>
</tr>
<!-- End Buttons Row -->

<?php if ((Horde::getFormData('is_reply') == 1) || isset($actionID) && (($actionID == REPLY) || ($actionID == REPLY_ALL))): ?>
<input type="hidden" name="is_reply" value="1" />
<input type="hidden" name="in_reply_to" value="<?php echo htmlspecialchars(Horde::getFormData('in_reply_to')) ?>" />
<input type="hidden" name="references" value="<?php echo htmlspecialchars(Horde::getFormData('references')) ?>" />
<?php endif; ?>

<?php if (!$prefs->isLocked('default_identity')): ?>
<tr>
    <td class="light" align="right"><b><?php echo _("Identity") ?>&nbsp;</b></td>
    <td class="item" align="left">

<table border="0" width="100%" cellpadding="0">
<tr>
    <td align="left">
      <input type="hidden" name="last_identity" value="<?php echo $identity->getDefault() ?>" />
      <select name="identity" tabindex="<?php echo $tabindex++ ?>" style="width:500px" onchange="change_identity(this.selectedIndex)">
      <?php foreach ($select_list as $key => $select): ?>
        <option value="<?php echo $key ?>"<?php if ($key == $identity->getDefault()) echo ' selected="selected"' ?>><?php echo htmlspecialchars($select) ?></option>
      <?php endforeach; ?>
      </select>
    </td>
<?php else: ?>
<tr>
    <td class="light" align="right"><b><?php echo _("From") ?>&nbsp;</b></td>
    <td class="item" align="left">

<table border="0" width="100%" cellpadding="0">
<tr>
<?php if (!$prefs->isLocked('from_addr')): ?>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="from" value="<?php echo htmlspecialchars($from) ?>" style="width:500px" /></td>
<?php else: ?>
    <td align="left"><b>&nbsp;<?php echo htmlspecialchars($from) ?></b></td>
<?php endif; ?>
<?php endif; ?>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td align="right"><?php echo Help::link('imp', 'compose-from') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
</table>

    </td>
</tr>

<tr>
    <td class="light" align="right" valign="top"><b><?php echo _("To") ?>&nbsp;</b></td>
    <td class="item" align="left">

<table border="0" width="100%" cellpadding="0">
<?php if (is_array($to)): $first_to = true; ?>
<?php foreach ($to as $to_item): ?>
<tr>
<?php if (count($to_item) > 1): ?>
    <td align="left">
        <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="350">
                <select tabindex="<?php echo $tabindex++ ?>" name="to_list[<?php echo htmlspecialchars($to_item[0]) ?>]" style="width:350px">
                    <option value="" selected="selected"><?php echo _("Please select or edit right next:") ?></option>
<?php for ($i = 1; $i < count($to_item); $i++): ?>
                    <option value="<?php echo htmlspecialchars($to_item[$i]) ?>"><?php echo htmlspecialchars($to_item[$i]) ?></option>
<?php endfor; ?>
                </select>
            </td>
            <td width="150">
                <input type="text" size="15" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="to_field[<?php echo htmlspecialchars($to_item[0]) ?>]" value="<?php echo htmlspecialchars($to_item[0]) ?>" style="width:150px" />
            </td>
        </tr>
        </table>
    </td>
<?php else: ?>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="to_field[]" value="<?php echo htmlspecialchars($to_item) ?>" style="width:500px" /></td>
<?php endif; ?>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript') && $first_to): $first_to = false; ?>
    <td align="right"><?php echo Help::link('imp', 'compose-to') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<tr>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="to_new" style="width:500px" /></td>
    <td>&nbsp;</td>
</tr>
<?php else: ?>
<tr>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="to" value="<?php echo htmlspecialchars($to) ?>" style="width:500px" /></td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td align="right"><?php echo Help::link('imp', 'compose-to') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
<?php endif; ?>
</table>

    </td>
</tr>

<?php if ($conf['compose']['allow_cc']): ?>
<tr>
    <td class="light" align="right" valign="top"><b><?php echo _("Cc") ?>&nbsp;</b></td>
    <td class="item" align="left">

<table border="0" width="100%" cellpadding="0">
<?php if (is_array($cc)): $first_cc = true; ?>
<?php foreach ($cc as $cc_item): ?>
<tr>
<?php if (count($cc_item) > 1): ?>
    <td align="left">
        <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="350">
                <select tabindex="<?php echo $tabindex++ ?>" name="cc_list[<?php echo htmlspecialchars($cc_item[0]) ?>]" style="width:350px">
                    <option value="" selected="selected"><?php echo _("Please select or edit right next:") ?></option>
<?php for ($i = 1; $i < count($cc_item); $i++): ?>
                    <option value="<?php echo htmlspecialchars($cc_item[$i]) ?>"><?php echo htmlspecialchars($cc_item[$i]) ?></option>
<?php endfor; ?>
                </select>
            </td>
            <td width="150">
                <input type="text" size="15" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="cc_field[<?php echo htmlspecialchars($cc_item[0]) ?>]" value="<?php echo htmlspecialchars($cc_item[0]) ?>" style="width:150px" />
            </td>
        </tr>
        </table>
    </td>
<?php else: ?>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="cc_field[]" value="<?php echo htmlspecialchars($cc_item) ?>" style="width:500px" /></td>
<?php endif; ?>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript') && $first_cc): $first_cc = false; ?>
    <td align="right"><?php echo Help::link('imp', 'compose-cc') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<tr>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="cc_new" style="width:500px" /></td>
    <td>&nbsp;</td>
</tr>
<?php else: ?>
<tr>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="cc" value="<?php echo htmlspecialchars($cc) ?>" style="width:500px" /></td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td align="right"><?php echo Help::link('imp', 'compose-cc') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
<?php endif; ?>
</table>

</td></tr>
<?php endif; ?>

<?php if ($conf['compose']['allow_bcc']): ?>
<tr>
    <td class="light" align="right" valign="top"><b><?php echo _("Bcc") ?>&nbsp;</b></td>
    <td class="item" align="left">

<table border="0" width="100%" cellpadding="0">
<?php if (is_array($bcc)): $first_bcc = true; ?>
<?php foreach ($bcc as $bcc_item): ?>
<tr>
<?php if (count($bcc_item) > 1): ?>
    <td align="left">
        <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="350">
                <select tabindex="<?php echo $tabindex++ ?>" name="bcc_list[<?php echo htmlspecialchars($bcc_item[0]) ?>]" style="width:350px">
                    <option value="" selected="selected"><?php echo _("Please select or edit right next:") ?></option>
<?php for ($i = 1; $i < count($bcc_item); $i++): ?>
                    <option value="<?php echo htmlspecialchars($bcc_item[$i]) ?>"><?php echo htmlspecialchars($bcc_item[$i]) ?></option>
<?php endfor; ?>
                </select>
            </td>
            <td width="150">
                <input type="text" size="15" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="bcc_field[<?php echo htmlspecialchars($bcc_item[0]) ?>]" value="<?php echo htmlspecialchars($bcc_item[0]) ?>" style="width:150px" />
            </td>
        </tr>
        </table>
    </td>
<?php else: ?>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="bcc_field[]" value="<?php echo htmlspecialchars($bcc_item) ?>" style="width:500px" /></td>
<?php endif; ?>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript') && $first_bcc): $first_bcc = false; ?>
    <td align="right"><?php echo Help::link('imp', 'compose-bcc') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<tr>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="bcc_new" style="width:500px" /></td>
    <td>&nbsp;</td>
</tr>
<?php else: ?>
<tr>
    <td align="left"><input type="text" size="60" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="bcc" value="<?php echo htmlspecialchars($bcc) ?>" style="width:500px" /></td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td align="right"><?php echo Help::link('imp', 'compose-bcc') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
<?php endif; ?>
</table>

</td></tr>
<?php endif; ?>

<tr>
    <td class="light" align="right"><b><?php echo _("Subject") ?>&nbsp;</b></td>
    <td class="item" align="left">

<table border="0" width="100%" cellpadding="0">
<tr>
    <td align="left"><input type="text" tabindex="<?php echo $tabindex++ ?>" class="fixed" name="subject" value="<?php echo htmlspecialchars($subject) ?>" size="60"<?php if ($browser->isBrowser('msie')) echo ' onkeydown="subjectTab();"' ?> style="width:500px" /></td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td align="right"><?php echo Help::link('imp', 'compose-subject') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
</table>

    </td>
</tr>

<tr>
    <td class="light" align="right" valign="top"><b><?php echo _("Options") ?>&nbsp;</b></td>
    <td class="control">

<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
    <td>

<table border="0" width="100%" cellspacing="1" cellpadding="0">
<tr valign="middle">
<?php if ($registry->hasMethod('contacts/search')): ?>
    <?php echo Menu::createItem(Horde::applicationUrl('contacts.php'), _("Address Book"), 'addressbook-red.gif', NULL, 'contacts', 'window.open(\'' . Horde::applicationUrl('contacts.php') . '\', \'contacts\', \'toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width=650,height=350,left=100,top=100\'); return false;', 'item', 'widget'); ?>
    <?php echo Menu::createItem('', _("Expand Names"), 'expand.gif', NULL, NULL, "document.compose.actionID.value='" . EXPAND_ADDRESSES  . "'; uniqSubmit(); return false;", 'item', 'widget'); ?>
<?php endif; ?>
<?php if (!empty($conf['utils']['spellchecker'])): ?>
    <?php echo Menu::createItem('', _("Spell Check"), 'spellcheck.gif', NULL, NULL, "document.compose.actionID.value='" . SPELL_CHECK . "'; uniqSubmit(); return false;", 'item', 'widget'); ?>
<?php endif; ?>
<?php if ($conf['compose']['special_characters']): ?>
    <?php echo Menu::createItem($registry->getParam('webroot', 'horde') . '/util/special_characters.php', _("Special Characters"), 'keyboard.gif', $registry->getParam('graphics', 'horde'), 'characters', 'window.open(\'' . $registry->getParam('webroot', 'horde') . '/util/special_characters.php\', \'chars\', \'height=220,width=400\'); return false;', 'item', 'widget'); ?>
<?php endif; ?>
    <?php echo Menu::createItem('#attachments', _("Attachments"), 'manage_attachments.gif', NULL, NULL, NULL, 'item', 'widget'); ?>
</tr>
</table>

    </td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td align="right" class="item" rowspan="2"><?php echo Help::link('imp', 'compose-options') ?>&nbsp;</td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>

</tr>
<tr>
    <td>

<table border="0" width="100%" cellspacing="1" cellpadding="0">
<tr>
<?php if ($conf['user']['allow_folders'] && !$prefs->isLocked('save_sent_mail')): ?>
    <td valign="bottom" class="item" align="left">
        <input type="checkbox" name="save_sent_mail"<?php echo $ssm_check ? ' checked="checked"' : '' ?> />
        <?php echo _("Save a copy in ") ?>

<?php
$sent_mail_folder = $identity->getSentmailFolder(null, Horde::getFormData('sent_mail_folder'));
if ($conf['user']['select_sentmail_folder'] && !$prefs->isLocked('sent_mail_folder')) {
    $folders = IMP::flistSelect('', false, array('INBOX'), $sent_mail_folder);
    echo '<select tabindex="' . $tabindex++ . '" name="sent_mail_folder">' . $folders . '</select>';
} else {
    if (!empty($sent_mail_folder)) {
        $sent_mail_folder = '&quot;' . IMP::displayFolder($sent_mail_folder) . '&quot;';
    }
    echo '<span id="sent_mail_folder">' . $sent_mail_folder . '</span>';
}
?>
    </td>
<?php endif; ?>
<?php if ($conf['compose']['allow_receipts']): ?>
    <td valign="bottom" class="item" align="left">
        <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td><input type="checkbox" name="request_return_receipt"<?php echo Horde::getFormData('request_return_receipt') == 'on' ? ' checked="checked"' : '' ?> /></td>
            <td><?php echo _("Request a Return Receipt") ?></td>
        </tr>
        </table>
    </td>
<?php endif; ?>
</tr>
</table>

    </td>
</tr>
</table>

    </td>
</tr>
<tr>
<td colspan="2" align="right" class="fixed">
  <textarea class="fixed" tabindex="<?php echo $tabindex++ ?>" name="message" rows="20" cols="<?php echo $prefs->getValue('wrap_width') ?>" wrap="hard"><?php echo htmlspecialchars($msg) ?></textarea></td>
</tr>

<!-- Buttons Row -->
<tr>
    <td>&nbsp;</td>
    <td>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
    <td class="header" nowrap="nowrap" align="left">
        <input type="button" class="button" onclick="document.compose.actionID.value='<?php echo SEND_MESSAGE ?>'; uniqSubmit();" value="<?php echo _("Send Message") ?>" />
        <?php if ($conf['user']['allow_folders']): ?>
        <input type="button" class="button" onclick="document.compose.actionID.value='<?php echo SAVE_DRAFT ?>'; uniqSubmit();" value="<?php echo _("Save Draft") ?>" />
        <?php endif; ?>
        <input type="button" class="button" onclick="confirmCancel();" value="<?php echo _("Cancel Message") ?>" />
    </td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td class="header" align="right"><?php echo Help::link('imp', 'compose-buttons') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
</table>

    </td>
</tr>
<!-- End Buttons Row -->

<!-- Attachment Form -->
<tr><td colspan="2">&nbsp;</td></tr>
<tr class="header">
    <td colspan="2" height="25" class="header">
        <b>&nbsp;<a name="attachments"></a><?php echo _("Attachments") ?></b>
    </td>
</tr>

<tr>
    <td align="right" class="light"><b><?php echo _("Attachment") ?>&nbsp;</b></td>
    <td class="item" align="left">

<table border="0" width="100%" cellpadding="0">
<tr>
    <td align="left">&nbsp;<input name="file_upload" tabindex="<?php echo $tabindex++ ?>" type="file" size="40" class="fixed" />&nbsp;<input type="button" class="button" onclick="attach()" value="<?php echo _("Attach") ?>" /></td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td align="right"><?php echo Help::link('imp', 'compose-attach') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
</table>

    </td>
</tr>

<?php if (isset($_POST['attachments_name']) && is_array($_POST['attachments_name']) && count($_POST['attachments_name']) > 0): ?>
<tr>
    <td>&nbsp;</td>
    <td class="item">

<table border="0" width="100%" cellpadding="0">
<tr>
    <td align="left">
<table class="item" border="0" cellpadding="1" cellspacing="2">
<tr>
    <th>&nbsp;</th>
    <th align="left"><?php echo _("Filename") ?></th>
    <th align="left"><?php echo _("Size") ?></th>
    <th align="left"><?php echo _("Mime Type") ?></th>
</tr>

<?php
$total_size = 0;
$localeinfo = localeconv();
for ($i = 0; $i < count($_POST['attachments_name']); $i++) {
	$total_size += $_POST['attachments_size'][$i]; ?>
<tr>
    <td>
        <input type="hidden" name="attachments_name[]" value="<?php echo $_POST['attachments_name'][$i] ?>" />
        <input type="hidden" name="attachments_size[]" value="<?php echo $_POST['attachments_size'][$i] ?>" />
        <input type="hidden" name="attachments_file[]" value="<?php echo $_POST['attachments_file'][$i] ?>" />
        <input type="hidden" name="attachments_type[]" value="<?php echo $_POST['attachments_type'][$i] ?>" />
        <input type="checkbox" name="delattachments[]" value="<?php echo $_POST['attachments_file'][$i] ?>" />
    </td>
    <td align="left"><?php echo MIME::decode($_POST['attachments_name'][$i]) ?></td>
    <td align="left"><?php echo number_format($_POST['attachments_size'][$i] / 1024, 2, $localeinfo['decimal_point'], '') ?> KB</td>
    <td align="left"><?php echo $_POST['attachments_type'][$i] ?></td>
</tr>
<?php } ?>

<tr>
    <td colspan="2"><a href="" onclick="attachDelete(); return false;"><?php echo _("Remove Selected") ?></a></td>
    <td colspan="2" align="left"><?php echo sprintf(_("Total Size: %s KB"), number_format($total_size / 1024, 2, $localeinfo['decimal_point'], '')) ?></th>
</tr>
</table>
    </td>
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <td align="right" valign="top"><?php echo Help::link('imp', 'compose-attachments') ?></td>
<?php else: ?>
    <td>&nbsp;</td>
<?php endif; ?>
</tr>
</table>

</td>
</tr>
<?php endif; ?>
</table>
</form>

<?php if ($browser->hasFeature('javascript')): ?>
<script language="JavaScript" type="text/javascript">
<!--
function attachDelete()
{
    document.compose.actionID.value = <?php echo DELETE_ATTACHMENT ?>;
    document.compose.attachmentAction.value = 'delete';
    if (attachment_check(document.compose)) {
        uniqSubmit();
    }
}

function attach()
{
    document.compose.attachmentAction.value = 'add';
    document.compose.actionID.value = <?php echo ADD_ATTACHMENT ?>;
    if (attachment_check(document.compose)) {
        uniqSubmit();
    }
}

if (document.compose.to && document.compose.to.value == "") {
    document.compose.to.focus();
} else if (document.compose.subject.value == "") {
    document.compose.subject.focus();
} else {
    document.compose.message.focus();
}

// -->
</script>
<?php endif; ?>

<?php if (isset($conf['utils']['spellchecker'])): ?>
<form action="<?php echo Horde::applicationUrl('spelling.php') ?>" method="post" name="spelling" target="impspelling">
  <input type="hidden" name="message" value="" />
  <input type="hidden" name="spell_lang" value="" />
</form>
<?php endif; ?>
