﻿//function to set the number of days for each month and year
function MonthDays(Month, Year)
{
    var MonthDays = 31;
         
    if (Month == "April" || Month == "June" || Month == "September" || Month == "November") MonthDays = 30;
    if (Month == "Apr" || Month == "Jun" || Month == "Sep" || Month == "Nov") MonthDays = 30;
    if (Month == "4" || Month == "6" || Month == "9" || Month == "11") MonthDays = 30;
    
    if (Month == "February" || Month == "Feb" || Month == "2")	{       
        if (isInteger(Year/4) == true) {
            MonthDays = 29;
        }
        else {
            MonthDays = 28;    
        }
    }
    
    return MonthDays;
}


//function to set the number of days for each month and year
function MonthYearDays(MonthYear)
{
    var Month = Left(MonthYear, 3);
    var Year = Right(MonthYear, 4);

    return MonthDays(Month, Year);
}


//function to change the number of days of Pickup Date
function ChangeDays(cboDay, cboMonth, cboYear)
{
    var adjDays = 0     //Checks to see if first value in drop down is empty and then adds an adjustment accordingly.
    if (cboDay.options[0].value == '') 
    {
        adjDays = 1    
    }

    MonthIndex = cboMonth.options.selectedIndex;    
    Month = cboMonth.options[MonthIndex].text;
    
    YearIndex = cboYear.options.selectedIndex;
    Year = cboYear.options[YearIndex].text;

    PreviousDays = cboDay.options.length;
    NewDays = MonthDays(Month, Year);

    if (PreviousDays>NewDays+adjDays) {
        for (i=0; i<(PreviousDays-(NewDays + adjDays)); i++) {
            cboDay.options[cboDay.options.length - 1] = null
        }
    }

    if (NewDays + adjDays>PreviousDays)
    {
        for (i=0; i<((NewDays+adjDays)-PreviousDays); i++) {
            NewOption = document.createElement('option');
            NewOption.text = cboDay.options.length + (1 - adjDays) ;
            NewOption.value = "day=" + cboDay.options.length + 1;
            
            try {
               cboDay.add(NewOption, null); // standards compliant; doesn't work in IE
            } 
            catch(ex) {
                cboDay.add(NewOption); // IE only
            }
        }   
    }

    if (cboDay.selectedIndex < 0) cboDay.selectedIndex == 0;
}
