

//Funcion para valida la fecha
function validarNumero(numero)
{
	if(numero.length==0)
	{
		return true;
	}
	
	if (isNaN(numero*1))
      {
			alert("Debe introducir un valor numérico.")                	
			return false;
	}else if(numero<0){
				alert("Debe introducir un valor positivo.")                	
			return false;
	}
	return true;
	
}

function validarNumeroSinMensaje(numero)
{
	if(numero.length==0)
	{
		return true;
	}
	
	if (isNaN(numero*1))
    {              	
			return false;
	}else if(numero<0){                	
			return false;
	}
	return true;
	
}

function valorFecha(dia,mes,ano)
{		
	if (mes == 4  ||	
	    mes == 6  ||
	    mes == 9  ||
	    mes == 11)
	{
		if (dia > 30)
		{
			return false;	
		}else
		{
			return true;
		}
	}	
	else if (mes == 2 && dia == 29)
	{				
		if ((ano%4==0 && ano%100!=0) || (ano%400 == 0))
		{
			return true;
		}else
		{
			return false;
		}
	}else
	{
		return true;
	}
}

function validarFecha(fecha)
{
	
	if(fecha.length==0)
	{
		return true;
	}
	else if (fecha.length != 10)
	{
		alert("El campo de \"Fecha\" debe tener el formarto : \"dd/MM/aaaa\"");
		return false;
	}else
	{
		
		dia = fecha.substring(0,2);
		
		barra = fecha.substring(2,3);
		
		if(barra!="/")
		{
			alert("El campo de \"Fecha\" debe tener el formarto : \"dd/MM/aaaa\"");
			return false;
		}		
		valDia = parseInt(dia,10);
		mes = fecha.substring(3,5);
		valMes = parseInt(mes,10);
		barra = fecha.substring(5,6);
		if(barra!="/")
		{
			alert("El campo de \"Fecha\" debe tener el formarto : \"dd/MM/aaaa\"");
			return false;
		}	
		ano = fecha.substring(6,10);
		valAno = parseInt(ano,10);
		
		if (isNaN(dia*1))
		{
			alert("El valor introducido para los días: \"" + dia + "\" no es correcto");
                	return false;
		}else if (isNaN(mes*1))
		{
			alert("El valor introducido para el mes: \"" + mes + "\" no es correcto");
                	return false;
		}else if (isNaN(ano*1))
		{
			alert("El valor introducido para los año: \"" + ano + "\" no es correcto");
                	return false;
		}else if ((valDia < 1) || (valDia > 31))
		{
			alert("El valor introducido para los días: \"" + dia + "\" no es correcto");
                	return false;
		}else if ((valMes < 1) || (valMes > 12))
		{
			alert("El valor introducido para el mes: \"" + mes + "\" no es correcto");
                	return false;
		}else if (valAno < 2000)
		{
			alert("El valor introducido para los año: \"" + ano + "\" no es valido.\nEl año debe ser mayor que 2000");
                	return false;
		}else if (valorFecha(valDia,valMes,valAno))
		{
			return true
		}else
		{
			alert("La fecha introducida: \"" + fecha + "\" no es válida.");
                	return false;
		}
	}
}

function validarRango(minimo, maximo, valor)
{
	if (isNaN(valor))
 	{
   		alert("Debe introducir un valor num&eacute;rico");                	
       	return false;
 	}
 	else if (valor < minimo || valor > maximo)
 	{
   		alert("El valor debe estar entre " + minimo + " y " + maximo);                	
       	return false;
 	}
 	else
	 	return true;
}

function esBlanco(texto)
{
	if (Trim(texto) == "")
		return true;
	else
		return false;
}

function Trim(str) {
	var resultStr = "";
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	return resultStr;
}

function TrimRight(str) {
	var resultStr = "";
	var i = 0;
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
}

function TrimLeft(str) {
	var resultStr = "";
	var i = len = 0;
	if (str+"" == "undefined" || str == null)
		return "";
	str += "";
	
	if (str.length == 0)
		resultStr = "";
	else {
		len = str.length;
		while ((i <= len) && (str.charAt(i) == " "))
		i++;
		resultStr = str.substring(i, len);
	}
	return resultStr;
}

function isValidEmail(str)
{
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

