// ------------------------------------------------------------------------------------------
//	Funciones para la validacion de formularios
//
//	Author:	Danix
//
//	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;
}

// ----------------------------------------------------------------------
//  TEMPLATE ejemplo, para la utilizacion de estas funciones
// ----------------------------------------------------------------------
/*
function onSubmitForm()
{
	var formDOMObj = document.UploadForm;

	campo = "";
	switch( "" ) {
		case formDOMObj.nombre.value:		campo = "Nombre";		break;
		case formDOMObj.apellido.value:		campo = "Apellido";	break;
		case formDOMObj.dni.value:			campo = "DNI";			break;

		case formDOMObj.direccion.value:	campo = "Dirección";	break;
		case formDOMObj.localidad.value:	campo = "Localidad";	break;
		case formDOMObj.provincia.value:	campo = "Provincia";	break;
		case formDOMObj.pais.value:			campo = "Pais";			break;
		//case formDOMObj.depto.value:		campo = "Estado";		break;
		//case formDOMObj.postal.value:		campo = "Código postal";		break;

		//case formDOMObj.telefono.value:		campo = "Telefono";		break;
		case formDOMObj.email.value:		campo = "E-mail";		break;
		//case formDOMObj.edad.value:			campo = "Edad";		break;
		case formDOMObj.dia.value:			campo = "Fecha de Nacimiento";		break;
		case formDOMObj.mes.value:			campo = "Fecha de Nacimiento";		break;
		case formDOMObj.ano.value:			campo = "Fecha de Nacimiento";		break;
		//case formDOMObj.e_civil.value:		campo = "Estado Civil";		break;
	}
	if( campo != "" )
	{
		showAlert( "El campo " + campo + " debe ser completado" );
		return false;
	}
	else
	{
		if( !dia_IsValid( formDOMObj.dia.value ) )
		{
			showAlert( 'El campo dia debe ser entre 1 y 31 !' );
			return false;
		}
		if( !mes_IsValid( formDOMObj.mes.value ) )
		{
			showAlert( 'El campo mes debe ser entre 1 y 12 !' );
			return false;
		}
		if( !ano_IsValid( formDOMObj.ano.value, 1906, 2006 ) )
		{
			showAlert( 'El campo año debe ser entre 1906 y 2006 !' );
			return false;
		}

		if( formDOMObj.pasaporte.value != "" )
		{
			if( !dia_IsValid( formDOMObj.pass_dia.value ) )
			{
				showAlert( 'El campo dia del vencimiento debe ser entre 1 y 31 !' );
				return false;
			}
			if( !mes_IsValid( formDOMObj.pass_mes.value ) )
			{
				showAlert( 'El campo mes del vencimiento debe ser entre 1 y 12 !' );
				return false;
			}
			if( !ano_IsValid( formDOMObj.pass_ano.value, 1996, 2016 ) )
			{
				showAlert( 'El campo año del vencimiento debe ser entre 1996 y 2016 !' );
				return false;
			}
		}
		if( !email_IsValid( formDOMObj.email.value ) )
		//if( formDOMObj.email.value.indexOf( "@" ) == -1 ||
		//	formDOMObj.email.value.indexOf( "." ) == -1 )
		{
			showAlert( 'El campo E-mail debe contener un e-mail valido!' );
			return false;
		}
	}
	//ventana()
	return true;
}
*/
