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