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