<?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: #ff0000">*</span>
      <?cs /if ?> 
<?cs /def ?>



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

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

<?cs def:print_start_time() ?>
  <tr>
    <th align="left">
      <?cs var:lang.calendar_event_edit.start ?>
    </th>
   <td>
    <?cs var:hourmin ?> <?cs var:lang.calendar_event_edit.ampm[hourmin_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_help ?>">
  <option value="0"><?cs var:lang.calendar_event_edit.hour ?></option>
  <?cs loop:x=#1, #12, #1 ?>
      <option value="<?cs var:x ?>" <?cs if:x == end_event_hour ?>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_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:x == end_event_min ?> selected="selected"<?cs /if ?>>0<?cs var:x ?></option>
     <?cs else ?> 
      <option value="<?cs var:x ?>" <?cs if:x == end_event_min ?> 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_help ?>">
  <option value="0" ><?cs var:lang.calendar_event_edit.ampm[0] ?></option>
  <option value="1" <?cs if:end_event_am == "AM" ?> selected="selected" <?cs /if ?>><?cs var:lang.calendar_event_edit.ampm["AM"] ?></option>
  <option value="2" <?cs if:end_event_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_freq() ?>
   <tr>
     <th align="left">
       <?cs call:print_red_star(freqstar) ?>
       <?cs var:lang.calendar_event_edit.frequency ?>
     </th>
     <td >
     <select name="freq" title="<?cs var:lang.calendar_event_edit.frequency_help ?>">
     <?cs each:item = lang.calendar_event_edit.freq_opt ?>
         <option value="<?cs var:name(item) ?>" <?cs if:freq == name(item) ?>selected="selected" <?cs /if ?>>
           <?cs var:item ?></option>
     <?cs /each ?>
     </select> 
     </td>
   </tr>
<?cs /def ?>

<?cs def:print_icon() ?>
   <tr>
     <th align="left">
       <?cs call:print_red_star(iconstar) ?>
       <?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=" " />
        <input type="radio" name="icon" value="<?cs var:name(item) ?>" <?cs if:icon == name(item) ?>checked="checked" <?cs /if ?> title="<?cs var:lang.calendar_event_edit.pick_help ?>" />
        &nbsp;&nbsp;&nbsp;
    <?cs /each ?> 
   </td>
  </tr>
<?cs /def ?>

<?cs def:print_end_data() ?>
   <tr>
    <th align="left" >
       <?cs call:print_red_star(enddatestar) ?>
       <?cs var:lang.calendar_event_edit.endDate ?>
    </th>
    <td  valign="middle">
    <a href="javascript:openBrWindow('<?cs var:pickdateurl ?>&amp;textId=enddate', 'pickdate')" title="<?cs var:lang.calendar_event_edit.endDate_help ?>">
    <img src="<?cs var:image_path ?>cal.gif" alt="" /></a>
    <input type="text" name="enddate" id="enddate" value="<?cs var:enddatevalue ?>" title="<?cs var:lang.calendar_event_edit.endDate_help ?>"  />
   </td>
  </tr>
<?cs /def ?>
<?cs def:print_submit() ?>
   <tr>
    <td  colspan="2" align="center">
     <input type="submit" value="<?cs var:lang.calendar_event_edit.submit ?>" name="oper" title="<?cs var:lang.calendar_event_edit.submit_help ?>" />
    </td>
   </tr>
<?cs /def ?>
 
<?cs def:error_detail(error_code) ?>
   <?cs with:myerror = lang.calendar_event_edit.error[error_code] ?>
        <div><?cs var:myerror ?></div>
   <?cs /with ?>
<?cs /def ?>

<?cs def:error_heading() ?>
   <h4 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_freq == 2 ?>
     <?cs call:error_detail(error_freq) ?>
   <?cs /if ?>
   <?cs if:error_icon == 3 ?>
     <?cs call:error_detail(error_icon) ?>
   <?cs /if ?>
   <?cs if:error_enddate == 4 ?>
     <?cs call:error_detail(error_enddate) ?>
   <?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.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"  />
<script type="text/javascript">
 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=170,screenX=150,screeny=200,left=150,top=200');
     new_window.focus();
   }
</script>
<?cs if:print_success ?>
<script type="text/javascript">
function dothis()
{
      opener.parent.location.reload();
      window.close();
}
</script>
<?cs /if ?>
</head>


<?cs call:define_body() ?> 
<?cs call:course_info() ?>
<div>
<?cs if:print_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>
 <br />
 <br />
</div>
<?cs if:freq_error_code ?>
 <fieldset style="width:80%">
  <legend class="fieldset_legend">
   <?cs var:lang.calendar_event_edit.freq_error_notes[freq_error_code] ?>
  </legend>
  <div class="instructions">
   <?cs var:lang.calendar_event_edit.frequency_error[freq_error_code] ?>
  </div>
 </fieldset>
<?cs elif:print_success ?>
 <fieldset style="width:80%">
  <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>
<?cs else ?>
<?cs call:error_report() ?>
<div>
 <br />
 <br />
</div>

<fieldset style="width: 90%">
 <legend class="fieldset_legend">
   <?cs var:lang.calendar_event_edit.myselect ?> <?cs var:selecttimestring ?>
 </legend>
 <div><form  method="post" action="calendar_event_edit">
        <div>
        <?cs call:print_hidden("crs", Query.crs) ?>
        <?cs call:print_hidden("id", Query.id) ?>
        <?cs call:print_hidden("year", Query.year) ?>
        <?cs call:print_hidden("month", Query.month) ?>
        <?cs call:print_hidden("today", Query.today) ?>
        <?cs call:print_hidden("hour", Query.hour) ?>
        <?cs call:print_hidden("min", Query.min) ?>
       </div>
    <table border="0" cellpadding="2" cellspacing="1">
    <tr><td colspan="2" >&nbsp;</td></tr>
    <?cs call:print_title(titlestar, titlevalue) ?>
    <?cs call:print_desc(descstar, descvalue) ?>
    <?cs call:print_start_time() ?>
    <?cs if:faculty ?>
      <?cs call:end_time() ?>
      <?cs call:print_freq() ?>
    <?cs /if ?> 
    <?cs call:print_icon() ?>
    <?cs if:faculty ?>
        <?cs call:print_end_data() ?>
    <?cs /if ?> 
    <?cs call:print_submit() ?>
    <tr><td colspan="2" >&nbsp;</td></tr>
   </table>
 </form></div>
</fieldset>
<?cs /if ?>
</body>
</html>
<?cs call:runtime() ?>
