//
// Javascript for the DateSelect control
//
function dateSelectUpdateDays(id)
{
    // Get the day select
    var ddlDay = $('#' + id + '_ddlDay');
    
    // Get the currently selected day
    var selectedDay = ddlDay.val();
    
    // Clear the list
    ddlDay.children().remove();
    //ddlDay[0].options.length = 0;
    ddlDay.append("<option value=''></option>");
    
    // Get the number of days for the month/year
    var month = $('#' + id + '_ddlMonth')[0].value;
    var cnt = daysInMonth(month, $('#' + id + '_ddlYear')[0].value);
    // Add option for each day in the month
    for (i = 1; i <= cnt; i++)
    {
        var option = "<option value='" + i.toString() + "'>" + i.toString() + "</option>";
        ddlDay.append(option);
    }
    
    // Set the selected item
    ddlDay[0].selectedIndex = selectedDay;
}

// Apparently, the javascript Date function allows you to overflow the day number
// parameter that you pass, creating a date in the next month. Deliberately
// overflowing the day parameter and checking how far the resulting date overlaps
// into the next month is a quick way to tell how many days there were in the
// queried month.
function daysInMonth(iMonth, iYear)
{
    var d = new Date(iYear, (iMonth - 1), 32);
    return (32 - d.getDate());
}        

