﻿/*
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 now = new Date();
var startYear = 1930;
var endYear = now.getFullYear();
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() {
    clearDropDown(selectYears);
    clearDropDown(selectMonths);
    clearDropDown(selectDays);
    
    for (i = startYear; i <= endYear; i ++ ) {
        var num = selectYears.options.length;
        selectYears.options[num] = new Option(i, i);
    }
    
    monthArray = eval(monthType);
    for (i = 0; i < monthArray.length; i ++ ) {
        var num = selectMonths.options.length;
        selectMonths.options[num] = new Option(monthArray[i], i);
    }
    
    for (i = 1; i <= 31; i ++ ) {
        var num = selectDays.options.length;
        selectDays.options[num] = new Option(i, i);
    }
}

function buildDateDropDown(selectDays, selectMonths, selectYears) {
    clearDropDown(selectYears);
    clearDropDown(selectMonths);
    clearDropDown(selectDays);
    for (i = startYear; i <= endYear; i ++ ) {
        var num = selectYears.options.length;
        selectYears.options[num] = new Option(i, i);
    }
    monthArray = eval(monthType);
    for (i = 0; i < monthArray.length; i ++ ) {
        var num = selectMonths.options.length;
        selectMonths.options[num] = new Option(monthArray[i], i);
    }
    for (i = 1; i <= 31; i ++ ) {
        var num = selectDays.options.length;
        selectDays.options[num] = new Option(i, i);
    }
}

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;
    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);
    }
}

function setOptionDays(optionDays, optionMonths, optionYears) {
    var dummySlots = 0;
    for (i = 0; i < optionDays.options.length; i ++ ) {
        if (optionDays.options[i].value == dummyValue)
            dummySlots ++ ;
    }
    optionDays.options.length = dummySlots;
    
    var month = optionMonths.options[optionMonths.selectedIndex].value;
    var numDays = 31;
    if (month == 3 || month == 5 || month == 8 || month == 10) {
        var numDays = 30;
    } else if (month == 1) {
        numDays = (checkLeap(optionYears.options[optionYears.selectedIndex].value)) ? 29: 28;
    }
    
    for (i = 1; i <= numDays; i ++ ) {
        var num = optionDays.options.length;
        optionDays.options[num] = new Option(i, i);
    }
}