var date_arr = new Array;
var days_arr = new Array;
var months_arr = new Array;

months_arr[0]=-1;
months_arr[1]=31;
months_arr[2]=28;
months_arr[3]=31;
months_arr[4]=30;
months_arr[5]=31;
months_arr[6]=30;
months_arr[7]=31;
months_arr[8]=31;
months_arr[9]=30;
months_arr[10]=31;
months_arr[11]=30;
months_arr[12]=31;

function fill_days() {

		//selM = document.getElementById('registration:months').selectedIndex;
		//selY = document.getElementById('registration:years').selectedIndex;

		selection = document.getElementById('mainForm:months').selectedIndex;

		update_days(document.getElementById('mainForm'));
}

function update_days(f)
{
		//days in cur month
		//temp = months_arr[document.getElementById('registration:days').selectedIndex];

		//selected day before submit
		previousSelection = document.getElementById('mainForm:days').selectedIndex;

		//number of selected month
		if (selection != 0) {

			for (x=document.getElementById('mainForm:days').options.length; x>1; x--) {
				document.getElementById('mainForm:days').options[x]=null;
			}

		}

		//
        for(x=days_arr.length;x>1;x--)
        {
                days_arr[x]=null;
                document.getElementById('mainForm:days').options[x]=null;
        }

        //days in cur month
        selection=months_arr[document.getElementById('mainForm:months').selectedIndex+1];

        ret_val = 0;

        if (document.getElementById('mainForm:months').selectedIndex == 1)
        {
        	year=parseInt(document.getElementById('mainForm:years')[document.getElementById('mainForm:years').selectedIndex].value);

                if (year % 4 == 0 && year % 100 != 0 ) 
						ret_val=1;
                else
                        if (year % 400 == 0)  
								ret_val=1;
                        else
                                ret_val=0;
        }
        //days in cur month - renew
        selection = selection + ret_val;


        for(x=1;x < selection+1;x++)
        {

                //days_arr[x]=new Option(x);
                //document.getElementById('registration:days').options[x-1]=days_arr[x];
        		document.getElementById('mainForm:days').options[x]=new Option(x,x);
        }


		if (previousSelection != 0 && previousSelection < document.getElementById('mainForm:days').options.length+1)
			document.getElementById('mainForm:days').selectedIndex = previousSelection;

		//if (previousSelection > )

		/*if (temp == -1) document.getElementById('registration:days').options[0].selected=true;
		else
			document.getElementById('registration:days').options[previousSelection].selected=true;*/


}

