/**
 * <p>Title: validar.js </p>
 * <p>Description: Funciones de Validación Generales</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: 11dos </p>
 * @author Kiko
 * @version 1.0 - 20/04/2004
 * @version 1.1 - 04/05/2004 -- enteroValido 
 * @version 1.2 - 10/07/2004 -- decimalValido +  decimalPositivoValido
 */

//  checkDate( fecha) 			comprueba que la fecha pasada sea del formato dd/mm/yyyy
//
//  enteroValido (numero)		comprueba que la cadena pasada esta formada solo por numeros
//
//  isEmail (string)			comprueba que la cadena pasada sea una dirección de email válida
//
//  decimalValido(numero) 		comprueba que la cadena pasada es un número decimal válido
//
//  decimalPositivoValido(numero)	comprueba que la cadena pasada es un número decimal positivo válido
//

function checkDate(fecha) 
{  // comprueba si la fecha esta en el formato dd/mm/yyyy 
    if (fecha.length == 10)
    {
        if (fecha.substring(2,3) == '/' && fecha.substring(5,6) == '/') 
        {
            var day   
            var month;
            if (fecha.substring(0,1)=="0")
            	day = parseInt(fecha.substring(1,2));   
            else
            	day = parseInt(fecha.substring(0,2));
            if (fecha.substring(3,4)=="0")
            	month = parseInt(fecha.substring(4,5))-1; 
            else
            	month = parseInt(fecha.substring(3,5))-1; 
            var year  = parseInt(fecha.substring(6,10));  
            var test = new Date(year,month,day);
            if ((year == test.getFullYear()) && (month == test.getMonth()) && (day == test.getDate()))
            {
                return true;
            }
            else 
            {
            	//alert(day+"="+test.getDay());
            	//alert(month+"="+test.getMonth());
            	//alert(year+"="+test.getFullYear());
                alert ("fecha invalida");
                return false;
            }
        }
        else 
        {
            alert("separador incorrecto");
            return false;
        }
    }
    else 
    {
        alert("longitud invalida");
        return false;
    }
}
function enteroValido(nval)
{
	var erEntero = new RegExp(/^\d+$/);
	var valido = erEntero.test(""+nval);
	if ( valido )
	{
		return true;
	}
	else 
	{
		return false;
	}
}

function  decimalValido(nVal) 
{
  var objRegExp  =  new RegExp(/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/);
  //check for numeric characters
  return objRegExp.test(""+nVal);
}

function  decimalPositivoValido(nVal) 
{
  if (nVal < 0) return false;
  var objRegExp  =  new RegExp(/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/);
  //check for numeric characters
  return objRegExp.test(""+nVal);
}

function isEmail( strAux )
{
	var erEmail = /^[^@]+@[^\.]+(\.[^\.]+)+$/;
	var valida = erEmail.test( strAux );
	if ( valida )
	{
		return true;
	}
	else 
	{
		// txtError += "El e-mail es incorrecto.<br>";
		return false;
	}
}

function fncKeyStop(el) 
{
	// Check if the control key is pressed.
	// If the Netscape way won't work (event.modifiers is undefined),
	// try the IE way (event.ctrlKey)
	var ctrl = typeof event.modifiers == 'undefined' ? event.ctrlKey : event.modifiers & Event.CONTROL_MASK;
	// Check if the 'V' key is pressed.
	// If the Netscape way won't work (event.which is undefined),
	// try the IE way (event.keyCode)
	var v = typeof event.which == 'undefined' ? event.keyCode == 86 : event.which == 86;
	// If the control and 'V' keys are pressed at the same time
	if ( ctrl && v ) 
	{
		alert("No se puede pegar sobre este campo.");
		// ... discard the keystroke and clear the text box
		el.value = '';
		return false;
	}
	return true;
}
