// Different DatePicker sets in a form can exist quite comfortably!
// Just use a different "PickerName" for each one
function populate(PickerName) {
    if (DatePickers[PickerName]) {
        YearControl     = DatePickers[PickerName]["year"];
        MonthControl    = DatePickers[PickerName]["month"];
        DayControl      = DatePickers[PickerName]["day"];
        selectedDay     = DayControl.selectedIndex;
        if (YearControl.selectedIndex != -1) {
            var yr          = YearControl.options[YearControl.selectedIndex].text;
            if (MonthControl.selectedIndex != -1) {
                var mn          = MonthControl.options[MonthControl.selectedIndex].value;
                timeA           = new Date(yr, mn, 1);
                timeDifference  = timeA - 86400000;
                timeB           = new Date(timeDifference);
                var daysInMonth = timeB.getDate();
                // Clear the "days" select box
                for (var i = 0; i < DayControl.options.length; i++) {
                    DayControl.options[0] = null;
                }
                // Add in the days for the current month
                for (var i = 0; i < daysInMonth; i++) {
                    DayControl.options[i] = new Option(i+1, i+1);
                }
                if(selectedDay >= daysInMonth) {
                    selectedDay = daysInMonth - 1;
                }
                DayControl.selectedIndex = selectedDay;
            }
        }
    } else {
        alert("DatePicker " + PickerName + " not found");
    }

}

function InitializeDatePicker(PickerName, y, m, d) {
    // You can easily customize what years can be used
    YearControl     = DatePickers[PickerName]["year"];
    MonthControl    = DatePickers[PickerName]["month"];
    DayControl      = DatePickers[PickerName]["day"];

    // Clear the years select box
    YearControl.options.length = 0;

    timeC     = new Date();
    firstYear = timeC.getFullYear();
    lastYear  = firstYear +15;
    if (y != 0 && y < firstYear)
        firstYear = y;
    //YearControl.options[0] = new Option("");
    for (var i = 0, yr = firstYear; yr < lastYear; i++, yr++) {
        YearControl.options[i] = new Option(yr, yr);
        if (yr == y)
            YearControl.selectedIndex = i;
    }

    var Months = new Array("January", "February", "March", "April", "May", "June", "July",
                           "August", "September", "October", "November", "December");
    for (var i = 0; i < Months.length; i++) {
        MonthControl.options[i] = new Option(Months[i], i+1);
    }
    MonthControl.selectedIndex = m -1;
    populate(PickerName);
    DayControl.selectedIndex = d -1;
}
