
function daysInMonth (year, month) 
{	 
     return 32 - new Date(year, month, 32).getDate();
} 	 

function setDays(field , days)
{	   
	field.options.length = days;
	for (i = 0; i < days; i++)
	{						 
	    field.options[i].text = i+1;
		field.options[i].value = i+1;
	}
}							  

function setOptionText(the_select, the_array)
{						
  the_select.options.length = the_array.length;
  for (i=0; i < the_select.options.length; i++)
  {
    the_select.options[i].text = the_array[i];
	the_select.options[i].value = the_array[i];
  }
}

function setSelectedOption(the_select,value)
{
  for (i=0; i < the_select.options.length; i++)
  {
    if (the_select.options[i].value==value)
	{
		the_select.selectedIndex=i;
	}
	
  }
}

function setFullDate()
{

    fullDate = eval(fullDateVar);
    myForm = eval(theForm);
    fullDate.value = myForm.date.value +"-"+ myForm.month.value +"-" + myForm.year_field.value;
}

function setDaysInMonth()
{			
	
	myForm = eval(theForm);
	theYear = myForm.year_field;
    if (theYear.selectedIndex<0){
	 theYear.selectedIndex = 0;
	}

    var	temp = daysInMonth(theYear.options[theYear.selectedIndex].value,myForm.month.selectedIndex);
	setDays(myForm.date,31);
	setFullDate();
	
}		 

function setDate(strDate,strMonth,strYear)
{
	myForm = eval(theForm);   
	myForm.date.selectedIndex = strDate;
	myForm.month.selectedIndex = strMonth;
	setSelectedOption(myForm.year_field,strYear);
}

function setYears()
{						
  the_select = myForm.year_field;
  the_select.options.length = numYearsBefore + 1;
  today = new Date(); 
  startYear = today.getFullYear() - numYearsBefore;	 
  for (i=0; i < numYearsBefore+1; i++)
  {
    the_select.options[i].text = startYear + i;
	the_select.options[i].value =startYear + i;
  }
    the_select.selectedIndex=0;	
}
function dateInit()
{
	setDaysInMonth();
	setYears();
	theDate = new Date(cYear,cMonth,cDate);
	cYear = theDate.getFullYear();
	setDate(cDate,cMonth,cYear);
	setFullDate();
}