function Disp_Calendar(today){
  loop = 0;
  leng = new monthleng(today);
  firstday = getFirstDay(today);
  //disp Month
  document.writeln("<TABLE border=0 cellpadding=4><TR><TH COLSPAN=7>");
  document.writeln(today.getMonth() + 1 + "");
  document.writeln("</TH> </TR")
  DispCalWeek();
  loop = -firstday;
  for ( cal_week = 0 ; cal_week < 6 ; cal_week++){
    document.writeln("<TR>\n");
    for ( cal_day = 0 ; cal_day < 7 ; cal_day++){
      loop++;
      ////// set color
      day_color="black";
      if ( cal_day == 0)day_color="red";
      if ( cal_day == 6)day_color="blue";
      if ( loop == today.getDate())day_color="limegreen";
      ///// print the day
      if (loop>0 && loop <=leng[today.getMonth()]){
        DispTheDay(day_color,loop);
      }else{
        document.writeln("<TD></TD>");
      }
    }
    document.writeln("<TR>\n");
  }
  document.writeln("</TABLE>");
  return true;
}
function DispTheDay(color,day){
  document.writeln("<TD ALIGN=CENTER>");
  document.writeln('<FONT COLOR="',color,'">');
  ///// green 
  if (color == "green") {
    document.writeln('<b>',day,'</b>');
  } else {
    document.writeln(day);
  }
  document.writeln("</FONT>");
  document.writeln("</TD>");
}
function monthleng(theDay){
  this[0] = 31;
  this[1] = 28;
  this[2] = 31;
  this[3] = 30;
  this[4] = 31;
  this[5] = 30;
  this[6] = 31;
  this[7] = 31;
  this[8] = 30;
  this[9] = 31;
  this[10] = 30;
  this[11] = 31;
  if (theDay.getYear() % 4 == 0){
    this[1] = 29;
  }
  if (theDay.getYear()%100 == 0 && theDay.getYear()%400 != 0){
    this[1] = 28;
  }
}
function getFirstDay(theDay){
  firstdate = new Date(theDay);
  firstdate.setDate(1);
  return firstdate.getDay();
}
function DispCalWeek(){
  document.writeln("<TR>")
  document.writeln("<TH><FONT COLOR=red>Sun</FONT></TH>")
  document.writeln("<TH>Mon</TH>")
  document.writeln("<TH>Tue</TH>");
  document.writeln("<TH>Wed</TH>");
  document.writeln("<TH>Thu</TH>");
  document.writeln("<TH>Fri</TH>");
  document.writeln("<TH><FONT COLOR=blue>Sat</FONT></TH>");
  document.writeln("</TR>");
}
