ÿþ/ /   F U N C I O N E S   D E   V A L I D A C I Ó N :  
 / /   * * * * * * * * * * * * * * * * * * * * * * *  
 / /   e s t a _ v a c i o   -   q u e   e l   c a m p o   n o   e s t é   v a c í o  
 / /   e s n u m e r i c o   -   q u e   e l   c a m p o   s e a   n u m é r i c o   ( e j . :   4 . 5 6 )  
 / /   s o l o _ n u m e r o s   -   q u e   s ó l o   c o n t e n g a   n ú m r o s   ( e j . :   3 4 7 5 3 7 6 8 3 4 6 5 8 7 3 4 5 )  
 / /   d e c i m a l _ c o m a   -   q u e   s ó l o   c o n t e n g a   n ú m r o s   ( e j . :   3 4 7 5 3 7 6 8 3 4 6 5 8 7 3 4 5 )   o   ' , '  
 / /   s o l o _ l e t r a s   -   q u e   s ó l o   c o n t e n g a   l e t r a s   ( e j . :   y u w e k w e h H U E R Y I )  
 / /   a l f a n u m e r i c o   -   q u e   s e a   a l f a n u m e r i c o  
 / /   E M a i l   -   q u e   e l   f o r m a t o   d e l   c a m p o   s e a   d e   E - M a i l  
 / /   e s p a c i o s   -   n o   p e r m i t e   e s c r i b i r   e s p a c i o s   e n   e l   c a m p o  
 / /   s e l e c c i o n a d o   -   o b l i g a   a   s e l e c c i o n a r   a l g o   e n   u n   S E L E C T   q u e   n o   s e a   l a   p r i m e r a   o p c i ó n .  
 / /   s e l e c c i o n a _ r a d i o   -   o b l i g a   a   s e l e c c i o n a r   u n a   o p c i ó n   e n   u n   R A D I O .  
 / /   g e t R a d i o V a l u e   -   d e v u e l v e   e l   v a l o r   d e   u n   R A D I O   s e l e c c i o n a d o  
 / /   c a r a c t e r _ r a r o   -   c h e c k e a   s i   h a y   a l g ú n   c a r a c t e r   d a d o   e n   e l   c a m p o   t e x t .  
 / /   c u e n t a _ c a r a c t e r e s   -   l i m i t a   e l   n ú m e r o   d e   c a r a c t e r e s   d e   u n   T E X T A R E A   o   T E X T .   ( m a x i m o )  
 / /   c u e n t a _ c a r a c t e r e s 2   -   l i m i t a   e l   n ú m e r o   d e   c a r a c t e r e s   d e   u n   T E X T A R E A   o   T E X T .   ( m i n i m o )  
 / /   C i f V a l i d o   -   c h e q u e a   e l   f o r m a t o   d e l   C I F .  
 / /   N i f V a l i d o   -   c h e q u e a   N I F  
 / /   C i f O N i f V a l i d o   -   c h e q u e a   q u e   s e a   u n   N I F   o   u n   C I F  
 / /   e n t r e _ c u a n t o s   -   c h e q u e a   q u e   l a   l o n g i t u d   d e l   c a m p o   e s t é   e n t r e   2   v a l o r e s   ( n , m )  
 / /   p o s i c i o n _ n o C e r o  
 / /   c u a n t o s O N a d a   -   c h e q u e a   q u e   u n a   c a m p o   t e n g a   v   c a r a c t e r e s   o   n i n g u n o  
 / /   c h e q u e a r f e c h a s   (   f e c h a _ f i n   ,   f e c h a _ i n i   , m e n s a j e )   c h e q u e a   l a s   f e c h a s  
 / /   C O N T A D O R   C u e n t a   l o s   c a r a c t e r e s   d e   u n   c a m p o  
 / /   c a r a c t e r V a l i d o   c h e c k e a   s i   h a y   a l g ú n   c a r a c t e r   n o   v á l i d o  
 / /   s e l e c i o n a C h e k B o x    
  
 f u n c t i o n   s e l e c i o n a C h e k B o x ( C h k B o x , u ) {  
  
 	 s e l e c c   =   f a l s e ;  
 	 m i S t r i n g   =   C h k B o x . v a l u e ;  
 	 / / m i S t r i n g = " 1 , 2 "  
 	 / / a r r C h k B o x   =   m i S t r i n g . s p l i t ( " , " ) 
 	 i f   ( C h k B o x . l e n g t h = = u n d e f i n e d ) {  
 	 	 i f ( C h k B o x . c h e c k e d )  
 	 	 s e l e c c   =   t r u e ;  
 	 } e l s e {  
 	 	 f o r ( r = 0 ; r < C h k B o x . l e n g t h ; r + + )   {  
 	 	 	 i f ( C h k B o x [ r ] . c h e c k e d )  
 	 	 	 s e l e c c   =   t r u e ;  
 	 	 }  
 	 }  
 	  
 	  
 	 i f ( ! s e l e c c )  
         e r r o r e s   + =   " \ n   -   D e b e   s e l e c c i o n a r   ' "   +   u   +   " ' . " ;  
 }    
  
 f u n c t i o n   e s _ h o r a ( t ) {  
   v a r   e s h o r a = / ^ ( \ d { 2 } \ : \ d { 2 } ) $ /  
   h o r a = t . v a l u e  
         i f ( ! e s h o r a . t e s t ( t . v a l u e ) )   {    
         	 e r r o r e s + = " \ n - D e b e   i n t r o d u c c i r   b i e n   l a   h o r a   ( h h : m m ) "              
       	 }  
         e l s e   {  
 	 	 	 	 h = h o r a . s p l i t ( ' : ' )  
 	 	 	 	 i f   (   ( h [ 0 ] > 2 3 )   | |   ( h [ 1 ] > 5 9 )   )   {  
               	 	 e r r o r e s + = " \ n - D e b e   i n t r o d u c c i r   u n a   h o r a   c o r r e c t a "              
               	 }  
         }  
      
     }  
  
 f u n c t i o n   c o n t a d o r ( s , u )   {  
     n u m c a r a c t   =   s . v a l u e . l e n g t h ;  
         a l e r t ( "   E l   n ú m e r o     c a r a c t e r e s   d e   ' "   +   u   +   " '   e s   "   +   n u m c a r a c t   +     " . " ) ;  
 }  
  
     f u n c t i o n   c h e q u e a r f e c h a s ( a , b , m )   {  
             d i a _ f i n = a . v a l u e . s u b s t r ( 0 , 2 )  
             m e s _ f i n = a . v a l u e . s u b s t r ( 3 , 2 )  
             a n n o _ f i n = a . v a l u e . s u b s t r ( 6 , 4 )  
             f e c h a = a n n o _ f i n + " / " + m e s _ f i n + " / " + d i a _ f i n  
             / / a l e r t ( f e c h a )  
             t i m e A   =   n e w   D a t e ( f e c h a )  
    
             d i a _ i n i = b . v a l u e . s u b s t r ( 0 , 2 )  
             m e s _ i n i = b . v a l u e . s u b s t r ( 3 , 2 )      
             a n n o _ i n i = b . v a l u e . s u b s t r ( 6 , 4 )  
             f e c h a = a n n o _ i n i + " / " + m e s _ i n i + " / " + d i a _ i n i  
             / / a l e r t ( f e c h a )  
             t i m e B   =   n e w   D a t e ( f e c h a )  
             d i f   =   t i m e A   -   t i m e B  
             i f   ( d i f < 0 )  
                 e r r o r e s + = " \ n - D e b e   i n t r o d u c c i r   b i e n   l a s   f e c h a s   e n   e l   c a m p o   " +   m   + "   ( r a n g o   f e c h a s ) - "  
                    
     }  
  
  
  
 f u n c t i o n   c u a n t o s O N a d a ( s , u , v )   {  
     i f ( s . v a l u e . l e n g t h   ! =   v   & &   s . v a l u e . l e n g t h   ! =   0 )  
         e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   n o   t i e n e   u n a   l o n g i t u d   c o r r e c t a   ( ' "   +   v   +   " '   c a r a c t e r e s ) . "  
 }  
  
 f u n c t i o n   e n t r e _ c u a n t o s ( s , u , n , m )   {  
     / / n :   c a r a c t .   m i n ;   m :   c a r a c t .   m a x .  
     i f ( s . v a l u e . l e n g t h < n   | |   s . v a l u e . l e n g t h > m )  
         e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   n o   t i e n e   u n a   l o n g i t u d   c o r r e c t a   ( e n t r e   ' "   +   n   +   " '   y   ' "   +   m   +   " '   c a r a c t e r e s . ) "  
 }  
  
 f u n c t i o n   c u e n t a _ c a r a c t e r e s ( s , u , v )   {  
     n u m c a r a c t   =   s . v a l u e . l e n g t h ;  
     i f ( n u m c a r a c t   >   v )  
         e r r o r e s   + =   " \ n   -   E l   n ú m e r o   m á x i m o   d e   c a r a c t e r e s   p a r a   e l   c a m p o   ' "   +   u   +   " '   e s   "   +   v   +   " .   S o b r a n   "   +   ( n u m c a r a c t   -   v )   +   " . " ;  
 }  
  
 f u n c t i o n   c u e n t a _ c a r a c t e r e s 2 ( s , u , v )   {  
     n u m c a r a c t   =   s . v a l u e . l e n g t h ;  
     i f ( n u m c a r a c t   <   v )  
         e r r o r e s   + =   " \ n   -   E l   n ú m e r o   m í n i m o   d e   c a r a c t e r e s   p a r a   e l   c a m p o   ' "   +   u   +   " '   e s   "   +   v   +   " .   F a l t a n   "   +   ( v   -   n u m c a r a c t )   +   " . " ;  
 }  
  
 f u n c t i o n   e s t a _ v a c i o ( s , u )   {  
 	 i f   ( s . v a l u e   = =   " " ) {  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   e s   o b l i g a t o r i o . "  
 	 } e l s e {  
 	 t o d o e s p a c i o s ( s , u )  
 	 }  
 }  
  
 / * f u n c t i o n   e s n u m T l f ( s , u )   {  
 	 t l f = s . v a l u e  
 	 v a r = t l f . s p l i t ( '   ' )  
 	 o k = t r u e  
 	 f o r   ( i = 0 ; i < t l f . l e n g t h   & &   ! o k ; i + + ) {  
 	 	 i f   ( i s N a N ( v a r ) )   {  
 	 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   h a   d e   s e r   n u m é r i c o . "  
 	 	 	 o k = f a l s e  
 	 	 }  
 	 }  
 } * /  
  
 f u n c t i o n   e s n u m e r i c o ( s , u )   {  
 	 i f   ( i s N a N ( s . v a l u e ) )  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   h a   d e   s e r   n u m é r i c o . "  
 }  
  
 f u n c t i o n   e s p a c i o s ( s , u )   {  
 	 l o n g 2   =   s . v a l u e . l e n g t h ;  
 	 e s p   =   f a l s e ;  
 	 f o r   ( i = 0 ; i < l o n g 2 ; i + + )   {  
 	 	 i f ( s . v a l u e . c h a r A t ( i )   = =   "   " )  
 	 	 	 e s p   =   t r u e ;  
 	 }  
 	 i f ( e s p )  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   n o   d e b e   c o n t e n e r   e s p a c i o s . "  
 }  
  
 f u n c t i o n   t o d o e s p a c i o s ( s , u )   {  
 	 l o n g 2   =   s . v a l u e . l e n g t h ;  
 	  
 	     i f   ( l o n g 2   ! =   0 ) {  
 	     e s p   =   t r u e ;  
     	 f o r   ( i = 0 ; i < l o n g 2 ; i + + )   {  
     	 	 i f ( s . v a l u e . c h a r A t ( i )   ! =   "   "   | |   s . v a l u e . l e n g t h   = =   0 )  
     	 	 	 e s p   =   f a l s e ;  
     	     }  
     	 }  
     	 i f ( e s p )  
     	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   n o   d e b e   c o n t e n e r   t o d o   e s p a c i o s . "  
 }  
  
 f u n c t i o n   s e l e c c i o n a d o ( s , u )   {  
 	 i f   ( s . s e l e c t e d I n d e x   = =   0 )  
 	 	 e r r o r e s   + =   " \ n   -   D e b e   s e l e c c i o n a r   u n a   o p c i ó n   p a r a   e l   c a m p o   ' "   +   u   +   " ' . "  
 }  
  
 f u n c t i o n   s e l e c c i o n a _ r a d i o ( s , u )   {  
 	 c u a n t o s   =   s . l e n g t h ;  
 	 r a d i o _ s e l   =   f a l s e ;  
 	 f o r ( k = 0 ; k < c u a n t o s ; k + + )   {  
 	 	 i f   ( s [ k ] . c h e c k e d   = =   t r u e )  
 	 	 	 r a d i o _ s e l   =   t r u e ;  
 	 }  
 	 i f ( ! r a d i o _ s e l ) {  
 	 	 e r r o r e s   + =   " \ n   -   D e b e   s e l e c c i o n a r   u n a   o p c i ó n   p a r a   e l   c a m p o   ' "   +   u   +   " ' . " ;  
 	 	 r e t u r n   f a l s e ;  
 	 }  
 	 e l s e {  
 	 	 r e t u r n   t r u e ;  
 	 }  
 	 	  
 }  
  
 f u n c t i o n   g e t R a d i o V a l u e ( s )   {  
 	 v a r   v a l o r = " " ;  
 	 f o r   ( v a r   i = 0 ; i < s . l e n g t h ; i + + )   {  
 	 	 i f   ( s [ i ] . c h e c k e d )   {  
           	 	 v a l o r   =   s [ i ] . v a l u e ;        
 	 	 }        
 	 }  
 	 r e t u r n   v a l o r ;  
 }  
  
  
 f u n c t i o n   s o l o _ n u m e r o s ( s , u )   {  
 	 l o n g i t u d   =   s . v a l u e . l e n g t h ;  
 	 n u m e r i c o   =   t r u e ;  
 	 f o r   ( i = 0 ; i < l o n g i t u d ; i + + )   {  
 	 	 i f ( i s N a N ( s . v a l u e . c h a r A t ( i ) )   | |   s . v a l u e . c h a r A t ( i ) = = "   " )  
 	 	 	 n u m e r i c o   =   f a l s e ;  
 	 }  
 	 i f ( ! n u m e r i c o )  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   s ó l o   d e b e   c o n t e n e r   n ú m e r o s . "  
 }  
  
 f u n c t i o n   d e c i m a l _ c o m a ( s , u )   {  
 	 l o n g i t u d   =   s . v a l u e . l e n g t h ;  
 	 n u m e r i c o   =   t r u e ;  
 	 f o r   ( i = 0 ; i < l o n g i t u d ; i + + )   {  
 	 	 i f ( s . v a l u e . c h a r A t ( i ) ! = " , " ) {  
 	 	 	 i f ( i s N a N ( s . v a l u e . c h a r A t ( i ) )   | |   s . v a l u e . c h a r A t ( i ) = = "   "   )  
 	 	 	 	 n u m e r i c o   =   f a l s e ;  
 	 	 }  
 	 }  
 	 i f ( ! n u m e r i c o )  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   s ó l o   d e b e   c o n t e n e r   n ú m e r o s   o   e l   c a r a c t e r   ' , ' . "  
 }  
  
 f u n c t i o n   s o l o _ l e t r a s ( s , u )   {  
 	 l e t r a s   =   " a b c d e f g h i j k l m n ñ o p q r s t u v w x y z A B C D E F G H I J K L M N Ñ O P Q R S T U V W X Y Z á é í ó ú Á É Í Ó Ú Ü ü " ;  
 	 l o n g l e t r a s   =   l e t r a s . l e n g t h ;  
 	 l o n g i t u d   =   s . v a l u e . l e n g t h ;  
 	 s o l o l e t r a s   =   t r u e ;  
 	 f o r   ( i = 0 ; i < l o n g i t u d ; i + + )   {  
 	 	 e s l e t r a   =   f a l s e ;  
 	 	 f o r ( j = 0 ; j < l o n g l e t r a s ; j + + )   {  
 	 	 	 i f ( s . v a l u e . c h a r A t ( i )   = =   l e t r a s . c h a r A t ( j ) )  
 	 	 	 	 e s l e t r a   =   t r u e ;  
 	 	 }  
 	 	 i f ( ! e s l e t r a )  
 	 	 	 s o l o l e t r a s   =   f a l s e ;  
 	 }  
 	 i f ( ! s o l o l e t r a s )  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   s ó l o   d e b e   c o n t e n e r   l e t r a s . "  
 }  
  
 f u n c t i o n   a l f a n u m e r i c o ( s , u )   {  
 	 c a r a c t e r e s   =   " a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 " ;  
 	 l o n g l e t r a s   =   c a r a c t e r e s . l e n g t h ;  
 	 l o n g i t u d   =   s . v a l u e . l e n g t h ;  
 	 s o l o c a r a c   =   t r u e ;  
 	 f o r   ( i = 0 ; i < l o n g i t u d ; i + + )   {  
 	 	 e s l e t r a   =   f a l s e ;  
 	 	 f o r ( j = 0 ; j < l o n g l e t r a s ; j + + )   {  
 	 	 	 i f ( s . v a l u e . c h a r A t ( i )   = =   c a r a c t e r e s . c h a r A t ( j ) )  
 	 	 	 	 e s l e t r a   =   t r u e ;  
 	 	 }  
 	 	 i f ( ! e s l e t r a )  
 	 	 	 s o l o c a r a c   =   f a l s e ;  
 	 }  
 	 i f ( ! s o l o c a r a c )  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   d e b e   s e r   a l f a n u m é r i c o . "  
 }  
  
 f u n c t i o n   c a r a c t e r _ r a r o ( s , u , v )   {  
     h a y r a r o   =   f a l s e ;  
     f o r ( h = 0 ; h < s . v a l u e . l e n g t h ; h + + )   {  
         i f ( s . v a l u e . c h a r A t ( h )   = =   v )  
               h a y r a r o   =   t r u e ;  
     }  
     i f ( h a y r a r o )  
         e r r o r e s   + =   " \ n   -   N o   u s e   e l   c a r a c t e r   (   "   +   v   +   "   )   e n   e l   c a m p o   ' "   +   u   +   " ' " ;  
 }  
  
 v a r   n u m A t t a c h m e n t s   =   0 ;  
 v a r   w h i t e s p a c e   =   " \ t \ n \ r   " ;  
 v a r   d e f a u l t E m p t y O K   =   f a l s e ;  
 v a r   i n v a l i d A d d r C h a r s   =   " \ \ \ / \ " < > ( ) , ; : $ & ! \ ` \ ' ^ * | [ ] { } " ;  
 v a r   i n v a l i d D o m a i n C h a r s   =   " \ \ \ / \ " < > ( ) , ; : $ & ! \ ` \ ' ^ * @ | { } " ;  
 v a r   e m p t y A d d r   =   t r u e ;  
 v a r   E r r o r A d d r C h a r s   =   " " ;  
 v a r   T o V a l   =   " " ; v a r   C C V a l   =   " " ; v a r   B c c V a l   =   " " ;  
 v a r   n u m A t t a c h m e n t s   =   0 ;  
  
 f u n c t i o n   i s W h i t e s p a c e ( s )  
 {       v a r   i , c ;  
    
         / /   I s   s   e m p t y ?  
         i f   ( i s E m p t y ( s ) )   r e t u r n   t r u e ;  
    
         / /   S e a r c h   t h r o u g h   s t r i n g ' s   c h a r a c t e r s   o n e   b y   o n e  
         / /   u n t i l   w e   f i n d   a   n o n - w h i t e s p a c e   c h a r a c t e r .  
         / /   W h e n   w e   d o ,   r e t u r n   f a l s e ;   i f   w e   d o n ' t ,   r e t u r n   t r u e .  
    
         f o r   ( i   =   0 ;   i   <   s . l e n g t h ;   i + + )  
         {  
               / /   C h e c k   t h a t   c u r r e n t   c h a r a c t e r   i s n ' t   w h i t e s p a c e .  
               c   =   s . c h a r A t ( i ) ;  
  
               i f   ( w h i t e s p a c e . i n d e x O f ( c )   ! =   - 1   )   r e t u r n   t r u e ;  
         }  
          
         / /   A l l   c h a r a c t e r s   a r e   w h i t e s p a c e .  
         r e t u r n   f a l s e ;  
 }  
 f u n c t i o n   i s E m p t y ( s )  
 {  
         i f   ( s   = =   n u l l   | |   s . l e n g t h   = =   0 )   r e t u r n   t r u e ;  
         r e t u r n   f a l s e ;  
 }  
  
 f u n c t i o n   i s _ s i m p l e _ a d d r e s s ( a d d r )  
 {  
                 v a r   g o o d _ a d d r e s s   =   t r u e ;  
                 v a r   a t _ s i g n   =   0 ;  
                 v a r   s p a c e   =   0 ;  
                  
                 s p a c e   =   a d d r . i n d e x O f ( "   " ) ;  
                 a t _ s i g n   =   a d d r . i n d e x O f ( " @ " ) ;  
  
                 i f   ( s p a c e > = 0   | |   a t _ s i g n < = 0   | |   a t _ s i g n = = ( a d d r . l e n g t h - 1 )   | |   ! i s E m a i l ( a d d r ) )   {  
                                 g o o d _ a d d r e s s   =   f a l s e ;  
                 }  
                  
                 r e t u r n   g o o d _ a d d r e s s ;  
 }  
  
 f u n c t i o n   i s E m a i l ( s )  
 {  
         i f   ( i s E m p t y ( s ) )  
               i f   ( i s E m a i l . a r g u m e n t s . l e n g t h   = =   1 )   r e t u r n   d e f a u l t E m p t y O K ;  
               e l s e   r e t u r n   ( i s E m a i l . a r g u m e n t s [ 1 ]   = =   t r u e ) ;  
    
         / /   i s   s   w h i t e s p a c e ?  
         i f   ( i s W h i t e s p a c e ( s ) )   r e t u r n   f a l s e ;  
    
         / /   t h e r e   m u s t   b e   > =   1   c h a r a c t e r   b e f o r e   @ ,   s o   w e  
         / /   s t a r t   l o o k i n g   a t   c h a r a c t e r   p o s i t i o n   1  
         / /   ( i . e .   s e c o n d   c h a r a c t e r )  
         v a r   i   =   1 ;  
         v a r   s L e n g t h   =   s . l e n g t h ;  
    
         / /   l o o k   f o r   @  
         w h i l e   ( ( i   <   s L e n g t h )   & &   ( s . c h a r A t ( i )   ! =   " @ " ) )  
         {   i + +  
         }  
         i f   ( ( i   > =   s L e n g t h )   | |   ( s . c h a r A t ( i )   ! =   " @ " ) )   r e t u r n   f a l s e ;  
         e l s e   i   + =   2 ;  
    
         / /   l o o k   f o r   .  
         w h i l e   ( ( i   <   s L e n g t h )   & &   ( s . c h a r A t ( i )   ! =   " . " ) )  
         {   i + +  
         }  
    
         / /   t h e r e   m u s t   b e   a t   l e a s t   o n e   c h a r a c t e r   a f t e r   t h e   .  
         i f   ( ( i   > =   s L e n g t h   -   1 )   | |   ( s . c h a r A t ( i )   ! =   " . " ) )   r e t u r n   f a l s e ;  
         e l s e   r e t u r n   t r u e ;  
 }  
  
 f u n c t i o n   e m a i l ( s , u )   {  
 	 v a r   x   =   s . v a l u e ;  
 	 v a r   f i l t e r     =   / ^ ( [ a - z A - Z 0 - 9 _ \ . \ - ] ) + \ @ ( ( [ a - z A - Z 0 - 9 \ - ] ) + \ . ) + ( [ a - z A - Z 0 - 9 ] ) + $ / ;  
 	 i f   ( ! f i l t e r . t e s t ( x ) & &   s . v a l u e   ! =   " " )  
 	 	 e r r o r e s   + =   " \ n   -   I n t r o d u c e   u n a   d i r e c c i ó n   c o r r e c t a   e n   e l   c a m p o   ' "   +   u   +   " ' . " 	  
 }  
  
  
 f u n c t i o n   C i f O N i f V a l i d o ( s , u )   {  
       i f ( ! N i f V a l i d o ( s , u )   & &   ! C i f V a l i d o ( s , u ) )  
           e r r o r e s   + =   " \ n   -   E l   f o r m a t o   d e l   ' "   +   u   +   " '   n o   e s   c o r r e c t o . "  
 }  
  
  
 / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
 / /   C O N T R O L   D E   L A   T A R J E T A   D E   R E S I D E N C I A  
 / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
 f u n c t i o n   T R e s V a l i d a ( s , u )   {  
  
 	 v a r   x   =   s . v a l u e ;  
 	 v a r   f i l t e r     =   / ^ ( [ a - z A - Z ] ) / ;  
 	 i f   ( f i l t e r . t e s t ( x ) & &   s . v a l u e   ! =   " " ) / / s i     e s   t a r j e t a   d e   r e s i d e n c i a   s e   e l i m i n a   l a   p r i m e r a   l e t r a  
 	 { 	  
 	  
 	  
 	 	   i f ( s . v a l u e . s u b s t r i n g ( 0 , 1 ) . t o L o w e r C a s e ( ) = = " y " )  
 	 	   {  
 	 	         s . v a l u e   =   " 1 " + x . s u b s t r i n g ( 1 , x . l e n g t h ) ;  
 	 	   } e l s e  
 	 	 {  
 	 	         s . v a l u e   =   x . s u b s t r i n g ( 1 , x . l e n g t h ) ; }  
  
 	 	  
 	 }  
 	  
 	 i f ( ! N i f V a l i d o ( s , u )   & &   ! C i f V a l i d o ( s , u ) ) {  
 	 	  
 	 	 e r r o r e s   + =   " \ n   -   E l   f o r m a t o   d e l   ' "   +   u   +   " '   n o   e s   c o r r e c t o . "  
 	 }  
 	 s . v a l u e   =   x ;  
      
 }  
  
 / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
 / /   C O N T R O L   D E L   N I F  
 / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
 f u n c t i o n   N i f V a l i d o ( s , u ) {  
      
     v a r   c o r r e c t o   =   f a l s e ;  
     v a r   l o n   =   ( ( s . v a l u e . l e n g t h )   -   1 ) ;  
      
     v a r   x   =   s . v a l u e . s u b s t r i n g ( 0 , l o n ) ;  
      
     v a r   y   =   ( x   %   2 3 ) ;  
     v a r   z   =   s . v a l u e . s u b s t r i n g ( l o n , ( l o n   +   1 ) ) ;  
     / / a l e r t ( " c a d e n a : "   +   s . v a l u e + " l o n : "   +   l o n + " y   m o d u l o : "   +   y + " x   n u m e r o s : "   +   x + " z   l e t r a : "   +   z ) ;  
  
     i f   ( y = = 0   & &   ( z = = " t "   | |   z = = " T " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1   & &   ( z = = " r "   | |   z = = " R " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 2   & &   ( z = = " w "   | |   z = = " W " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 3   & &   ( z = = " a "   | |   z = = " A " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 4   & &   ( z = = " g "   | |   z = = " G " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 5   & &   ( z = = " m "   | |   z = = " M " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 6   & &   ( z = = " y "   | |   z = = " Y " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 7   & &   ( z = = " f "   | |   z = = " F " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 8   & &   ( z = = " p "   | |   z = = " P " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 9   & &   ( z = = " d "   | |   z = = " D " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 0   & &   ( z = = " x "   | |   z = = " X " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 1   & &   ( z = = " b "   | |   z = = " B " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 2   & &   ( z = = " n "   | |   z = = " N " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 3   & &   ( z = = " j "   | |   z = = " J " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 4   & &   ( z = = " z "   | |   z = = " Z " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 5   & &   ( z = = " s "   | |   z = = " S " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 6   & &   ( z = = " q "   | |   z = = " Q " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 7   & &   ( z = = " v "   | |   z = = " V " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 8   & &   ( z = = " h "   | |   z = = " H " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 1 9   & &   ( z = = " l "   | |   z = = " L " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 2 0   & &   ( z = = " c "   | |   z = = " C " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 2 1   & &   ( z = = " k "   | |   z = = " K " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 2 2   & &   ( z = = " e "   | |   z = = " E " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f   ( y = = 2 3   & &   ( z = = " t "   | |   z = = " T " ) ) {  
     	 c o r r e c t o   =   t r u e ;  
     }  
     i f ( ! c o r r e c t o )   {  
 	 	 / / e r r o r e s   + =   " \ n   -   E l   f o r m a t o   d e l   ' "   +   u   +   " '   n o   e s   c o r r e c t o . " ;  
         r e t u r n   f a l s e ;  
     }   e l s e   {  
         r e t u r n   t r u e ;  
     }  
 }  
  
  
 / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
 / /   C O N T R O L   D E L   C I F  
 / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  
 f u n c t i o n   C i f V a l i d o ( s , u ) {  
  
 v a r   c 1 , c 4 ;  
 v a r   e r r o r = t r u e ;  
 v a r   m a l = f a l s e ;  
 / / r e c o g e m o s   p r i m e r   y   U L T I M O   c a r a c t e r  
 c 1 = s . v a l u e . s u b s t r i n g ( 0 , 1 ) ;  
 i f   ( s . v a l u e . l e n g t h   ! =   9 )  
   m a l = t r u e ;  
 e l s e  
   c 4 = s . v a l u e . s u b s t r i n g ( 8 , 9 ) ;  
  
 i f   ( s . v a l u e . l e n g t h   <   1 0 )  
   / /   c o m p r o b a r   q u e   e s   u n   n u m e r o  
   i f   ( ! e s E n t e r o ( s . v a l u e . s u b s t r i n g ( 1 , s . v a l u e . l e n g t h - 1 ) ) )  
       m a l = t r u e ;  
  
   e l s e  
     {  
     i f   ( ( c 1   > =   " A "   & &   c 1   < =   " H " )   & &   ( c 4   > =   0   & &   c 4   < =   9 ) )   / / e s p a n o l a s  
       {  
        
       e r r o r = c o n t r o l 1 ( s ) ;  
       }  
     e l s e  
       i f   ( ( c 1   > =   " S " )   & &   ( c 4   > =   " A "   & &   c 4   < =   " J " ) )  
         e r r o r = c o n t r o l 2 ( s ) ;  
     e l s e  
       i f   ( ( c 1   > =   " P "   & &   c 1   < =   " Q " )   & &   ( c 4   > =   " A "   & &   c 4   < =   " J " ) )  
         e r r o r = c o n t r o l 2 ( s ) ;  
     e l s e  
       i f   ( ( c 1   > =   " A "   & &   c 1   < =   " H " )   & &   ( c 4   > =   " A "   & &   c 4   < =   " J " ) )  
         e r r o r = c o n t r o l 2 ( s ) ;  
     e l s e  
       i f   ( ( c 1   > =   " N " )   & &   ( c 4   > =   " A "   & &   c 4   < =   " J " ) )  
         e r r o r = c o n t r o l 2 ( s ) ;  
     e l s e  
       m a l = t r u e ;  
     }  
     i f   ( e r r o r )  
       m a l = t r u e ;  
      
     i f   ( m a l )   {  
         / / e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   n o   e s   c o r r e c t o . " ;  
         r e t u r n   f a l s e ;  
     }   e l s e   {  
         r e t u r n   t r u e ;  
     }  
 }  
  
 f u n c t i o n   c o n t r o l 1 ( n u m _ c i f ) {  
  
 v a r   n u m e r o s ;  
 v a r   R 1 ;  
  
 n u m e r o s = n u m _ c i f . v a l u e . s u b s t r i n g ( 1 , 8 ) ;  
 R 1 =   ( e v a l ( n u m e r o s . s u b s t r i n g ( 1 , 2 ) ) + e v a l ( n u m e r o s . s u b s t r i n g ( 3 , 4 ) ) + e v a l ( n u m e r o s . s u b s t r i n g ( 5 , 6 ) ) ) ;  
  
  
 R 2 1 = ( n u m e r o s . s u b s t r i n g ( 0 , 1 ) * 2 ) ;  
  
  
 i f   ( R 2 1   > =   1 0 )  
     R 2 1 =   ( 1   +   ( R 2 1   % 1 0 ) ) ;  
  
 R 2 2 = ( n u m e r o s . s u b s t r i n g ( 2 , 3 ) * 2 ) ;  
 i f   ( R 2 2   > =   1 0 )  
   R 2 2 = ( 1 +   ( R 2 2   % 1 0 ) ) ;  
  
 R 2 3 = ( n u m e r o s . s u b s t r i n g ( 4 , 5 ) * 2 ) ;  
 i f   ( R 2 3   > =   1 0 )  
   R 2 3 = ( 1 + ( R 2 3   % 1 0 ) ) ;  
  
  
 R 2 4 = ( n u m e r o s . s u b s t r i n g ( 6 , 7 ) * 2 ) ;  
 i f   ( R 2 4   > = 1 0 )  
   R 2 4   =   ( 1   +   ( R 2 4 % 1 0 ) ) ;  
  
  
 R 2   =   ( R 2 1   + R 2 2 + R 2 3   + R 2 4 ) ;  
  
  
 R   =   ( R 1   +   R 2 ) ;  
  
 R e s t o   =   ( R   % 1 0 ) ;  
  
 i f   ( R e s t o   ! =   0   )  
   R e s t o =   1 0   - R e s t o ;  
    
  
 i f   ( R e s t o   = =   n u m _ c i f . v a l u e . s u b s t r i n g ( 8 , 9 ) )  
   r e t u r n   f a l s e ;  
 e l s e  
   r e t u r n   t r u e ;  
  
 }  
  
 f u n c t i o n   c o n t r o l 2 ( n u m _ c i f ) {  
  
 v a r   n u m e r o s ;  
 v a r   R 1 ;  
  
 n u m e r o s = n u m _ c i f . v a l u e . s u b s t r i n g ( 1 , 8 ) ;  
 R 1 =   ( e v a l ( n u m e r o s . s u b s t r i n g ( 1 , 2 ) ) + e v a l ( n u m e r o s . s u b s t r i n g ( 3 , 4 ) ) + e v a l ( n u m e r o s . s u b s t r i n g ( 5 , 6 ) ) ) ;  
  
  
 R 2 1 = ( n u m e r o s . s u b s t r i n g ( 0 , 1 ) * 2 ) ;  
  
  
 i f   ( R 2 1   > =   1 0 )  
     R 2 1 =   ( 1   +   ( R 2 1   % 1 0 ) ) ;  
  
 R 2 2 = ( n u m e r o s . s u b s t r i n g ( 2 , 3 ) * 2 ) ;  
 i f   ( R 2 2   > =   1 0 )  
   R 2 2 = ( 1 +   ( R 2 2   % 1 0 ) ) ;  
  
 R 2 3 = ( n u m e r o s . s u b s t r i n g ( 4 , 5 ) * 2 ) ;  
 i f   ( R 2 3   > =   1 0 )  
   R 2 3 = ( 1 + ( R 2 3   % 1 0 ) ) ;  
  
  
 R 2 4 = ( n u m e r o s . s u b s t r i n g ( 6 , 7 ) * 2 ) ;  
 i f   ( R 2 4   > = 1 0 )  
   R 2 4   =   ( 1   +   ( R 2 4 % 1 0 ) ) ;  
  
  
 R 2   =   ( R 2 1   + R 2 2 + R 2 3   + R 2 4 ) ;  
  
  
 R   =   ( R 1   +   R 2 ) ;  
  
 R e s t o   =   ( R   % 1 0 ) ;  
  
 i f   ( R e s t o   ! =   0   )  
   R e s t o =   1 0   - R e s t o ;  
  
 s w i t c h   ( R e s t o ) {  
  
 c a s e   1 : c o n t r o l = " A "  
               b r e a k ;  
 c a s e   2 : c o n t r o l = " B "  
               b r e a k ;  
 c a s e   3 : c o n t r o l = " C "  
               b r e a k ;  
 c a s e   4 : c o n t r o l = " D "  
               b r e a k ;  
 c a s e   5 : c o n t r o l = " E "  
               b r e a k ;  
 c a s e   6 : c o n t r o l = " F "  
               b r e a k ;  
 c a s e   7 : c o n t r o l = " G "  
               b r e a k ;  
 c a s e   8 : c o n t r o l = " H "  
               b r e a k ;  
 c a s e   9 : c o n t r o l = " I "  
               b r e a k ;  
 c a s e   0 : c o n t r o l = " J "  
               b r e a k ;  
 d e f a u l t :   b r e a k ;  
 }  
  
 i f   ( c o n t r o l   = =   n u m _ c i f . v a l u e . s u b s t r i n g ( 8 , 9 ) )  
   r e t u r n   f a l s e ;  
 e l s e  
   r e t u r n   t r u e ;  
  
 }  
  
 f u n c t i o n   e s E n t e r o ( e n t e r o )    
 {  
 	   v a r   i ;  
 	   f o r   ( i   =   0 ;   i   <   e n t e r o . l e n g t h ;   i + + )    
 	   {  
                   	 v a r   c   =   e n t e r o . c h a r A t ( i ) ;  
                   	 i f   ( ! i s D i g i t ( c ) )    
 	   	 {  
 	   	 	 r e t u r n   f a l s e ;  
                   	 }  
         	 }  
 	 r e t u r n   t r u e ;  
 }  
  
 f u n c t i o n   i s D i g i t ( c )     {  
 	 r e t u r n   (   (   c   > =   " 0 "   )     & &     (   c   < =   " 9 "   )   ) ;  
 }  
  
 f u n c t i o n   c h e q u e a ( )   {  
 	 i f   ( e r r o r e s   ! =   " " )  
 	 	 / / a l e r t ( " P o r   f a v o r ,   c o r r i j a   l o s   s i g u i e n t e s   f a l l o s : "   +   e r r o r e s ) ;  
 	 	 r e t u r n   f a l s e ;  
 	 e l s e  
 	 	 / / a l e r t ( " T o d o   O K " ) ;  
 	 	 r e t u r n   t r u e ;  
 }  
 f u n c t i o n   p o s i c i o n _ n o C e r o ( t )   {  
 	 i f   ( t . v a l u e   < = 0 )  
         e r r o r e s   + =   " \ n   -   E l   n ú m e r o   d e   p o s i c i ó n   d e b e   s e r   m a y o r   q u e   0 " ;  
 	 }  
 	  
 f u n c t i o n   m u e s t r a ( s , m , n )   {  
     / / s   =   n o m b r e   d e l   c a m p o   d e   t i p o   " f i l e " .   E j e m p l o :   t h i s  
     / / m   =   n o m b r e   d e   l a   i m a g e n   q u e   s e   m u e s t r a .   E j e m p l o :   d o c u m e n t . i m a g e n 1  
     / / n   =   e j e m p l o :   t h i s . f o r m  
     / / e j e m p l o :   o n C h a n g e = m u e s t r a ( t h i s , d o c u m e n t . i m a g e n 1 b , t h i s . f o r m )      
     v a l o r C a d e n a   =   s . v a l u e ;  
     e x t e n s i o n   =   v a l o r C a d e n a . s u b s t r i n g ( v a l o r C a d e n a . i n d e x O f ( " . " ) , v a l o r C a d e n a . i n d e x O f ( " . " )   +   5 ) ;  
     i f ( e x t e n s i o n   = =   " . j p g "   | |   e x t e n s i o n   = =   " . j p e g "   | |   e x t e n s i o n   = =   " . g i f "   | |   e x t e n s i o n   = =   " . J P G "   | |   e x t e n s i o n   = =   " . J P E G "   | |   e x t e n s i o n   = =   " . G I F " )   {  
         m . s r c   =   s . v a l u e ;              
     }  
 }  
  
 f u n c t i o n   c a r a c t e r V a l i d o ( s , u )   {  
 	 p a t r o n   =   / [ \ w \ d \ s \ . á é í ó ú Á É Í Ó Ú à è ì ò ù À È Ì Ò Ù ñ Ñ \ + < > \ / \ [ \ ] { } ' ! " \ $ % & / ( ) = ? ¿ | @ # ~ ¬ ¬ ¡ ` \ + * ü Ü ¨ Ç , ; : \ - ] / ;  
 	 i f ( ! p a t r o n . t e s t ( s . v a l u e )   & &   s . v a l u e ! = " " )  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   n o   d e b e   c o n t e n e r   c a r a c t e r e s   e x t r a ñ o s . "  
 }  
 f u n c t i o n   c l a v e M a i l V a l i d a ( s , u )   {  
 	 p a t r o n   =   / [ \ w \ d \ s \ . \ + < > \ / \ [ \ ] { } ! " \ $ & / ( ) = ? ¿ @ # ~ ¬ ¡ * \ - ] / ;  
 	 i f ( ! p a t r o n . t e s t ( s . v a l u e )   & &   s . v a l u e ! = " " )  
 	 	 e r r o r e s   + =   " \ n   -   E l   c a m p o   ' "   +   u   +   " '   n o   d e b e   c o n t e n e r   c a r a c t e r e s   e x t r a ñ o s . "  
 }  
 
