function padOptionsItem(mySelect, sText, sValue)
{
	var oe = new Option();
	oe.text = sText;
	oe.value = sValue;
	mySelect.options.add(oe);
	delete oe;
}

function GenYears(FromYear, ToYear, TheYear, yyList)
{
//alert("genyears");
	var cnt, oe, iYear, sYear;
	var myList, IsDashed = false;
		
	function padDashYear()
	{
		if (!IsDashed)
		{
			padOptionsItem(myList, "------", "------");
			IsDashed = true;
		}
	}

	myList = yyList;
	this.insertDashYear = padDashYear;

	yyList.options.length = 0;

	for (iYear = FromYear; iYear <= ToYear; iYear++)
	{
		oe = new Option();

		sYear = "000" + iYear;
		sYear = sYear.substr(sYear.length - 4, 4);
		oe.text = sYear;
		oe.value = sYear;
		yyList.options.add(oe);

		delete oe;
	}
		
//alert("the year=" + TheYear);
	if (TheYear == "none")
	{
		padDashYear();
		yyList.selectedIndex = yyList.options.length - 1;
	}
	else
		yyList.selectedIndex = TheYear - FromYear;
}

function GenMonths(TheMonth, mmList)
{
//alert("genmonths");
	var cnt, oe, iMonth, sMonth;
	var myList, IsDashed = false;
		
	function padDashMonth()
	{
		if (!IsDashed)
		{
			padOptionsItem(myList, "---", "---");
			IsDashed = true;
		}
	}

	myList = mmList;
	this.insertDashMonth = padDashMonth;
	
	mmList.options.length = 0;

	for (iMonth = 1; iMonth <= 12; iMonth++)
	{
		oe = new Option();

		sMonth = "0" + iMonth;
		sMonth = sMonth.substr(sMonth.length - 2, 2);
		oe.text = sMonth;
		oe.value = sMonth;
		mmList.options.add(oe);

		delete oe;
	}
        
	if (TheMonth == "none")
	{
		padDashMonth();
		mmList.selectedIndex = mmList.options.length - 1;
	}
	else
		mmList.selectedIndex = TheMonth;
}

function GenYearMonths(TheYear, TheMonth, mmList)
{
	var dm = new GenMonths(TheMonth, mmList);
	this.insertDashMonth = dm.insertDashMonth;
	
	if (TheYear == "------")
	{
		mmList.options.length = 0;
		dm.insertDashMonth();
		mmList.selectedIndex = mmList.options.length - 1;
	}
}
/*function GenYearMonths(TheYear, TheMonth, mmList)
{
	this.prototype = new GenMonths(TheMonth, mmList);
	this.insertDashMonth = this.prototype.insertDashMonth;
	
	if (TheYear == "------")
	{
		mmList.options.length = 0;
		this.insertDashMonth();
		mmList.selectedIndex = mmList.options.length - 1;
	}
}*/

function GenMonthDays(TheYear, TheMonth, TheDay, ddList)
{
//alert("genmonthdays");
	var cnt, oe, iDay, sDay, isLeap;
	var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var myList, IsDashed = false;
		
	function padDashDay()
	{
		if (!IsDashed)
		{
			padOptionsItem(myList, "---", "---");
			IsDashed = true;
		}
	}

	myList = ddList;
	this.insertDashDay = padDashDay;

	ddList.options.length = 0;

	if (TheYear == "------" || TheMonth == "---")
	{
		padDashDay();
		ddList.selectedIndex = ddList.options.length - 1;
		return;
	}
			
	TheMonth = TheMonth - 1;

	isLeap = ((TheYear % 4 ) == 0) ? true : false;
	if (((TheYear % 100) == 0) && ((TheYear % 400) != 0))
		isLeap = false;
	if (isLeap) MonthDays[1] = 29;
				
//	for (iDay = ddList.options.length + 1; iDay <= MonthDays[TheMonth]; iDay++)
	for (iDay = 1; iDay <= MonthDays[TheMonth]; iDay++)
	{
		oe = new Option();

		sDay = "0" + iDay;
		sDay = sDay.substr(sDay.length - 2, 2);
		oe.text = sDay;
		oe.value = sDay;
		ddList.options.add(oe);

		delete oe;
	}

	if (TheDay == "none")
	{
		padDashDay();
		ddList.selectedIndex = ddList.options.length - 1;
	}
	else
	{
		if (TheDay > MonthDays[TheMonth])
			ddList.selectedIndex = MonthDays[TheMonth] - 1;
		else
			ddList.selectedIndex = TheDay - 1;
	}	
}
