//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 == "4" || WhichMonth == "6" || WhichMonth == "9" || WhichMonth == "11") DaysInMonth = 30;
if (WhichMonth == "2" && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 28;
if (WhichMonth == "2" && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 29;
return DaysInMonth;
}

//function to change the available days in a months
function ChangeOptionDays(Which)
{
DaysObject = eval("document.Form1." + Which + "_dia");
MonthObject = eval("document.Form1." + Which + "_mes");
YearObject = eval("document.Form1." + Which + "_ano");

Month = MonthObject[MonthObject.selectedIndex].value;
Year = YearObject[YearObject.selectedIndex].value;

DaysForThisSelection = DaysInMonth(Month, Year);
CurrentDaysInSelection = DaysObject.length;
if (CurrentDaysInSelection > DaysForThisSelection)
{
for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
{
DaysObject.options[DaysObject.options.length - 1] = null
}
}
if (DaysForThisSelection > CurrentDaysInSelection)
{
for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
{
NewOption = new Option(DaysObject.options.length + 1);
DaysObject.add(NewOption);
}
}
if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

//function to set options to today
function SetToToday(Which,Whichtwo)
{
DaysObject = eval("document.Form1." + Which + "_dia");
MonthObject = eval("document.Form1." + Which + "_mes");
YearObject = eval("document.Form1." + Which + "_ano");

Days2Object = eval("document.Form1." + Whichtwo + "_dia");
Month2Object = eval("document.Form1." + Whichtwo + "_mes");
Year2Object = eval("document.Form1." + Whichtwo + "_ano");


YearObject[0].selected = true;
Year2Object[0].selected = true;
MonthObject[NowMonth].selected = true;
Month2Object[NowMonth].selected = true;

ChangeOptionDays(Which);
ChangeOptionDays(Whichtwo);

DaysObject[NowDay-1].selected = true;
}

//function to write option years plus x
function WriteYearOptions(YearsAhead,selected)
{
line = "";
for (i=0; i<YearsAhead; i++)
{
line += '<option value="';
line += NowYear + i;
if  (parseInt(selected) == (NowYear + i)) {
line += '" selected="selected">';
} else {
line += '">';
}
line += NowYear + i;
line += '</option>';
}

return line;
}