<%args>
$Ticket
</%args>
<%init>
return unless $Ticket->CurrentUserHasRight('ShowOutgoingEmail')
  or RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'});
</%init>
<script type="text/javascript">
jQuery( function() {
   var updateScrips = function() {
       if (CKEDITOR.instances && CKEDITOR.instances['UpdateContent']) {
           CKEDITOR.instances['UpdateContent'].updateElement();
       }
       var syncCheckboxes = function(ev) {
           var target = ev.target;
           jQuery("input[name=TxnSendMailTo]").filter( function() { return this.value == target.value; } ).prop("checked",jQuery(target).prop('checked'));
       };
       jQuery('#recipients div.titlebox-content').load( '<% RT->Config->Get('WebPath')%>/Helpers/ShowSimplifiedRecipients',
           jQuery('form[name=TicketUpdate]').serialize(),
           function() {
               var txn_send_field = jQuery("#recipients input[name=TxnSendMailTo]");
               txn_send_field.change( syncCheckboxes );
               txn_send_field.click( function () { setCheckbox(this) } );
               jQuery("#recipients input[name=TxnSendMailToAll]").click( function() { setCheckbox(this, 'TxnSendMailTo'); } );
               setCheckbox(txn_send_field);
           }
       );
       jQuery('#previewscrips div.titlebox-content').load( '<% RT->Config->Get('WebPath')%>/Helpers/PreviewScrips',
           jQuery('form[name=TicketUpdate]').serialize(),
           function() {
               var txn_send_field = jQuery("#previewscrips input[name=TxnSendMailTo]");
               txn_send_field.change( syncCheckboxes );
               txn_send_field.click( function () { setCheckbox(this) } );
               jQuery("#previewscrips input[name=TxnSendMailToAll]").click( function() { setCheckbox(this, 'TxnSendMailTo'); } );
               setCheckbox(txn_send_field);
           }
       );
   };

   var old_checkboxToInput = checkboxToInput;
   checkboxToInput = function (target,checkbox,val) {
       old_checkboxToInput(target, checkbox, val);
       jQuery('#' + escapeCssSelector(target)).change();
   };

   updateScrips();
   if (CKEDITOR.instances && CKEDITOR.instances['UpdateContent']) {
       CKEDITOR.instances['UpdateContent'].on('blur', updateScrips );
   }
   jQuery("#ticket-update-metadata :input, #UpdateCc, #UpdateBcc").change( updateScrips );
});
</script>
