function showhide( id )
{
	if( document.getElementById )
	{
		obj = document.getElementById( id );
		if ( obj.style.display == "none" )
		{
			obj.style.display = "";
			document.getElementById( 'span_' + id ).style.color = "#C13F45";
		}
		else
		{
			obj.style.display = "none";
			document.getElementById( 'span_' + id ).style.color = "#497895";
		}
	}
}

function isValidDate( year, month, day )
{
	return day > 0 && ( day <= [, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][ month ] ||
		day == 29 && month == 2 && year % 4 == 0 && ( year % 100 > 0 || year % 400 == 0 ) );
}

function isValid( element, type )
{
	switch( type )
	{
		// date
		case 0:
			if( element.value.search( /^\d\d?\/\d\d?\/\d{1,4}$/ ) != 0 )
			{
				alert( "Formato da data incorrecto." );
				window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 );
				return false;
			}
			date_value = element.value.split( "/" );
			if( ! isValidDate( date_value[ 2 ], date_value[ 1 ], date_value[ 0 ] ) )
			{
				alert( "Data inválida." );
				window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 );
				return false;
			}
			break;
		// integer
		case 1:
			if( element.value.search( /^\d\d:\d\d$/ ) != 0 )
			{
				alert( "Formato da hora incorrecto." );
				window.setTimeout( "document.getElementById( '" + element.name + "' ).focus()", 1 );
				return false;
			}
			time_value = element.value.split( ":" );
			if( time_value[ 0 ] > 23 || time_value[ 1 ] > 59 )
			{
				alert( "Hora inválida." );
				window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 );
				return false;
			}
			break;
	}

	return true;
}
