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