/*
clearDropDown(dDown)
and the extra blank <option></option>s on the html page
are simply for netscape display corrections and may be removed if that is not a issue
*/

var startYear = 2002;
var endYear = 1900;
var dummyValue = "-";
var monthType = "abv"; //display of the month name  "abv" or "full"

var abv = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec");
var full = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

function checkLeap(year) {
 return ( ( (year % 4 == 0) && (year % 100 != 0) ) || (year % 400 == 0) ) ? 1 : 0;
}


function buildTheDropDown(sMonth, sDay, sYear){
  clearDropDown(selectYears);
  clearDropDown(selectMonths);
  clearDropDown(selectDays);

  var sYearIndex = 0;
  var sMonthIndex = 0;
  var sDayIndex = 0;

  for(i=startYear;i>=endYear;i--){
    var num = selectYears.options.length;
    selectYears.options[num] = new Option(i,i);
    if(i == sYear) sYearIndex = num;
  }

  monthArray = eval(monthType);
  for(i=0;i<monthArray.length;i++){
    var num = selectMonths.options.length;
    selectMonths.options[num] = new Option(monthArray[i],i);
    if(i == sMonth) sMonthIndex = num;
  }

  for(i=1;i<=31;i++){
    var num = selectDays.options.length;
    selectDays.options[num] = new Option(i,i);
    if(i == sDay) sDayIndex = num;
  }

  selectYears.selectedIndex = sYearIndex;
  selectMonths.selectedIndex = sMonthIndex;
  selectDays.selectedIndex = sDayIndex;
}

function clearDropDown(dDown){
  var dummySlots=0;
  for(i=0;i<dDown.options.length;i++){
    if(dDown.options[i].value == dummyValue) dummySlots ++;
  }
  dDown.options.length = dummySlots;
}

function setDays(){
  var dummySlots=0;
  var currentDay = selectDays.selectedIndex;

  for(i=0;i<selectDays.options.length;i++){
    if(selectDays.options[i].value == dummyValue) dummySlots ++;
  }
  selectDays.options.length = dummySlots;

  var month = selectMonths.options[selectMonths.selectedIndex].value;
  var numDays = 31;
  if(month==3||month==5||month==8||month==10){
   var numDays = 30;
  }else if(month==1){
   numDays = (checkLeap(selectYears.options[selectYears.selectedIndex].value)) ? 29 : 28;
  }

  for(i=1;i<=numDays;i++){
   var num = selectDays.options.length;
   selectDays.options[num] = new Option(i,i);
  }
  if(selectDays.options.length > currentDay) {
   selectDays.selectedIndex = currentDay;
  } else {
   selectDays.selectedIndex = selectDays.options.length-1;
  }

}