<?cs include:"util.cs" ?>
<?cs include:"add_smile.cs" ?>

<?cs #################################
     # prints a Back Arrow, plus some info about the course
     ################################
?>

<?cs def:print_back_arrow_course_info() ?>
  <?cs call:course_info() ?>
 <?cs with:lang = lang.post_new_memo ?>
   <div>
      <a href="<?cs var:back_url ?>" title="<?cs var:lang.back_arrow_title ?>"><img src="<?cs var:image_path ?>/back_arrow.gif" width="50" height="34" alt="<?cs var:lang.back_arrow_title ?>" onclick="return confirm_discard('<?cs var:lang.discard_msg_confirm ?>')" /></a>
   </div>

<?cs /with ?>
<?cs /def ?>




<?cs ##################################
     # prints a simple heading for the page.
     #################################
?>
<?cs def:print_heading() ?>
 <div class="center_msg">
       <span class="alert_color"><?cs if:is_forward ?><?cs var:lang.post_new_memo.forward_message_heading ?><?cs else ?><?cs var:lang.post_new_memo.new_message_heading ?><?cs /if ?></span>
 </div>
<?cs /def ?>




<?cs #################################
     # prints a "Paste message from clipboard button" (form)
     ################################
?>

<?cs def:print_paste_form() ?>
  <table cellspacing="0" cellpadding="1">
   <tr><td>
    <form method="post" action="post_new_memo" onsubmit="return confirm_discard('<?cs var:lang.post_new_memo.overwrite_msg_confirm ?>')">
    <div>
    <input type="hidden" name="crs" value="<?cs var:crs ?>" />
    <input type="hidden" name="id" value="<?cs var:id ?>" />
    <input type="hidden" name="grp" value="<?cs var:grp ?>" />
    <input type="hidden" name="loc" value="<?cs var:loc ?>" />
    <input type="hidden" name="paste" value="yes" />
    <input type="hidden" name="from" value="<?cs var:from ?>" />
    <input type="submit" value="<?cs var:lang.post_new_memo.paste_button ?>" title="<?cs var:lang.post_new_memo.paste_button_help ?>"  />
   </div>
   </form>
  </td></tr>
 </table>
<?cs /def ?>





<?cs def:print_recipient_lists() ?>
<tr><td>
<table>
<tr>
<td valign="bottom" align="right"><b><?cs var:lang.post_new_memo.to_list_label ?></b></td>
<td><select name="to" id="to" title="<?cs var:lang.post_new_memo.to_list_title ?>" size="5" multiple="multiple">
   <?cs each:person = user ?>
      <option value="<?cs var:person.value ?>" <?cs each:to_item = to ?><?cs if:to_item == person.value ?> selected="selected"<?cs /if ?><?cs /each ?>><?cs var:person.realname ?></option> 
   <?cs /each ?>
  </select>
</td>

<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>

<td valign="bottom" align="right"><b><?cs var:lang.post_new_memo.cc_list_label ?></b></td>
<td><select name="cc" id="cc" title="<?cs var:lang.post_new_memo.cc_list_title ?>" size="5" multiple="multiple">
   <?cs each:person = user ?>
      <option value="<?cs var:person.value ?>" <?cs each:cc_item = cc ?><?cs if:cc_item == person.value ?> selected="selected"<?cs /if ?><?cs /each ?>><?cs var:person.realname ?></option> 
   <?cs /each ?>
  </select>
</td>
</tr>
</table>
</td>
</tr>
<?cs /def ?>







<?cs #################################
     # prints "Check Spelling" button
     ################################
?>

<?cs def:print_spellcheck_button() ?>
<?cs with:lang = lang.post_new_memo ?>
 <tr>
   <td align="right">
   <?cs if:content_clipboard ?>
    <input type="button" value="<?cs var:lang.spell_button ?>" title="<?cs var:lang.spell_button_help ?>" onclick="openSpellChecker( document.forms[1].msg );" />
   <?cs else ?>
    <input type="button" value="<?cs var:lang.spell_button ?>" title="<?cs var:lang.spell_button_help ?>" onclick="openSpellChecker( document.forms[0].msg );" />
   <?cs /if ?>
   </td><td>&nbsp;</td>
 </tr>
<?cs /with ?>
<?cs /def ?>


<?cs #################################
     # prints "Send Message" button, and a prompt to enter a Subject:
     ################################
?>

<?cs def:print_subject() ?>
  <tr>
     <td>
     <input type="submit" value="<?cs var:lang.post_new_memo.send_button ?>" title="<?cs var:lang.post_new_memo.send_button_help ?>" />
     <span class="regheading"><?cs var:lang.post_new_memo.subject_label ?></span>
     <input type="text" name="subject" id="subject" size="<?cs if:msg.subject.size ?><?cs var:msg.subject.size ?><?cs else ?><?cs var:msg.subject.max ?><?cs /if ?>" maxlength="<?cs var:msg.subject.max ?>" title="<?cs var:lang.post_new_memo.subject_help ?>" value="<?cs if:is_reply || is_group_reply ?><?cs var:lang.post_new_memo.regarding_abbrev ?><?cs elif:is_forward ?><?cs var:lang.post_new_memo.forward_abbrev ?><?cs /if ?><?cs var:msg.subject.value ?>" />
     </td>
  </tr>
<?cs /def ?>


<?cs #################################
     # prints the textarea used for the body of the message
     ################################
?>

<?cs def:print_textarea() ?>
  <tr>
     <td>
     <table>
   <?cs if:check_spelling ?>
     <?cs call:print_spellcheck_button() ?>
   <?cs /if ?>
<?cs with:lang = lang.post_new_memo ?>
    <tr><td>
       <textarea  title="<?cs var:lang.body_help ?>" name="msg" id="msg" cols="<?cs var:msg.textarea.cols ?>" rows="12" wrap=<?cs if:msg.textarea.hard_wrap ?>"hard"<?cs else ?>"virtual"<?cs /if?>><?cs if:msg.textarea.author ?><?cs var:msg.textarea.author ?> <?cs var:lang.wrote_prompt ?><?cs /if ?><?cs var:msg.textarea.body ?></textarea>
     </td><td><?cs if:!emoticons_disabled ?><?cs call:add_smile_faces() ?><?cs /if ?></td></tr>
     </table>
     </td>
  </tr>
<?cs /with ?>
<?cs /def ?>




<?cs #################################
     # handles prelude to attachment area, 
     # including any pasted attachments,
     # and checkboxes for "I'm attaching 
     # a website", etc.
     ################################
?>
<?cs def:print_attach() ?>
<?cs with: lang=lang.post_new_memo ?>

<?cs ### deal with pasted website or file(s) ## ?>
 <?cs if:has_attach ?>
   <tr>
     <td class="regheading"><?cs if:is_forward ?><?cs var:lang.include_from_forwarded_label ?><?cs else ?><?cs if:!attach.not_allow ?><?cs var:lang.include_from_clipboard_label ?><?cs /if ?><?cs /if ?>
     <?cs if:attach.website == #1 ?> 
         <input type="hidden" name="pasted_website" value="1" />
         <?cs if:!is_forward ?><br /><input type="checkbox" name="f1" value="<?cs var:attach.file[0].value ?>" title="<?cs var:lang.include_from_clipboard_help ?>" checked="checked" /><?cs var:lang.attachedwebsite ?><?cs /if ?>
     <?cs else ?>
        <?cs set:file_num = #1 ?>
         <input type="hidden" name="pasted_files" value="1" />
        <?cs each:this = attach.file ?>
             <br /><input type="checkbox" name="f<?cs var:file_num ?>" value="<?cs var:this.value ?>" title="<?cs var:lang.include_from_clipboard_help ?>" checked="checked" /><?cs var:this.orig ?>
             <?cs set:file_num = file_num + #1 ?>
        <?cs /each ?>
     <?cs /if ?>
     </td>
   </tr>
 <?cs /if ?>

<?cs ### the standard attachment area begins here ### ?>
<?cs if:is_forward ?>
<tr>
    <td>
     <span class="regheading"><?cs var:lang.attach_label ?></span>
    </td>
 </tr>
<?cs else ?>
 <tr>
    <td>
     <span class="regheading"><?cs var:lang.attach_label ?></span>
     <?cs if:has_attach && !attach.not_allow ?><div  class="instructions"><span style="margin-left:6em"><?cs var:lang.pasted_note ?></span></div><?cs /if ?>
    </td>
 </tr>


   <tr>
     <td>
       <table>
        <tr>
         <td valign="middle">
         <input type="checkbox" name="website" title="<?cs var:lang.attach_website_help ?>"  />
        </td>
        <td class="attachment_instructions"><?cs var:lang.attach_website_label?></td>
        </tr>
      </table> 
     </td>
   </tr>
<?cs /if ?>
<?cs /with ?>
<?cs /def ?>




<?cs #################################
     # prints <input type=file...> attachment file attachement elements
     ################################
?>

<?cs def:print_upload_form() ?>
  <?cs loop:x = #0, attach.max_files - #1, #1 ?>
  <?cs set:file_num =  x + #1 ?>
  <?cs set:name = "file" + file_num ?>
  <?cs if:x  == #0 ?>
   <tr><td>
  <?cs elif:x % 2 == #0  ?>
   </td></tr><tr><td>
  <?cs /if ?>
   <input type="file" name="<?cs var:name ?>" title="<?cs var:lang.post_new_memo.file_checkbox_help ?>" />
  <?cs /loop ?>  
  </td></tr>
<?cs /def ?>


<?cs #################################
     # prints the Submit button found at the bottom of the page
     ################################
?>

<?cs def:print_submit_button() ?>
 <tr>
   <td align="center">
    <input type="submit" value="<?cs var:lang.post_new_memo.send_button ?>" title="<?cs var:lang.post_new_memo.send_button_help ?>"  />
   </td>
 </tr>
<?cs /def ?>




<?cs ### 

     HTML OUTPUT STARTS HERE 

### ?>
<?cs call:html_heading() ?>
<head>
      <title><?cs var:course_no ?> <?cs var:lang.post_new_memo.module_name ?></title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <link rel="StyleSheet" href="<?cs var:image_path ?>common.css" type="text/css"  />
    <script type="text/javascript" src="<?cs var:server_name ?><?cs var:image_path ?>form_validation.js"></script>
    <script type="text/javascript" src="<?cs var:server_name ?><?cs var:image_path ?>xp_progress.js"></script>

<?cs #### 

    If spell check enabled, insert required JavaScript 

### ?>
<?cs if:check_spelling ?>
    <script type="text/javascript" src="<?cs var:server_name ?><?cs var:image_path ?>spellChecker.js"></script>
    <script type="text/javascript">
      function openSpellChecker(txt) 
         {
          var speller = new spellChecker( txt,'<?cs var:server_name ?><?cs var:image_path ?>spellchecker.html','<?cs var:server_name ?>/<?cs var:alias ?>/spellchecker' );
          speller.openChecker();
         }
    </script>
<?cs /if ?>



<?cs #### 
    
    Insert script to validate the form before submission

### ?>
<script type="text/javascript">
   function confirm_send()
     {
            
      <?cs if:content_clipboard ?>
           <?cs set: form_number = "1" ?>
      <?cs else ?>
           <?cs set: form_number = "0" ?>      
      <?cs /if ?>


      var index = window.document.forms[<?cs var:form_number ?>].to.selectedIndex;
   
     if((index < 0)  || window.document.forms[<?cs var:form_number ?>].to.options[index].value == "")   
       {
        window.alert('<?cs var:lang.post_new_memo.message_not_addressed ?>');
        return false;
       }
     else
      if(window.document.forms[<?cs var:form_number ?>].subject.value == "")
         {
            window.alert('<?cs var:lang.post_new_memo.no_blank_subject ?>');
            return false;
         }
<?cs if:!is_forward ?>
      else
         if( (window.document.forms[<?cs var:form_number ?>].website.checked) &&
             !(window.document.forms[<?cs var:form_number ?>].file1.value) )
         {
            window.alert('<?cs var:lang.post_new_memo.attached_website_error ?>');
            return false;
         }
<?cs /if ?>
       else
         {
            var answer = window.confirm('<?cs var:lang.post_new_memo.send_msg_confirm ?>');
            if(answer)
            {
                bar1.showBar();
                scroll(0,0);
                return true; 
            }
            else
              return false;
         }
     }
</script>


<?cs #### 
    
    If paste button will be presented, insert script to 
    warn user if they are about to abandon a message

### ?>
<script type="text/javascript">
   function confirm_discard(warning)
     {
<?cs if:content_clipboard ?>
       if( (window.document.forms[1].subject.value != "") || (window.document.forms[1].msg.value != "") )
<?cs else ?>
       if( (window.document.forms[0].subject.value != "") || (window.document.forms[0].msg.value != "") )
<?cs /if ?>
         {
            var answer=window.confirm(warning);
            if(answer)
               return true;
            else 
               return false;
         }
        else
              return true;
     }
</script>
</head>

<?cs call:define_onload_onunload_body("subject") ?>
<?cs call:print_back_arrow_course_info() ?>
<?cs call:print_heading() ?>
<table width="100%">
<tr><td align="center">
   <?cs if:content_clipboard == #1 ?>
      <?cs call:print_paste_form() ?>
   <?cs /if ?>
   <form method="post" enctype="multipart/form-data" action=<?cs if:is_forward ?>"post_send_forward"<?cs else ?>"post_send_mail"<?cs /if ?> onsubmit="return confirm_send()"> 
   <table width="20%" cellspacing="0" cellpadding="1">
   <tr><td>
    <input type="hidden" name="crs" value="<?cs var:crs ?>" />
    <input type="hidden" name="id" value="<?cs var:id ?>" />
    <input type="hidden" name="from" value="<?cs var:from ?>" />
    <input type="hidden" name="width" value="<?cs var:msg.textarea.cols ?>" />
    <?cs if:is_forward && has_attach ?>
    <input type="hidden" name="sender" value="<?cs var:sender ?>" />
    <input type="hidden" name="inf" value="<?cs var:inf ?>" />
    <input type="hidden" name="files" value="<?cs var:files ?>" />
    <?cs /if ?>
    </td></tr>
   <?cs call:print_recipient_lists() ?>
   <?cs call:print_subject() ?>
   <?cs call:print_textarea() ?>
   <?cs call:print_attach() ?>
   <?cs call:print_upload_form() ?>
   <?cs call:print_submit_button() ?>
  </table>
  </form>
</td></tr></table>
<script type="text/javascript">
     var bar1 = createBar( 'white', 1, 'black', 'blue', 85, 7, 3, "");
</script>

</body>
</html>
<?cs call:runtime() ?> 
