	/* 
		=====================================================================
		=== Proposito:	Este archivo contiene funciones para validar Fechas,
		===				verificar numeros, cadenas vacias, trasformar un XML
		=== Programador: Israel Ochoa P. (OPI)
		=== E-mail:		israel_ochoap@hotmail.com, ochoai@hildebrando.com.mx
		=====================================================================
	*/
	
	var objFecha;	//
	var strFecha;	//Esta variable es moficada desde el calendario
	
	//Deshabiltamos el menu contextual del browser
	//document.onmousedown = MouseDown;	
	//document.oncontextmenu = MouseDown;
	
    function ValidarLongitud(Obj,NumCaracteres)
	 {
	  if (Obj.value != "")
	    {	    	    
	       var m
	       m = Obj.value.length
           if (m>=NumCaracteres+1)
             {
               alert("se ha excedido de " + NumCaracteres)
               Obj.value = Obj.value.substring(0,NumCaracteres)
               Obj.focus()
             }
        }
     }
	
    function MouseDown()
        {
        Boton = event.button;
        if(Boton==2)
            {
            alert('Por politicas de seguridad el código de esta página no puede ser mostrado');
            }
        else return false;

        }
        
	function  MuestraDatos(pXMLDoc,pXSLDoc,pDivHTML)
	{	/* 
	    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		::	Parameros:	XML ,XSL, DIVHTML                                   ::
		::				XML es el objeto que contiene los datos en XML      ::
		::				XSL es el objeto que tiene el Stilo para los datos  ::
		::				DIVHTML es el objeto donde se mostrara el resultado ::
		::				de la mezcla entre el XML y XSL                     ::
		::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		*/
		/* ::::: Asignamos los Documentos a Variables ::::: */	
		ObjXML = document.all(pXMLDoc);
		ObjXSL = document.all(pXSLDoc);
		ObjDIV = document.all(pDivHTML); 
		
		//alert(ObjXML.xml);
		//alert(ObjXSL.xml);
		
		ObjXML.preserveWhiteSpace=false;
		ObjXSL.preserveWhiteSpace=false;
		
		/* ::::: Identificamos si los Documentos (XML y XSL) estan bien formateados :::: */
		if (ObjXML.parseError.reason != "")	alert("xml: "+ObjXML.parseError.reason);
		if (ObjXSL.parseError.reason != "")	alert("xsl: "+ObjXSL.parseError.reason);	

		/*  :::: Verificamos si contiene el mensaje de Error :::: */
		objNodeList = ObjXML.getElementsByTagName("ERROR");  
		if (objNodeList.length >0) alert(objNodeList.item(0).nodeTypedValue);
		
		/*  :::: Verificamos si se Termino la Sesion :::: */
		objNodeList = ObjXML.getElementsByTagName("FINDESESION");  
		if (objNodeList.length >0) self.location = objNodeList.item(0).nodeTypedValue;

		
        /* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
           :: Realizamos la mezcla entre XML y XSL, y el resultado 
           :: se inserta en el Div Indicado 
           :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        */
        
		ObjDIV.innerHTML  = ObjXML.transformNode(ObjXSL.XMLDocument);
		//alert(ObjDIV.innerHTML);
		return true;
	}
	
        
	function LeePermiso(pPermiso)
		{
		/* 
		::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		:: Obtiene el Valor del Permiso que se Encuentra en La Pagina Principal ::::
		:: pPermiso = Permiso a Obtener su valor                                ::::
		:: Regresa el Valor del Permiso, En caso de Error lo indica y regresa 0 ::::
		::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		*/
		permiso = 'parent.top.'+pPermiso;
		permiso = eval(permiso);
		if (isNaN(permiso))
			{
			alert('Permiso: '+pPermiso+' no definido');
			return 0;
			}
		else return permiso;
		
		}
	
	function EsNumero(pValor,pstrMensaje)
		{/* Verifica si el parametro indicado es un Número */
			if(isNaN(pValor)==true || pValor =="")
			    {
			    if(pstrMensaje!="") alert(pstrMensaje);
			    return false;   
			    }
			 
			else return true;		
		}
	
	function Convierte_a_Numero(pValor)
	    {
            //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
            //:: Quita las comas que puediera tener un Número, ya que 
            //:: en JavaScript los números que contiene comas son tratados
            //:: como cadenas de caracteres y no como tales
            //::
            //:: Entradas : pValor es el número al cual se le van a quitar
            //::            las comas.
            //:: Salidas  : Regresa el Nuevo string con el Número pero sin
            //::            comas.
            //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
            
	        var dblValorSinComas ="";
	        if(pValor.indexOf(",")>=0) //:: Se verifica si el Numero biene con comas
                {
                pValor = pValor.split(","); //:: Creamos un arreglo de datos, separados por comas
                items = pValor.length;
                for(y=0;y<items;y++)
                    dblValorSinComas = dblValorSinComas + pValor[y];
                
                }
           else dblValorSinComas = pValor;
           
           return dblValorSinComas; //:: Regresamos el Número pero sin comas
                        
	    }
	    
    function strTrim(pStr)
        {
        //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        //:: Esta función quita espacios tanto a la Izquierda como a  ::
        //:: la derecha de una cadena de caracteres, parecida a la    ::
        //:: función de Visual Basic TRIM.                            ::
        //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        
        var Len = pStr.length;
        while (pStr.charAt(0)==" ")
            {
            pStr = pStr.substring(1);
            }

        Len = pStr.length;
        
        while (pStr.charAt(Len-1)==" ")
            {
            pStr = pStr.substring(0,Len-1);
            Len = pStr.length;
            }
        return pStr;
                
        }
    
    function EsMayordeCero(pValor,strMensaje)
        {
        if(pValor>0) return true;
        
        alert(strMensaje);
        return false;
        }
        
    function EstaVacio(pObj,strMensaje,strDivaMostrar)
        {
        if(pObj.value != "") return false;
        
        if (strMensaje != "" ) 
			{
			if(strDivaMostrar!=null) MuestraDatosTab(strDivaMostrar);
			alert(strMensaje);
			pObj.focus();
			}
        return true;
        }
        
    function ElementoSeleccionado(pObj,strMensaje)
		{
		if ((pObj.length==0) || (pObj.options[pObj.selectedIndex].value == "0") || (pObj.options[pObj.selectedIndex].value == "")) 
			{
			if (strMensaje != "" ) alert(strMensaje);
			pObj.focus();
			return false;
			}
			
		return true;
		}


//-----------------------------------------------------------------------------        
    function Verifica_Fecha(pstrFecha)
	    {
        // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        // :: Proposito : Verifica si pstrFecha, contiene un formato y fecha ::
        // ::             correcta, del tipo dd/mm/aaaa                      ::
        // :: Entradas  : pstrFecha, string a validar                        ::
        // :: Salidad   : True (Válida) o False (Incorrecta)                 ::
        // ::                                                                ::
        // :: Programador : Israel Ochoa P. (OPI)   Fecha: 5 Marzo 2001      ::
        // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        
        var strCharCorrectos = "0123456789/";
        var Fecha = pstrFecha;
	    if (Fecha == "")
		    return false;
	
	    for (i=0; i < Fecha.length;i++)
    		{   var car = Fecha.substr(i,1);
			    if (strCharCorrectos.indexOf(car)==-1)
			        {
				    return false;
				    }
		    }
	    
	    /* ::::::::::::::::::::::::::::::::::::::::::::::
	       Creamos un arreglo con los datos de la fecha 
	       separados por la diagonal
	       ::::::::::::::::::::::::::::::::::::::::::::::
	    */ dd=0
	       mm=1
	       aaaa=2
	    ArrayFecha = Fecha.split("/");
	    if(ArrayFecha.length!=3)
    	    return false;
    
	    var Dia  = Number(ArrayFecha[0]);
	    var Mes  = Number(ArrayFecha[1]);
	    var Anno = Number(ArrayFecha[2]);
	    var TemAno =String(ArrayFecha[2]);
	    
    	
    	if (TemAno.length != 4 )  return false;
    	if (Dia > 31 || Dia < 1 ) return false;
    	if (Mes >12 || Mes < 1 )  return false;
    	if (Mes == 4 || Mes == 6 || Mes == 9 || Mes == 11)
    	    {
	        if (Dia > 30 ) return false;
	        }	
	    if ( Mes == 2 )
	        {
    	    if ((Anno % 4)==0 )  /* Se verifica si el Anno es biciesto **/
			    { 
			    //alert(Dia > 29);
			    if (Dia > 29 ) return false;				
			    }
		    else{
				 if (Dia > 28) return false;
				}
            }
    
        return true;
	
        }

//-------------------------------------------------------------------       
		/*	
			Esta función selecciona el contenido de una caja de texto
			recibe como parametros el objeto a seleccionar
		*/
		function Selecciona(obj)
			{
			obj.select();
			}

//--------------------------------------------------------------------			
		/*
			Esta función muestra el calendario para seleccionar una fecha
			Recibe como parametro el nombre del objeto sobre el cual se regresara la 
			fecha seleccionada
		*/
		function MuestraCalendario(obj,Path)
				{
				if (Path!=null) var strURL = Path + "CalendarioJS.aspx";
				else var strURL = "../CalendarioJS.aspx";
				//var winCalendario= window.showModalDialog (strURL,"winCalendario","width=250,Height=200");
				var winCalendario = window.showModalDialog (strURL,self,"dialogHeight: 245px; dialogWidth: 215px; center: Yes; resizable: no; status: no;");
				if(strFecha!=null) obj.value = strFecha; 
				strFecha=null;
				}
				
		/*
			Esta función Válida que los datos que se capturen en la caja de texto
			sea un valor numérico correcto, si no es así, le asigna el valor de cero
			y lo enfoca
			regresa true o false		
		*/
		function Valida_Monto(obj)
			{
			var Monto = obj.value;
			if (EsNumero(Monto,"")==false)
				{
				alert('Por favor indique una cantidad correcta');
				obj.value = '';
				obj.focus();
				return false;
				}
			return true;
			
			}
			
		function Redondea(obj)
			{
			if (EsNumero(obj.value,"")==true)
				obj.value = RedondeaNumero(obj.value)
			else
				obj.value = 0;
			}
		
		function Ucase(pObj)
			{
			var str = strTrim(pObj.value);
			pObj.value = str.toUpperCase();
			}
			
		function ComparaFechas(pFecha1, pFecha2)
			{
			// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
			// :: Proposito : Realizar la comparación de dos fechas              ::
			// :: Entradas  : pFecha1 y pFecha2  fechas a comparar               ::
			// :: Salidad   : igual, menor, mayor o Error en fechas 			 ::
			// ::                                                                ::
			// :: Programador : Israel Ochoa P. (OPI)   Fecha: 24 Abril 2002     ::
			// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
			
			//Creamos los objetos de Tipo Fecha
			var pFechaIni = new Date();
			var pFechaFin = new Date();
			//Se verifica que las fechas tengan un formato correcto
			if((Verifica_Fecha(pFecha1)==true)&& (Verifica_Fecha(pFecha2)==true))
				{
				//generamos un arreglo para separar el mes dia y año de los strings
				pFecha1 = pFecha1.split("/");	
				pFecha2 = pFecha2.split("/");
				
				//A le indicamos a los objetos fecha el año, mes y dia
				pFechaIni.setFullYear (pFecha1[2],pFecha1[1],pFecha1[0]);
				pFechaFin.setFullYear (pFecha2[2],pFecha2[1],pFecha2[0]);

				//Se hace la comparación de las fechas
				if(pFechaIni.valueOf() == pFechaFin.valueOf())return "igual";
				if(pFechaIni.valueOf() < pFechaFin.valueOf()) return "menor";
				if(pFechaIni.valueOf() > pFechaFin.valueOf()) return "mayor";
			
				}
			else{
				alert('Las fechas indicadas no son correctas');
				return "Error en fechas"
				}
			
			}
			
            function VerificaCaracteres(Cadena,CaracteresValidos)
             {
                var i   = 0;  
                for(i = 0 ;i < Cadena.length ; i++ ) 
                   {
                     if( CaracteresValidos.indexOf(Cadena.charAt(i)) < 0 ) return false;
                   }
                return true;
             }		
             
             function ValidarCaracteres(obj,CaracteresNoValidos)
             {
               var i = 0 ;
               var cadSeparada = "";
               
                 for(i = 0 ;i < obj.value.length ; i++ ) 
                   {
                     if( CaracteresNoValidos.indexOf(obj.value.charAt(i)) > -1 ) 
                        {
                          for(i = 0 ;i < CaracteresNoValidos. length ; i++ ) 
                              {
                                cadSeparada += CaracteresNoValidos.charAt(i) + " ";
                              }
                              
                               alert("Caracteres no aceptados: \n"+cadSeparada);
                               return false;
                        }
                   }
               return true;
             }
             	
             function RedondeaNumero(pValue)
				{
				temp      = Number(pValue) * 100;
				return Math.round(temp)/100;
				
				}
				
				
function Habilita_text_otro(pctrLista,pctrOtro,pValueOtro) {
        
	    var strValue = new String();
	    var strListValue = new String();
	    
	    strListValue = pctrLista.value;
	    strValue = pValueOtro;

		if(strListValue==strValue)
			{
			eval("document.forms[0]." + pctrOtro + ".disabled=false");
			eval("document.forms[0]." + pctrOtro + ".focus()");
			}
		else{
			eval("document.forms[0]." + pctrOtro + ".value=''");
			eval("document.forms[0]." + pctrOtro + ".disabled=true");
			}


}

  function EsEmail(pObj,strMensaje,strDivaMostrar)
    {      
      dato = pObj.value;      
      s = dato
	  i = 1
      sLength = dato.length;
      while ((i < sLength) && (s.charAt(i) != "@"))
        { i++
        }
        if ((i >= sLength) || (s.charAt(i) != "@")) 
          dato = ""
        else 
          i += 2
          while ((i < sLength) && (s.charAt(i) != "."))
            { i++
            }
            if ((i >= sLength - 1) || (s.charAt(i) != "."))
              dato = ""                           
      if (dato == "")  
        {
          if(strDivaMostrar!=null) MuestraDatosTab(strDivaMostrar);
		  alert(strMensaje);
		  pObj.focus();
		  return false;
		} 
	  else
         return true;        
    }


function Ayuda()
		{
		window.open("http://fondos-dbweb:81/ayuda.html","ayuda","width=650,height=500");
		}
		
function valida_len_cp(control,strDivaMostrar)
	{
	if (control.value.length < 5)
		{
		alert("El código postal debe ser de 5 dígitos");
		if(strDivaMostrar!=null) MuestraDatosTab(strDivaMostrar);
		control.select();
		control.focus();
		return false;
		}
	}
