ÿþ/ / 1 0 0 %   o f   c r e d i t   b e l o n g s   t o   d s w i t z e r   a t   h t t p : / / w w w . p e n g o w o r k s . c o m / w o r k s h o p / j s / m a s k /  
 / / P l e a s e   s e n d   y o u r   t h a n k s   t h a t   d i r e c t i o n .   A l s o   n o t e   t h e   d o c u m e n a t i o n   o n   t h a t   p a g e .    
 / /  
 / / M o d i f i e d   s l i g h t l y   b y   d m a r k s ,   a l t h o u g h   I ' m   n o t   s u r e   e x a c t l y   w h e r e   a l l   m y   m o d i f i c a t i o n s   a r e  
 / / - t h e   s p e c i a l   c h a r   ' x '   i s   n o w   ' @ '   i n s t e a d .  
 / /     i e /   ' @ @ @ '   w o u l d   b e   a   m a s k   f o r   A B C ,   b u t   n o t   1 2 3 .  
 / / - t w e a k s   t o   g e t   d a t e   f o r m a t t i n g   t o   w o r k   b e t t e r .  
 / *  
 / / a p p l y   a   m a s k   t o   a   t e x t b o x   l i k e   s o :  
 v a r   o S t r i n g M a s k   =   n e w   M a s k ( " m m / d d / Y Y Y Y " ) ;  
 o S t r i n g M a s k . a t t a c h ( d o c u m e n t . g e t E l e m e n t B y I d ( " m y T e x t B o x _ d o m I D " ) ) ;  
 * /  
 f u n c t i o n   _ M a s k A P I ( ) {  
 	 t h i s . v e r s i o n   =   " 0 . 4 a " ;  
 	 t h i s . i n s t a n c e s   =   0 ;  
 	 t h i s . o b j e c t s   =   { } ;  
 }  
 M a s k A P I   =   n e w   _ M a s k A P I ( ) ;  
  
 f u n c t i o n   M a s k ( m ,   t ) {  
 	 t h i s . m a s k   =   m ;  
 	 t h i s . t y p e   =   ( t y p e o f   t   = =   " s t r i n g " )   ?   t   :   " s t r i n g " ;  
 	 t h i s . e r r o r   =   [ ] ;  
 	 t h i s . e r r o r C o d e s   =   [ ] ;  
 	 t h i s . v a l u e   =   " " ;  
 	 t h i s . s t r i p p e d V a l u e   =   " " ;  
 	 t h i s . a l l o w P a r t i a l   =   f a l s e ;  
 	 t h i s . i d   =   M a s k A P I . i n s t a n c e s + + ;  
 	 t h i s . r e f   =   " M a s k A P I . o b j e c t s [ ' "   +   t h i s . i d   +   " ' ] " ;  
 	 M a s k A P I . o b j e c t s [ t h i s . i d ]   =   t h i s ;  
 }  
  
 / /   d e f i n e   t h e   a t t a c h ( o E l e m e n t )   f u n c t i o n  
 M a s k . p r o t o t y p e . a t t a c h   =   f u n c t i o n   ( o ) {  
 	 $ a d d E v e n t ( o ,   " o n k e y d o w n " ,   " r e t u r n   "   +   t h i s . r e f   +   " . i s A l l o w K e y P r e s s ( e v e n t ,   t h i s ) ; " ,   t r u e ) ;  
 	 $ a d d E v e n t ( o ,   " o n k e y u p " ,   " r e t u r n   "   +   t h i s . r e f   +   " . g e t K e y P r e s s ( e v e n t ,   t h i s ) ; " ,   t r u e ) ;  
 	 $ a d d E v e n t ( o ,   " o n b l u r " ,   " t h i s . v a l u e   =   "   +   t h i s . r e f   +   " . f o r m a t ( t h i s . v a l u e ) ; " ,   t r u e ) ;  
 }  
  
 M a s k . p r o t o t y p e . i s A l l o w K e y P r e s s   =   f u n c t i o n   ( e ,   o ) {  
 	 i f (   t h i s . t y p e   ! =   " s t r i n g "   )   r e t u r n   t r u e ;  
 	 v a r   x e   =   n e w   q E v e n t ( e ) ;  
  
 	 i f (   ( ( x e . k e y C o d e   >   4 7 )   & &   ( o . v a l u e . l e n g t h   > =   t h i s . m a s k . l e n g t h ) )   & &   ! x e . c t r l K e y   )   r e t u r n   f a l s e ;  
 	 r e t u r n   t r u e ;  
 }  
  
 M a s k . p r o t o t y p e . g e t K e y P r e s s   =   f u n c t i o n   ( e ,   o ,   _ u ) {  
 	 t h i s . a l l o w P a r t i a l   =   t r u e ;  
 	 v a r   x e   =   n e w   q E v e n t ( e ) ;  
  
 / / 	 v a r   k   =   S t r i n g . f r o m C h a r C o d e ( x e . k e y C o d e ) ;  
  
 	 i f (   ( x e . k e y C o d e   >   4 7 )   | |   ( _ u   = =   t r u e )   | |   ( x e . k e y C o d e   = =   8   | |   x e . k e y C o d e   = =   4 6 )   ) {  
 	 	 v a r   v   =   o . v a l u e ,   d ;  
 	 	 i f (   x e . k e y C o d e   = =   8   | |   x e . k e y C o d e   = =   4 6   )   d   =   t r u e ;  
 	 	 e l s e   d   =   f a l s e  
  
 	 	 i f (   t h i s . t y p e   = =   " n u m b e r "   )   t h i s . v a l u e   =   t h i s . s e t N u m b e r ( v ,   d ) ;  
 	 	 e l s e   i f (   t h i s . t y p e   = =   " d a t e "   )   t h i s . v a l u e   =   t h i s . s e t D a t e K e y P r e s s ( v ,   d ) ;  
 	 	 e l s e   t h i s . v a l u e   =   t h i s . s e t G e n e r i c ( v ,   d ) ;  
  
 	 	 o . v a l u e   =   t h i s . v a l u e ;  
 	 }  
 	 / *   * /  
  
 	 t h i s . a l l o w P a r t i a l   =   f a l s e ;  
 	 r e t u r n   t r u e ;  
 }  
  
 M a s k . p r o t o t y p e . f o r m a t   =   f u n c t i o n   ( s ) {  
 	 i f (   t h i s . t y p e   = =   " n u m b e r "   )   t h i s . v a l u e   =   t h i s . s e t N u m b e r ( s ) ;  
 	 e l s e   i f (   t h i s . t y p e   = =   " d a t e "   )   t h i s . v a l u e   =   t h i s . s e t D a t e ( s ) ;  
 	 e l s e   t h i s . v a l u e   =   t h i s . s e t G e n e r i c ( s ) ;  
 	 r e t u r n   t h i s . v a l u e ;  
 }  
  
 M a s k . p r o t o t y p e . t h r o w E r r o r   =   f u n c t i o n   ( c ,   e ,   v ) {  
 	 t h i s . e r r o r [ t h i s . e r r o r . l e n g t h ]   =   e ;  
 	 t h i s . e r r o r C o d e s [ t h i s . e r r o r C o d e s . l e n g t h ]   =   c ;  
 	 i f (   t y p e o f   v   = =   " s t r i n g "   )   r e t u r n   v ;  
 	 r e t u r n   t r u e ;  
 }  
  
 M a s k . p r o t o t y p e . s e t G e n e r i c   =   f u n c t i o n   ( _ v ,   _ d ) {  
 	 v a r   v   =   _ v ,   m   =   t h i s . m a s k ;  
 	 v a r   r   =   " @ # * ^ " ,   r t   =   [ ] ,   n v   =   " " ,   t ,   x ,   a   =   [ ] ,   j = 0 ,   r x   =   { " @ " :   " A - Z a - z " , " # " :   " 1 - 5 " , " * " :   " A - Z a - z 0 - 9 " , " ^ " :   " G g S s R r P p "   } ;   / /   r e m o v e d   t h i s   d e f i n i t i o n   o f   ' x '   a s   a   v a l i d   c h a r  
  
 	 / /   s t r i p   o u t   i n v a l i d   c h a r a c t e r s  
 	 v   =   v . r e p l a c e ( n e w   R e g E x p ( " [ ^ "   +   r x [ " * " ]   +   " ] " ,   " g i " ) ,   " " ) ;  
 	  
 	 i f (   ( _ d   = =   t r u e )   & &   ( v . l e n g t h   = =   t h i s . s t r i p p e d V a l u e . l e n g t h )   )   v   =   v . s u b s t r i n g ( 0 ,   v . l e n g t h - 1 ) ;  
 	 t h i s . s t r i p p e d V a l u e   =   v ;  
 	 v a r   b = [ ] ;  
 	 f o r (   v a r   i = 0 ;   i   <   m . l e n g t h ;   i + +   ) {  
 	 	 / /   g r a b   t h e   c u r r e n t   c h a r a c t e r  
 	 	 x   =   m . c h a r A t ( i ) ;  
 	 	 / /   c h e c k   t o   s e e   i f   c u r r e n t   c h a r a c t e r   i s   a   m a s k ,   e s c a p e   c o m m a n d s   a r e   n o t   a   m a s k   c h a r a c t e r  
 	 	 t   =   ( r . i n d e x O f ( x )   >   - 1 ) ;  
 	 	 / /   i f   t h e   c u r r e n t   c h a r a c t e r   i s   a n   e s c a p e   c o m m a n d ,   t h e n   g r a b   t h e   n e x t   c h a r a c t e r  
 	 	 i f (   x   = =   " ! "   )   x   =   m . c h a r A t ( i + + ) ;  
 	 	 / /   b u i l d   a   r e g e x   t o   t e s t   a g a i n s t  
 	 	 i f (   ( t   & &   ! t h i s . a l l o w P a r t i a l )   | |   ( t   & &   t h i s . a l l o w P a r t i a l   & &   ( r t . l e n g t h   <   v . l e n g t h ) )   )   r t [ r t . l e n g t h ]   =   " [ "   +   r x [ x ]   +   " ] " ;  
 	 	 / /   b u i l d   m a s k   d e f i n i t i o n   t a b l e  
 	 	 a [ a . l e n g t h ]   =   {   " c h r " :   x ,   " m a s k " :   t   } ;  
 	 }  
  
 	 v a r   h a s O n e V a l i d C h a r   =   f a l s e ;  
 	 / /   i f   t h e   r e g e x   f a i l s ,   r e t u r n   a n   e r r o r  
 	 i f (   ! t h i s . a l l o w P a r t i a l   & &   ! ( n e w   R e g E x p ( r t . j o i n ( " " ) ) ) . t e s t ( v )   )   r e t u r n   t h i s . t h r o w E r r o r ( 1 ,   " T h e   v a l u e   \ " "   +   _ v   +   " \ "   m u s t   b e   i n   t h e   f o r m a t   "   +   t h i s . m a s k   +   " . " ,   _ v ) ;  
 	 / /   l o o p   t h r o u g h   t h e   m a s k   d e f i n i t i o n ,   a n d   b u i l d   t h e   f o r m a t t e d   s t r i n g  
 	 e l s e   i f (   ( t h i s . a l l o w P a r t i a l   & &   ( v . l e n g t h   >   0 ) )   | |   ! t h i s . a l l o w P a r t i a l   ) {  
 	 	 f o r (   i = 0 ;   i   <   a . l e n g t h ;   i + +   ) {  
 	 	 	 i f (   a [ i ] . m a s k   ) {  
 	 	 	 	 w h i l e (   v . l e n g t h   >   0   & &   ! ( n e w   R e g E x p ( r t [ j ] ) ) . t e s t ( v . c h a r A t ( j ) )   )   v   =   ( v . l e n g t h   = =   1 )   ?   " "   :   v . s u b s t r i n g ( 1 ) ;  
 	 	 	 	 i f (   v . l e n g t h   >   0   ) {  
 	 	 	 	 	 n v   + =   v . c h a r A t ( j ) ;  
 	 	 	 	 	 h a s O n e V a l i d C h a r   =   t r u e ;  
 	 	 	 	 }  
 	 	 	 	 j + + ;  
 	 	 	 }   e l s e   n v   + =   a [ i ] . c h r ;  
 	 	 	 i f (   t h i s . a l l o w P a r t i a l   & &   ( j   >   v . l e n g t h )   )   b r e a k ;  
 	 	 }  
 	 }  
 	  
 	 i f (   t h i s . a l l o w P a r t i a l   & &   ! h a s O n e V a l i d C h a r   )   n v   =   " " ;  
 	 i f (   t h i s . a l l o w P a r t i a l   ) {  
 	 	 i f (   n v . l e n g t h   <   a . l e n g t h   )   t h i s . n e x t V a l i d C h a r   =   r x [ a [ n v . l e n g t h ] . c h r ] ;  
 	 	 e l s e   t h i s . n e x t V a l i d C h a r   =   n u l l ;  
 	 }  
  
 	 r e t u r n   n v ;  
 }  
  
 M a s k . p r o t o t y p e . s e t N u m b e r   =   f u n c t i o n ( _ v ,   _ d ) {  
 	 v a r   v   =   S t r i n g ( _ v ) . r e p l a c e ( / [ ^ \ d . - ] * / g i ,   " " ) ,   m   =   t h i s . m a s k ;  
 	 / /   m a k e   s u r e   t h e r e ' s   o n l y   o n e   d e c i m a l   p o i n t  
 	 v   =   v . r e p l a c e ( / \ . / ,   " d " ) . r e p l a c e ( / \ . / g ,   " " ) . r e p l a c e ( / d / ,   " . " ) ;  
  
 	 / /   c h e c k   t o   s e e   i f   a n   i n v a l i d   m a s k   o p e r a t i o n   h a s   b e e n   e n t e r e d  
 	 i f (   ! / ^ [ \ $ ] ? ( ( \ $ ? [ \ + - ] ? ( [ 0 # ] { 1 , 3 } , ) ? [ 0 # ] * ( \ . [ 0 # ] * ) ? ) | ( [ \ + - ] ? \ ( [ \ + - ] ? ( [ 0 # ] { 1 , 3 } , ) ? [ 0 # ] * ( \ . [ 0 # ] * ) ? \ ) ) ) $ / . t e s t ( m )   )  
 	 	 r e t u r n   t h i s . t h r o w E r r o r ( 1 ,   " A n   i n v a l i d   m a s k   w a s   s p e c i f i e d   f o r   t h e   \ n M a s k   c o n s t r u c t o r . " ,   _ v ) ;  
  
 	 i f (   ( _ d   = =   t r u e )   & &   ( v . l e n g t h   = =   t h i s . s t r i p p e d V a l u e . l e n g t h )   )   v   =   v . s u b s t r i n g ( 0 ,   v . l e n g t h - 1 ) ;  
  
 	 i f (   t h i s . a l l o w P a r t i a l   & &   ( v . r e p l a c e ( / [ ^ 0 - 9 ] / ,   " " ) . l e n g t h   = =   0 )   )   r e t u r n   v ;  
 	 t h i s . s t r i p p e d V a l u e   =   v ;  
  
 	 i f (   v . l e n g t h   = =   0   )   v   =   N a N ;  
 	 v a r   v n   =   N u m b e r ( v ) ;  
 	 i f (   i s N a N ( v n )   )   r e t u r n   t h i s . t h r o w E r r o r ( 2 ,   " T h e   v a l u e   e n t e r e d   w a s   n o t   a   n u m b e r . " ,   _ v ) ;  
  
 	 / /   i f   n o   m a s k ,   s t o p   p r o c e s s i n g  
 	 i f (   m . l e n g t h   = =   0   )   r e t u r n   v ;  
  
 	 / /   g e t   t h e   v a l u e   b e f o r e   t h e   d e c i m a l   p o i n t  
 	 v a r   v i   =   S t r i n g ( M a t h . a b s ( ( v . i n d e x O f ( " . " )   >   - 1   )   ?   v . s p l i t ( " . " ) [ 0 ]   :   v ) ) ;  
 	 / /   g e t   t h e   v a l u e   a f t e r   t h e   d e c i m a l   p o i n t  
 	 v a r   v d   =   ( v . i n d e x O f ( " . " )   >   - 1 )   ?   v . s p l i t ( " . " ) [ 1 ]   :   " " ;  
 	 v a r   _ v d   =   v d ;  
  
 	 v a r   i s N e g a t i v e   =   ( v n   ! =   0   & &   M a t h . a b s ( v n ) * - 1   = =   v n ) ;  
  
 	 / /   c h e c k   f o r   m a s k i n g   o p e r a t i o n s  
 	 v a r   s h o w   =   {  
 	 	 " $ "   :   / ^ [ \ $ ] / . t e s t ( m ) ,  
 	 	 " ( " :   ( i s N e g a t i v e   & &   ( m . i n d e x O f ( " ( " )   >   - 1 ) ) ,  
 	 	 " + "   :   (   ( m . i n d e x O f ( " + " )   ! =   - 1 )   & &   ! i s N e g a t i v e   )  
 	 }  
 	 s h o w [ " - " ]   =   ( i s N e g a t i v e   & &   ( ! s h o w [ " ( " ]   | |   ( m . i n d e x O f ( " - " )   ! =   - 1 ) ) ) ;  
  
  
 	 / /   r e p l a c e   a l l   n o n - p l a c e   h o l d e r s   f r o m   t h e   m a s k  
 	 m   =   m . r e p l a c e ( / [ ^ # 0 . , ] * / g i ,   " " ) ;  
  
 	 / *  
 	 	 m a k e   s u r e   t h e r e   a r e   t h e   c o r r e c t   n u m b e r   o f   d e c i m a l   p l a c e s  
 	 * /  
 	 / /   g e t   n u m b e r   o f   d i g i t s   a f t e r   d e c i m a l   p o i n t   i n   m a s k  
 	 v a r   d m   =   ( m . i n d e x O f ( " . " )   >   - 1   )   ?   m . s p l i t ( " . " ) [ 1 ]   :   " " ;  
 	 i f (   d m . l e n g t h   = =   0   ) {  
 	 	 v i   =   S t r i n g ( M a t h . r o u n d ( N u m b e r ( v i ) ) ) ;  
 	 	 v d   =   " " ;  
 	 }   e l s e   {  
 	 	 / /   f i n d   t h e   l a s t   z e r o ,   w h i c h   i n d i c a t e s   t h e   m i n i m u m   n u m b e r  
 	 	 / /   o f   d e c i m a l   p l a c e s   t o   s h o w  
 	 	 v a r   m d   =   d m . l a s t I n d e x O f ( " 0 " ) + 1 ;  
 	 	 / /   i f   t h e   n u m b e r   o f   d e c i m a l   p l a c e s   i s   g r e a t e r   t h a n   t h e   m a s k ,   t h e n   r o u n d   o f f  
 	 	 i f (   v d . l e n g t h   >   d m . l e n g t h   )   v d   =   S t r i n g ( M a t h . r o u n d ( N u m b e r ( v d . s u b s t r i n g ( 0 ,   d m . l e n g t h   +   1 ) ) / 1 0 ) ) ;  
 	 	 / /   o t h e r w i s e ,   p a d   t h e   s t r i n g   w / t h e   r e q u i r e d   z e r o s  
 	 	 e l s e   w h i l e (   v d . l e n g t h   <   m d   )   v d   + =   " 0 " ;  
 	 }  
  
 	 / *  
 	 	 p a d   t h e   i n t   w i t h   a n y   n e c e s s a r y   z e r o s  
 	 * /  
 	 / /   g e t   n u m b e r   o f   d i g i t s   b e f o r e   d e c i m a l   p o i n t   i n   m a s k  
 	 v a r   i m   =   ( m . i n d e x O f ( " . " )   >   - 1   )   ?   m . s p l i t ( " . " ) [ 0 ]   :   m ;  
 	 i m   =   i m . r e p l a c e ( / [ ^ 0 # ] + / g i ,   " " ) ;  
 	 / /   f i n d   t h e   f i r s t   z e r o ,   w h i c h   i n d i c a t e s   t h e   m i n i m u m   l e n g t h  
 	 / /   t h a t   t h e   v a l u e   m u s t   b e   p a d d e d   w / z e r o s  
 	 v a r   m v   =   i m . i n d e x O f ( " 0 " ) + 1 ;  
 	 / /   i f   t h e r e   i s   a   z e r o   f o u n d ,   m a k e   s u r e   i t ' s   p a d d e d  
 	 i f (   m v   >   0   ) {  
 	 	 m v   =   i m . l e n g t h   -   m v   +   1 ;  
 	 	 w h i l e (   v i . l e n g t h   <   m v   )   v i   =   " 0 "   +   v i ;  
 	 }  
  
  
 	 / *  
 	 	 c h e c k   t o   s e e   i f   w e   n e e d   c o m m a s   i n   t h e   t h o u s a n d s   p l a c e   h o l d e r  
 	 * /  
 	 i f (   / [ # 0 ] + , [ # 0 ] { 3 } / . t e s t ( m )   ) {  
 	 	 / /   a d d   t h e   c o m m a s   a s   t h e   p l a c e   h o l d e r  
 	 	 v a r   x   =   [ ] ,   i = 0 ,   n = N u m b e r ( v i ) ;  
 	 	 w h i l e (   n   >   9 9 9   ) {  
 	 	 	 x [ i ]   =   " 0 0 "   +   S t r i n g ( n % 1 0 0 0 ) ;  
 	 	 	 x [ i ]   =   x [ i ] . s u b s t r i n g ( x [ i ] . l e n g t h   -   3 ) ;  
 	 	 	 n   =   M a t h . f l o o r ( n / 1 0 0 0 ) ;  
 	 	 	 i + + ;  
 	 	 }  
 	 	 x [ i ]   =   S t r i n g ( n % 1 0 0 0 ) ;  
 	 	 v i   =   x . r e v e r s e ( ) . j o i n ( " , " ) ;  
 	 }  
  
  
 	 / *  
 	 	 c o m b i n e   t h e   n e w   v a l u e   t o g e t h e r  
 	 * /  
 	 i f (   ( v d . l e n g t h   >   0   & &   ! t h i s . a l l o w P a r t i a l )   | |   ( ( d m . l e n g t h   >   0 )   & &   t h i s . a l l o w P a r t i a l   & &   ( v . i n d e x O f ( " . " )   >   - 1 )   & &   ( _ v d . l e n g t h   > =   v d . l e n g t h ) )   ) {  
 	 	 v   =   v i   +   " . "   +   v d ;  
 	 }   e l s e   i f (   ( d m . l e n g t h   >   0 )   & &   t h i s . a l l o w P a r t i a l   & &   ( v . i n d e x O f ( " . " )   >   - 1 )   & &   ( _ v d . l e n g t h   <   v d . l e n g t h )   ) {  
 	 	 v   =   v i   +   " . "   +   _ v d ;  
 	 }   e l s e   {  
 	 	 v   =   v i ;  
 	 }  
  
 	 i f (   s h o w [ " $ " ]   )   v   =   t h i s . m a s k . r e p l a c e ( / ( ^ [ \ $ ] ) ( . + ) / g i ,   " $ " )   +   v ;  
 	 i f (   s h o w [ " + " ]   )   v   =   " + "   +   v ;  
 	 i f (   s h o w [ " - " ]   )   v   =   " - "   +   v ;  
 	 i f (   s h o w [ " ( " ]   )   v   =   " ( "   +   v   +   " ) " ;  
 	 r e t u r n   v ;  
 }  
  
 M a s k . p r o t o t y p e . s e t D a t e   =   f u n c t i o n   ( _ v ) {  
 	 v a r   v   =   _ v ,   m   =   t h i s . m a s k ;  
 	 v a r   a ,   e ,   m m ,   d d ,   y y ,   x ,   s ;  
  
 	 / /   s p l i t   m a s k   i n t o   a r r a y ,   t o   s e e   p o s i t i o n   o f   e a c h   d a y ,   m o n t h   &   y e a r  
 	 a   =   m . s p l i t ( / [ ^ m d y ] + / ) ;  
 	 / /   s p l i t   m a s k   i n t o   a r r a y ,   t o   g e t   d e l i m i t e r s  
 	 s   =   m . s p l i t ( / [ m d y ] + / ) ;  
 	 / /   c o n v e r t   t h e   s t r i n g   i n t o   a n   a r r a y   i n   w h i c h   d i g i t s   a r e   t o g e t h e r  
 	 e   =   v . s p l i t ( / [ ^ 0 - 9 ] / ) ;  
 	  
 	 i f (   s [ 0 ] . l e n g t h   = =   0   )   s . s p l i c e ( 0 ,   1 ) ;  
  
 	 f o r (   v a r   i = 0 ;   i   <   a . l e n g t h ;   i + +   ) {  
 	 	 x   =   a [ i ] . c h a r A t ( 0 ) . t o L o w e r C a s e ( ) ;  
 	 	 i f (   x   = =   " m "   )   m m   =   p a r s e I n t ( e [ i ] ,   1 0 ) - 1 ;  
 	 	 e l s e   i f (   x   = =   " d "   )   d d   =   p a r s e I n t ( e [ i ] ,   1 0 ) ;  
 	 	 e l s e   i f (   x   = =   " y "   )   y y   =   p a r s e I n t ( e [ i ] ,   1 0 ) ;  
 	 }  
  
 	 / /   i f   y e a r   i s   a b b r e v i a t e d ,   g u e s s   a t   t h e   y e a r  
 	 i f (   S t r i n g ( y y ) . l e n g t h   <   3   ) {  
 	 	 y y   =   2 0 0 0   +   y y ;  
 	 	 i f (   ( n e w   D a t e ( ) ) . g e t F u l l Y e a r ( ) + 2 0   <   y y   )   y y   =   y y   -   1 0 0 ;  
 	 }  
  
 	 / /   c r e a t e   d a t e   o b j e c t  
 	 v a r   d   =   n e w   D a t e ( y y ,   m m ,   d d ) ;  
  
 	 i f (   d . g e t D a t e ( )   ! =   d d   )   r e t u r n   t h i s . t h r o w E r r o r ( 1 ,   " A n   i n v a l i d   d a y   w a s   e n t e r e d . " ,   _ v ) ;  
 	 e l s e   i f (   d . g e t M o n t h ( )   ! =   m m   )   r e t u r n   t h i s . t h r o w E r r o r ( 2 ,   " A n   i n v a l i d   m o n t h   w a s   e n t e r e d . " ,   _ v ) ;  
  
 	 v a r   n v   =   " " ;  
  
 	 f o r (   i = 0 ;   i   <   a . l e n g t h ;   i + +   ) {  
 	 	 x   =   a [ i ] . c h a r A t ( 0 ) . t o L o w e r C a s e ( ) ;  
 	 	 i f (   x   = =   " m "   ) {  
 	 	 	 m m + + ;  
 	 	 	 i f (   a [ i ] . l e n g t h   = =   2   ) {  
 	 	 	 	 m m   =   " 0 "   +   m m ;  
 	 	 	 	 m m   =   m m . s u b s t r i n g ( m m . l e n g t h - 2 ) ;  
 	 	 	 }  
 	 	 	 n v   + =   m m ;  
 	 	 }   e l s e   i f (   x   = =   " d "   ) {  
 	 	 	 i f (   a [ i ] . l e n g t h   = =   2   ) {  
 	 	 	 	 d d   =   " 0 "   +   d d ;  
 	 	 	 	 d d   =   d d . s u b s t r i n g ( d d . l e n g t h - 2 ) ;  
 	 	 	 }  
 	 	 	 n v   + =   d d ;  
 	 	 }   e l s e   i f (   x   = =   " y "   ) {  
 	 	 	 i f (   a [ i ] . l e n g t h   = =   2   )   n v   + =   d . g e t Y e a r ( ) ;  
 	 	 	 e l s e   n v   + =   d . g e t F u l l Y e a r ( ) ;  
 	 	 }  
  
 	 	 i f (   i   <   a . l e n g t h - 1   )   n v   + =   s [ i ] ;  
 	 }  
  
 	 r e t u r n   n v ;  
 }  
  
 M a s k . p r o t o t y p e . s e t D a t e K e y P r e s s   =   f u n c t i o n   ( _ v ,   _ d ) {  
 	 v a r   v   =   _ v ,   m   =   t h i s . m a s k ,   k   =   v . c h a r A t ( v . l e n g t h - 1 ) ;  
 	 v a r   a ,   e ,   c ,   m l ,   v l ,   m m   =   " " ,   d d   =   " " ,   y y   =   " " ,   x ,   p ,   z ;  
  
 	 i f (   _ d   = =   t r u e   ) {  
 	 	 w h i l e (   ( / [ ^ 0 - 9 ] / g i ) . t e s t ( v . c h a r A t ( v . l e n g t h - 1 ) )   )   v   =   v . s u b s t r i n g ( 0 ,   v . l e n g t h - 1 ) ;  
 	 	 i f (   ( / [ ^ 0 - 9 ] / g i ) . t e s t ( t h i s . s t r i p p e d V a l u e . c h a r A t ( t h i s . s t r i p p e d V a l u e . l e n g t h - 1 ) )   )   v   =   v . s u b s t r i n g ( 0 ,   v . l e n g t h - 1 ) ;  
 	 	 i f (   v . l e n g t h   = =   0   )   r e t u r n   " " ;  
 	 }  
  
 	 / /   s p l i t   m a s k   i n t o   a r r a y ,   t o   s e e   p o s i t i o n   o f   e a c h   d a y ,   m o n t h   &   y e a r  
 	 a   =   m . s p l i t ( / [ ^ m d y ] / ) ;  
 	 / /   s p l i t   m a s k   i n t o   a r r a y ,   t o   g e t   d e l i m i t e r s  
 	 s   =   m . s p l i t ( / [ m d y ] + / ) ;  
 	 / /   m o z i l l a   w a n t s   t o   a d d   a n   e m p t y   a r r a y   e l e m e n t   w h i c h   n e e d s   r e m o v e d  
 	 i f (   s [ 0 ] . l e n g t h   = =   0   )   s . s p l i c e ( 0 , 1 ) ;  
 	 / /   c o n v e r t   t h e   s t r i n g   i n t o   a n   a r r a y   i n   w h i c h   d i g i t s   a r e   t o g e t h e r  
 	 e   =   v . s p l i t ( / [ ^ 0 - 9 ] / ) ;  
 	 / /   p o s i t i o n   i n   m a s k  
 	 p   =   ( e . l e n g t h   >   0 )   ?   e . l e n g t h - 1   :   0 ;  
 	 / /   d e t e r m i n e   w h a t   m a s k   v a l u e   t h e   u s e r   i s   c u r r e n t l y   e n t e r i n g  
 	 c   =   a [ p ] . c h a r A t ( 0 ) ;  
 	 / /   d e t e r m i n e   t h e   l e n g t h   o f   t h e   c u r r e n t   m a s k   v a l u e  
 	 m l   =   a [ p ] . l e n g t h ;  
  
 	 f o r (   v a r   i = 0 ;   i   <   e . l e n g t h ;   i + +   ) {  
 	 	 x   =   a [ i ] . c h a r A t ( 0 ) . t o L o w e r C a s e ( ) ;  
 	 	 i f (   x   = =   " m "   )   m m   =   p a r s e I n t ( e [ i ] ,   1 0 ) - 1 ;  
 	 	 e l s e   i f (   x   = =   " d "   )   d d   =   p a r s e I n t ( e [ i ] ,   1 0 ) ;  
 	 	 e l s e   i f (   x   = =   " y "   )   y y   =   p a r s e I n t ( e [ i ] ,   1 0 ) ;  
 	 }  
 	  
 	 i f   ( i s N a N ( m m ) )   m m   =   " " ;  
 	 i f   ( i s N a N ( d d ) )   d d   =   " " ;  
 	 i f   ( i s N a N ( y y ) )   y y   =   " " ;  
 	  
 	 v a r   n v   =   " " ;  
 	 v a r   j = 0 ;  
  
 	 f o r (   i = 0 ;   i   <   e . l e n g t h ;   i + +   ) {  
 	 	 x   =   a [ i ] . c h a r A t ( 0 ) . t o L o w e r C a s e ( ) ;  
 	  
 	 	 i f (   x   = =   " m "   ) {  
 	 	 	 i f   ( S t r i n g ( m m ) . l e n g t h   = =   0 )   b r e a k ;  
 	 	 	 z   =   ( ( / [ ^ 0 - 9 ] / ) . t e s t ( k )   & &   c   = =   " m " ) ;  
 	 	 	 m m + + ;  
 	 	 	 i f (   ( e [ i ] . l e n g t h   = =   2   & &   m m   <   1 0 )   | |   ( a [ i ] . l e n g t h   = =   2   & &   c   ! =   " m " )   | |   ( m m   >   1   & &   c   = =   " m " )   | |   ( z   & &   a [ i ] . l e n g t h   = =   2 )   ) {  
 	 	 	 	 m m   =   " 0 "   +   m m ;  
 	 	 	 	 m m   =   m m . s u b s t r i n g ( m m . l e n g t h - 2 ) ;  
 	 	 	 }  
 	 	 	 v l   =   S t r i n g ( m m ) . l e n g t h ;  
 	 	 	 m l   =   2 ;  
 	 	 	 n v   + =   m m ;  
 	 	 }   e l s e   i f (   x   = =   " d "   ) {  
 	 	 	 i f   ( S t r i n g ( d d ) . l e n g t h   = =   0 )   b r e a k ;  
 	 	 	 z   =   ( ( / [ ^ 0 - 9 ] / ) . t e s t ( k )   & &   c   = =   " d " ) ;  
 	 	 	 i f (   ( e [ i ] . l e n g t h   = =   2   & &   d d   <   1 0 )   | |   ( a [ i ] . l e n g t h   = =   2   & &   c   ! =   " d " )   | |   ( d d   >   3   & &   c   = =   " d " )   | |   ( z   & &   a [ i ] . l e n g t h   = =   2 )   ) {  
 	 	 	 	 d d   =   " 0 "   +   d d ;  
 	 	 	 	 d d   =   d d . s u b s t r i n g ( d d . l e n g t h - 2 ) ;  
 	 	 	 }  
 	 	 	 v l   =   S t r i n g ( d d ) . l e n g t h ;  
 	 	 	 m l   =   2 ;  
 	 	 	 n v   + =   d d ;  
 	 	 }   e l s e   i f (   x   = =   " y "   ) {  
 	 	 	 z   =   ( ( / [ ^ 0 - 9 ] / ) . t e s t ( k )   & &   c   = =   " y " ) ;  
 	 	 	 i f (   c   = =   " y "   )   y y   =   S t r i n g ( y y ) ;  
 	 	 	 e l s e   {  
 	 	 	 	 i f (   a [ i ] . l e n g t h   = =   2   )   y y   =   d . g e t Y e a r ( ) ;  
 	 	 	 	 e l s e   y y   =   d . g e t F u l l Y e a r ( ) ;  
 	 	 	 }  
 	 	 	 i f (   ( e [ i ] . l e n g t h   = =   2   & &   y y   <   1 0 )   | |   ( a [ i ] . l e n g t h   = =   2   & &   c   ! =   " y " )   | |   ( z   & &   a [ i ] . l e n g t h   = =   2 )   ) {  
 	 	 	 	 y y   =   " 0 "   +   y y ;  
 	 	 	 	 y y   =   y y . s u b s t r i n g ( y y . l e n g t h - 2 ) ;  
 	 	 	 }  
 	 	 	 m l   =   a [ i ] . l e n g t h ;  
 	 	 	 v l   =   S t r i n g ( y y ) . l e n g t h ;  
 	 	 	 n v   + =   y y ;  
 	 	 }  
  
 	 	 i f (   ( ( m l   = =   v l   | |   z )   & &   ( x   = =   c )   & &   ( i   <   s . l e n g t h ) )   | |   ( i   <   s . l e n g t h   & &   x   ! =   c   )   )   n v   + =   s [ i ] ;  
 	 }  
  
 	 i f (   n v . l e n g t h   >   m . l e n g t h   )   n v   =   n v . s u b s t r i n g ( 0 ,   m . l e n g t h ) ;  
  
 	 t h i s . s t r i p p e d V a l u e   =   ( n v   = =   " N a N " )   ?   " "   :   n v ;  
  
 	 r e t u r n   t h i s . s t r i p p e d V a l u e ;  
 }  
  
 f u n c t i o n   q E v e n t ( e ) {  
 	 / /   r o u t i n e   f o r   N S ,   O p e r a ,   e t c   D O M   b r o w s e r s  
 	 i f (   e   & &   e . t a r g e t   ) {  
 	 	 v a r   i s K e y P r e s s   =   ( e . t y p e . s u b s t r i n g ( 0 , 3 )   = =   " k e y " ) ;  
  
 	 	 t h i s . k e y C o d e   =   ( i s K e y P r e s s )   ?   p a r s e I n t ( e . w h i c h ,   1 0 )   :   0 ;  
 	 	 t h i s . b u t t o n   =   ( ! i s K e y P r e s s )   ?   p a r s e I n t ( e . w h i c h ,   1 0 )   :   0 ;  
 	 	 t h i s . s r c E l e m e n t   =   e . t a r g e t ;  
 	 	 t h i s . t y p e   =   e . t y p e ;  
 	 	 t h i s . x   =   e . p a g e X ;  
 	 	 t h i s . y   =   e . p a g e Y ;  
 	 	 t h i s . s c r e e n X   =   e . s c r e e n X ;  
 	 	 t h i s . s c r e e n Y   =   e . s c r e e n Y ;  
 	 	 i f (   d o c u m e n t . l a y e r s   ) {  
 	 	 	 t h i s . a l t K e y   =   ( ( e . m o d i f i e r s   &   E v e n t . A L T _ M A S K )   >   0 ) ;  
 	 	 	 t h i s . c t r l K e y   =   ( ( e . m o d i f i e r s   &   E v e n t . C O N T R O L _ M A S K )   >   0 ) ;  
 	 	 	 t h i s . s h i f t K e y   =   ( ( e . m o d i f i e r s   &   E v e n t . S H I F T _ M A S K )   >   0 ) ;  
 	 	 	 t h i s . k e y C o d e   =   t h i s . t r a n s l a t e K e y C o d e ( t h i s . k e y C o d e ) ;  
 	 	 }   e l s e   {  
 	 	 	 t h i s . a l t K e y   =   e . a l t K e y ;  
 	 	 	 t h i s . c t r l K e y   =   e . c t r l K e y ;  
 	 	 	 t h i s . s h i f t K e y   =   e . s h i f t K e y ;  
 	 	 }  
 	 / /   r o u t i n e   f o r   I n t e r n e t   E x p l o r e r   D O M   b r o w s e r s  
 	 }   e l s e   {  
 	 	 e   =   w i n d o w . e v e n t ;  
 	 	 t h i s . k e y C o d e   =   p a r s e I n t ( e . k e y C o d e ,   1 0 ) ;  
 	 	 t h i s . b u t t o n   =   e . b u t t o n ;  
 	 	 t h i s . s r c E l e m e n t   =   e . s r c E l e m e n t ;  
 	 	 t h i s . t y p e   =   e . t y p e ;  
 	 	 i f (   d o c u m e n t . a l l   ) {  
 	 	 	 t h i s . x   =   e . c l i e n t X   +   d o c u m e n t . b o d y . s c r o l l L e f t ;  
 	 	 	 t h i s . y   =   e . c l i e n t Y   +   d o c u m e n t . b o d y . s c r o l l T o p ;  
 	 	 }   e l s e   {  
 	 	 	 t h i s . x   =   e . c l i e n t X ;  
 	 	 	 t h i s . y   =   e . c l i e n t Y ;  
 	 	 }  
 	 	 t h i s . s c r e e n X   =   e . s c r e e n X ;  
 	 	 t h i s . s c r e e n Y   =   e . s c r e e n Y ;  
 	 	 t h i s . a l t K e y   =   e . a l t K e y ;  
 	 	 t h i s . c t r l K e y   =   e . c t r l K e y ;  
 	 	 t h i s . s h i f t K e y   =   e . s h i f t K e y ;  
 	 }  
 	 i f (   t h i s . b u t t o n   = =   0   ) {  
 	 	 t h i s . s e t K e y P r e s s e d ( t h i s . k e y C o d e ) ;  
 	 	 t h i s . k e y C h a r   =   S t r i n g . f r o m C h a r C o d e ( t h i s . k e y C o d e ) ;  
 	 }  
 }  
  
 / /   t h i s   m e t h o d   w i l l   t r y   t o   r e m a p   t h e   k e y c o d e s   s o   t h e   k e y c o d e   v a l u e  
 / /   r e t u r n e d   w i l l   b e   c o n s i s t e n t .   t h i s   d o e s n ' t   w o r k   f o r   a l l   c a s e s ,  
 / /   s i n c e   s o m e   b r o w s e r s   d o n ' t   a l w a y s   r e t u r n   a   u n i q u e   v a l u e   f o r   a  
 / /   k e y   p r e s s .  
 q E v e n t . p r o t o t y p e . t r a n s l a t e K e y C o d e   =   f u n c t i o n   ( i ) {  
 	 v a r   l   =   { } ;  
 	 / /   r e m a p   N S 4   k e y c o d e s   t o   I E / W 3 C   k e y c o d e s  
 	 i f (   ! ! d o c u m e n t . l a y e r s   ) {  
 	 	 i f (   t h i s . k e y C o d e   >   9 6   & &   t h i s . k e y C o d e   <   1 2 3   )   r e t u r n   t h i s . k e y C o d e   -   3 2 ;  
 	 	 l   =   {  
 	 	 	 9 6 : 1 9 2 , 1 2 6 : 1 9 2 , 3 3 : 4 9 , 6 4 : 5 0 , 3 5 : 5 1 , 3 6 : 5 2 , 3 7 : 5 3 , 9 4 : 5 4 , 3 8 : 5 5 , 4 2 : 5 6 , 4 0 : 5 7 , 4 1 : 4 8 , 9 2 : 2 2 0 , 1 2 4 : 2 2 0 , 1 2 5 : 2 2 1 ,  
 	 	 	 9 3 : 2 2 1 , 9 1 : 2 1 9 , 1 2 3 : 2 1 9 , 3 9 : 2 2 2 , 3 4 : 2 2 2 , 4 7 : 1 9 1 , 6 3 : 1 9 1 , 4 6 : 1 9 0 , 6 2 : 1 9 0 , 4 4 : 1 8 8 , 6 0 : 1 8 8 , 4 5 : 1 8 9 , 9 5 : 1 8 9 , 4 3 : 1 8 7 ,  
 	 	 	 6 1 : 1 8 7 , 5 9 : 1 8 6 , 5 8 : 1 8 6 ,  
 	 	 	 " n u l l " :   n u l l  
 	 	 }  
 	 }  
 	 r e t u r n   ( ! ! l [ i ] )   ?   l [ i ]   :   i ;  
 }  
  
 / /   t r y   t o   d e t e r m i n e   t h e   a c t u a l   v a l u e   o f   t h e   k e y   p r e s s e d  
 q E v e n t . p r o t o t y p e . s e t K P   =   f u n c t i o n   ( i ,   s ) {  
 	 t h i s . k e y P r e s s e d C o d e   =   i ;  
 	 t h i s . k e y N o n C h a r   =   ( t y p e o f   s   = =   " s t r i n g " ) ;  
 	 t h i s . k e y P r e s s e d   =   ( t h i s . k e y N o n C h a r )   ?   s   :   S t r i n g . f r o m C h a r C o d e ( i ) ;  
 	 t h i s . i s N u m e r i c   =   ( p a r s e I n t ( t h i s . k e y P r e s s e d ,   1 0 )   = =   t h i s . k e y P r e s s e d ) ;  
 	 t h i s . i s A l p h a   =   ( ( t h i s . k e y C o d e   >   6 4   & &   t h i s . k e y C o d e   <   9 1 )   & &   ! t h i s . a l t K e y   & &   ! t h i s . c t r l K e y ) ;  
 	 r e t u r n   t r u e ;  
 }  
  
 / /   t r y   t o   d e t e r m i n e   t h e   a c t u a l   v a l u e   o f   t h e   k e y   p r e s s e d  
 q E v e n t . p r o t o t y p e . s e t K e y P r e s s e d   =   f u n c t i o n   ( i ) {  
 	 v a r   b   =   t h i s . s h i f t K e y ;  
 	 i f (   ! b   & &   ( i   >   6 4   & &   i   <   9 1 )   )   r e t u r n   t h i s . s e t K P ( i   +   3 2 ) ;  
 	 i f (   i   >   9 5   & &   i   <   1 0 6   )   r e t u r n   t h i s . s e t K P ( i   -   4 8 ) ;  
 	  
 	 s w i t c h (   i   ) {  
 	 	 c a s e   4 9 :   c a s e   5 1 :   c a s e   5 2 :   c a s e   5 3 :   i f (   b   )   i   =   i   -   1 6 ;   b r e a k ;  
 	 	 c a s e   5 0 :   i f (   b   )   i   =   6 4 ;   b r e a k ;  
 	 	 c a s e   5 4 :   i f (   b   )   i   =   9 4 ;   b r e a k ;  
 	 	 c a s e   5 5 :   i f (   b   )   i   =   3 8 ;   b r e a k ;  
 	 	 c a s e   5 6 :   i f (   b   )   i   =   4 2 ;   b r e a k ;  
 	 	 c a s e   5 7 :   i f (   b   )   i   =   4 0 ;   b r e a k ;  
 	 	 c a s e   4 8 :   i f (   b   )   i   =   4 1 ;   b r e a k ;  
 	 	 c a s e   1 9 2 :   i f (   b   )   i   =   1 2 6 ;   e l s e   i   =   9 6 ;   b r e a k ;  
 	 	 c a s e   1 8 9 :   i f (   b   )   i   =   9 5 ;   e l s e   i   =   4 5 ;   b r e a k ;  
 	 	 c a s e   1 8 7 :   i f (   b   )   i   =   4 3 ;   e l s e   i   =   6 1 ;   b r e a k ;  
 	 	 c a s e   2 2 0 :   i f (   b   )   i   =   1 2 4 ;   e l s e   i   =   9 2 ;   b r e a k ;  
 	 	 c a s e   2 2 1 :   i f (   b   )   i   =   1 2 5 ;   e l s e   i   =   9 3 ;   b r e a k ;  
 	 	 c a s e   2 1 9 :   i f (   b   )   i   =   1 2 3 ;   e l s e   i   =   9 1 ;   b r e a k ;  
 	 	 c a s e   2 2 2 :   i f (   b   )   i   =   3 4 ;   e l s e   i   =   3 9 ;   b r e a k ;  
 	 	 c a s e   1 8 6 :   i f (   b   )   i   =   5 8 ;   e l s e   i   =   5 9 ;   b r e a k ;  
 	 	 c a s e   1 9 1 :   i f (   b   )   i   =   6 3 ;   e l s e   i   =   4 7 ;   b r e a k ;  
 	 	 c a s e   1 9 0 :   i f (   b   )   i   =   6 2 ;   e l s e   i   =   4 6 ;   b r e a k ;  
 	 	 c a s e   1 8 8 :   i f (   b   )   i   =   6 0 ;   e l s e   i   =   4 4 ;   b r e a k ;  
  
 	 	 c a s e   1 0 6 :   c a s e   5 7 3 7 9 :   i   =   4 2 ;   b r e a k ;  
 	 	 c a s e   1 0 7 :   c a s e   5 7 3 8 0 :   i   =   4 3 ;   b r e a k ;  
 	 	 c a s e   1 0 9 :   c a s e   5 7 3 8 1 :   i   =   4 5 ;   b r e a k ;  
 	 	 c a s e   1 1 0 :   i   =   4 6 ;   b r e a k ;  
 	 	 c a s e   1 1 1 :   c a s e   5 7 3 7 8 :   i   =   4 7 ;   b r e a k ;  
  
 	 	 c a s e   8 :   r e t u r n   t h i s . s e t K P ( i ,   " [ b a c k s p a c e ] " ) ;  
 	 	 c a s e   9 :   r e t u r n   t h i s . s e t K P ( i ,   " [ t a b ] " ) ;  
 	 	 c a s e   1 3 :   r e t u r n   t h i s . s e t K P ( i ,   " [ e n t e r ] " ) ;  
 	 	 c a s e   1 6 :   c a s e   5 7 3 8 9 :   r e t u r n   t h i s . s e t K P ( i ,   " [ s h i f t ] " ) ;  
 	 	 c a s e   1 7 :   c a s e   5 7 3 9 0 :   r e t u r n   t h i s . s e t K P ( i ,   " [ c t r l ] " ) ; d  
 	 	 c a s e   1 8 :   c a s e   5 7 3 8 8 :   r e t u r n   t h i s . s e t K P ( i ,   " [ a l t ] " ) ;  
 	 	 c a s e   1 9 :   c a s e   5 7 4 0 2 :   r e t u r n   t h i s . s e t K P ( i ,   " [ b r e a k ] " ) ;  
 	 	 c a s e   2 0 :   r e t u r n   t h i s . s e t K P ( i ,   " [ c a p s l o c k ] " ) ;  
 	 	 c a s e   3 2 :   r e t u r n   t h i s . s e t K P ( i ,   " [ s p a c e ] " ) ;  
 	 	 c a s e   9 1 :   r e t u r n   t h i s . s e t K P ( i ,   " [ w i n d o w s ] " ) ;  
 	 	 c a s e   9 3 :   r e t u r n   t h i s . s e t K P ( i ,   " [ p r o p e r t i e s ] " ) ;  
  
 	 	 c a s e   3 3 :   c a s e   5 7 3 7 1 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ p g u p ] " ) ;  
 	 	 c a s e   3 4 :   c a s e   5 7 3 7 2 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ p g d o w n ] " ) ;  
 	 	 c a s e   3 5 :   c a s e   5 7 3 7 0 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ e n d ] " ) ;  
 	 	 c a s e   3 6 :   c a s e   5 7 3 6 9 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ h o m e ] " ) ;  
 	 	 c a s e   3 7 :   c a s e   5 7 3 7 5 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ l e f t ] " ) ;  
 	 	 c a s e   3 8 :   c a s e   5 7 3 7 3 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ u p ] " ) ;  
 	 	 c a s e   3 9 :   c a s e   5 7 3 7 6 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ r i g h t ] " ) ;  
 	 	 c a s e   4 0 :   c a s e   5 7 3 7 4 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ d o w n ] " ) ;  
 	 	 c a s e   4 5 :   c a s e   5 7 3 8 2 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ i n s e r t ] " ) ;  
 	 	 c a s e   4 6 :   c a s e   5 7 3 8 3 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ d e l e t e ] " ) ;  
 	 	 c a s e   1 4 4 :   c a s e   5 7 4 0 0 :   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ n u m l o c k ] " ) ;  
 	 }  
 	  
 	 i f (   i   >   1 1 1   & &   i   <   1 2 4   )   r e t u r n   t h i s . s e t K P ( i * - 1 ,   " [ f "   +   ( i - 1 1 1 )   +   " ] " ) ;  
  
 	 r e t u r n   t h i s . s e t K P ( i ) ;  
 }  
 / /   d e f i n e   t h e   a d d E v e n t ( o E l e m e n t ,   s E v e n t ,   s C m d ,   b A p p e n d )   f u n c t i o n  
 f u n c t i o n   $ a d d E v e n t ( o ,   _ e ,   c ,   _ b ) {  
 	 v a r   e   =   _ e . t o L o w e r C a s e ( ) ,   b   =   ( t y p e o f   _ b   = =   " b o o l e a n " )   ?   _ b   :   t r u e ,   x   =   ( o [ e ] )   ?   o [ e ] . t o S t r i n g ( )   :   " " ;  
 	 / /   s t r i p   o u t   t h e   b o d y   o f   t h e   f u n c t i o n  
 	 x   =   x . s u b s t r i n g ( x . i n d e x O f ( " { " ) + 1 ,   x . l a s t I n d e x O f ( " } " ) ) ;  
 	 x   =   ( ( b )   ?   ( x   +   c )   :   ( c   +   x ) )   +   " \ n " ;  
 	 r e t u r n   o [ e ]   =   ( ! ! w i n d o w . E v e n t )   ?   n e w   F u n c t i o n ( " e v e n t " ,   x )   :   n e w   F u n c t i o n ( x ) ;  
 } 
