function ControlNumerico(Toma,Nombre,Minimo,Maximo,Decimales,Requerido) 
{
    var bien = true;
 	tira = new String(Toma);
	tira = QuitameComas(tira);
	var Mensaje = Nombre + " debe ser numérico."
	
	if (EsTodoNumero(tira,"S")==false)
	{
	alert(Mensaje);
	bien = false;
	
    return bien;
	}

	var valor = parseFloat(tira);
	var msg = "";
	var min = parseFloat(Minimo);
	var max = parseFloat(Maximo);
	var numDecimales = Decimales
    
	var Longitud = Trim(tira).length

	
	if (Longitud == 0)	
	{
		if (Requerido== false )
		{
		  
		 return bien;	
		}
		else 
		{
		bien = false;
		alert(Mensaje);
		
		return bien;
        }
    }    
	if (!isNaN(valor))
	{	
	   if (Decimales == 0)
	    {
	    posi = tira.indexOf(".")
	    if (posi != -1)
	    {
			alert("Revise puntos y decimales, por favor");
         	bien = false;
	        return bien;
	    
	    }
	    }
	
	    if (Decimales != 0)
	    {
		posi = tira.indexOf(".")
		if (posi > 0)
		{
			resto = Toma.substring(posi + 1,tira.length)			
			if (resto.length > numDecimales)
			{
			
			alert("Revise puntos y decimales, por favor");
			bien=false;
			return bien;
			}
		}
		}     		
		if ((valor < min) || (valor > max))
			{
				Mensaje = "Por favor,en " + Nombre + " introduzca un número entre " + min + " y " + max + ".";
				alert(Mensaje);
				bien=false;
				return bien;
			}
			else
			{
			
			
			return bien;
			}
	}
	else
	{
	alert(Mensaje);
	bien = false;
    return bien;
    }
 
return bien;   
}
function QuitameComas(Campo)
{
 var apoya="" ;
 for (var J = 0; J <Campo.length; J++)
  {
  if (Campo.substring(J,J+1) != ",")
       {
         apoya = apoya + Campo.substring(J,J+ 1);
       }
   }
   if (apoya == "." )
   {
   apoya = "0";
   }
  
   return apoya;
}

function PonmeComas(Valor,Decimales)
{
var Desde;

if (Valor == "")
{
return "";
}
var Destino="";
if (Decimales != 0)
{
var n = Valor.indexOf(".");
  if (n != -1)
  {
 
  var completa = CompletarDerecha(Valor.substring(n+1,n+Decimales+1),Decimales-1,"0");
  Destino ="." + completa;
  Desde= n-1;
  }
  else
  {
 
  Destino ="." + CompletarDerecha("",Decimales-1,"0");
  Desde = Valor.length-1;
  }
}
else
{
  Desde = Valor.length;
}

var fin =false;
var cuenta=0;
var i = Desde;
while (fin== false)
{ 
 if (Valor.charAt(i) == "-")
 {
   Destino = "-" + Destino;
   fin=true;
 }
 else
 {
   if (cuenta == 3) 
   {
       if (i > 0 && Valor.charAt(i-1) != "-")
       {
        Destino = "," + Valor.charAt(i) + Destino;
           
       }
       else
       {
       Destino =  Valor.charAt(i) + Destino;
         
       }
      cuenta=1;
   }
   else
   {
      cuenta= cuenta +1;
      Destino = Valor.charAt(i) + Destino;
     
   }
   i = i-1;
   if (i <0)
   {
    fin=true;
   }
 }
 
}


return Destino;
}
function CompletarDerecha(dame,longitud,relleno)
{
if (dame==null) dame ="";
while(dame.length <= longitud)
{
dame +=relleno;
}
return dame;
}
function Ceros(dame,label,longitud)
{
if (EsTodoNumero(dame,'Char','N')==false)
 {
 alert(label + ' debe ser numérico')
 return dame;
 }
 else
  {
 return  CompletarIzquierda(dame,longitud,'0')
  }
}
function CompletarIzquierda(dame,longitud,relleno)
{
if (dame==null) dame ="";
while(dame.length < longitud)
{
dame =relleno+dame;
}
return dame;
}


