//Current date in form script
//By Lee Hinder (lee.hinder@ntlworld.com)
//Modified for DenaliParkSalmonBake by Michael Mulchaey @ opensourcealaska.com
//Visit http://javascriptkit.com for this script and more
//set todays 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 == "June") DaysInMonth = 30;
  if (WhichMonth == "September" || WhichMonth == "May") DaysInMonth = 18;
  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 append new option to days.
function appendOptionLast(num)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = num;
  elOptNew.value = num;
  var elSel = document.getElementById('zDay');

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}



//function to change the available days in a months
function ChangeOptionDays(Which)
{
  DaysObject = eval("document.Form1." + "zday");
  MonthObject = eval("document.Form1."  + "zmonth");
  YearObject = eval("document.Form1."  + "zyear");
  Month = MonthObject[MonthObject.selectedIndex].text;
  Year = YearObject[YearObject.selectedIndex].text;
  DaysForThisSelection = DaysInMonth(Month, Year);
  CurrentDaysInSelection = DaysObject.length;

  //Clear all elements in DaysObject.
  for (i=0; i<CurrentDaysInSelection; i++){
    DaysObject.options[DaysObject.options.length - 1] = null
  }
  //Load all elements in DaysObject for new month and year objects.
  if (Month == "May") {
     for (i=0; i<DaysForThisSelection; i++)
          appendOptionLast(i + 14);
  } else {
     for (i=0; i<DaysForThisSelection; i++)
          appendOptionLast(i + 1);
  }
  //Set selected index to first day.
  if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0
}

//function to set options to today
function SetToToday(Which)
{
  DaysObject = eval("document.Form1."  + "zday");
  MonthObject = eval("document.Form1."  + "zmonth");
  YearObject = eval("document.Form1."  + "zyear");
  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;
}



