var date_arr = new Array;
var month_arr = new Array;
var days_arr = new Array;
var nowDate = new Date();

date_arr[0]=new Option("Enero",01);
date_arr[1]=new Option("Febrero",02);
date_arr[2]=new Option("Marzo",03);
date_arr[3]=new Option("Abril",04);
date_arr[4]=new Option("Mayo",05);
date_arr[5]=new Option("Junio",06);
date_arr[6]=new Option("Julio",07);
date_arr[7]=new Option("Agosto",08);
date_arr[8]=new Option("Septiembre",09);
date_arr[9]=new Option("Octubre",10);
date_arr[10]=new Option("Noviembre",11);
date_arr[11]=new Option("Diciembre",12);

month_arr[1]=new Option("Enero",31);
month_arr[2]=new Option("Febrero",28);
month_arr[3]=new Option("Marzo",31);
month_arr[4]=new Option("Abril",30);
month_arr[5]=new Option("Mayo",31);
month_arr[6]=new Option("Junio",30);
month_arr[7]=new Option("Julio",31);
month_arr[8]=new Option("Agosto",31);
month_arr[9]=new Option("Septiembre",30);
month_arr[10]=new Option("Octubre",31);
month_arr[11]=new Option("Noviembre",30);
month_arr[12]=new Option("Diciembre",31);

function fill_select(f)

{
	    document.writeln("<SELECT name=\"months\"              onchange=\"update_days(Calculo)\">");

        for(x=0;x<12;x++) 

                document.writeln("<OPTION value=\""+date_arr[x].value+"\">"+date_arr[x].text);

        document.writeln("</SELECT><SELECT name=\"days\"></SELECT>");

        selection=month_arr[f.months[f.months.selectedIndex].value].value;

}



function update_days(f)

{

        temp=f.days.selectedIndex; 

        for(x=days_arr.length;x>0;x--)

        {

                days_arr[x]=null;

                f.days.options[x]=null;

         }

        selection=parseInt(month_arr[f.months[f.months.selectedIndex].value].value);

        ret_val = 0;

		if(month_arr[f.months[f.months.selectedIndex].value].value == 28)
        {

                year=parseInt(f.years.options[f.years.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.days.options[x-1]=days_arr[x-1];

        } 

        if (temp == -1) f.days.options[0].selected=true;

        else

             f.days.options[temp].selected=true;  

}       

function year_install(f)

{
	var anoActual;
	if (nowDate.getYear()< 1000)
	{
		anoActual= nowDate.getYear() + 1900;
	}
	else
	{
		anoActual= nowDate.getYear();
	}

       document.writeln("<SELECT name=\"years\" onchange=\"update_days(Calculo)\">");

        for(x=1980;x< anoActual+1;x++) 
	{
		document.writeln("<OPTION value=\""+x+"\">"+x);
	}

        document.writeln("</SELECT>");

        update_days(f);

}

//******************************************************************************
function fill_select2(f)

{

        document.writeln("<SELECT name=\"months2\"               onchange=\"update_days2(Calculo)\">");

        for(x=0;x<12;x++) 

                document.writeln("<OPTION value=\""+date_arr[x].value+"\">"+date_arr[x].text);

        document.writeln("</SELECT><SELECT name=\"days2\"></SELECT>");

        selection=month_arr[f.months2[f.months2.selectedIndex].value].value;

}



function update_days2(f)

{

        temp=f.days2.selectedIndex; 

        for(x=days_arr.length;x>0;x--)

        {

                days_arr[x]=null;

                f.days2.options[x]=null;

         }

        selection=parseInt(month_arr[f.months2[f.months2.selectedIndex].value].value);

        ret_val = 0;

        if(month_arr[f.months2[f.months2.selectedIndex].value].value == 28)

        {

                year=parseInt(f.years2.options[f.years2.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.days2.options[x-1]=days_arr[x-1];

        } 

        if (temp == -1) f.days2.options[0].selected=true;

        else

             f.days2.options[temp].selected=true;  

}                                

function year_install2(f)
{
        
	var anoActual;

	if (nowDate.getYear()< 1000)
	{
		anoActual= nowDate.getYear() + 1900;
	}
	else
	{
		anoActual= nowDate.getYear();
	}

	document.writeln("<SELECT name=\"years2\" onchange=\"update_days2(Calculo)\">")
        for(x=anoActual-1;x< anoActual+1;x++) document.writeln("<OPTION value=\""+x+"\">"+x);
        document.writeln("</SELECT>");
        update_days2(f)
}

//******************************************************************************
function fill_select3(f)

{

        document.writeln("<SELECT name=\"months3\"               onchange=\"update_days3(Calculo)\">");

        for(x=0;x<12;x++) 

                document.writeln("<OPTION value=\""+date_arr[x].value+"\">"+date_arr[x].text);

        document.writeln("</SELECT><SELECT name=\"days3\"></SELECT>");

        selection=month_arr[f.months3[f.months3.selectedIndex].value].value;

}



function update_days3(f)

{

        temp=f.days3.selectedIndex; 

        for(x=days_arr.length;x>0;x--)

        {

                days_arr[x]=null;

                f.days3.options[x]=null;

         }

        selection=parseInt(month_arr[f.months3[f.months3.selectedIndex].value].value);

        ret_val = 0;

        if(month_arr[f.months3[f.months3.selectedIndex].value].value == 28)

        {

                year=parseInt(f.years2.options[f.years2.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.days3.options[x-1]=days_arr[x-1];

        } 

        if (temp == -1) f.days3.options[0].selected=true;

        else

             f.days3.options[temp].selected=true;  

}                                

function year_install3(f)
{
        
	var anoActual;

	if (nowDate.getYear()< 1000)
	{
		anoActual= nowDate.getYear() + 1900;
	}
	else
	{
		anoActual= nowDate.getYear();
	}

	document.writeln("<SELECT name=\"years3\" onchange=\"update_days3(Calculo)\">")
        for(x=anoActual-2;x< anoActual+1;x++) document.writeln("<OPTION value=\""+x+"\">"+x);
        document.writeln("</SELECT>");
        update_days3(f);
}