ÿþ/ *  
 A u t h o r :   R o b e r t   H a s h e m i a n  
 h t t p : / / w w w . h a s h e m i a n . c o m /  
  
 Y o u   c a n   u s e   t h i s   c o d e   i n   a n y   m a n n e r   s o   l o n g   a s   t h e   a u t h o r ' s  
 n a m e ,   W e b   a d d r e s s   a n d   t h i s   d i s c l a i m e r   i s   k e p t   i n t a c t .  
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
 U s a g e   S a m p l e :  
  
 < s c r i p t   l a n g u a g e = " J a v a S c r i p t " >  
 T a r g e t D a t e   =   " 1 2 / 3 1 / 2 0 2 0   5 : 0 0   A M " ;  
 B a c k C o l o r   =   " p a l e g r e e n " ;  
 F o r e C o l o r   =   " n a v y " ;  
 C o u n t A c t i v e   =   t r u e ;  
 C o u n t S t e p p e r   =   - 1 ;  
 L e a d i n g Z e r o   =   t r u e ;  
 D i s p l a y F o r m a t   =   " % % D % %   D a y s ,   % % H % %   H o u r s ,   % % M % %   M i n u t e s ,   % % S % %   S e c o n d s . " ;  
 F i n i s h M e s s a g e   =   " I t   i s   f i n a l l y   h e r e ! " ;  
 < / s c r i p t >  
 < s c r i p t   l a n g u a g e = " J a v a S c r i p t "   s r c = " h t t p : / / s c r i p t s . h a s h e m i a n . c o m / j s / c o u n t d o w n . j s " > < / s c r i p t >  
 * /  
  
 f u n c t i o n   c a l c a g e ( s e c s ,   n u m 1 ,   n u m 2 )   {  
     s   =   ( ( M a t h . f l o o r ( s e c s / n u m 1 ) ) % n u m 2 ) . t o S t r i n g ( ) ;  
     i f   ( L e a d i n g Z e r o   & &   s . l e n g t h   <   2 )  
         s   =   " 0 "   +   s ;  
     r e t u r n   " < b > "   +   s   +   " < / b > " ;  
 }  
  
 f u n c t i o n   C o u n t B a c k ( s e c s )   {  
     i f   ( s e c s   <   0 )   {  
         d o c u m e n t . g e t E l e m e n t B y I d ( " c n t d w n " ) . i n n e r H T M L   =   F i n i s h M e s s a g e ;  
         r e t u r n ;  
     }  
     D i s p l a y S t r   =   D i s p l a y F o r m a t . r e p l a c e ( / % % D % % / g ,   c a l c a g e ( s e c s , 8 6 4 0 0 , 1 0 0 0 0 0 ) ) ;  
     D i s p l a y S t r   =   D i s p l a y S t r . r e p l a c e ( / % % H % % / g ,   c a l c a g e ( s e c s , 3 6 0 0 , 2 4 ) ) ;  
     D i s p l a y S t r   =   D i s p l a y S t r . r e p l a c e ( / % % M % % / g ,   c a l c a g e ( s e c s , 6 0 , 6 0 ) ) ;  
     D i s p l a y S t r   =   D i s p l a y S t r . r e p l a c e ( / % % S % % / g ,   c a l c a g e ( s e c s , 1 , 6 0 ) ) ;  
  
     d o c u m e n t . g e t E l e m e n t B y I d ( " c n t d w n " ) . i n n e r H T M L   =   D i s p l a y S t r ;  
     i f   ( C o u n t A c t i v e )  
         s e t T i m e o u t ( " C o u n t B a c k ( "   +   ( s e c s + C o u n t S t e p p e r )   +   " ) " ,   S e t T i m e O u t P e r i o d ) ;  
 }  
  
 f u n c t i o n   p u t s p a n ( b a c k c o l o r ,   f o r e c o l o r )   {  
   d o c u m e n t . w r i t e ( " < s p a n   i d = ' c n t d w n '   s t y l e = ' b a c k g r o u n d - c o l o r : "   +   b a c k c o l o r   +    
                                 " ;   c o l o r : "   +   f o r e c o l o r   +   " ' > < / s p a n > " ) ;  
 }  
  
 i f   ( t y p e o f ( B a c k C o l o r ) = = " u n d e f i n e d " )  
     B a c k C o l o r   =   " w h i t e " ;  
 i f   ( t y p e o f ( F o r e C o l o r ) = = " u n d e f i n e d " )  
     F o r e C o l o r =   " b l a c k " ;  
 i f   ( t y p e o f ( T a r g e t D a t e ) = = " u n d e f i n e d " )  
     T a r g e t D a t e   =   " 1 2 / 3 1 / 2 0 2 0   5 : 0 0   A M " ;  
 i f   ( t y p e o f ( D i s p l a y F o r m a t ) = = " u n d e f i n e d " )  
     D i s p l a y F o r m a t   =   " % % D % %   D a y s ,   % % H % %   H o u r s ,   % % M % %   M i n u t e s ,   % % S % %   S e c o n d s . " ;  
 i f   ( t y p e o f ( C o u n t A c t i v e ) = = " u n d e f i n e d " )  
     C o u n t A c t i v e   =   t r u e ;  
 i f   ( t y p e o f ( F i n i s h M e s s a g e ) = = " u n d e f i n e d " )  
     F i n i s h M e s s a g e   =   " " ;  
 i f   ( t y p e o f ( C o u n t S t e p p e r ) ! = " n u m b e r " )  
     C o u n t S t e p p e r   =   - 1 ;  
 i f   ( t y p e o f ( L e a d i n g Z e r o ) = = " u n d e f i n e d " )  
     L e a d i n g Z e r o   =   t r u e ;  
  
  
 C o u n t S t e p p e r   =   M a t h . c e i l ( C o u n t S t e p p e r ) ;  
 i f   ( C o u n t S t e p p e r   = =   0 )  
     C o u n t A c t i v e   =   f a l s e ;  
 v a r   S e t T i m e O u t P e r i o d   =   ( M a t h . a b s ( C o u n t S t e p p e r ) - 1 ) * 1 0 0 0   +   9 9 0 ;  
 p u t s p a n ( B a c k C o l o r ,   F o r e C o l o r ) ;  
 v a r   d t h e n   =   n e w   D a t e ( T a r g e t D a t e ) ;  
 v a r   d n o w   =   n e w   D a t e ( ) ;  
 i f ( C o u n t S t e p p e r > 0 )  
     d d i f f   =   n e w   D a t e ( d n o w - d t h e n ) ;  
 e l s e  
     d d i f f   =   n e w   D a t e ( d t h e n - d n o w ) ;  
 g s e c s   =   M a t h . f l o o r ( d d i f f . v a l u e O f ( ) / 1 0 0 0 ) ;  
 C o u n t B a c k ( g s e c s ) ; 
