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