
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Created by: Lee Hinder, lee.hinder@ntlworld.com -->

//  call .....<BODY onLoad="SetToDate('In',7,7,2004);SetToDate('Out');">
	

<!-- Begin

Form_name = "Form1";

//set todays date
Now = new Date();
 NowDay = Now.getDate();
 NowMonth = Now.getMonth();
 NowYear = Now.getYear();
NowDayofweek = Now.getDay();

TomorrowDay = NowDay + 1;
TomorrowMonth = NowMonth;
TomorrowYear = NowYear;
TomorrowDayofweek = NowDayofweek + 1;
if (TomorrowDayofweek > 7)
	{
	TomorrowDayofweek = 1;
	}
if (TomorrowDay > DaysInMonth(TomorrowMonth, TomorrowYear))
	{
	TomorrowDay = 1;
	TomorrowMonth = TomorrowMonth +1;
	if (TomorrowMonth > 12)
		{
		TomorrowMonth = 1;
		TomorrowYear = TomorrowYear + 1;
		}
	}

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 == "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(Which)
{
  DaysObject = eval("document." + Form_name + "." + Which + "Day");
  MonthObject = eval("document." + Form_name + "." + Which + "Month");
  YearObject = eval("document." + Form_name + "." + 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 set options to date or today

function SetToDate(Which,setday,setmonth,setyear)
{
  DaysObject = eval("document." + Form_name + "." + Which + "Day");
  MonthObject = eval("document." + Form_name + "." + Which + "Month");
  YearObject = eval("document." + Form_name + "." + Which + "Year");

		if (setmonth > 0) // date specified 
			{
//			YearObject[setyear-NowYear].selected = true;
//			MonthObject[setmonth-1].selected = true;
//	 		DaysObject[setday-1].selected = true;

			NowDay = TomorrowDay;
			NowMonth = TomorrowMonth;
			NowYear = TomorrowYear;


			}
//		else	// date not specified - make it today
//			{
			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;
}
//  End -->

