 /* Especiales */         
    function std_ValRangoFechas( strFecIni , strFecFin){          
        var dFecIni = new Date(Number(strFecIni.charAt(6)+strFecIni.charAt(7)+strFecIni.charAt(8)+strFecIni.charAt(9))
                              ,Number(strFecIni.charAt(3)+strFecIni.charAt(4))
                              ,Number(strFecIni.charAt(0)+strFecIni.charAt(1)));      
        var dFecFin = new Date(Number(strFecFin.charAt(6)+strFecFin.charAt(7)+strFecFin.charAt(8)+strFecFin.charAt(9))
                              ,Number(strFecFin.charAt(3)+strFecFin.charAt(4))
                              ,Number(strFecFin.charAt(0)+strFecFin.charAt(1)));
        if(dFecIni > dFecFin){
          alert("La Fecha Inicio no puede ser mayor a la Fecha Fin.");
          return false;
        } 
        return true;            
    }
    function std_ValDifFechas( strFecIni, strFecFin, strDias ){
    
        var dFecIni = new Date(Number(strFecIni.charAt(6)+strFecIni.charAt(7)+strFecIni.charAt(8)+strFecIni.charAt(9))
                              ,Number(strFecIni.charAt(3)+strFecIni.charAt(4))-1
                              ,Number(strFecIni.charAt(0)+strFecIni.charAt(1)));      
                              
        var dFecFin = new Date(Number(strFecFin.charAt(6)+strFecFin.charAt(7)+strFecFin.charAt(8)+strFecFin.charAt(9))
                              ,Number(strFecFin.charAt(3)+strFecFin.charAt(4))-1
                              ,Number(strFecFin.charAt(0)+strFecFin.charAt(1)));
                                                            
        iDias = parseInt(strDias,10);
        iDif  = parseInt(std_CountDay(dFecIni , dFecFin),10);
        
        if( iDif  >  iDias  ){
          alert("El intervalo de consulta no debe ser mayor de " + strDias + " dias." );
          return false;
        } 
        return true;            
    }    
    function std_CountDay(dateBegin, dateEnd) {    
      var iCount = 0;
      while (dateBegin <= dateEnd) {
        iCount++;
        dateBegin.setDate(dateBegin.getDate() + 1);
      }
      return iCount;
    }    
    
    
/* limites menor y mayor */
    function std_Val_MinMax(obj){
    //alert("in std_Val_MinMax 1");
        if ( obj.value == "" ) return true;    
        //alert("in std_Val_MinMax 2");
        switch (obj.tipoDato){
          case "ENTERO"   : return std_Val_MinMaxEntero(obj); 
                            break ; 
          case "DECIMALES": return std_Val_MinMaxEntero(obj); 
                            break;
          case "TEXTO"    : return true ;
                            break;
          case "FECHA"    : return true; //std_Val_MinMaxFecha(obj) ;
                            break;
          case "HORA"     : return true ;
                            break;
          case "TARGET"   : return true ;
                            break;
          case "COLOR"    : return  true;
                            break;
        }        
        return true;  
    }
    function std_Val_MinMaxEntero(obj){//alert(" obj.value=" + obj.value + " minValue=" +obj.minValue + " maxValue=" + obj.maxValue);
        if ( obj.value == "" ) return true;
          if (obj.minValue!=""){
              if ( Number(obj.value) < Number(obj.minValue) ){
                  alert("La valor no debe ser menor a " + obj.minValue );
                  return false;
              }
          }
          if (obj.maxValue!=""){
              if ( Number(obj.value) > Number(obj.maxValue) ){
                  alert("La valor no debe ser mayor a " + obj.maxValue );
                  return false;
              }
          }
    }
    function std_Val_MinMaxFecha(obj){  //alert("name\t=" + obj.name  +  " \nvalue\t=" +  obj.value +  " \nminValue\t=" + obj.minValue + " \nmaxValue\t="  + obj.maxValue);      
          if ( obj.value == "" ) return true;   
          valor = obj.value
          d1=valor.charAt(0) // <=3
          d2=valor.charAt(1) // <=9  
          m1=valor.charAt(3) //<=1
          m2=valor.charAt(4) //<=9  
          a1=valor.charAt(6) //<2
          a2=valor.charAt(7) //<=9
          a3=valor.charAt(8) //<=9
          a4=valor.charAt(9) //<=9                                              
          dHoraIni = new Date(Number(a1+a2+a3+a4),Number(m1+m2) - 1,Number(d1+d2));               
          if (obj.minValue!=""){
            var FechaTopeMinimo = new Date();
            if ( obj.minValue.indexOf("now")>=0 ){
                if (obj.minValue.indexOf("+")>0){
                  v2 = obj.minValue.substring(obj.minValue.indexOf("+")+1, obj.minValue.lenght);
                  FechaTopeMinimo.setDate( FechaTopeMinimo.getDate() + Number(v2) );
                }else{
                  v2= obj.minValue.substring(obj.minValue.indexOf("-")+1, obj.minValue.lenght);            
                  FechaTopeMinimo.setDate( FechaTopeMinimo.getDate() - Number(v2) );  
                }            
                strFechaTopeMinimo= FechaTopeMinimo.getDay() + "/" + FechaTopeMinimo.getMonth()+"/"+ FechaTopeMinimo.getYear();
            }else{
                valorMin = obj.minValue;        
                d1=valorMin.charAt(0) // <=3
                d2=valorMin.charAt(1) // <=9    
                m1=valorMin.charAt(3) //<=1
                m2=valorMin.charAt(4) //<=9    
                a1=valorMin.charAt(6) //<2
                a2=valorMin.charAt(7) //<=9
                a3=valorMin.charAt(8) //<=9
                a4=valorMin.charAt(9) //<=9                                              
                FechaTopeMinimo = new Date(Number(a1+a2+a3+a4),Number(m1+m2) - 1,Number(d1+d2));    
                strFechaTopeMinimo = Number(d1+d2) + "/" + Number(m1+m2)  + "/" + Number(a1+a2+a3+a4)
            }
            if ( dHoraIni < FechaTopeMinimo ){
                alert("La fecha no debe ser menor a " + strFechaTopeMinimo );
                return false;
            }
          }  
          if (obj.maxValue!=""){
            var FechaTopeMaximo = new Date();
            if ( obj.maxValue.indexOf("now")>=0 ){
                if (obj.maxValue.indexOf("+")>0){
                  v2= obj.maxValue.substring(obj.maxValue.indexOf("+")+1, obj.maxValue.lenght);             
                  FechaTopeMaximo.setDate( FechaTopeMaximo.getDate() + Number(v2) );
                }else{
                  v2= obj.maxValue.substring(obj.maxValue.indexOf("-")+1, obj.maxValue.lenght);             
                  FechaTopeMaximo.setDate( FechaTopeMaximo.getDate() - Number(v2) );
                }            
                strFechaTopeMaximo= FechaTopeMaximo.getDay() + "/" + FechaTopeMaximo.getMonth()+"/"+ FechaTopeMaximo.getYear();
            }else{
                valorMax = obj.maxValue;        
                d1=valorMax.charAt(0) // <=3
                d2=valorMax.charAt(1) // <=9    
                m1=valorMax.charAt(3) //<=1
                m2=valorMax.charAt(4) //<=9    
                a1=valorMax.charAt(6) //<2
                a2=valorMax.charAt(7) //<=9
                a3=valorMax.charAt(8) //<=9
                a4=valorMax.charAt(9) //<=9                                              
                FechaTopeMaximo = new Date(Number(a1+a2+a3+a4),Number(m1+m2) - 1,Number(d1+d2));    
                strFechaTopeMaximo = Number(d1+d2) + "/" + Number(m1+m2)  + "/" + Number(a1+a2+a3+a4)
            }        
            if ( dHoraIni > FechaTopeMaximo ){
                alert("La fecha no debe ser mayor a " + strFechaTopeMaximo );
                return false;
            }
          }  
          return true;    
    }    

/*  Validaciones  de captura */
    function std_ValidaCaptura(e, obj) {    
	
        var charCode;        
        if (navigator.appName == "Netscape")  charCode = e.which   
        else                                  charCode = e.keyCode;         
//        alert(obj.maxLen);
          if ( obj.maxLen != "" ){      //alert("obj.value.length=" + obj.value.length + " obj.maxLen=" + obj.maxLen);
            if  (  obj.value.length > obj.maxLen ) return false;    
          }              
        switch (obj.tipoDato){
          case "ENTERO"   : return  std_isNumericEntero     (charCode) 
                                   || ( (Number(obj.minValue) < 0) && (charCode == 45) )  ; 
                            break; //ok
          case "DECIMALES": if (charCode== "46" &&  obj.value.indexOf(".")>=0 ) return false;
                            return  std_isNumericDecimales  (charCode) || 
                            ( (Number(obj.minValue) < 0) && (charCode == 45) ); 
                            break;
          case "TEXTO"    :  //alert(charCode);
                            charCode = ((String.fromCharCode(charCode)).toUpperCase()).charCodeAt(0);
                            if ( obj.upper=="true" )  
                                if (navigator.appName == "Netscape")  e.which   = charCode;
                                else                                  e.keyCode = charCode;                           
                            
                            return  std_isTexto             (charCode); break;
          case "FECHA"    : //alert(" code="+charCode);
                            return  std_isFecha             (charCode); 
                            break;
          case "HORA"     : if (charCode== "58" &&  obj.value.indexOf(":")>=0 ) return false;
                            return  std_isHora              (charCode); break;
          case "TARGET"   :                                         break; //ok
          case "COLOR"    : return  std_isHexadecimalNumeric(charCode); break; //ok
        }
    }
    function std_isNumericEntero   (num){  return (num>=48 && num<=57) ;}
    function std_isNumericDecimales(num){  return (num>=48 && num<=57 || num==46);}
    function std_isLetterCode      (key){  return (key>=65 && key<=90 || key==192)  || (key>=97 && key<=122) ;}
    function std_isTexto (num){//alert(num);
        /* 
           33 !   34 "    35 #    36 $    37 %    38 &    39 '    40 (   41 )    42 *    43 +   44 ,    45 -   46 .    47 / 
           58 :   59 ;    60 <    61 =    62 >    63 ?    64 @
           91 [   92 \    93 ]  
           95 _              
           98 ^
           123 {  124 |   125 }           
           193 Á  201 É   205 Í   211 Ó   218 Ú
           225 á  233 e   237 í   243 ó   250 ú           
           
            96 `
           191 ¿   192 À   193 Á
           196 ä
           200 È   201 É
           203 ë   204 Ì   205 Í
           207 ï      
           210 Ò   211 Ó
           214 ö
           217 Ù   218 Ú
           220 ü
           224 à   225 á
           228 Ä
           232 è   233 e
           235 Ë   236 ì   237 í
           239 Ï           
           242 ò   243 ó
           246 Ö
           249 ù
           250 ú
           252 Ü
           196 ä
           203 ë
           207 ï
           214 ö
           220 ü           
           228 Ä
           235 Ë
           239 Ï
           246 Ö
           252 Ü                         
           192 À
           200 È
           204 Ì
           210 Ò
           217 Ù            
           224 à
           232 è
           236 ì
           242 ò 
           249 ù           
        */
        return (std_isNumericEntero(num) || std_isLetterCode(num))
            || (num>=32 && num<=47 && num!=37) || (num>=58 && num<=64) || (num>=91 && num<=93)
            || num == 95  || num == 89
            || num == 123 || num == 124 || num == 125
            //|| num == 193 || num == 201 || num == 205 || num == 211 || num == 218  // LETRAS CON ACENTOS  
            || num == 225 || num == 233 || num == 237 || num == 243 || num == 250
            || num == 209 || num == 241                 
           || num == 96 //`
           || num == 191 //¿  
           || num == 233 //e
           ;
        
           //|| num == 192 //À   
           //|| num == 193 //Á
           //|| num == 196 //ä
           //|| num == 200 //È   
           //|| num == 201 //É
           //|| num == 203 //ë   
           //|| num == 204 //Ì   
           //|| num == 205 //Í
           //|| num == 207 //ï      
           //|| num == 210 //Ò   
           //|| num == 211 //Ó
           //|| num == 214 //ö
           //|| num == 217 //Ù   
           //|| num == 218 //Ú
           //|| num == 220 //ü
           //|| num == 224 //à   
           //|| num == 225 //á
           //|| num == 228 //Ä
           //|| num == 232 //è           
           //|| num == 235 //Ë   
           //|| num == 236 //ì   
           //|| num == 237 //í
           //|| num == 239 //Ï           
           //|| num == 242 //ò   
           //|| num == 243 //ó
           //|| num == 246 //Ö
           //|| num == 249 //ù
           //|| num == 250 //ú
           //|| num == 252 //Ü
           //|| num == 196 //ä
           //|| num == 203 //ë
           //|| num == 207 //ï
           //|| num == 214 //ö
           //|| num == 220 //ü           
           //|| num == 228 //Ä
           //|| num == 235 //Ë
           //|| num == 239 //Ï
           //|| num == 246 //Ö
           //|| num == 252 //Ü                         
           //|| num == 192 //À
           //|| num == 200 //È
           //|| num == 204 //Ì
           //|| num == 210 //Ò
           //|| num == 217 //Ù            
           //|| num == 224 //à
           //|| num == 232 //è
           //|| num == 236 //ì
           //|| num == 242 //ò 
           //|| num == 249 //ù
        
    }
    function std_isFecha(charCode){   return (charCode>=47 && charCode<=57); }
    function std_isHora(charCode) {   return (charCode>=48 && charCode<=58); }
    function std_isHexadecimalNumeric(charCode){
        if (  (charCode < 97 || charCode > 102)  && ( charCode < 48 || charCode > 57 ) && ( charCode < 65 || charCode > 70 ) ){
          return false;
        }
        return true;
    }
    function std_isNumericChar(num) {
        return num=='0' || num=='1' || num=='2' || num=='3' || num=='4' || num=='5' || num=='6' || num=='7' || num=='8' || num=='9';
    }

/*  validaciones deformato lost focus */
    function std_ValidaFormato(e, obj) {      
    //alert("in std_ValidaFormato"); 
        var charCode;
        pTipo = obj.tipoDato;
        pLongitud = obj.value.length;    
        switch (pTipo){
          case "ENTERO"   : return  stdVal_Entero_Formato  (obj); break; //ok
          case "DECIMALES": return  stdVal_Entero_Formato  (obj); break; //ok
          case "TEXTO"    : return  stdVal_Texto_Formato   (obj); break;
          case "FECHA"    : return  stdVal_Fecha_Formato   (obj); break;
          case "HORA"     : return  stdVal_Hora_Formato    (obj); break;
          case "TARGET"   :                                       break; //ok
          case "COLOR"    :                                       break; //ok
       }
    } 
    function stdVal_Entero_Formato  (obj) {
        if ( obj.value == '' ) return true;      
        
         //alert("1");
         
//var splitStr = obj.value.split('.');
//var splitLeft = splitStr[0];
//var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';


  //       obj.value=splitLeft;
         //obj.value= obj.value.replace(",","");

//alert(" splitLeft=" + splitLeft+ " splitRight=" + splitRight + "  obj.value=" + obj.value);
         
        //frm_moneda(obj);
        //alert("1111");
        
        //alert("-"+Number(obj.value)+"-");
        if (isNaN(obj.value)){ 
            alert("El valor debe ser numerico.");
            obj.focus();
            return false;
        }
        if (obj.minValue!= "" ){
            if ( Number(obj.value) < Number(obj.minValue) ){
                    obj.focus();
                    alert("El valor no puede ser menor a " + toCurrencyOnly(obj.minValue) + ".");
                    obj.focus();
                    return false;
            }
        }
        if (obj.maxValue!= "" ){        
            if ( Number(obj.value) > Number(obj.maxValue) ){
                    obj.focus();
                    alert("El valor no puede ser mayor a " + toCurrencyOnly(obj.maxValue) + ".");
                    obj.focus();
                    return false;
            }
        }         
       
    }            
    
    
function frm_moneda( fld ){
milSep=",";
decSep=".";

          //aux += ""; 
          aux = fld.value + "";

          len = aux.length; 

          if (len == 0) fld.value = ''; 

          if (len == 1) fld.value = '0'+ decSep + '0' + aux; 

          if (len == 2) fld.value = '0'+ decSep + aux; 

          if (len > 2) { 
            aux2 = ''; 
            for (j = 0, i = len - 3; i >= 0; i--) { 
                if (j == 3) { 
                    aux2 += milSep; 
                    j = 0; 
                } 
                aux2 += aux.charAt(i); 
                j++; 
            } 
             fld.value = ''; 
             len2 = aux2.length; 
           for (i = len2 - 1; i >= 0; i--) 
                fld.value += aux2.charAt(i); 
           fld.value += decSep + aux.substr(len - 2, len); 
          } 
          
}    
    
    function stdVal_Texto_Formato  (obj) {
        if ( obj.value == ''  ) return true;              //alert("-"+Number(obj.value)+"-");
        //alert();
       // if ( obj.upper=="true" ) obj.value = obj.value.toUpperCase();            
    }
    function stdVal_Fecha_Formato(obj){
    
        valor=obj.value;
        if (valor=='') {        
            return true;
        }else{
            if (valor.length>10) {
                //alert("valor.legtn >10");
                obj.focus();
                alert("Introdujo una cadena mayor a 10 caracteres");
                obj.focus();
                return false;
            }else{
                  if (valor.length!=10) {
                      obj.focus();
                      alert("Introducir DD/MM/AAAA");
                      obj.focus();
                      return false;
                  }else{
                        d1=valor.charAt(0) // <=3
                        d2=valor.charAt(1) // <=9
                        sep1=valor.charAt(2) // /
                        m1=valor.charAt(3) //<=1
                        m2=valor.charAt(4) //<=9
                        sep2=valor.charAt(5) // 
                        a1=valor.charAt(6) //<2
                        a2=valor.charAt(7) //<=9
                        a3=valor.charAt(8) //<=9
                        a4=valor.charAt(9) //<=9                                                                
                        if(!std_isNumericChar(d1 ) || !std_isNumericChar(d2)) { obj.focus();alert("El valor que introdujo en el dia no corresponde, introduzca un digito entre 01 y 31"); obj.focus(); return false;}
                        if(!std_isNumericChar(m1 ) || !std_isNumericChar(m2)) { obj.focus();alert("El valor que introdujo en el mes no corresponde, introduzca un digito entre 01 y 12");obj.focus();return false;}        
                        if(!std_isNumericChar(a1 ) || !std_isNumericChar(a2) || !std_isNumericChar(a3) || !std_isNumericChar(a4)) { obj.focus();alert("El valor que introdujo en el año no es valido."); obj.focus(); return false;}
                        if (sep1!="/" || sep2!="/"  ) { str.focus();alert("Caracter no valido como separador."); obj.focus(); return false;}
    //alert("stdVal_Fecha_Formato dia=" + Number(d1+d2)  + " mes=" +  Number(m1+m2) );
                        if( (Number(d1+d2)<1) || (Number(d1+d2)>31)      ){
                            obj.focus();
                            alert("El valor que introdujo en el Día no corresponde, introduzca un digito entre 01 y 31"); 
                            obj.focus(); 
                            return false;
                        }
                        if( (Number(d1+d2)<1) || (Number(d1+d2)>31)      ){
                            obj.focus();
                            alert("El valor que introdujo en el Día no corresponde, introduzca un digito entre 01 y 31."); 
                            obj.focus(); 
                            return false;
                        }
                        if( (Number(m1+m2)<1) || ( Number(m1+m2)>12)    ){
                            obj.focus();
                            alert("El valor que introdujo en el Mes no corresponde, introduzca un digito entre 01 y 12."); 
                            obj.focus(); 
                            return false;
                        }
                        if( ( Number(a1+a2+a3+a4)<1900)    ){
                            obj.focus();
                            alert("El valor que introdujo en el Año no es valido."); 
                            obj.focus(); 
                            return false;
                        }                                            
                        if ((Number(m1+m2)==4 || Number(m1+m2)==6 || Number(m1+m2)==9 || Number(m1+m2)==11) && Number(d1+d2)==31)	{
                            obj.focus();
                            alert("El mes "+Number(m1+m2)+" no tiene 31 dias.")
                            obj.focus();
                            return false
                        }		  
                        if (Number(m1+m2) == 2) 	{ // check for february 29th
                          var isleap = (Number(a1+a2+a3+a4) % 4 == 0 && (Number(a1+a2+a3+a4) % 100 != 0 || Number(a1+a2+a3+a4) % 400 == 0));
                          if (Number(d1+d2)>29 || (Number(d1+d2)==29 && !isleap)){ 
                            obj.focus();
                            alert("Febrero de " + Number(a1+a2+a3+a4) + " no tiene " + Number(d1+d2) + " dias");
                            obj.focus();
                            return false;
                          }
                        }                   
                        return true;
                  }
            }
        }
    }
    function stdVal_Hora_Formato(str){
        valor=str.value;
        if (valor=='') {
            str.focus();
            alert("La Hora no puede ser vacia.");
            str.focus();
          return false
        }else{
            if (valor.length>5) {
            str.focus();
                alert("Introdujo una cadena mayor a 5 caracteres.");
                str.focus();
                return false;
            }else{
                  if (valor.length!=5) {
                  str.focus();
                      alert("Introducir HH:MM");
                      str.focus();
                      return false;
                  }else{
                        h1=valor.charAt(0) //<=2
                        h2=valor.charAt(1) //<=9
                        sep3=valor.charAt(2) //:
                        min1=valor.charAt(3) //<=5    
                        min2=valor.charAt(4) //<=9  
                        if(!isNumericChar(h1 )   || !isNumericChar(h2))   { str.focus();alert("El valor que introdujo en la Hora no corresponde, introduzca un digito entre 00 y 23."); str.focus(); return false;}
                        if(!isNumericChar(min1 ) || !isNumericChar(min2)) { str.focus();alert("El valor que introdujo en los minutos no corresponde, introduzca un digito entre 00 y 59.");str.focus();return false;}                            
                        if (sep3!=":") { str.focus();alert("Caracter no valido como separador."); str.focus(); return false;}
                        if( Number(h1+h2)>24 ){
                            str.focus();
                            alert("El valor que introdujo en la Hora no corresponde, introduzca un digito entre 00 y 23."); 
                            str.focus(); 
                            return false;
                        }
                        if( Number(min1+min2)>60 ){
                            str.focus();
                            alert("El valor que introdujo en los Minutos no corresponde, introduzca un digito entre 00 y 59."); 
                            str.focus(); 
                            return false;
                        }
                        return true;   
                  }
            }
        }
    }
              
              
function toCurrencyOnly(strValue) {
  strValue = strValue.replace(/([^0-9])/g, "");
	strValue = strValue.replace(/^0*/, "");
	return toFormatCurrency(strValue);
}
function toFormatCurrency(strAmount, iMaxLength) {
	var strEntero = "";
	var strDecimal = "";
	var strBuff = "";
	var iAux = 0;
 	var arrNumber = strAmount.split(".");

 	strEntero = arrNumber[0];
	if(arrNumber.length > 1) strDecimal = arrNumber[1];		

	for (var i = strEntero.length; i > 0; i--) {
		if (iAux % 3 == 0 && iAux != 0) strBuff = strEntero.charAt(i - 1) + "," + strBuff;
		else strBuff = strEntero.charAt(i - 1) + strBuff;
		iAux++;
		if(iAux >= (iMaxLength - (iMaxLength % 4))) {
			break;
		}
	}
	if (strDecimal != "") strBuff += "." + strDecimal;
	return strBuff;
}              
