﻿// Archivo JScript
	//Validaciones numericas
	function ComprobarNum(Campo, sNombreCampo) 
	{
		var Cadena
		Cadena=Campo.value
		for (var x=0; x<Cadena.length;x++) 
		{
			c= Cadena.substring(x,x+1)
			if (c<"0"||c>"9") 
			{
				if (c!="-")
				{
					alert("El campo" + " " + sNombreCampo + " debe ser numerico.");
					Campo.focus();
					return true;
				} // del if
			} // del if
		} // del for
		return false;
	} // de comprobarNum
	
	function ComprobarNum2(Cadena,Campo) 
	{
		for (var x=0; x<Cadena.length;x++) 
		{
			c= Cadena.substring(x,x+1)
			if (c<"0"||c>"9") 
			{
				if (c!="-")
				{
					return true
				} // del if
			} // del if
		} // del foR
		return false
	}	
	
	//FUNCION PARA COMPROBAR CAMPOS NUMERICOS (CON O SIN DECIMALES)
	function decimales(Cantidad,NumeroDec,sNombreCampo)
	{
		var ValorDecimal=".";
		var ValorNoDecimal=","
	
		var Decimales= NumeroDec //Numero de decimales
		var Valor=Cantidad.value; //Numero 
		
		if (Valor.indexOf(ValorNoDecimal)!=-1)
		{
			//Valor no permitido (, en vez de .)
			alert("Recuerde: No incluya separadores de miles, y el valor decimal para los campos numericos es el punto (.)");
			Cantidad.focus();
			return false;
		}
		
		if (Valor.indexOf(ValorDecimal)!= -1) // Compruebo si es decimal
		{
			ParteEntera=Cantidad.value.substring(0,Cantidad.value.lastIndexOf(ValorDecimal));
			Centenas = Cantidad.value.substring(Cantidad.value.lastIndexOf(ValorDecimal)+1,Cantidad.value.length);
			
			//Compruebo cada una de las partes para ver si son numéricas
			if (ComprobarNum2(ParteEntera,Cantidad))
			{
				alert("La parte entera de " + " " + sNombreCampo + " debe ser numerica.");
				Cantidad.focus();
				return false
			}
			if (ComprobarNum2(Centenas,Cantidad))
			{
				alert("La parte decimal de " + " " + sNombreCampo + " debe ser numerica.");
				Cantidad.focus();
				return false
			}
			
			//Compruebo el numero de decimales
			if (Centenas.length>Decimales)
			{
				alert("Cantidad de " + sNombreCampo + " errónea")
				Cantidad.focus();
				return false
			}
			else
			{
				return true;
			}
		}
		else // Si no es decimal compruebo si es  numerico
		{
			if (ComprobarNum(Cantidad, sNombreCampo))
			{
				return false
			}
			return true;
		}
	}	
