﻿// Archivo JScript

     function trimLeft(str)
     {
       if (str+"" == "undefined" || str == null)	
  		 return null;
       if (str.length == 0) 
 		 resultStr = "";
        i=0;
        while ((i <= str.length-1) && (str.charAt(i) == " "))
			i++;
        return str.substring(i, str.length);
     }

     function trimRight(str)
     {
      
       if (str+"" == "undefined" || str == null)	
  		 return null;
       if (str.length == 0) 
 		 resultStr = "";
        i=str.length-1;
        while ((i > 0 ) && (str.charAt(i) == " "))
        {
           i--;
        }
        return str.substring(0,i+1);
     }


     function Trim(componente)
     {
         if (componente.value ==null)
           return;
         componente.value=trimLeft(componente.value);       
         componente.value=trimRight(componente.value);       
     }
     
    function noHTML (comp)
    {
      comp.value=comp.value.replace(/<\/?[^>]*>/g, " ");
    }
     

    function ComerEspacios (comp)
    {
      if (comp==null || comp.value==null ||comp.value.length==0)
         return;
      strAux="";
      for (i=0;i< comp.value.length;i++)
         if (comp.value.charAt(i)!=" ")
            strAux+=comp.value.charAt(i);
      comp.value=strAux;
    }
  
    
    function sinCaracteresBasura (comp)
    {
      if (comp==null || comp.value==null ||comp.value.length==0)
         return;
      strAux=comp.value;
      patron = /([\s]*)([\wáéíóúÁÉÍÓÚ.,ñÑ]*)([\s]*)([\W]*)/g;
      if (patron.test(strAux)) { strAux = strAux.replace(patron, '$1$2$3'); }
      comp.value=strAux;
    }
     
     
    function arreglarTexto(e)
    {
      hayEspacio=false;      
      srtAux='';
      strAux=e.value.charAt(0).toUpperCase();
      for (kk=1; kk < e.value.length; kk++)
      {
        if (e.value.charAt(kk)==' ')
        {
          if(!hayEspacio)
          {
            strAux+=' '
            hayEspacio=true;
          }
        }
        else
        {
          if (hayEspacio)
             strAux+=e.value.charAt(kk);
          else
             strAux+=e.value.charAt(kk).toLowerCase(); 
          hayEspacio=false;    
        }  
      }
      return strAux
    }
     
     
     
     function AuxiliarTexto(comp)
     {
      
        if (comp == null || comp.value ==null || comp.value.length==0 )
          return;

        noHTML (comp);
        Trim(comp);
       
        //Depuro qué funciones no debo realizar en base a un tipo
        switch(comp.type)  
        {
            //case "submit":
            //case "checkbox":
            //case "text":
            //case "textarea":
            //case "select":
            //case "select-one":
            //case "radio":
            case "file":   
            case "password":           
                             return;
                             break;               
        }                   
        

        //funciones especiales
       // i=comp.name.indexOf("txtCOperadorNombre",0) // en operadores, es el usuario
        //if (i!=-1)
         // ComerEspacios(comp);
            
         

        //Depuro qué funciones no debo realizar en base a un nombre
        i=comp.name.toLowerCase().indexOf("tbnombre",0) //nombre del label de inicio
        if (i!=-1)return;
        i=comp.name.toLowerCase().indexOf("tbclave",0) //nombre del label de password
        if (i!=-1)return;
        i=comp.name.toLowerCase().indexOf("txtcoperadornombre",0) // en operadores, es el usuario
        if (i!=-1)return;
        i=comp.name.toLowerCase().indexOf("nif",0) // ignoro los cif
        if (i!=-1)return;
        i=comp.name.toLowerCase().indexOf("cif",0) // ignoro los nif
        if (i!=-1)return;                
        i=comp.name.toLowerCase().indexOf("mail",0) // ignoro los mail
        if (i!=-1)return;                
        i=comp.name.toLowerCase().indexOf("txtcclave",0) // clave de operador
        if (i!=-1)return;                
        i=comp.name.toLowerCase().indexOf("txtcconfirmar",0) // confirmar teclas
        if (i!=-1)return;  
        i=comp.name.toLowerCase().indexOf("txtcnombre",0) // nombre usuario
        if (i!=-1)return;  
        i=comp.name.toLowerCase().indexOf("url",0) //dejo que los validadores propios validen la url
        if (i!=-1)return;  
        
        
        
        
        //sinCaracteresBasura(comp);
        
        i=comp.name.toLowerCase().indexOf("txtcadena",0) // ignoro el buscador principal
        if (i!=-1)return;                
        
        
        comp.value=arreglarTexto(comp);
     }    
     
     // José Miguel 17/10/2006 - es para controlar en los txtbox multilinea queno supere la cantidad de caracteres
     function ValidarLongitud(txt, max)
     {
        if(txt.value.length >= max){ 
            //alert('Has superado el tamaño máximo permitido = ' + txt.value.length); 
            txt.value = txt.value.substring(0, max)
            return false; 
        }; 
        return true
     }
