/* 
   Script to place Month/day/year onto a web page, leap year enabled
   @author nicholas doucette (nicholas.doucette@freecause.com)
*/

var date_arr = new Array;
var days_arr = new Array;

date_arr[0]=new Option("Jan",31);
date_arr[1]=new Option("Feb",28);
date_arr[2]=new Option("Mar",31);
date_arr[3]=new Option("Apr",30);
date_arr[4]=new Option("May",31);
date_arr[5]=new Option("Jun",30);
date_arr[6]=new Option("Jul",31);
date_arr[7]=new Option("Aug",30);
date_arr[8]=new Option("Sept",30);
date_arr[9]=new Option("Oct",31);
date_arr[10]=new Option("Nov",31);
date_arr[11]=new Option("Dec",30);

function fill_select(f)
{
        document.writeln("<SELECT name=\"birthday_month\"  id=\"birthday_month\" onchange=\"update_days(info)\">");
        for(x=0;x<12;x++)
                document.writeln("<OPTION value=\""+(x+1)+"\" id=\""+date_arr[x].value+"\">"+date_arr[x].text);
        document.writeln("</SELECT><SELECT name=\"birthday_day\" id=\"birthday_day\"></SELECT>");
        selection=f.birthday_month[f.birthday_month.selectedIndex].value;
}

function update_days(f)
{
        temp=f.birthday_day.selectedIndex;
        for(x=days_arr.length;x>0;x--)
        {
                days_arr[x]=null;
                f.birthday_day.options[x]=null;
         }
        selection=parseInt(f.birthday_month[f.birthday_month.selectedIndex].id);
        ret_val = 0;
        if(f.birthday_month[f.birthday_month.selectedIndex].id == 28)
        {
                year=parseInt(f.birthday_year.options[f.birthday_year.selectedIndex].value);
                if (year % 4 != 0 || year % 100 == 0 ) ret_val=0;
                else
                        if (year % 400 == 0)  ret_val=1;
                        else
                                ret_val=1;
        }
        selection = selection + ret_val;
        for(x=1;x < selection+1;x++)

        {
                days_arr[x-1]=new Option(x);
                f.birthday_day.options[x-1]=days_arr[x-1];
        }
        if (temp == -1) f.birthday_day.options[0].selected=true;
        else
             f.birthday_day.options[temp].selected=true;
}

function year_install(f)
{
        document.writeln("<SELECT name=\"birthday_year\" id=\"birthday_year\"onchange=\"update_days(info)\">")
        for(x=1900;x<2009;x++) document.writeln("<OPTION value=\""+x+"\">"+x);
        document.writeln("</SELECT>");
        update_days(f)
}
