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

<?cs def:print_paste(paste) ?>
   <tr><td align="center">
    <div><form method="post" action="survey_new_memo"  >
    <div>
          <input type="hidden" name="crs" value="<?cs var:crs ?>" />
          <input type="hidden" name="id" value="<?cs var:id ?>" />
          <input type="hidden" name="paste" value="yes" />
          <input type="hidden" name="survey_id" value="<?cs var:survey_id ?>" />
    </div>
    <input type="submit" value="<?cs var:paste.msg ?>" title="<?cs var:paste.help ?>" />
   </form></div>
  </td></tr>
<?cs /def ?>

<?cs def:print_mark_hide(mark) ?> 
  <tr>
    <td align="right">
      <input type="checkbox" name="hide" title="<?cs var:mark.help ?>" />
    </td>
    <td>
     <?cs var:mark.msg ?>
    </td>
  </tr>
<?cs /def ?>

<?cs def:print_spell(spell) ?>
 <tr>
   <td align="right">
   <?cs if:paste_action ?>
    <input type="button" value="<?cs var:spell.msg ?>" title="<?cs var:spell.help ?>" onclick="openSpellChecker( document.forms[1].msg );" />
   <?cs else ?>
    <input type="button" value="<?cs var:spell.msg ?>" title="<?cs var:spell.help ?>" onclick="openSpellChecker( document.forms[0].msg );" />
   <?cs /if ?>
   </td><td>&nbsp;</td>
 </tr>
<?cs /def ?>


<?cs def:print_subject(data, subject) ?>
  <tr>
     <td class="regheading" colspan="2">
     <input type="submit" value="<?cs var:data.send.msg ?>" title="<?cs var:data.send.help ?>" />
     <?cs var:data.subject.msg ?>
     <input type="text" name="subject" id="subject" size="<?cs if:subject.size ?><?cs var:subject.size ?><?cs else ?><?cs var:subject.max ?><?cs /if ?>" maxlength="<?cs var:subject.max ?>" title="<?cs var:data.subject.help ?>" value="<?cs var:subject.value ?>" />
     </td>
  </tr>
<?cs /def ?>

<?cs def:print_textarea(data, textarea) ?>
  <tr>
     <td colspan="2">
    <table>
   <?cs if:check_spelling ?>
     <?cs call:print_spell(lang.survey_new_memo.spell) ?>
   <?cs /if ?>
    <tr><td>
       <textarea title="<?cs var:data.help ?>" name="msg" id="msg" cols="<?cs var:textarea.cols ?>" rows="12" wrap=<?cs if:textarea.wrap ?>"hard"<?cs else ?>"virtual"<?cs /if ?>><?cs if:textarea.feedback ?>[<?cs var:textarea.feedback ?> <?cs var:data.wrote ?>]<?cs /if ?><?cs var:textarea.body ?></textarea>
     </td>
     <td><?cs call:add_smile_faces() ?></td>
     </tr>
     </table>
      <input type="hidden" name="width" value="<?cs var:textarea.cols ?>" />
     </td>
  </tr>
<?cs /def ?>

<?cs def:print_hour(data) ?>
 <select name="result_hour" id="result_hour" title="<?cs var:data.help_1 ?>">
   <?cs loop:x=#1, #12, #1 ?>
     <?cs if:x < #10 ?>
     <option value="<?cs var:x ?>" <?cs if:x == current_hour ?>selected="selected" <?cs /if ?>>0<?cs var:x ?></option>   
     <?cs else ?>
     <option value="<?cs var:x ?>" <?cs if:x == current_hour ?>selected="selected" <?cs /if ?>><?cs var:x ?></option>
    <?cs /if ?>
   <?cs /loop ?> 
 </select>
<?cs /def ?>

<?cs def:print_minute(data) ?>
 <select name="result_min" id="result_min" title="<?cs var:data.help_2 ?>">
   <?cs loop:x=#0, #59, #1 ?>
     <?cs if:x < #10 ?>
     <option value="<?cs var:x ?>" <?cs if:x == current_minute ?> selected="selected" <?cs /if ?> >0<?cs var:x ?></option>
     <?cs else ?>
     <option value="<?cs var:x ?>" <?cs if:x == current_minute ?> selected="selected" <?cs /if ?> ><?cs var:x ?></option>
    <?cs /if ?>
   <?cs /loop ?> 
 </select>
<?cs /def ?>

<?cs def:print_ampm(data) ?>
 <select name="result_am" id="result_am" title="<?cs var:data.help_3 ?>">
   <?cs loop:x=#0, #1, #1 ?>
     <option value="<?cs var:x ?>" <?cs if:x == #0 && current_is_am ?> selected="selected" <?cs elif:x == #1 && !current_is_am ?> selected="selected" <?cs /if ?> ><?cs var:lang.survey_new_memo.ampm[x] ?></option>
   <?cs /loop ?> 
 </select>
<?cs /def ?>

<?cs def:print_date(data) ?>
 <tr>
    <td class="regheading" colspan="2"><?cs var:data.msg ?>&nbsp;&nbsp;
       <a href="javascript:openBrWindow('calendar_pick?textId=result', 'pickdate')" title="<?cs var:data.help_0 ?>"><img src="<?cs var:image_path ?>pickdate.jpg" alt="<?cs var:data.help_0 ?>" align="center" /></a>
    <input type="text" name="result" id="result" maxlength="<?cs var:mm_dd_yyyy_len ?>" size="<?cs var:mm_dd_yyyy_len ?>" title="<?cs var:data.help_0 ?>" /> 
     <?cs call:print_hour(data) ?>:
     <?cs call:print_minute(data) ?>
     <?cs call:print_ampm(data) ?>
    </td>
 </tr>
 <tr>
   <td class="attach" colspan="2"><?cs var:data.note ?></td>
 </tr>
<?cs /def ?>

<?cs def:print_student_option() ?>
 <?cs set:value = #1 ?>
 <?cs each:this = lang.survey_new_memo.choice ?>
 <?cs set:name = "student_" + value ?>
  <tr>
    <td align="right">
    <input type="checkbox" name="<?cs var:name ?>" id="<?cs var:name ?>" title="<?cs var:this.help ?>" />
     </td>
     <td>
       <?cs var:this.msg ?>
     </td>
  </tr>
 <?cs set:value = value + #1 ?>
 <?cs /each ?>
 <tr><td colspan="2">&nbsp;</td><tr>
<?cs /def ?>


<?cs call:html_heading() ?>
   <head>
      <title><?cs var:course_no ?> <?cs var:lang.survey_new_memo.title ?></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"  />
   <link rel="StyleSheet" href="<?cs var:image_path ?>manhattan.css" type="text/css"  />
    <script type="text/javascript" src="<?cs var:image_path ?>form_validation.js"></script>
    <script type="text/javascript" src="<?cs var:image_path ?>xp_progress.js"></script>
    <?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 ?>

  <script type="text/javascript">
   function get_ampm(value)
   {
      if(value == 1)
         return "<?cs var:lang.survey_new_memo.ampm[1] ?>";
      else if(value == 0)
         return "<?cs var:lang.survey_new_memo.ampm[0] ?>";
        
   }

   function warn()
   {
       var value = document.getElementById('subject').value;
       if(is_whitespace(value))
       {
           window.alert('<?cs var:lang.survey_new_memo.subject_warn ?>');
           return false;
       }

       var mmddyyyy = document.getElementById('result').value;
       if(checkvalid_date_string(mmddyyyy) == false)
       {
           window.alert('<?cs var:lang.survey_new_memo.date_format ?>');
           return false;
       }
          var hour = get_selected_value('result_hour'); 
          var min = get_selected_value('result_min'); 
          var ampm = get_selected_value('result_am'); 

          var release_day = mmddyyyy + " ";
          var hour_int = parseInt(hour);
          var min_int = parseInt(min);
          var str_hour = "";
          var str_min = "";
          if(hour_int < 10 )
              str_hour = "0";
          if(min_int < 10 )
              str_min = "0";
          
          release_day += str_hour + hour + ":" + str_min + min + " " + get_ampm(ampm);
          var check1 = document.getElementById('student_1').checked;
          var check2 = document.getElementById('student_2').checked;
          var check3 = document.getElementById('student_3').checked;
          var check_str;
          if(check1 == 0)
             check_str = "\n" + "<?cs var:lang.survey_new_memo.choice[0].not_msg ?>";
          else 
             check_str = "\n" + "<?cs var:lang.survey_new_memo.choice[0].msg ?>";

         if(check2 == 0)
          check_str +="\n" + "<?cs var:lang.survey_new_memo.choice[1].not_msg ?>";
         else 
          check_str += "\n" + "<?cs var:lang.survey_new_memo.choice[1].msg ?>";

          if(check3 == 0)
             check_str += "\n" + "<?cs var:lang.survey_new_memo.choice[2].not_msg ?>";
          else 
             check_str += "\n" + "<?cs var:lang.survey_new_memo.choice[2].msg ?>";
	 
         var mystring = "<?cs var:lang.survey_new_memo.confirm ?>" + " " + release_day + "\n";
         mystring += check_str;
        
         var an =  window.confirm(mystring);    
         if(an)
         {
             bar1.showBar();
             scroll(0,0);
             return true;
         }
         else
            return false;
   }

   function discard()
   {
      var subject = document.getElementById('subject').value;
      var msg = document.getElementById('msg').value;
      if(is_whitespace(subject) == false || is_whitespace(msg) == false)
         return window.confirm('<?cs var:lang.survey_new_memo.discard ?>');
      return true; 
      
   }
   function openBrWindow(some_url,winname)
   {
     var new_window = window.open(some_url, winname,'menubar=0,toolbar=0,status=0,scrollbars=yes,resizable=yes,width=300,height=250,screenX=150,screeny=200,left=150,top=200');
     new_window.focus();
   }
</script>


  </head>

<?cs call:define_onload_onunload_body('result') ?>
 <?cs call:print_course_heading(back_url, lang.survey_new_memo.goback) ?>

 <div class="center_msg">
  <span class="alert_color"><?cs var:lang.survey_new_memo.title ?></span>
 </div>

<table width="100%">
<tr><td align="center">
  <table width="20%">
   <?cs if:paste_action == #1 ?>
      <?cs call:print_paste(lang.survey_new_memo.paste) ?>
   <?cs /if ?>
   <tr><td>
   <div><form method="post" action="survey_send_mail" onsubmit="return warn()">
    <div>
      <input type="hidden" name="crs" value="<?cs var:crs ?>" />
      <input type="hidden" name="id" value="<?cs var:id ?>" />
      <input type="hidden" name="public" value="<?cs var:public ?>" />
      <input type="hidden" name="dir" value="<?cs var:dir ?>" />
    </div>
   <table border="0">
   <tr><td colspan="2">
      <span class="regheading"><?cs var:lang.survey_new_memo.survey[0].msg ?>&nbsp;&nbsp;</span>
      <?cs var:survey_title ?>  <i>(<?cs var:lang.survey_new_memo.survey_type[survey_type] ?>)</i>
   </td></tr> 
   <?cs call:print_date(lang.survey_new_memo.survey[1]) ?>
   <?cs call:print_student_option() ?>
   <?cs call:print_mark_hide(lang.survey_new_memo.mark) ?> 
   <?cs call:print_subject(lang.survey_new_memo, msg.subject) ?>
   <?cs call:print_textarea(lang.survey_new_memo.body, msg.textarea) ?>
   <tr><td align="center" colspan="2">
     <input type="submit" value="<?cs var:lang.survey_new_memo.send.msg ?>" title="<?cs var:lang.survey_new_memo.send.help ?>" />
   </td></tr>
   
   </form></div>
   </td></tr>
  </table>
</td></tr>
</table>
<script type="text/javascript">
     var bar1 = createBar( 'white', 1, 'black', 'blue', 85, 7, 3, "");
   </script>

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