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

<?cs def:print_hidden(s_name, s_value) ?>
 <input type="hidden" name="<?cs var:s_name ?>" value="<?cs var:s_value ?>" />
<?cs /def ?>

<?cs def:print_red_star(is_star) ?>
      <?cs if:is_star ?>
         <span style="color:red">*</span>
      <?cs /if ?>
<?cs /def ?>




<?cs def:print_date(vname, value) ?>
  <tr>
    <th align="left">
      <?cs var:vname ?>
    </th>
   <td >
     <?cs var:value ?>
   </td>
  </tr>
<?cs /def ?>

<?cs def:print_title(vname, value) ?>
  <tr>
    <th align="left">
     <?cs call:print_red_star(titlestar) ?>
      <?cs var:vname ?>
    </th>
   <td >
    <input type="text" name="title" value="<?cs var:value ?>" title="<?cs var:lang.calendar_event_edit.title_help ?>" size="<?cs var:titlelen ?>" maxlength="<?cs var:titlelen ?>" />
   </td>
  </tr>
<?cs /def ?>

<?cs def:print_desc() ?>
  <tr>
    <th align="left">
     <?cs call:print_red_star(descstar) ?>
        <?cs var:lang.calendar_event_edit.desc ?>
    </th>
    <td>&nbsp;</td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td >
    <textarea rows="3" cols="30" name="desc" title="<?cs var:lang.calendar_event_edit.desc_help ?>"><?cs var:desc ?></textarea>
 </td></tr>
<?cs /def ?>

<?cs def:print_time(vname, time_value) ?>
  <tr>
    <th align="left" >
      <?cs var:vname ?>
    </th>
   <td >
    <?cs var:time_value ?> <?cs var:lang.calendar_event_edit.ampm[event_start_am] ?>
   </td>
 </tr> 
<?cs /def ?>

<?cs def:print_hour() ?>
  <?cs call:print_red_star(e_hourstar) ?>
  <select name="e_hour" title="<?cs var:lang.calendar_event_edit.end_time_help ?>">
  <option value="0"><?cs var:lang.calendar_event_edit.hour ?></option>
  <?cs loop:x = #1, #12, #1 ?>
      <?cs if:e_hour > 12 ?>
         <?cs set:e_hour = e_hour - #12 ?>
      <?cs /if ?>
      <option value="<?cs var:x ?>" <?cs if:e_hour == x ?>selected="selected" <?cs /if ?> ><?cs var:x ?></option>
  <?cs /loop ?>
  </select>
<?cs /def ?>

<?cs def:print_min() ?>
  <?cs call:print_red_star(e_minstar) ?>
  <select name="e_min" title="<?cs var:lang.calendar_event_edit.end_time_help ?>">
  <option value="-1"><?cs var:lang.calendar_event_edit.min ?></option>
   <?cs loop:x= #0, #55, #5 ?>
     <?cs if:x < #10 ?>
      <option value="<?cs var:x ?>" <?cs if:e_min == x ?> selected="selected" <?cs /if ?>>0<?cs var:x ?></option>
     <?cs else ?>
      <option value="<?cs var:x ?>" <?cs if:e_min == x ?> selected="selected" <?cs /if ?>><?cs var:x ?></option>
     <?cs /if ?>
    <?cs /loop ?>
  </select>
<?cs /def ?>

<?cs def:print_am() ?>
  <?cs call:print_red_star(e_amstar) ?>
  <select name="e_am" title="<?cs var:lang.calendar_event_edit.end_time_help ?>">
      <option value="0"><?cs var:lang.calendar_event_edit.ampm[0] ?></option>
         <option value="1" <?cs if:event_end_am == "AM" ?>selected="selected" <?cs /if ?> ><?cs var:lang.calendar_event_edit.ampm["AM"] ?></option> 
         <option value="2" <?cs if:event_end_am == "PM" ?>selected="selected" <?cs /if ?> ><?cs var:lang.calendar_event_edit.ampm["PM"] ?></option> 
  </select>
<?cs /def ?>

<?cs def:end_time() ?>
   <tr>
     <th align="left">
       <?cs var:lang.calendar_event_edit.end ?>
     </th>
     <td >
       <?cs call:print_hour() ?>:&nbsp;
       <?cs call:print_min() ?>:&nbsp;
       <?cs call:print_am() ?>
     </td>
   </tr>
<?cs /def ?>

<?cs def:print_icon() ?>
   <tr>
     <th align="left" >
       <?cs var:lang.calendar_event_edit.pick ?>
     </th>
     <td >
     <?cs each:item = lang.calendar_event_edit.imageicon ?>
        <img src="<?cs var:image_path ?><?cs var:item ?>" style="width:12px; height:12px" alt="" />
       <?cs if:icon == name(item) ?>
          <input type="radio" name="icon" value="<?cs var:name(item) ?>" checked="checked" title="<?cs var:lang.calencar_event_modify.pick_help ?>" />
       <?cs else ?>
          <input type="radio" name="icon" value="<?cs var:name(item) ?>" title="<?cs var:lang.calendar_event_edit.pick_help ?>" />
       <?cs /if ?>
        &nbsp;&nbsp;&nbsp;
    <?cs /each ?>
   </td>
<?cs /def ?>

<?cs def:print_submit() ?>
  <tr><th colspan="2" >
     <input type="submit" title="<?cs var:lang.calendar_event_edit.edit_help ?>" value="<?cs var:lang.calendar_event_edit.edit ?>" name="oper" />
    </th>
   </tr>
<?cs /def ?>

<?cs def:print_form() ?>
  <form method="post"  action="calendar_event_modify">
  <div><?cs call:print_hidden("crs", Query.crs) ?>
  <?cs call:print_hidden("id", Query.id) ?>
  <?cs call:print_hidden("event_id", Query.event_id) ?>
  <?cs call:print_hidden("year", year) ?>
  <?cs call:print_hidden("month", month) ?>
  <?cs call:print_hidden("today", day) ?>
  <?cs call:print_hidden("hour", s_hour) ?>
  <?cs call:print_hidden("min", s_min) ?>
  </div>
<?cs /def ?>
 
<?cs def:error_detail(error_code) ?>
   <?cs with:myerror = lang.calendar_event_edit.error[error_code] ?>
      <div><span class="errorfont">
        <?cs var:myerror ?>
     </span><br />
     </div>
   <?cs /with ?>
<?cs /def ?>

<?cs def:error_heading() ?>
   <h4><span style="color:red">
    <?cs var:lang.calendar_event_edit.errorReport ?>
   </h4>
<?cs /def ?>

<?cs def:error_report() ?>
<?cs if:Query.oper ?>
   <?cs call:error_heading() ?>
   <?cs if:error_title ==0 ?>
      <?cs call:error_detail(error_title) ?>
   <?cs /if ?>
   <?cs if:error_endtime == 1 ?>
      <?cs call:error_detail(error_endtime) ?>
   <?cs /if ?>
   <?cs if:error_icon == 3 ?>
     <?cs call:error_detail(error_icon) ?>
   <?cs /if ?>
<?cs /if ?>
<?cs /def ?>


<?cs ###########################
     # HTML starts here
     ###########################
?>
<?cs call:html_heading() ?>
<head>
<title><?cs var:course_title ?> <?cs var:course_no ?> <?cs var:lang.calendar_event_edit.modify_page_title ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="StyleSheet" href="<?cs var:image_path ?>calendar_style.css" type="text/css"  />
<link rel="StyleSheet" href="<?cs var:image_path ?>common.css" type="text/css"  />
<?cs if:success ?>
<script type="text/javascript">
function dothis()
{
      opener.parent.location.reload();
      window.close();
}
</script>
<?cs /if ?>
</head>

<?cs call:define_body() ?> 
<div>
   <?cs call:course_info() ?>
   <div>
   <?cs if:success ?>
   <a href="javascript:dothis()" title="<?cs var:lang.calendar_event_edit.closewindow ?>">
   <?cs else ?>
   <a href="javascript:window.close()" title="<?cs var:lang.calendar_event_edit.closewindow ?>">
   <?cs /if ?>
   <img src="<?cs var:image_path ?>close.gif" alt="<?cs var:lang.calendar_event_edit.closewindow ?>" /></a>
   </div>
</div>
<?cs if:success ?>
<div>
<br />
<fieldset style="width:90%">
<legend class="fieldset_legend">
    <?cs var:lang.calendar_event_edit.success_notes ?>
</legend>
    <div class="instructions"><?cs var:lang.calendar_event_edit.success_instruction ?></div>
</fieldset>
</div>
<?cs else ?>
<div>
<?cs call:error_report() ?>
</div>

<br />
<div>
<fieldset style="width:90%">
<legend class="fieldset_legend">
<?cs var:lang.calendar_event_edit.modify_page_title ?>
</legend>
<div>
<?cs call:print_form() ?>
    <table  cellpadding="4" >
      <?cs call:print_date(lang.calendar_event_edit.date, event_date) ?>
      <?cs call:print_title(lang.calendar_event_edit.title, title) ?>
      <?cs call:print_desc() ?>
      <?cs call:print_time(lang.calendar_event_edit.start, event_start) ?>
      <?cs if:show_para == 0 ?>
      <?cs call:end_time() ?>
      <?cs /if ?>
      <?cs call:print_icon() ?>
      <?cs call:print_submit() ?>
    </table>
</form>
</div>
</fieldset>
</div>
<?cs /if ?>
</body>
</html>
<?cs call:runtime() ?>

