Today = new Date();
CurrentYear = Today.getFullYear();
NextYear = CurrentYear + 1;
CurrentMonth = Today.getMonth()+ 1;
CurrentDay = Today.getDate();
NextYearMonth = CurrentMonth-2;

function WriteMonths()
{
        Months = "";
        for (i = CurrentMonth; i <= 12; i++)
        {
                Months = Months + "<option value=\"" + i + "\">" + MonthName(i) + ", " + CurrentYear + "</option>";
                Months += i;
                Months += "</option>";
        }
        for (i = 1; i <= NextYearMonth; i++)
        {
                Months = Months + "<option value=\"" + i + "\">" + MonthName(i) + ", " + NextYear + "</option>";
                Months += i;
                Months += "</option>";
        }
        return Months;
}

function MonthName(MonthNumber)     
{                                  
        var Month=new Array();             

        Month[1]="Jan";
        Month[2]="Feb";
        Month[3]="Mar";
        Month[4]="Apr";
        Month[5]="May";
        Month[6]="Jun";
        Month[7]="Jul";
        Month[8]="Aug";
        Month[9]="Sep";
        Month[10]="Oct";
        Month[11]="Nov";
        Month[12]="Dec";

        return Month[MonthNumber];
}          

function WriteDays(MonthNumber,DaysPointReference,SelectDaysInAdvance)     
{                                  
        Days = "";
        DaysInMonth = 31;
        iSelected = 0;
       
        if (DaysPointReference == '') {
                DaysPointReference = CurrentDay;
        }
       
        if (MonthNumber%2 == 0) {
                DaysInMonth = 30;
        } else {
                DaysInMonth = 31;
        }
       
        if (MonthNumber == 2) {
                if (CurrentYear%4 == 0) { //check for leap year
                        DaysInMonth = 29;
                } else {
                        DaysInMonth = 28;
                }
        }
       
        //force this to 31 days max
        DaysInMonth = 31;

        //      iSelected = DateAdd(parseInt(DaysPointReference),SelectDaysInAdvance,0,0);
        iSelected = parseInt(DaysPointReference) + parseInt(SelectDaysInAdvance);      
        if (iSelected >= DaysInMonth) {
                iSelected = DaysInMonth; //not exact           
        }
       
        for (i = 1; i <= DaysInMonth; i++)
        {
                if (iSelected == i) {
                        Days = Days + "<option value=\"" + i + "\" selected>" + i + "</option>";
                } else {
                        Days = Days + "<option value=\"" + i + "\">" + i + "</option>";
                }
               
                Days += i;
                Days += "</option>";
        }
        return Days;
}

function DateAdd(startDate, numDays, numMonths, numYears)
{
        var returnDate = new Date(startDate.getTime());
        var yearsToAdd = numYears;
       
        var month = returnDate.getMonth() + numMonths;
        if (month > 11)
        {
                yearsToAdd = Math.floor((month+1)/12);
                month -= 12*yearsToAdd;
                yearsToAdd += numYears;
        }
        returnDate.setMonth(month);
        returnDate.setFullYear(returnDate.getFullYear() + yearsToAdd);
       
        returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
       
        return returnDate;

}

function doSubmitPopup(f)
{
        f.submit();
        window.close();
}
