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