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

<?cs #############################
     # a macro that print week day 
     #############################
?>
<?cs def:week_day(w_day) ?>
   <th class="cellbg"  style="width:10%">
   <?cs var:w_day ?>
   </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: #000;" width="250">
<tr><th class="cellbg">&nbsp;&nbsp;
<a class="normal" href="<?cs var:preurl ?>" title="<?cs var:lang.calendar.pre_month_help ?>" >&lt;&lt;</a>
&nbsp;&nbsp;
<?cs with:item = lang.calendar.month[month_name] ?>
  <?cs var:item ?>
<?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_name) ?>
  <?cs if:#today == #day_name  ?>
    <?cs set:mybg = "celltoday" ?>
  <?cs elif:#selected_day == day_name ?>
    <?cs set:mybg = "cellselbg" ?>
  <?cs else ?>
    <?cs set:mybg = "cellbg" ?>
  <?cs /if ?>
<td valign="middle" align="center" onmouseover="this.className='cellover'" onmouseout="this.className='<?cs var:mybg ?>'" class="<?cs var:mybg ?>">
<a href="<?cs var:common_url ?><?cs var:day_name ?>" class="normal" title="<?cs var:lang.calendar.select_help ?>">
<?cs var:day_name ?></a>
</td>
<?cs /def ?>

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

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

<?cs def:weekatglance() ?>
  <tr>
     <th valign="middle" align="center" class="cellbg">
     <?cs var:lang.calendar.glance ?>
     </th>
  </tr>
<?cs /def ?>

<?cs def:setIcon(number) ?>
  <?cs with:this = lang.calendar.imageicon[number] ?>
    <img src="<?cs var:image_path ?><?cs var:this ?>" alt=""  style="width:12px; height:12px" />
  <?cs /with ?>
<?cs /def ?>

<?cs def:print_weekday(item) ?>
   <?cs if:item.is_selected ?>
       <?cs set:bg = "cellselbg" ?>
   <?cs else ?>
      <?cs set:bg = "cellbg" ?>
   <?cs /if ?>
  <tr onmouseover="this.className='cellover'" onmouseout="this.className='<?cs var:bg ?>'" class="<?cs var:bg ?>" >
    <td valign="top" onclick="window.location='<?cs var:item.url ?>';">
    <a href="<?cs var:item.url ?>" class="normal" title="<?cs var:lang.calendar.select_help ?>">
    <?cs with:mywday = lang.calendar.week[item.w] ?>
      <?cs var:mywday ?>--<?cs var:item.mday ?>
    <?cs /with ?>
    </a>&nbsp;&nbsp;
    <?cs each:this = item.icon ?>
       <?cs call:setIcon(this) ?>
    <?cs /each ?>   
    </td>
</tr>
<?cs /def ?>


<?cs def:print_selectedday() ?>
    <table border="0" cellpadding="2" cellspacing="1" style="background: #000;" width="250">
      <tr>
       <th class="cellbg">
       <?cs var:lang.calendar.myselect ?> <?cs var:selecttimestring ?>
     </th></tr>
     </table> 
<?cs /def ?>

<?cs def:system_calendar() ?>
<table width="100%">
<tr><td align="center">
  <table border="1" cellpadding="2" cellspacing="0" width="200">
   <tr onmouseover="this.className='cellover'" onmouseout="this.className='cellbg'" class="cellbg">
   <td valign="top" align="center">
      <a href="javascript:openBrWindow('<?cs var:systemurl ?>', 'systemWin')" class="normal" title="<?cs var:lang.calendar.system_calendar_help ?>">
      <span class="regheading"><?cs var:lang.calendar.system_calendar ?></span></a>
   </td></tr>
  </table>
</td></tr>
</table>
<?cs /def ?>

<?cs def:print_calendar() ?>
   <?cs call:month_nav(month_name, preurl, nexturl) ?>
   <table border="0" cellpadding="2" cellspacing="1" width="250" style="background: #000;">
   <tr>
     <?cs each:item = lang.calendar.week ?>
     <?cs call:week_day(item) ?>
     <?cs /each ?>
   </tr>
   <tr>
      <?cs if:start ?>
      <?cs loop:x = #0, #start - #1, #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>
<?cs /def ?>

<?cs def:print_week_at_glance() ?>
  <table border="0" cellpadding="2" cellspacing="1" style="background:#000000; width: 250px; height:240px;">
  <?cs call:weekatglance() ?>
  <?cs each:item = wday ?>
    <?cs call:print_weekday(item) ?>
  <?cs /each ?>
  </table>

<?cs /def ?>


<?cs def:print_left() ?>
 <table cellpadding="2" cellspacing="1" width="250">
  <tr><td>
   <?cs call:print_calendar() ?>
  </td></tr>
  <tr><td>&nbsp;</td></tr>
  <tr><td>&nbsp;</td></tr>
  <tr><td>
   <?cs call:print_week_at_glance() ?>
  </td></tr>
  <tr><td align="center">
  <a href="<?cs var:todayurl ?>" class="normal" title="<?cs var:lang.calendar.backtoday_help ?>"><?cs var:lang.calendar.backtoday ?></a>
  </td></tr>
</table>
<?cs /def ?>

<?cs def:print_right() ?>
  <table cellpadding="2" cellspacing="1" width="250">
    <tr><td>
    <?cs call:print_selectedday() ?>
    </td></tr>
   <tr><td>
   <iframe src="<?cs var:sloturl ?>" width="250" height="440">
   </iframe>

  </td></tr>
  </table>
<?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,width=650,height=600');
    new_window.focus();
}
</script>
</head>

<?cs call:define_body() ?> 
<?cs call:print_course_heading(back_url, lang.calendar.goback) ?>
<?cs call:system_calendar() ?>
<table width="100%" >
<tr><td align="center">

  <table>
  <tr>
    <td valign="top"><?cs call:print_left() ?></td>
    <td valign="top"><?cs call:print_right() ?></td>
  </tr>
  </table>
</td></tr>  
</table>
</body>
</html>
<?cs call:runtime() ?>
