function numerico(pInString,piDecimal)
{
	var RefStringE = "1234567890";
	var RefStringD = "1234567890.";

	if (pInString.length==0)
		return false;
	if (piDecimal == 0)
		RefString = RefStringE ;
	else
		RefString = RefStringD;
	Punto = 0 ;
	for (Count=0; Count < pInString.length; Count++)
	{
		TempChar= pInString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)
		{
			return false;
		}
		if (TempChar == ".")
		{
			Punto = Punto + 1;
		} 
	}
	if (Punto > 1)
		return false;
	return true;
}

function ValidaFormatoFecha(pistrFecha)
	{
	var datFecha=pistrFecha;
	var strDia=datFecha.substring(0,datFecha.indexOf("/",0));
	var strMes=datFecha.substring(datFecha.indexOf("/",0)+1,datFecha.indexOf("/",datFecha.indexOf("/",0)+1));
	var strAnno=datFecha.substring(datFecha.indexOf("/",datFecha.indexOf("/",0)+1)+1,datFecha.length);
	/*if ((strDia.length == 1) || (strMes.length == 1) || (strAnno.length == 2))*/
	if ((strDia.length < 1) || (strDia.length > 2) || (strMes.length < 1) || (strMes.length > 2) || (strAnno.length < 4))
		{
			return (false);
		}
	else
		return (true);
	}
	
function ValidarFecha(pistrFechaA)
	{
	var strNuevaFecha
		if ((pistrFechaA.substring(1,2) == "/") || (pistrFechaA.substring(1,2) == "-"))
			{
			iDia = "0" + pistrFechaA.substring(0,1);
			strNuevaFecha = iDia + pistrFechaA.substring(1,pistrFechaA.length);
			pistrFechaA = strNuevaFecha;
			}
		if ((pistrFechaA.substring(4,5) == "/") || (pistrFechaA.substring(4,5) == "-"))
			{
			iMes = "0" + pistrFechaA.substring(3,4);
			strNuevaFecha = pistrFechaA.substring(0,3) + iMes + pistrFechaA.substring(4,pistrFechaA.length);
			pistrFechaA = strNuevaFecha;
			}
	if (pistrFechaA.length == 8) 
		{
		iFecha = parseFloat(pistrFechaA.substring(6,8))
		if (iFecha > 20)			
			{
			strNuevaFechaA = pistrFechaA.substring(0,6) + "19" + pistrFechaA.substring(6,8)
			}
		else
			{
			strNuevaFechaA = pistrFechaA.substring(0,6) + "20" + pistrFechaA.substring(6,8)
			}
		pistrFechaA = strNuevaFechaA
		}
	strNuevaFechaA = pistrFechaA.substring(0,2) + pistrFechaA.substring(3,5) + pistrFechaA.substring(6,10);
	strSlash       = pistrFechaA.substring(2,3) + pistrFechaA.substring(5,6);	
	if (!(strNuevaFechaA.length == 0))
		{
		if (!(numerico(strNuevaFechaA,0)))
			{
			return(false) ;
			}
		else
			{                                                                                                                                                                                                                        
			if ((strSlash != "//") && (strSlash != "--"))
				{
				return(false);	
				}
			else
				{
				if (!(Bisiesto(strNuevaFechaA)))
					{
					return(false);
					}	
				}
			}
		}

	if ((pistrFechaA.length != 8) && (pistrFechaA.length != 10) && (pistrFechaA.length !=0))
		{
		return(false);
		}
	return(true);
	}
	
function Bisiesto(pistrFecha)
{
	anno  = pistrFecha.substring(4,8);
	mes1   = pistrFecha.substring(2,4);
	dia   = pistrFecha.substring(0,2);	
	resto = anno % 4;
	if ((mes1 == 1) || (mes1 == 3) || (mes1 == 5) || (mes1 == 7) ||(mes1 == 8) || (mes1 == 10) || (mes1 == 12))
	{
		maxdia = 31;
	}
    else
	{
		if (mes1 == 2)
		{
			if (resto == 0)
			{
				maxdia = 29;
			}
			else
			{
				maxdia = 28 ;
			}
		}
		else
		{
			if ((mes1 == 4) || (mes1 == 6) || (mes1 == 9) || (mes1 == 11))
			{
				maxdia = 30;
			}
			else
			{
				return(false);
			}
		}   
	}
	if ((dia > maxdia) || (dia < 1))
		return(false);
	if ((anno > 2500) || (anno < 1800))
		return(false);
	return (true);
}

function ValidarFechaFormulario ( formulario, campo )
{
	if ((ValidaFormatoFecha(document.forms[formulario].elements[campo].value)==false) || 
	    (ValidarFecha(document.forms[formulario].elements[campo].value)==false))	    
	{
		alert('Fecha incorrecta');
		return false;
	}else{
		return true;
	}
}		

function EsVacio ( formulario, campo )
{
	
	var i=1;
	var blancos ='';

	
	while (i<=document.forms[formulario].elements[campo].value.length)
        {
           blancos = blancos + ' ';
           i++;
        }   	
        return (document.forms[formulario].elements[campo].value == blancos);
}        
        
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function Entero(formulario, campo) {
	
	if (isNaN(document.forms[formulario].elements[campo].value)){
   	   alert('El campo debe ser un número entero');
   	   alert (campo);
   	   document.forms[formulario].elements[campo].focus();
   	   return false;
   	}   
   	else
   	  if (document.forms[formulario].elements[campo].value.indexOf('.') != -1){
   	    alert('El campo debe ser un número entero');
   	    document.forms[formulario].elements[campo].focus();
   	    return false;
   	  }
   	return true;
}	  
   	           