// JavaScript Document
function init_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.encodages.jours" + Which);
	MonthObject = eval("document.encodages.mois" + Which);
	YearObject = eval("document.encodages.annees" + Which);
	Day = DaysObject[DaysObject.selectedIndex].text;
	Month = MonthObject[MonthObject.selectedIndex].text;
	Year = YearObject[YearObject.selectedIndex].text;
	DaysForThisSelection = DaysInMonth(Month, Year);
	CurrentDaysInSelection = DaysObject.length;

	if (DaysForThisSelection > CurrentDaysInSelection)
	{
		for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
		{
		    DaysObject.options[DaysObject.options.length] = new Option(DaysObject.options.length + 1);	
		}
	}

	if (CurrentDaysInSelection > DaysForThisSelection)
	{
		for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
		{
			DaysObject.options[DaysObject.options.length - 1] = null
		}
		if(Day > DaysForThisSelection)
		{
			window.alert('Le jours est incorrecte, veuillez le changer');
			DaysObject.focus();
		}
	}

	if (DaysObject.selectedIndex < 0)
	{
		DaysObject.selectedIndex = 0;
	}
}
//function to write option years plus x
function WriteYearOptions(YearsAhead,YearFichier)
{
	test = parseInt(YearFichier);
	if(test == 0)
	{	YearFichier = parseInt(NowYear);
	}else{
		YearFichier = parseInt(YearFichier);
	}
	line = "";
	for (i=YearsAhead; i>0; i--)
	{
//		YearsAhead2 = parseInt(YearsAhead/2)
		if((YearFichier - i + 1) == YearFichier)
			line += "<OPTION selected>";
		else
			line += "<OPTION>";
		line += YearFichier -i + 1;
		line += "</OPTION>";
	}
	return line;
}
