	function getDays(month, year) 
	{
		if (1 == month)
			return ((0 == year % 4) && (0 != (year % 100))) ||
				(0 == year % 400) ? 29 : 28;
		else
			return daysInMonth[month];
	}
	
	function fillMonthDays(monthIndex,yearValue)
	{
		var NrDays=getDays(monthIndex-1,yearValue);
		for(i=1; i<=NrDays; i++)
		{
			addOption(obj('day'),i,i);
		}
	}
	
	function removeMonthDays()
	{							
		for (i = obj('day').length - 1; i>0; i--) 
		{
			obj('day').remove(i);
		}
		if(obj('month').selectedIndex!=0 && obj('year').selectedIndex!=0) 
		{
			fillMonthDays(obj('month').selectedIndex,obj('year').options[obj('year').selectedIndex].value);
		}
	}
	
	var months = new Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");
	var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	
	$(function()
	{		
    if($('#s_dist') && $('#s_dist').value!="")
    {
      var s_index;
      for(i=0; i<obj('dist').length - 1; i++)
			{
				if(obj('dist').options[i].value==obj('s_dist').value)
				{
					s_index=i;
					break;
				}
			}
			obj('dist').selectedIndex=s_index;
			$('#dist').trigger('change');	
    }					
	});
	
	$(function()
	{
		var j=0;
		for(i=0; i<months.length; i++)
		{
			j=i+1;
			addOption(obj('month'),months[i],j);
		}
		
		for(i=1920; i<2008; i++)
		{
			addOption(obj('year'),i,i);
		}
		
		if(obj('s_year').value && obj('s_month').value && obj('s_day').value)
		{									
			s_year=parseInt(obj('s_year').value) - obj('year').options[1].value + 1;
			//alert(s_year+" "+parseInt(obj('s_month').value)+" "+parseInt(obj('s_day').value));									
			if(!isNaN(s_year) && s_year > 0)
				obj('year').selectedIndex=s_year;
			obj('month').selectedIndex=parseInt(obj('s_month').value);
			fillMonthDays(parseInt(obj('s_month').value),obj('s_year').value);
			obj('day').selectedIndex=parseInt(obj('s_day').value);
		} 
		
		if(gup('op')=="editdata")
		{
			obj('terms').checked=true;
		}
				
	});

