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

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





<?cs ##################################
     # prints "You are starting a completely new topic", etc.
     #################################
?>
<?cs def:print_heading() ?>

<?cs with:lang=lang.news_new_memo ?>
 <div class="center_msg">
   <?cs if:no_topic_type ?>
       <span class="alert_color"><?cs var:lang.new_item_label ?></span>
   <?cs elif:topic_assign ?>
       <span class="alert_color"><?cs var:lang.new_assignment_label ?></span>
   <?cs elif:feedbackto_recipient ?>
        <span class="alert_color"><?cs var:lang.assign_feedback_to ?></span> <?cs var:feedbackto_realname ?> (<?cs var:feedbackto_recipient ?>)
        <br /><span class="alert_color"><?cs var:lang.assign_feedback_regarding ?></span> <?cs var:topic_subject ?>
   <?cs elif:grp == 6 ?>
        <span class="alert_color"><?cs var:lang.current_assignment_label ?></span> <?cs var:topic_subject ?><br />
        <span class="alert_color"><?cs var:lang.reply_is_private ?></span>
   <?cs elif:reply_to == #-1 ?>
        <span class="alert_color"><?cs var:lang.new_topic_label ?></span> 
   <?cs else ?>
        <span class="alert_color"><?cs var:lang.current_topic_label ?></span> <?cs var:topic_subject ?><br />
        <span class="alert_color"><?cs var:lang.current_topic_author ?></span> <?cs var:topic_author_realname ?>
   <?cs /if ?>
   <?cs if:team && team_name ?>
        <br> <span class="alert_color"><?cs var:lang.team_label ?> <?cs var:team_name ?></span>
   <?cs /if ?>
   </div>

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



<?cs ##########################################
     # these hidden form elements are used in the "Paste from clipboard"
     # as well as the main message form on this page
     ############################################
?>

<?cs def:print_hidden_form_elements() ?>
      <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="topic" value="<?cs var:topic ?>" />
      <input type="hidden" name="reply_to" value="<?cs var:reply_to ?>" />
      <input type="hidden" name="from" value="<?cs var:from ?>" />
      <input type="hidden" name="width" value="<?cs var:msg.textarea.cols ?>" />
      <?cs if:team ?>
         <input type="hidden" name="team" value="<?cs var:team ?>" />
      <?cs /if ?>
      <?cs if:to ?>
         <input type="hidden" name="to" value="<?cs var:to ?>" />
      <?cs /if ?>
      </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="news_new_memo" onsubmit="return confirm_discard('<?cs var:lang.news_new_memo.overwrite_msg_confirm_JAVASCRIPT ?>')">
    <?cs call:print_hidden_form_elements() ?>
    <div>
    <input type="hidden" name="paste" value="yes"  />
    <input type="submit" value="<?cs var:lang.news_new_memo.paste_button ?>" title="<?cs var:lang.news_new_memo.paste_button_help ?>"  />
   </div>
   </form>
  </td></tr>
 </table>
<?cs /def ?>




<?cs #################################
     # prints a "Mark message as teacher-hidden" checkbox
     ################################
?>

<?cs def:print_mark_hidden_option() ?> 
<?cs with:lang = lang.news_new_memo ?>
  <tr>
    <td>
      <input type="checkbox" name="hide" title="<?cs var:lang.mark_hidden_checkbox_help ?>" /><?cs var:lang.mark_hidden_checkbox_label ?>
    </td>
  </tr>
<?cs /with ?>
<?cs /def ?>



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

<?cs def:print_spellcheck_button() ?>
<?cs with:lang = lang.news_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.news_new_memo.send_button ?>" title="<?cs var:lang.news_new_memo.send_button_help ?>" />
     <span class="regheading"><?cs var:lang.news_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.news_new_memo.subject_help ?>" value="<?cs if:msg.subject.add_re ?><?cs var:lang.news_new_memo.regarding_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.news_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.feedback ?><?cs var:msg.textarea.feedback ?> <?cs var:lang.wrote_prompt ?><?cs var:msg.textarea.feedback_newline ?><?cs /if ?><?cs var:msg.textarea.body ?></textarea>
      </td>
     <?cs if:!emoticons_disabled ?><td valign="top"><?cs call:add_smile_faces() ?></td><?cs /if ?>
     </tr>
     </table>
     </td>
  </tr>
<?cs /with ?>
<?cs /def ?>


<?cs def:special_attachment_radio_button(label, help, num) ?>
   <tr>
     <td>
       <table>
        <tr>
         <td valign="middle">
         <input type="radio" name="website" value="<?cs var:num ?>" title="<?cs var:help ?>" <?cs if:!num ?>checked="checked"<?cs /if ?> />
        </td>
        <td class="attachment_instructions""><?cs var:label ?></td>
        </tr>
      </table> 
     </td>
   </tr>
<?cs /def ?>


<?cs def:special_attachment_checkbox(label, help) ?>
   <tr>
     <td>
       <table>
        <tr>
         <td valign="middle">
         <input type="checkbox" name="website" title="<?cs var:help ?>"  />
        </td>
        <td class="attach"><?cs var:label ?></td>
        </tr>
      </table> 
     </td>
   </tr>
<?cs /def ?>


<?cs def:description_of_podcasting_file_format() ?>
 <tr>
 <td><span class="instructions"><?cs var:lang.podcast_attachment_instructions ?></span></td>
</tr>
<?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.news_new_memo ?>

<?cs ### deal with pasted website or file(s) ## ?>
 <?cs if:has_attach ?>
   <tr>
     <td class="regheading"><?cs if:attach.not_allow != #1 ?><?cs var:lang.include_from_clipboard_label ?><?cs /if ?>
     <?cs if:attach.website == #1 ?> 
         <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 else ?>
       <?cs if:!attach.not_allow ?> 
        <?cs set:file_num = #1 ?>

        <?cs each:this = attach.file ?>
	      <?cs if:grp == 16 ?>   <?cs ## 16 is Podcasts module ## ?>
             <br /><input type="radio" name="pod_paste" value="<?cs var:this.value ?>" title="<?cs var:lang.include_from_clipboard_help ?>" <?cs if:file_num == #1 ?>checked="checked"<?cs /if ?> /><?cs var:this.orig ?>
             <?cs else ?> 
	     <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 /if ?>
             <?cs set:file_num = file_num + #1 ?>
        <?cs /each ?>
	    <?cs if:grp == 16 ?>     <?cs ## 16 is Podcasts module ## ?>
             <br /><input type="radio" name="pod_paste" value="-1" title="<?cs var:lang.attach_no_pasted_files ?>"  /><span style="color:#f00"><?cs var:lang.attach_no_pasted_files ?></span>
	     <?cs /if ?>
       <?cs /if ?>
      <?cs /if ?>
     <input type="hidden" name="<?cs var:attach.type ?>" value="<?cs var:attach.value ?>" />
     </td>
   </tr>
 <?cs /if ?>

<?cs ### the standard attachment area begins here ### ?>
 <tr>
    <td>
     <span class="regheading"><?cs var:lang.attach_label ?></span>
     <?cs if:has_attach == #1 ?>   
        <?cs if:grp == 16 ?> <?cs ## 16 is Podcasts module ## ?>
            <p  class="instructions"><span style="margin-left:0em"><?cs var:lang.pasted_podcast_note ?></span></p>
        <?cs else ?>
            <p  class="instructions"><span style="margin-left:6em"><?cs var:lang.pasted_note ?></span></p>
        <?cs /if ?>
    <?cs /if ?>
    </td>
 </tr>

<?cs ## if we're supposed to allow attachment of Hot Pot Exams
     ## (teacher in Assignments, posting new Assignment)
     ## then we need to also provide a checkbox for no files
     ## or only 'normal' files
?>

 <?cs if:attach.allow_hotpot_exam == #1 ?>
   <?cs call:special_attachment_radio_button(lang.attach_normal_label, lang.attach_normal_help, 0) ?>
   <?cs call:special_attachment_radio_button(lang.attach_website_label, lang.attach_website_help, 1) ?>
   <?cs call:special_attachment_radio_button(lang.attach_hotpot_label, lang.attach_hotpot_help, 2) ?>
 <?cs elif:grp == 16  ?>    <?cs ## 16 is Podcasts ## ?>
    <?cs call:description_of_podcasting_file_format() ?>
 <?cs else ?>
    <?cs call:special_attachment_checkbox(lang.attach_website_label, lang.attach_website_help) ?>
 <?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.news_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.news_new_memo.send_button ?>" title="<?cs var:lang.news_new_memo.send_button_help ?>"  />
   </td>
 </tr>
<?cs /def ?>

<?cs def:print_one_upload_form() ?>
 <tr><td class="regheading">
    <?cs var:lang.news_new_memo.podcast_file_label ?> <input type="file" name="podcasting" title="<?cs var:lang.news_new_memo.upload_audio_file ?>" /><br /><br />
 </td></tr>
<?cs /def ?>



<?cs ### 

     HTML OUTPUT STARTS HERE 

### ?>

<?cs call:html_heading() ?>
<head>
      <title><?cs var:course_no ?> <?cs var:lang.news_new_memo.grp[grp].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 force user to enter a Subject:

### ?>
<script type="text/javascript">
 function confirm_send()
 {
  <?cs if:content_clipboard ?>
     var myform = window.document.forms[1];
  <?cs else ?>
    var myform = window.document.forms[0];
  <?cs /if ?>


    if(myform.subject.value == "" )
     {
       window.alert('<?cs var:lang.news_new_memo.no_blank_subject_JAVASCRIPT ?>');
       return false;
     }
        
 <?cs if:grp == 16 ?>
  <?cs if:do_clipboard == 1 && attach.file[0].value ?>
    var len = myform.pod_paste.length;
    var pasted_file = "-1";
    for(i = 0; i<len; i++)
     {
	if(myform.pod_paste[i].checked)
  	    pasted_file = myform.pod_paste[i].value;
     }

     if( (myform.podcasting.value == "") && (pasted_file == "-1") )
      {
        window.alert('<?cs var:lang.news_new_memo.must_select_one_audio_file_JAVASCRIPT ?>');
        return false;
      }


     if( (myform.podcasting.value.length > 0) && (pasted_file.length > 0) && (pasted_file != "-1"))
       {
         window.alert('<?cs var:lang.news_new_memo.only_one_audio_file_JAVASCRIPT ?>');
	 return false;
       }
             
   <?cs else ?>   <?cs ## clipboard not active ## ?>
       if(myform.subject.value == "" )
         {
           window.alert('<?cs var:lang.news_new_memo.no_blank_subject ?>');
   	   return false;
	 }

        if( myform.podcasting.value == "")
          {
           window.alert('<?cs var:lang.news_new_memo.no_blank_audio_JAVASCRIPT ?>');
   	   return false;
          }
   <?cs /if ?>
   
   var answer=window.confirm('<?cs var:lang.news_new_memo.send_msg_confirm_JAVASCRIPT ?>');
   if(answer)
    {
     bar1.showBar();
     scroll(0,0);
     return true;
    }
   else
     return false;
		    
  <?cs else ?>  <?cs ### this is not the Podcasts module ## ?>
     <?cs if: attach.allow_hotpot_exam == #1 ?>
           if( ((myform.website[1].checked) || (myform.website[2].checked)) && !(myform.file1.value) )
             {
               window.alert('<?cs var:lang.news_new_memo.attached_website_error_JAVASCRIPT ?>');
               return false;
	     }
     <?cs else ?>
           if( (myform.website.checked) && !(myform.file1.value) )
             {
               window.alert('<?cs var:lang.news_new_memo.attached_website_error_JAVASCRIPT ?>');
               return false;
             }
      <?cs /if ?>
	     else
             {
                var answer=window.confirm('<?cs var:lang.news_new_memo.send_msg_confirm_JAVASCRIPT ?>');
                if(answer)
                 {
                   bar1.showBar();
                   scroll(0,0);
                   return true;
                 }
                else 
                   return false;
              }
   <?cs /if ?>
 }
</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(back_url) ?>
<?cs call:print_heading() ?>

<table width="100%">
<tr><td align="center">
   <?cs if:content_clipboard == #1 ?>
      <?cs call:print_paste_form() ?>
   <?cs /if ?>
   <?cs if:grp == 16 ?>
   <form method="post" enctype="multipart/form-data" action="podcasting_send_mail" onsubmit="return confirm_send()"> 
   <?cs else ?>
   <form method="post" enctype="multipart/form-data" action="news_send_mail" onsubmit="return confirm_send()"> 
   <?cs /if ?>
   <table width="20%" cellspacing="0" cellpadding="1">
   <tr><td>
   <?cs call:print_hidden_form_elements() ?>
    </td></tr>
   <?cs if:include_mark_hidden_option == #1 ?>
     <?cs call:print_mark_hidden_option() ?> 
   <?cs /if ?>
   <?cs call:print_subject() ?>
   <?cs call:print_textarea() ?>
    <?cs call:print_attach() ?>

   <?cs if:grp != 16 ?>
     <?cs call:print_upload_form() ?>
   <?cs else ?>
     <?cs call:print_one_upload_form() ?>
   <?cs /if ?>

   <?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() ?> 
