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