﻿/** ----------------------------------------------------------------------- 
      date.js    This file has functions that deal with the date.
      Programmer:     Alfred K Chan
       
      9/28/2005      Initial draft with carry-over from general.js
                        by achan
      
  -----------------------------------------------------------------------  */

/* -------------------------------------------------------------------------
   FillInDay   - Fill in the day for select box 
   parameter(s) - monthSelectBox - the month select box to be selected
                - daySelectBox - the day select box to be filled        
   -------------------------------------------------------------------------*/                                        
function FillInDay(monthSelectBox, daySelectBox){
   var monthObj = getFormObj(monthSelectBox);
   var dayObj = getFormObj(daySelectBox);   
   var monthValue = monthObj.selectedIndex;
   
   // remove all options in the day select box 
   removeAllOptionsInSelectBox(dayObj); 
         
   switch(monthObj.selectedIndex){
      case 1:  case 3:  case 5:  case 7:  case 8:  case 10: case 12:         
         addDayOption(dayObj,31);
         break;
         
      case 2:
         if (isCurrYearLeap())   addDayOption(dayObj, 29);         
         else                    addDayOption(dayObj, 28);         
         break;
         
      case 4:  case 6:  case 9:  case 11:  
         addDayOption(dayObj,30);
         break;  
      default:
         break;    
   }  // end switch   
}
  
/* -------------------------------------------------------------------------
   isLeapYear   - check whether a year is a leap year. 
   parameter(s) - year2Check - the year to be checked. 
   -------------------------------------------------------------------------*/                     
function isLeapYear(year2Check){
   return (year2Check % 4 == 0 ) ? true : false;
}

/* -------------------------------------------------------------------------
   isCurrYearLeap - check whether current year is a leap year. 
   -------------------------------------------------------------------------*/                     
function isCurrYearLeap(){
   return isLeapYear((new Date()).getFullYear());
}

/* -------------------------------------------------------------------------
   getTodayInStr -  Set the today string to the today(id) in HTML file. 
   -------------------------------------------------------------------------*/                     
function getTodayInStr(){
   document.getElementById('today').innerHTML = getToday();
}

/* -------------------------------------------------------------------------
   getToday -  Return today's date in string(whole day)
   -------------------------------------------------------------------------*/                     
function getToday(){
   var todayStr;
   var currDate = new Date();
   var monthArr = new Array( "1","2","3","4","5","6","7","8","9","10","11","12");
   
   return monthArr[currDate.getMonth()] + "/" + currDate.getDate() + "/" + currDate.getFullYear();   
}

/* -------------------------------------------------------------------------
   getTodayDay -  Return today's date in string  (just the date, ie [1,31]
   -------------------------------------------------------------------------*/                     
function getTodayDay(){
   return (new Date()).getDate();
}

/* -------------------------------------------------------------------------
   getTodayMonth -  Return today's month in string  (just the month, ie [1,12]
   -------------------------------------------------------------------------*/                     
function getTodayMonth(){
   return (new Date()).getMonth();
}
