// ------------------------------------------------------------------------------------------
//	Funciones para la validacion de formularios
//
//	Author:	Daniel Gonzalez
//
//	Ultima actualizacion:		10/01/07
// ------------------------------------------------------------------------------------------


// ----------------------------------------------------------------------
//  Funciones auxiliares

// para mostrar errores personalizados
function showAlert( str )
{
	alert( str );
	//div = document.getElementById( "msgError" );
	//div.innerHTML = '<font color="#FF0000">' + str + </font><br>';
	//window.scrollTo( 0, 0 );
}

// limitacion del lenguaje: las cadenas que empiezan con 0 no las comvierte a interger
function toInt( str )
{
	idx = 0;
	while( str.charAt( idx ) == '0' )
		idx++;		
	return parseInt( str.substr( idx ) );
}

// ----------------------------------------------------------------------
//  Validacion de Fecha
function dia_IsValid( dia )
{
	if( isNaN( toInt( dia ) )	||
		toInt( dia ) < 1 || toInt( dia ) > 31 )
		return false;
	return true;
}
function mes_IsValid( mes )
{
	if( isNaN( toInt( mes ) )	||
		toInt( mes ) < 1 || toInt( mes ) > 12 )
		return false;
	return true;
}
function ano_IsValid( ano, min, max )
{
	if( isNaN( toInt( ano ) )	||
		toInt( ano ) < min || toInt( ano ) > max )
		return false;
	return true;
}

// ----------------------------------------------------------------------
function email_IsValid( sEmail )
{
	emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/

	if( !emailRe.test( sEmail ) )
		return false;

	return true;
}
