<!--

/*******************************************************************

Libreria de funciones para validar datos de formularios

******************************************************************/

/******************************************************************
Validacion de email
******************************************************************/
function isValidEmail( sEmail ) 
{ 
	var emailexp = /[a-z_0-9\-\.]@[a-z_0-9\-\.]+\.([a-z]{2}|[a-z]{3})$/i;
	if( emailexp.test( sEmail ) ) 
		return true;
	else 
		return false; 
} 

/******************************************************************
Devuelve el valor de un campo radio, independientemente del numero de elementos que tenga
******************************************************************/
function getRadioValue(element) 
{
	for (var n = 0; n < element.length; n++) 
	{
		if (element[n].checked)
			return element[n].value;
	}
	// Caso particular en el que hay solo un elemento en el objeto radio button
	// porque lentgh no devuelve nada.
	if (element.checked) 
		return element.value;
	else 
		return ("");
}

/******************************************************************
Esta funcion muestra un alert y pasa el foco al campo que queramos
******************************************************************/
function ShowMessage( element, message, BolSelect ) 
{
	alert( message );
	element.focus();
	if( BolSelect )
		element.select();
}

/******************************************************************
Validacion de fecha; se acepta cadena en blanco como valor incorrecto
******************************************************************/
function CheckDateInput( FieldName )
{
	if( FieldName.value == "" ) return false;

	var IntDay = FieldName.value.substring( 0, FieldName.value.indexOf( "-" ) );
	if( IntDay == "" || isNaN( IntDay ) || IntDay > 31 ) return false;

	var IntMonth = FieldName.value.substring( FieldName.value.indexOf( "-" ) + 1, FieldName.value.lastIndexOf( "-" ) );
	if( IntMonth == "" || isNaN( IntMonth ) || IntMonth > 12 ) return false;

	var IntYear = FieldName.value.substring( FieldName.value.lastIndexOf( "-" ) + 1, FieldName.value.length );
	if( IntYear == "" || isNaN( IntYear ) ) return false;

	if( CheckDate( IntYear, IntMonth, IntDay ) ) 
		{ return true; }
	else 
		{ return false; }
}

// funcion auxiliar para la validacion de fecha
function CheckDate( Year, Month, Day ) 
{
	DateFrom = new Date( Year, Month - 1, Day );
    if( DateFrom.getDate()!= Day || Day > DaysInMonth( Year, Month ) )
		{ return false; }
	else
		{ return true; }
} 

// funcion auxiliar para la validacion de fecha
function DaysInMonth( WhichYear, WhichMonth ) 
{
  var DaysInMonth = 31;

  if( WhichMonth == 4 || WhichMonth == 6 || WhichMonth == 9 || WhichMonth == 11) 
  	DaysInMonth = 30;

  else if( WhichMonth == 2 && ( WhichYear/4 ) != Math.floor( WhichYear/4 ) )
  	DaysInMonth = 28;

  else if( WhichMonth == 2 && ( WhichYear/4 ) == Math.floor( WhichYear/4 ) )
  	DaysInMonth = 29;

  return DaysInMonth;
}

/******************************************************************
A diferencia de isNaN esta funcion solo acepta enteros
******************************************************************/
function isInt(Num)
{
	if (isNaN(Num))
		return false;

	else if(Num.indexOf(".") == -1)
		return true;
		
	else
		return false;
}

/******************************************************************
Esta funcion devuelve un array con los Id de los elementos seleccionados 
en un select multiple
******************************************************************/
function getMultipleSelectId(objSelect)
{
	var selVals = new Array();
	var i, j, total;
	
	total = objSelect.length;

	for (i = j = 0; i < total; i++)
		if (objSelect.options[i].selected)
		{
			selVals[j] = i;
			j++;
		}
	
	return selVals;	
}
//-->