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