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