
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Created by: Lee Hinder, lee.hinder@ntlworld.com -->
<!-- Updated by: Jim Mallmann, jim@topicalnetworks.com -->
<!-- Updates: 	--corrected leap year check to account for years -->
<!--			  ending in '00' needing to be divisible by 400 -->
<!--			--changed script to account for blank first	-->
<!--			  option in month, day, and year dropdowns	-->

<!-- Begin
//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
    var DaysInMonth = 31;
    if(WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
    if(WhichMonth == "Feb")
    {
        if(WhichYear%100 == 0)
        {
            if(WhichYear%400 == 0) DaysInMonth = 29;
            else DaysInMonth = 28;
        }
        else
        {
            if(WhichYear%4 == 0) DaysInMonth = 29;
            else DaysInMonth = 28;
        }
    }
    return DaysInMonth;
}

//function to change the available days in a months
function ChangeOptionDays(formName, Which)
{
    DaysObject = eval("document." + formName + "." + Which + "Day");
    MonthObject = eval("document." + formName + "." + Which + "Month");
    YearObject = eval("document." + formName + "." + Which + "Year");

    Month = MonthObject[MonthObject.selectedIndex].text;
    Year = YearObject[YearObject.selectedIndex].text;

    DaysForThisSelection = DaysInMonth(Month, Year);
    CurrentDaysInSelection = DaysObject.length-1;
    if (CurrentDaysInSelection > DaysForThisSelection)
    {
        for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
        {
            DaysObject.options[DaysObject.length - 1] = null
        }
    }
    if (DaysForThisSelection > CurrentDaysInSelection)
    {
        for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
        {
        NewOption = new Option(DaysObject.length);
        //DaysObject.add(NewOption);
        DaysObject.options[DaysObject.options.length] = NewOption;
        }
    }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

//function to set options to today
function SetToToday(formName, Which)
{
    DaysObject = eval("document." + formName + "." + Which + "Day");
    MonthObject = eval("document." + formName + "." + Which + "Month");
    YearObject = eval("document." + formName + "." + Which + "Year");

    YearObject[0].selected = true;
    MonthObject[NowMonth].selected = true;

    ChangeOptionDays(Which);

    DaysObject[NowDay-1].selected = true;
}

//function to write option years plus x
function WriteYearOptions(YearsAhead)
{
    line = "";
    for (i=0; i<YearsAhead; i++)
    {
        line += "<OPTION>";
        line += NowYear + i;
    }
    return line;
}
