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

<?cs #############################
     # a macro that print week day 
     #############################
?>
<?cs def:week_day(w_day) ?>
   <td class="cellbg" valign="middle" align="center" style="width:10%">
   <?cs var:w_day ?>
   </td> 
<?cs /def ?>





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

<?cs def:month_nav(month_name, preurl, nexturl) ?>
<table border="0" cellpadding="2" cellspacing="1" width="250" class="black_border">
<tr>
  <th class="cellbg" align="center">&nbsp;&nbsp;
     <a class="normal" href="<?cs var:preurl ?>" title="<?cs var:lang.calendar_pick.previous ?>" >&lt;&lt;</a>
    &nbsp;&nbsp;
   <?cs with:item = lang.calendar_pick.month[month_name] ?>
     <?cs var:item ?>
   <?cs /with ?>
   &nbsp;&nbsp;
  <a class="normal" href="<?cs var:nexturl ?>" title="<?cs var:lang.calendar_pick.next ?>" >&gt;&gt;</a>&nbsp;&nbsp;
 </th>
</tr>
</table>
<?cs /def ?>

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

<?cs def:day_cell(day_name,  url) ?>
  <?cs if:#today == #day_name ?>
    <?cs set:mybg = "celltoday" ?>
  <?cs else ?>
    <?cs set:mybg = "cellbg" ?>
  <?cs /if ?>
<td valign="middle" align="center"  class="<?cs var:mybg ?>">
<a href='#' class="normal" onclick="<?cs var:url ?>" title="<?cs var:lang.calendar_pick.pick_day ?>">
<?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" valign="middle" align="center">  
   <?cs var:year ?>
</th>
<?cs /def ?>


<?cs ###########################
     # HTML starts here
     ###########################
?>
<?cs call:html_heading() ?>
   <head>
      <title><?cs var:lang.calendar_pick.page_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 ?>calendar_style.css" type="text/css"  />
</head>
<?cs call:define_body() ?> 
<table  width="100%">
     <tr><td align="center">
        <?cs call:month_nav(month_name, preurl, nexturl) ?>
        <table border="0" cellpadding="2" cellspacing="1"  width="250" class="black_border">
        <tr>
           <?cs each:item = lang.calendar_pick.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:count % #7 == #0 ?>
           </tr><tr>
           <?cs set:count = #0 ?>
         <?cs /if ?>
         <?cs call:day_cell(x,  day[x].url) ?>
        <?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() ?>
