function onDateChange(ActiveDatePickerID)
{
   var date = GetDate(ActiveDatePickerID)
   if(typeof DateChangeHandler == 'function') {DateChangeHandler()}
}

function onCalendarChange(ActiveDatePickerID, newDate)
{
   SetDate(ActiveDatePickerID, newDate)
}

function SetDate(ActiveDatePickerID, newDate)
{
   var dayControl = document.getElementById(ActiveDatePickerID + "_dayDropDownList")
   var monthControl = document.getElementById(ActiveDatePickerID + "_monthDropDownList")
   if (dayControl != null && monthControl != null)
   {
      dayControl.selectedIndex = newDate.getDate() - 1
      monthControl.value = newDate.getMonth() + "|" + newDate.getFullYear()
   }
}

function GetDate(ActiveDatePickerID)
{
   var dayControl = document.getElementById(ActiveDatePickerID + "_dayDropDownList")
   var monthControl = document.getElementById(ActiveDatePickerID + "_monthDropDownList")
   var selectedDay = 0
   var selectedMonth = 0
   var selectedYear = 0

   if (dayControl != null && monthControl != null)
   {
      var monthElements = monthControl.options[monthControl.selectedIndex].value.split("|");
      selectedDay = parseInt(dayControl.options[dayControl.selectedIndex].text);
      selectedMonth = parseInt(monthElements[0]);
      selectedYear = parseInt(monthElements[1]);
      var daysInMonth = GetDaysInMonth(selectedYear);
      if (selectedDay > daysInMonth[selectedMonth])
      {
         selectedDay = daysInMonth[selectedMonth];
         dayControl.selectedIndex = daysInMonth[selectedMonth] - 1;
      }
   }
   return new Date(selectedYear, selectedMonth, selectedDay, 0, 0, 0);
}

function GetDaysInMonth(Year)
{
   var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   if (((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0)) daysInMonth[1] = "29"
   return daysInMonth;
}