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

<?cs #############################
     # a macro that print week day 
     #############################
?>
<?cs def:week_day(w_day) ?>
   <th style="width:14%" class="cellbg" valign="middle" > 
   <span class="systemheading"><?cs var:w_day ?></span>
   </th>
<?cs /def ?>





<?cs #############################
     # a macro that print month navigation 
     #############################
?>

<?cs def:month_nav(month_name, preurl, nexturl) ?>
<table border="0" cellpadding="2" cellspacing="1" style="background:#000000" width="100%">
<tr><th class="cellbg">&nbsp;&nbsp;
<a class="normal" href="<?cs var:preurl ?>" title="<?cs var:lang.calendar.pre_month_help ?>">&lt;&lt;</a>
<?cs with:item = lang.calendar.month[month_name] ?>
<span class="systemheading">
  <?cs var:item ?>
</span>
<?cs /with ?>
&nbsp;&nbsp;
<a class="normal" href="<?cs var:nexturl ?>" title="<?cs var:lang.calendar.next_month_help ?>">&gt;&gt;</a>&nbsp;&nbsp;</th>
</tr>
</table>
<?cs /def ?>

<?cs #############################
     # a macro that print day 
     #############################
?>

<?cs def:day_cell(day_num) ?>

  <?cs if:day_num == selected_day ?>
    <?cs set:mybg = "cellselbg" ?>
  <?cs else ?>
    <?cs set:mybg = "cellbg" ?>
  <?cs /if ?>

  <td style="width:14%" valign="top" class="<?cs var:mybg ?>">
    <table border="0" style="width:100%; height:10px">
     <tr>
       <td align="right" class="<?cs var:mybg ?>">
       <span class="system"><?cs var:day_num ?></span>
       </td>
    </tr>
   </table>
   <?cs set:my_event = #0 ?>
   <?cs if:event[day_num].0.title ?>
   <?cs each:link = event[day_num] ?>
     <a class="normal" href="javascript:openBrWindow('<?cs var:link.url ?>','system')" title="<?cs var:lang.calendar.view_event_help ?>">
     <img src="<?cs var:image_path ?><?cs with:this = lang.calendar.imageicon[link.icon] ?><?cs var:this ?><?cs /with ?>" style="width:12px; height:12px; border:0px" alt="" />
     <?cs var:link.title ?>
     </a><br />
      <?cs set:my_event = #my_event + #1 ?>
   <?cs /each ?>
   <?cs /if ?>
    <?cs if:my_event < #3 ?>
     <?cs loop:ee = #1, #3 - #my_event, #1 ?>
         <br />
     <?cs /loop ?>
    <?cs /if ?>
  </td>
<?cs /def ?>

<?cs #############################
     # a macro that print empty cell 
     #############################
?>
<?cs def:empty_cell() ?>
<td style="width:14%" class="cellbg"><span class="system">&nbsp;</span></td>
<?cs /def ?>

<?cs def:print_year(year) ?>
 <th colspan="7" class="cellbg" valign="middle" > 
  <span class="systemheading"> <?cs var:year ?></span>
 </th>
<?cs /def ?>



<?cs ###########################
     # HTML starts here
     ###########################
?>
<?cs call:html_heading() ?>
<head>
<title><?cs var:course_title ?> <?cs var:course_no ?> <?cs var:lang.calendar.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,widt=450,height=450');
    new_window.focus();
}
</script>
</head>

<?cs call:define_body() ?> 
<div>
<?cs call:course_info() ?>
  <div>
  <a href="javascript:window.close()" title="<?cs var:lang.calendar.closewin ?>">
  <img src="<?cs var:image_path ?>close.gif" alt="<?cs var:lang.calendar.closewin ?>" /></a>
  </div>
<br />
<br />
</div>

<table  width="100%">
<tr><td align="center">
    <?cs call:month_nav(month_name, preurl, nexturl) ?>
        <table border="0" cellpadding="2" cellspacing="1" style="background:#000000" width="100%">
        <tr>
           <?cs each:item = lang.calendar.week ?>
           <?cs call:week_day(item) ?>
           <?cs /each ?>
        </tr>
        <tr>
         <?cs if:start ?>
          <?cs loop:x = #1, #start, #1 ?>
          <?cs call:empty_cell() ?>
          <?cs /loop ?>
        <?cs /if ?>
        <?cs set:count = #start ?>
          <?cs loop:x = #1, #month_days, #1 ?>
          <?cs if:x > #1 ?>
           <?cs if:count % #7 == #0 ?>
              </tr><tr>
              <?cs set:count = #0 ?>
           <?cs /if ?>
          <?cs /if ?>   
            <?cs call:day_cell(x) ?>
          <?cs set:count = #count + #1 ?>
          <?cs /loop ?>
         <?cs if:count < #7 ?> 
            <?cs loop:x = #1, #7 - #count, #1 ?> 
              <?cs call:empty_cell() ?>
            <?cs /loop ?>
         <?cs /if ?>
        </tr>
        <tr>  
        <?cs call:print_year(year) ?>
       </tr>
      </table>
  </td></tr>
</table>

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