{include file="header.tpl.html"}

{if $send_result != '' and $smarty.post.form_stays != 1}
<br />
<center>
{if $send_result == -1}
  <span class="default"><b>{t}An error occurred while trying to run your query{/t}</b></span>
{elseif $send_result == -2}
  <span class="default"><b>{t}Sorry, but the email could not be queued. This might be related to problems with your SMTP account settings.{/t}<br />
 {t}Please contact the administrator of this application for further assistance.{/t}</b></span>
{elseif $send_result == 1}
  <span class="default"><b>{t}Thank you, the email was queued to be sent successfully.{/t}</b></span>
  {include file="app_messages.tpl.html"}
{/if}

</center>
<script language="JavaScript">
<!--
{if $current_user_prefs.close_popup_windows}
setTimeout('closeAndRefresh()', 2000);
{/if}
//-->
</script>
<br />
{if not $current_user_prefs.close_popup_windows}
  <center>
    <span class="default"><a class="link" href="javascript:void(null);" onClick="javascript:closeAndRefresh();">{t}Continue{/t}</a></span>
  </center>
{/if}
{elseif $draft_result != ''}
<br />
<center>
  <span class="default">
{if $draft_result == -1}
  <b>{t}An error occurred while trying to run your query{/t}</b>
{elseif $draft_result == 1}
  <b>{t}Thank you, the email message was saved as a draft successfully.{/t}</b>
{/if}
  </span>
</center>
<script language="JavaScript">
<!--
{if $current_user_prefs.close_popup_windows == '1'}
setTimeout('closeAndRefresh()', 2000);
{/if}
//-->
</script>
<br />
{if not $current_user_prefs.close_popup_windows}
  <center>
    <span class="default"><a class="link" href="javascript:void(null);" onClick="javascript:closeAndRefresh();">{t}Continue{/t}</a></span>
  </center>
{/if}
{else}
<script language="JavaScript">
<!--
checkWindowClose('{t}If you close this window, you will lose your message{/t}');

var contact_list = new Array();
{section name="i" loop=$assoc_emails}
contact_list[contact_list.length] = '{$assoc_emails[i]|replace:"'":"\\'"}';
{/section}

var email_responses = new Array();
{section name="i" loop=$js_canned_responses}
email_responses[{$js_canned_responses[i].ere_id}] = "{$js_canned_responses[i].ere_response_body}";
{/section}
{literal}
function validate(f)
{
    if (f.to != null) {
        if (isWhitespace(f.to.value)) {
            alert('{/literal}{t escape=js}Please enter the recipient of this email.{/t}{literal}');
            selectField(f, 'to');
            return false;
        }
    }
    if (isWhitespace(f.subject.value)) {
        alert('{/literal}{t escape=js}Please enter the subject of this email.{/t}{literal}');
        selectField(f, 'subject');
        return false;
    }
    if (isWhitespace(f.message.value)) {
        alert('{/literal}{t escape=js}Please enter the message body of this email.{/t}{literal}');
        selectField(f, 'message');
        return false;
    }
{/literal}
{if $current_role != $roles.customer and $issue_id != 0}
    {if !$can_send_email}
    var warning_msg = "{t}WARNING: You are not assigned to this issue so your email will be blocked.\\nYour blocked email will be converted to a note that can be recovered later.\\nFor more information, please see the topic 'email blocking' in help.{/t}";
    {elseif $has_customer_integration}
    var warning_msg = "{t}WARNING: This email will be sent to all names on this issue's Notification List, including CUSTOMERS.\\nIf you want the CUSTOMER to receive your message now, press OK.\\nOtherwise, to return to your editing window, press CANCEL.{/t}";
    {else}
    var warning_msg = "{t}WARNING: This email will be sent to all names on this issue's Notification List.\\nIf you want all users to receive your message now, press OK.\\nOtherwise, to return to your editing window, press CANCEL.{/t}";
    {/if}
{literal}
    if (!confirm(warning_msg)) {
        return false;
    } else {
        checkWindowClose(false);
        return true;
    }
{/literal}
{else}
    checkWindowClose(false);
    return true;
{/if}
{literal}
}
function setResponseBody(f)
{
    var response_id = getSelectedOption(f, 'email_response');
    if (email_responses[response_id]) {
        f.message.value = email_responses[response_id];
    }
}
function saveDraft(f)
{
    checkWindowClose(false);
    f.cat.value = 'save_draft';
    f.submit();
}
function updateDraft(f)
{
    checkWindowClose(false);
    f.cat.value = 'update_draft';
    f.submit();
}
var old_message = '';
function setSignature(f)
{
{/literal}
    var signature = "{$current_user_prefs.email_signature|replace:'"':'\"'|replace:"\r":""|replace:"\n":'\n'}";
{literal}
    if (f.add_email_signature.checked) {
        old_message = f.message.value;
        f.message.value += "\n";
        f.message.value += signature;
    } else {
        f.message.value = old_message;
    }
}
//-->
</script>
{/literal}
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<script language="JavaScript" src="js/overlib_mini.js"></script>
<script language="JavaScript" src="js/autocomplete.js"></script>
<form onSubmit="javascript:return validate(this);" name="send_email_form" method="post" action="{$smarty.server.PHP_SELF}" enctype="multipart/form-data">
<input type="hidden" name="cat" value="send_email">
<input type="hidden" name="parent_id" value="{$parent_email_id}">
<input type="hidden" name="ema_id" value="{$ema_id}">
<input type="hidden" name="issue_id" value="{$issue_id}">
{if $smarty.get.cat == 'view_draft'}
<input type="hidden" name="draft_id" value="{$draft_id}">
{/if}
{if $draft_status == 'sent'}
    <br /><center class="banner_red"><img src="images/icons/error.gif"> {t}Warning: This draft has already been sent. You cannot resend it.{/t}</center>
{elseif $draft_status == 'edited'}
    <br /><center class="banner_red"><img src="images/icons/error.gif"> {t}Warning: This draft has already been edited. You cannot send or edit it.{/t}</center>
{/if}
<table align="center" width="100%" cellpadding="3">
  <tr>
    <td>
      <table width="100%" cellspacing="1" cellpadding="2" border="0">
        <tr>
          <td colspan="2" class="default">
            {if $smarty.get.cat == 'create_draft'}
                <b>{t}Create Draft{/t}</b>
            {else}
                <b>{t}Send Email{/t}</b>
            {/if}
          </td>
        </tr>
        {if $send_result != ""}
        <tr>
          <td bgcolor="{$cell_color}" colspan="2" class="error" align="center">
            {if $send_result == -1}
              <b>{t}An error occurred while trying to run your query{/t}</b>
            {elseif $send_result == -2}
              <b>{t}Sorry, but the email could not be sent. This might be related to problems with your SMTP account settings.{/t}<br />
              {t}Please contact the administrator of this application for assistance.{/t}</b>
            {elseif $send_result == 1}
              <b>{t}Thank you, the email was sent successfully.{/t}</b>
            {/if}
          </td>
        </tr>
        {/if}
        <tr>
          <td width="120" bgcolor="{$cell_color}" class="default_white">
            <b>{t}From{/t}:</b>
          </td>
          <td bgcolor="{$light_color}" class="default">
            <input type="hidden" name="from" value="{$from|escape:"html"}">
            <b>{$from|escape:"html"}</b>
          </td>
        </tr>
        <tr>
          <td width="120" bgcolor="{$cell_color}" class="default_white">
            <b>{t}To{/t}: *</b>
          </td>
          <td bgcolor="{$light_color}">
            {if $issue_id == ''}
                <input type="text" name="to" class="default" size="50" value="{$email.sup_from|escape:"html"}" onKeyUp="javascript:autoComplete(this, contact_list);">
                {if not ($os.mac and $browser.ie)}<a href="javascript:void(null);" onClick="return overlib(getFillInput('{include file="lookup_layer.tpl.html" list=$assoc_users}', 'send_email_form', 'to'), STICKY, HEIGHT, 50, WIDTH, 160, BELOW, LEFT, CLOSECOLOR, '#FFFFFF', FGCOLOR, '#FFFFFF', BGCOLOR, '#333333', CAPTION, 'Lookup Details', CLOSECLICK);" onMouseOut="javascript:nd();"><img src="{$rel_url}images/lookup.gif" border="0"></a>{/if}
                {include file="error_icon.tpl.html" field="to"}
            {else}
                <span class="default">{t}Issue{/t} #{$issue_id} {t}Notification List{/t} ({t}Members{/t}: {$subscribers.staff|replace:"<":"&lt;"|replace:">":"&gt;"}{if $subscribers.customers != ''}, {$subscribers.customers|replace:"<":"&lt;"|replace:">":"&gt;"}{/if})</span>
            {/if}
          </td>
        </tr>
        <tr>
          <td width="120" bgcolor="{$cell_color}" class="default_white">
            <b>{t}Cc{/t}:</b>
          </td>
          <td bgcolor="{$light_color}">
            <input type="text" name="cc" class="default" size="50" value="{$email.cc|escape:"html"}" {if $read_only == 1}readonly{/if}>
            {if not ($os.mac and $browser.ie)}<a href="javascript:void(null);" onClick="return overlib(getFillInput('{include file="lookup_layer.tpl.html" list=$assoc_users multiple="1"}', 'send_email_form', 'cc'), STICKY, HEIGHT, 50, WIDTH, 160, BELOW, LEFT, CLOSECOLOR, '#FFFFFF', FGCOLOR, '#FFFFFF', BGCOLOR, '#333333', CAPTION, 'Lookup Details', CLOSECLICK);" onMouseOut="javascript:nd();"><img src="{$rel_url}images/lookup.gif" border="0"></a>{/if}
          </td>
        </tr>
        {if $issue_id and $current_role != $roles.customer and $read_only != 1}
        <tr>
          <td width="120" bgcolor="{$cell_color}" class="default_white">
            &nbsp;
          </td>
          <td bgcolor="{$light_color}" class="default">
            <input type="checkbox" name="add_unknown" value="yes">
            <a id="link" class="link" href="javascript:void(null);" onClick="javascript:toggleCheckbox('send_email_form', 'add_unknown');">{t}Add Unknown Recipients to Issue Notification List{/t}</a>
          </td>
        </tr>
        {else}
        <input type="hidden" name="add_unknown" value="no">
        {/if}
        <tr>
          <td width="120" bgcolor="{$cell_color}" class="default_white">
            <b>{t}Subject{/t}: *</b>
          </td>
          <td bgcolor="{$light_color}">
            <input type="text" name="subject" class="default" size="50" value="{if $smarty.get.cat == 'view_draft'}{$email.sup_subject|escape:"html"}{else}{$email.reply_subject|escape:"html"}{/if}" {if $read_only == 1}readonly{/if}>
            {include file="error_icon.tpl.html" field="subject"}
          </td>
        </tr>
        <tr>
          <td bgcolor="{$light_color}" colspan="2">
            {if $current_role != $roles.customer and $canned_responses != '' and $read_only != 1}
            <span class="default"><b>{t}Canned Responses{/t}:</b></span>
            <select name="email_response" class="default">
              {html_options options=$canned_responses}
            </select>&nbsp;<input type="button" class="shortcut" value="{t}Use Canned Response{/t}" onClick="javascript:setResponseBody(this.form);"><br />
            {/if}
            <textarea name="message" rows="15" style="width: 97%" {if $read_only == 1}readonly{/if}>{$email.seb_body|escape:"html"}{if $current_user_prefs.auto_append_sig == 'yes' && $body_has_sig_already != 1}


{$current_user_prefs.email_signature|escape:"html"}{/if}</textarea>
            {include file="error_icon.tpl.html" field="message"}
          </td>
        </tr>
        <tr>
          <td width="120" bgcolor="{$cell_color}" class="default_white">
            <b>Attachment:</b>
          </td>
          <td bgcolor="{$light_color}" >
            <input type="file" name="attachment[]" size="30"></input>
          </td>
        </tr>
        {if $issue_id and $current_role > $roles.customer and $read_only != 1}
            {if $hide_email_buttons != 'yes'}
        <tr>
          <td width="120" bgcolor="{$cell_color}" class="default_white">
            <b>{t}New Status for Issue{/t} #{$issue_id}:</b>
          </td>
          <td bgcolor="{$light_color}">
            <select name="new_status" class="default">
              {html_options options=$statuses selected=$current_issue_status}
            </select>
          </td>
        </tr>
        {/if}
        <tr>
          <td width="120" bgcolor="{$cell_color}" class="default_white">
            <b>{t}Time Spent{/t}:</b>
          </td>
          <td bgcolor="{$light_color}">
            <input type="text" size="5" name="time_spent" class="default"> <span class="small_default"><i>({t}in minutes{/t})</i></span>
          </td>
        </tr>
        {elseif $issue_id and $current_role == $roles.customer}
        <input type="hidden" name="new_status" value="{$new_status}">
        {/if}
        {if $hide_email_buttons != 'yes'}
        <tr>
          <td colspan="2" bgcolor="{$cell_color}">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
              <tr>
                <td align="center">
                  {if $read_only != 1}
                  <input class="button" type="submit" value="{t}Send Email{/t}">&nbsp;&nbsp;
                  <input class="button" type="button" value="{t}Reset{/t}" onClick="javascript:resetForm(this.form);">&nbsp;&nbsp;
                  {/if}
                  <input class="button" type="button" value="{t}Cancel{/t}" onClick="javascript:confirmCloseWindow();">
                </td>
                {if $app_setup.spell_checker == 'enabled'}
                <td align="center" width="150">
                  <input class="button" type="button" value="{t}Check Spelling{/t}" onClick="javascript:checkSpelling('send_email_form', 'message');">
                </td>
                {/if}
                {if $current_user_prefs.email_signature != "" and $current_user_prefs.auto_append_sig != 'yes'}
                <td class="default_white" align="right" width="150">
                  <nobr>
                  <input type="checkbox" name="add_email_signature" value="yes" onClick="javascript:setSignature(this.form);">
                  <a id="white_link" class="white_link" href="javascript:void(null);" onClick="javascript:toggleCheckbox('send_email_form', 'add_email_signature');setSignature(getForm('send_email_form'));">{t}Add Email Signature{/t}</a>
                  &nbsp;&nbsp;
                  </nobr>
                </td>
                {/if}
              </tr>
            </table>
          </td>
        </tr>
        {/if}
        {if $issue_id and $current_role != $roles.customer}
        <tr>
          <td bgcolor="{if $hide_email_buttons == 'yes'}{$cell_color}{else}{$dark_color}{/if}" colspan="2">
            {if $read_only != 1}
            {if $smarty.get.cat == 'view_draft'}
            <input type="button" class="button" value="{t}Save Draft Changes{/t}" onClick="javascript:updateDraft(this.form);">
            {else}
            <input type="button" class="button" value="{t}Save as Draft{/t}" onClick="javascript:saveDraft(this.form);">
            {/if}
            {/if}
          </td>
        </tr>
        {/if}
        <tr>
          <td colspan="2" class="default">
            <b>* {t}Required fields{/t}</b>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>

{if $parent_email_id or $smarty.get.cat == 'reply'}
{literal}
<script language="JavaScript">
<!--
window.onload = focusMessageBox;
function focusMessageBox()
{
    var f = getForm('send_email_form');
    f.message.focus();
}
//-->
</script>
{/literal}
{/if}

{/if}

{include file="footer.tpl.html"}
