nAvailableYears = 5;
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 + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");

  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);
    }
  }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}


//function to change the available days in a months
function loadMonthDays( nListId, nYear, nMonth )
{
  DaysForThisSelection = DaysInMonth(nMonth, nYear);
  CurrentDaysInSelection = $( nListId ).length;

  if (CurrentDaysInSelection > DaysForThisSelection)
  {

    for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
    {
      $( nListId ).options[ $( nListId ).options.length - 1 ] = null
    }
  }
  
  if (DaysForThisSelection > CurrentDaysInSelection)
  {

    for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
    {
		
      $( nListId ).options[ $( nListId ).options.length ] = new Option( $( nListId ).options.length + 1,$( nListId ).options.length + 1);
	
    }
  }
    if ($( nListId ).selectedIndex < 0) 
		$( nListId ).selectedIndex == 0;
}
//function to set options to today
function SetToToday(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");

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

  ChangeOptionDays(Which);

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

//function to write option years plus x
function WriteYearOptions(YearsAhead)
{
  line = "";
  for (i=0; i<YearsAhead; i++)
  {
    line += "<OPTION>";
    line += NowYear + i;
  }
  return line;
}

function loadHours( sSelectId )
	{
		var lista = $( sSelectId );
		for (i=0; i<24; i++)
 		{
			var id    = i;
			var type  = i;
			lista.options[i] = new Option(type, id);			

		}
		lista.selectedIndex = 0;
		
	}
function loadMins( sSelectId )
	{
		var lista = $( sSelectId );
		for (i=0; i<60; i++)
 		{
			var id    = i;
			var type  = i;
			lista.options[i] = new Option(type, id);			

		}
		lista.selectedIndex = 0;
		
	}	
function loadyears( sSelectId, nYears)
	{
		var lista = $( sSelectId );
		for (i=0; i<nYears; i++)
 		{
			var id    = NowYear + i;
			var type  = NowYear + i;
			lista.options[i] = new Option(type, id);			

		}
		lista.selectedIndex = 0;
		
	}
	
 	function selectByValue( lst, value )
	{
		bFounded = false;
		for (i=0; ! bFounded && i<lst.options.length;i++) 
	    {

			if( lst.options[i].value == value )
			{
				lst.options[i].selected = true;
				bFounded = true;
			}
	    }
	}
 	function selectByValue( lst, value )
	{
		bFounded = false;
		for (i=0; ! bFounded && i<lst.options.length;i++) 
	    {

			if( lst.options[i].value == value )
			{
				lst.options[i].selected = true;
				bFounded = true;
			}
	    }
	}