// Checks date of birth

MinAge = 14;
BaseDate = new Date();
BaseYear = BaseDate.getYear() - 100;
NowYear = BaseDate.getYear();
if (navigator.appName == "Netscape Navigator" || navigator.appName == "Netscape") {
	BaseYear += 1900; //for Netscape
	NowYear += 1900;
}
BaseDay = BaseDate.getDate();
BaseMonth = BaseDate.getMonth();
YearRange = NowYear - BaseYear - MinAge; // allow range from 100 years back to at least 18 years ago!

//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" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;

	if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;

	return DaysInMonth;
}


//function to change the available days in a months

function ChangeOptionDays()
{
	//DaysObject = eval("document." + form1 + "." + Which + "day");
	//MonthObject = eval("document." + form1 + "." + Which + "month");
	//YearObject = eval("document." + form1 + "." + Which + "year");
	DaysObject = document.getElementById("pd-dobday");
	MonthObject = document.getElementById("pd-dobmonth");
	YearObject = document.getElementById("pd-dobyear");

	Month = MonthObject[MonthObject.selectedIndex].text;
	Year = YearObject[YearObject.selectedIndex].text;

	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);
		}
	}*/

	for (i=0;i < CurrentDaysInSelection ;i++ )
	{
		DaysObject.options[DaysObject.options.length - 1] = null;
	}

	for (i=0; i<DaysForThisSelection; i++)
	{
			//NewOption = new Option(DaysObject.options.length + 1,DaysObject.options.length + 1);
			//DaysObject.add(NewOption);
			DaysObject.options[i] = new Option(DaysObject.options.length + 1,DaysObject.options.length + 1);
	}

	if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}


function WriteDayOptions(day) {

	line = "";
	for (i=1; i <= 31; i++)
	{
		if (i > 9) {
			line +="<option value=\"" + i + "\"";
		} else {
			line +="<option value=\"0" + i + "\"";
		}
		if (day == i)
		{
			line += ' selected="selected"';
		}
		line += ">"
		line += i;
		line += "</option>";
	}
	return line;
}

//function to write option years plus x

function WriteYearOptions(selyear)
{
	line = "";
	for (i=0; i< YearRange; i++)
	{
		var year = (NowYear - MinAge) - i;
		line += "<option value=\"" + year + "\"";
		if (year == selyear)
		{
			line += ' selected="selected"';
		}
		line +=">";
		line += year;
		line += "</option>";
	}
	return line;
}

function setDay(val,day_select) {
	day_select.options.selectedIndex = val;
}

function setMonth(val,month_select) {
	month_select.options.selectedIndex = val;
}

function setYear(val,year_select) {
	year_select.options.selectedIndex = val;
}