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