function styleDateOfBirth()
{

	$('#tx-srfeuserregister-pi1-date_of_birth').each(function(i){
		if (i) return;

		now = new Date();
		day = createSelectOptions('day', 'dob_day', 1, 31, 1);
		month = createSelectOptions('month', 'dob_month', 1, 12, 1); 
		year = createSelectOptions('year', 'dob_year', 1980, now.getFullYear()-9, 1);
		$(this).css('position', 'absolute')
			.css('top', -100)
			.css('left', -100)
			.after(year)
			.after(month)
			.after(day)
			.val('1.1.1980');
	});

}

function updateDOBDay(month, year)
{

	if ( month==2 )
	{
		$('#dob_day').html(createSelectOptions('day', 'dob_day', 1, year%4==0 ? 29 : 28, $('#dob_day').val()).html());
	}
	else if ( month%2==0 )
	{
		$('#dob_day').html(createSelectOptions('day', 'dob_day', 1, 30, $('#dob_day').val()).html());
	}
	else
	{
		$('#dob_day').html(createSelectOptions('day', 'dob_day', 1, 31, $('#dob_day').val()).html());
	}

}

function createSelectOptions(sType, sID, iMin, iMax, iSelected)
{
//console.log(iSelected);
	result = $('<select id="'+sID+'"></select>');

	for (i=iMin; i<=iMax; i++)
	{
		result.append($('<option value="'+i+'"'+(i==iSelected ? ' selected="selected"' : '')+'>'+i+'</option>'));
	}

	switch (sType)
	{
		case 'month':
			result.change(function(){
				updateDOBDay($(this).val(), $('#dob_year').val());
			});
			break;
		case 'year':
			result.change(function(){
				updateDOBDay($('#dob_month').val(), $(this).val());
			});
			break;
	}

	result.change(function(){
		$('#tx-srfeuserregister-pi1-date_of_birth').val($("#dob_day").val()+'.'+$("#dob_month").val()+'.'+$("#dob_year").val());
	});

	return result;

}

$(styleDateOfBirth);