/* Datumvalaszto
** 3 SELECTET kezel, a napnak, honapnak es evnek. 
** Csak ervenyes datumot lehet rajta beallitani, kezeli a szokoeveket is.  A write optionsokat a html megfelelo reszerol kell kiiratni.
** Pl.: <SCRIPT language="JavaScript">  document.write(WriteMonthOptions()); /SCRIPT> 
** Erre azert van szukseg, mert addloadeventet nem lehet parameterezni, es a kezdoerteket be kell allitani.
*/

Now = new Date();
NowYear = Now.getYear(); //Aktuális ev, eddig lesz feltoltve year SELECT
if (NowYear < 2000) NowYear += 1900; //netscape miatt kell, mashogy adja vissza a datumot
 
var DaysObject;
var MonthObject;
var YearObject;

//vissza adja, hogy hany nap van az adott ev adott honapjaban
function DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == getLocString("profileedit.calendar.month.april") || WhichMonth == getLocString("profileedit.calendar.month.june") || WhichMonth == getLocString("profileedit.calendar.month.september") || WhichMonth == getLocString("profileedit.calendar.month.november")) DaysInMonth = 30;
  if (WhichMonth == getLocString("profileedit.calendar.month.february") && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == getLocString("profileedit.calendar.month.february") && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}

//a days lehullomenu elemeinek valtoztatasa (hozzaad elemet, ha tobb nap van az adott honapban, mint ami a listaban van, es elvesz, ha kevesebb)
function ChangeOptionDays()
{
  DaysObject = document.getElementById("SelectDay");
  MonthObject = document.getElementById("SelectMonth");
  YearObject = document.getElementById("SelectYear");

  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.options.length - 1] = null
    }
  }
  if (DaysForThisSelection > CurrentDaysInSelection)
  {
    for (i=CurrentDaysInSelection+1; i<=DaysForThisSelection; i++)
    {
	  DaysObject[i]=new Option(i,i);
    }
  }
  if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

//kezdoertek beallitasa, ha nem valid a kezdoertek (valamelyik SELECT erteke null)
function SetToToday(Yea,Mont,Da)
{ 


	var Year = parseInt(Yea);
	var Month = parseInt(Mont);
	var Day = parseInt(Da);
	DaysObject = document.getElementById("SelectDay");
	MonthObject = document.getElementById("SelectMonth");
	YearObject = document.getElementById("SelectYear");
	

if (Yea!='' && Mont!=''&& Da!=''){
		YearObject[Year-1899].selected = true;
		MonthObject[Month].selected = true;
		ChangeOptionDays();
		DaysObject[Day].selected = true;
		
		if(YearObject[Year-1899]==null || MonthObject[Month]==null || DaysObject[Day]==null)
		{
			YearObject[0].selected = true;
			MonthObject[0].selected = true;
			ChangeOptionDays();
			DaysObject[0].selected = true;
		}
	}
	else
		{
			YearObject[0].selected = true;
			MonthObject[0].selected = true;
			ChangeOptionDays();
			DaysObject[0].selected = true;
		}
	
}

//years menu feltoltesehez, irassuk ki a html megfelelo reszen
function WriteYearOptions()
{
  line = "";
  line += "<OPTION value=' '>"+getLocString("profileedit.calendar.select");
  for (i=1900; i!=NowYear+1; i++)
  {
    line += "<OPTION value='"+i+"'>";
    line += i;
  }
  return line;
}

//days menu feltoltese, irassuk ki a html megfelelo reszen
function WriteDayOptions()
{
  line = "";
  line += "<OPTION value=' '>"+getLocString("profileedit.calendar.select");
  for (i=1; i<=31; i++)
  {
    line += "<OPTION value='"+i+"'>";
    line += i;
  }
  return line;
}

//months menu feltoltese, irassuk ki a html megfelelo reszen
function WriteMonthOptions()
{
  line = "";
  line += "<OPTION value=' '>"+getLocString("profileedit.calendar.select");
  for (i=0; i<=11; i++)
  {
    line += "<OPTION value='"+i+"'>";
    if (i==0) line += getLocString("profileedit.calendar.month.january");
	if (i==1) line += getLocString("profileedit.calendar.month.february");
	if (i==2) line += getLocString("profileedit.calendar.month.march");
	if (i==3) line += getLocString("profileedit.calendar.month.april");
	if (i==4) line += getLocString("profileedit.calendar.month.may");
	if (i==5) line += getLocString("profileedit.calendar.month.june");
	if (i==6) line += getLocString("profileedit.calendar.month.july");
	if (i==7) line += getLocString("profileedit.calendar.month.august");
	if (i==8) line += getLocString("profileedit.calendar.month.september");
	if (i==9) line += getLocString("profileedit.calendar.month.october");
	if (i==10) line += getLocString("profileedit.calendar.month.november");
	if (i==11) line += getLocString("profileedit.calendar.month.december");	
  } 
  return line;
}

