ÿþ/ *   - - -   S w a z z   J a v a s c r i p t   C a l e n d a r   - - -  
 / *   - - -   v   1 . 0   3 r d   N o v e m b e r   2 0 0 6  
 B y   O l i v e r   B r y a n t  
 h t t p : / / c a l e n d a r . s w a z z . o r g   * /  
  
 f u n c t i o n   g e t O b j ( o b j I D )  
 {  
         i f   ( d o c u m e n t . g e t E l e m e n t B y I d )   { r e t u r n   d o c u m e n t . g e t E l e m e n t B y I d ( o b j I D ) ; }  
         e l s e   i f   ( d o c u m e n t . a l l )   { r e t u r n   d o c u m e n t . a l l [ o b j I D ] ; }  
         e l s e   i f   ( d o c u m e n t . l a y e r s )   { r e t u r n   d o c u m e n t . l a y e r s [ o b j I D ] ; }  
 }  
  
 f u n c t i o n   c h e c k C l i c k ( e )   {  
 	 e ? e v t = e : e v t = e v e n t ;  
 	 C S E = e v t . t a r g e t ? e v t . t a r g e t : e v t . s r c E l e m e n t ;  
 	 i f   ( g e t O b j ( ' f c ' ) )  
 	 	 i f   ( ! i s C h i l d ( C S E , g e t O b j ( ' f c ' ) ) )  
 	 	 	 g e t O b j ( ' f c ' ) . s t y l e . d i s p l a y = ' n o n e ' ;  
 }  
  
 f u n c t i o n   i s C h i l d ( s , d )   {  
 	 w h i l e ( s )   {  
 	 	 i f   ( s = = d )    
 	 	 	 r e t u r n   t r u e ;  
 	 	 s = s . p a r e n t N o d e ;  
 	 }  
 	 r e t u r n   f a l s e ;  
 }  
  
 f u n c t i o n   L e f t ( o b j )  
 {  
 	 v a r   c u r l e f t   =   1 2 0 ;  
 	 i f   ( o b j . o f f s e t P a r e n t )  
 	 {  
 	 	 w h i l e   ( o b j . o f f s e t P a r e n t )  
 	 	 {  
 	 	 	 c u r l e f t   + =   o b j . o f f s e t L e f t  
 	 	 	 o b j   =   o b j . o f f s e t P a r e n t ;  
 	 	 }  
 	 }  
 	 e l s e   i f   ( o b j . x )  
 	 	 c u r l e f t   + =   o b j . x ;  
 	 r e t u r n   c u r l e f t ;  
 }  
  
 f u n c t i o n   T o p ( o b j )  
 {  
 	 v a r   c u r t o p   =   - 1 7 ;  
 	 i f   ( o b j . o f f s e t P a r e n t )  
 	 {  
 	 	 w h i l e   ( o b j . o f f s e t P a r e n t )  
 	 	 {  
 	 	 	 c u r t o p   + =   o b j . o f f s e t T o p  
 	 	 	 o b j   =   o b j . o f f s e t P a r e n t ;  
 	 	 }  
 	 }  
 	 e l s e   i f   ( o b j . y )  
 	 	 c u r t o p   + =   o b j . y ;  
 	 r e t u r n   c u r t o p ;  
 }  
 	  
 d o c u m e n t . w r i t e ( ' < t a b l e   i d = " f c "   s t y l e = " p o s i t i o n : a b s o l u t e ; t o p : 2 5 0 p x ; l e f t : 5 3 0 p x ; b o r d e r - c o l l a p s e : c o l l a p s e ; b a c k g r o u n d : # F F F F F F ; b o r d e r : 1 p x   s o l i d   # 9 2 1 9 2 A ; d i s p l a y : n o n e "   c e l l p a d d i n g = 2 > ' ) ;  
 d o c u m e n t . w r i t e ( ' < t r > < t d   s t y l e = " c u r s o r : p o i n t e r ; f o n t : b o l d   1 3 p x   A r i a l ;   c o l o r :   # 9 2 1 9 2 A ; b a c k g r o u n d : # F 1 E 9 D 9 ; "   o n c l i c k = " c s u b m ( ) " > < < < / t d > < t d   c o l s p a n = 5   i d = " m n s "   a l i g n = " c e n t e r "   s t y l e = " f o n t : b o l d   1 3 p x   A r i a l ;   c o l o r :   # 9 2 1 9 2 A ; b a c k g r o u n d : # F 1 E 9 D 9 ; " > < / t d > < t d   a l i g n = " r i g h t "   s t y l e = " c u r s o r : p o i n t e r ; f o n t : b o l d   1 3 p x   A r i a l ;   c o l o r :   # 9 2 1 9 2 A ; b a c k g r o u n d : # F 1 E 9 D 9 ; "   o n c l i c k = " c a d d m ( ) " > > > < / t d > < / t r > ' ) ;  
 d o c u m e n t . w r i t e ( ' < t r > < t d   a l i g n = c e n t e r   s t y l e = " b a c k g r o u n d : # 9 2 1 9 2 A ; f o n t : 1 2 p x   A r i a l ; c o l o r : # F F F F F F " > fgåe< / t d > < t d   a l i g n = c e n t e r   s t y l e = " b a c k g r o u n d : # 9 2 1 9 2 A ; f o n t : 1 2 p x   A r i a l ; c o l o r : # F F F F F F " > fg N< / t d > < t d   a l i g n = c e n t e r   s t y l e = " b a c k g r o u n d : # 9 2 1 9 2 A ; f o n t : 1 2 p x   A r i a l ; c o l o r : # F F F F F F " > fgŒN< / t d > < t d   a l i g n = c e n t e r   s t y l e = " b a c k g r o u n d : # 9 2 1 9 2 A ; f o n t : 1 2 p x   A r i a l ; c o l o r : # F F F F F F " > fg	N< / t d > < t d   a l i g n = c e n t e r   s t y l e = " b a c k g r o u n d : # 9 2 1 9 2 A ; f o n t : 1 2 p x   A r i a l ; c o l o r : # F F F F F F " > fgÛV< / t d > < t d   a l i g n = c e n t e r   s t y l e = " b a c k g r o u n d : # 9 2 1 9 2 A ; f o n t : 1 2 p x   A r i a l ; c o l o r : # F F F F F F " > fg”N< / t d > < t d   a l i g n = c e n t e r   s t y l e = " b a c k g r o u n d : # 9 2 1 9 2 A ; f o n t : 1 2 p x   A r i a l ; c o l o r : # F F F F F F " > fgmQ< / t d > < / t r > ' ) ;  
 f o r ( v a r   k k = 1 ; k k < = 6 ; k k + + )   {  
 	 d o c u m e n t . w r i t e ( ' < t r > ' ) ;  
 	 f o r ( v a r   t t = 1 ; t t < = 7 ; t t + + )   {  
 	 	 n u m = 7   *   ( k k - 1 )   -   ( - t t ) ;  
 	 	 d o c u m e n t . w r i t e ( ' < t d   i d = " v '   +   n u m   +   ' "   s t y l e = " w i d t h : 1 8 p x ; h e i g h t : 1 8 p x " > & n b s p ; < / t d > ' ) ;  
 	 }  
 	 d o c u m e n t . w r i t e ( ' < / t r > ' ) ;  
 }  
 d o c u m e n t . w r i t e ( ' < / t a b l e > ' ) ;  
  
 d o c u m e n t . a l l ? d o c u m e n t . a t t a c h E v e n t ( ' o n c l i c k ' , c h e c k C l i c k ) : d o c u m e n t . a d d E v e n t L i s t e n e r ( ' c l i c k ' , c h e c k C l i c k , f a l s e ) ;  
  
  
 / /   C a l e n d a r   s c r i p t  
 v a r   n o w   =   n e w   D a t e ;  
 v a r   s c c m = n o w . g e t M o n t h ( ) ;  
 v a r   s c c y = n o w . g e t F u l l Y e a r ( ) ;  
 v a r   c c m = n o w . g e t M o n t h ( ) ;  
 v a r   c c y = n o w . g e t F u l l Y e a r ( ) ;  
  
 v a r   u p d o b j ;  
 f u n c t i o n   l c s ( i e l e m )   {  
 	 u p d o b j = i e l e m ;  
 	 g e t O b j ( ' f c ' ) . s t y l e . l e f t = L e f t ( i e l e m ) ;  
 	 g e t O b j ( ' f c ' ) . s t y l e . t o p = T o p ( i e l e m ) + i e l e m . o f f s e t H e i g h t ;  
 	 g e t O b j ( ' f c ' ) . s t y l e . d i s p l a y = ' ' ;  
 	  
 	 / /   F i r s t   c h e c k   d a t e   i s   v a l i d  
 	 c u r d t = i e l e m . v a l u e ;  
 	 c u r d t a r r = c u r d t . s p l i t ( ' / ' ) ;  
 	 i s d t = t r u e ;  
 	 f o r ( v a r   k = 0 ; k < c u r d t a r r . l e n g t h ; k + + )   {  
 	 	 i f   ( i s N a N ( c u r d t a r r [ k ] ) )  
 	 	 	 i s d t = f a l s e ;  
 	 }  
 	 i f   ( i s d t & ( c u r d t a r r . l e n g t h = = 3 ) )   {  
 	 	 c c m = c u r d t a r r [ 0 ] ;  
 	 	 c c y = c u r d t a r r [ 2 ] ;  
 	 	 p r e p c a l e n d a r ( c u r d t a r r [ 1 ] , c u r d t a r r [ 0 ] - 1 , c u r d t a r r [ 2 ] ) ;  
 	 }  
 	  
 }  
  
 f u n c t i o n   e v t T g t ( e )  
 {  
 	 v a r   e l ;  
 	 i f ( e . t a r g e t ) e l = e . t a r g e t ;  
 	 e l s e   i f ( e . s r c E l e m e n t ) e l = e . s r c E l e m e n t ;  
 	 i f ( e l . n o d e T y p e = = 3 ) e l = e l . p a r e n t N o d e ;   / /   d e f e a t   S a f a r i   b u g  
 	 r e t u r n   e l ;  
 }  
 f u n c t i o n   E v t O b j ( e ) { i f ( ! e ) e = w i n d o w . e v e n t ; r e t u r n   e ; }  
 f u n c t i o n   c s _ o v e r ( e )   {  
 	 e v t T g t ( E v t O b j ( e ) ) . s t y l e . b a c k g r o u n d = ' # F F F F F F ' ;  
 }  
 f u n c t i o n   c s _ o u t ( e )   {  
 	 e v t T g t ( E v t O b j ( e ) ) . s t y l e . b a c k g r o u n d = ' # F F F F F F ' ;  
 }  
 f u n c t i o n   c s _ c l i c k ( e )   {  
 	 u p d o b j . v a l u e = c a l v a l a r r [ e v t T g t ( E v t O b j ( e ) ) . i d . s u b s t r i n g ( 1 , e v t T g t ( E v t O b j ( e ) ) . i d . l e n g t h ) ] ;  
 	 g e t O b j ( ' f c ' ) . s t y l e . d i s p l a y = ' n o n e ' ;  
 	  
 }  
  
 v a r   m n = n e w   A r r a y ( '  Ng' , ' ŒNg' , ' 	Ng' , ' ÛVg' , ' ”Ng' , ' mQg' , ' Ng' , ' kQg' , ' ]Ng' , ' ASg' , ' AS Ng' , ' ASŒNg' ) ;  
 v a r   m n n = n e w   A r r a y ( ' 3 1 ' , ' 2 8 ' , ' 3 1 ' , ' 3 0 ' , ' 3 1 ' , ' 3 0 ' , ' 3 1 ' , ' 3 1 ' , ' 3 0 ' , ' 3 1 ' , ' 3 0 ' , ' 3 1 ' ) ;  
 v a r   m n l = n e w   A r r a y ( ' 3 1 ' , ' 2 9 ' , ' 3 1 ' , ' 3 0 ' , ' 3 1 ' , ' 3 0 ' , ' 3 1 ' , ' 3 1 ' , ' 3 0 ' , ' 3 1 ' , ' 3 0 ' , ' 3 1 ' ) ;  
 v a r   c a l v a l a r r = n e w   A r r a y ( 4 2 ) ;  
  
 f u n c t i o n   f _ c p s ( o b j )   {  
 	 o b j . s t y l e . b a c k g r o u n d = ' # F F F F F F ' ;  
 	 o b j . s t y l e . f o n t = ' 1 0 p x   A r i a l ' ;  
 	 o b j . s t y l e . c o l o r = ' # 3 3 3 3 3 3 ' ;  
 	 o b j . s t y l e . t e x t A l i g n = ' c e n t e r ' ;  
 	 o b j . s t y l e . t e x t D e c o r a t i o n = ' n o n e ' ;  
 	 o b j . s t y l e . b o r d e r = ' 1 p x   s o l i d   # F F F F F F ' ;  
 	 o b j . s t y l e . c u r s o r = ' p o i n t e r ' ;  
 }  
  
 f u n c t i o n   f _ c p p s ( o b j )   {  
 	 o b j . s t y l e . b a c k g r o u n d = ' # F F F F F F ' ;  
 	 o b j . s t y l e . f o n t = ' 1 0 p x   A r i a l ' ;  
 	 o b j . s t y l e . c o l o r = ' # A A B 9 D 5 ' ;  
 	 o b j . s t y l e . t e x t A l i g n = ' c e n t e r ' ;  
 	 o b j . s t y l e . t e x t D e c o r a t i o n = ' l i n e - t h r o u g h ' ;  
 	 o b j . s t y l e . b o r d e r = ' 1 p x   s o l i d   # F F F F F F ' ;  
 	 o b j . s t y l e . c u r s o r = ' d e f a u l t ' ;  
 }  
  
 f u n c t i o n   f _ h d s ( o b j )   {  
 	 o b j . s t y l e . b a c k g r o u n d = ' # F F F F F F ' ;  
 	 o b j . s t y l e . f o n t = ' b o l d   1 0 p x   A r i a l ' ;  
 	 o b j . s t y l e . c o l o r = ' # 3 3 3 3 3 3 ' ;  
 	 o b j . s t y l e . t e x t A l i g n = ' c e n t e r ' ;  
 	 o b j . s t y l e . b o r d e r = ' 1 p x   s o l i d   # F F F F F F ' ;  
 	 o b j . s t y l e . c u r s o r = ' p o i n t e r ' ;  
 }  
  
 / /   d a y   s e l e c t e d  
 f u n c t i o n   p r e p c a l e n d a r ( h d , c m , c y )   {  
 	 n o w = n e w   D a t e ( ) ;  
 	 s d = n o w . g e t D a t e ( ) ;  
 	 t d = n e w   D a t e ( ) ;  
 	 t d . s e t D a t e ( 1 ) ;  
 	 t d . s e t F u l l Y e a r ( c y ) ;  
 	 t d . s e t M o n t h ( c m ) ;  
 	 c d = t d . g e t D a y ( ) ;  
 	 g e t O b j ( ' m n s ' ) . i n n e r H T M L = m n [ c m ] +   '   '   +   c y ;  
 	 m a r r = ( ( c y % 4 ) = = 0 ) ? m n l : m n n ;  
 	 f o r ( v a r   d = 1 ; d < = 4 2 ; d + + )   {  
 	 	 f _ c p s ( g e t O b j ( ' v ' + p a r s e I n t ( d ) ) ) ;  
 	 	 i f   ( ( d   > =   ( c d   - ( - 1 ) ) )   & &   ( d < = c d - ( - m a r r [ c m ] ) ) )   {  
 	 	 	 d i p = ( ( d - c d   <   s d ) & & ( c m = = s c c m ) & & ( c y = = s c c y ) ) ;  
 	 	 	 h t d = ( ( h d ! = ' ' ) & & ( d - c d = = h d ) ) ;  
 	 	 	 i f   ( d i p )  
 	 	 	 	 f _ c p p s ( g e t O b j ( ' v ' + p a r s e I n t ( d ) ) ) ;  
 	 	 	 e l s e   i f   ( h t d )  
 	 	 	 	 f _ h d s ( g e t O b j ( ' v ' + p a r s e I n t ( d ) ) ) ;  
 	 	 	 e l s e  
 	 	 	 	 f _ c p s ( g e t O b j ( ' v ' + p a r s e I n t ( d ) ) ) ;  
  
 	 	 	 g e t O b j ( ' v ' + p a r s e I n t ( d ) ) . o n m o u s e o v e r = ( d i p ) ? n u l l : c s _ o v e r ;  
 	 	 	 g e t O b j ( ' v ' + p a r s e I n t ( d ) ) . o n m o u s e o u t = ( d i p ) ? n u l l : c s _ o u t ;  
 	 	 	 g e t O b j ( ' v ' + p a r s e I n t ( d ) ) . o n c l i c k = ( d i p ) ? n u l l : c s _ c l i c k ;  
 	 	 	  
 	 	 	 g e t O b j ( ' v ' + p a r s e I n t ( d ) ) . i n n e r H T M L = d - c d ; 	  
 	 	 	 c a l v a l a r r [ d ] = ' ' + ( c m - ( - 1 ) ) + ' / ' + ( d - c d ) + ' / ' + c y ;  
 	 	 }  
 	 	 e l s e   {  
 	 	 	 g e t O b j ( ' v ' + d ) . i n n e r H T M L = ' & n b s p ; ' ;  
 	 	 	 g e t O b j ( ' v ' + p a r s e I n t ( d ) ) . o n m o u s e o v e r = n u l l ;  
 	 	 	 g e t O b j ( ' v ' + p a r s e I n t ( d ) ) . o n m o u s e o u t = n u l l ;  
 	 	 	 g e t O b j ( ' v ' + p a r s e I n t ( d ) ) . s t y l e . c u r s o r = ' d e f a u l t ' ;  
 	 	 	 }  
 	 }  
 }  
  
 p r e p c a l e n d a r ( ' ' , c c m , c c y ) ;  
 / / g e t O b j ( ' f c ' + c c ) . s t y l e . v i s i b i l i t y = ' h i d d e n ' ;  
  
 f u n c t i o n   c a d d m ( )   {  
 	 m a r r = ( ( c c y % 4 ) = = 0 ) ? m n l : m n n ;  
 	  
 	 c c m + = 1 ;  
 	 i f   ( c c m > = 1 2 )   {  
 	 	 c c m = 0 ;  
 	 	 c c y + + ;  
 	 }  
 	 c d a y f ( ) ;  
 	 p r e p c a l e n d a r ( ' ' , c c m , c c y ) ;  
 }  
  
 f u n c t i o n   c s u b m ( )   {  
 	 m a r r = ( ( c c y % 4 ) = = 0 ) ? m n l : m n n ;  
 	  
 	 c c m - = 1 ;  
 	 i f   ( c c m < 0 )   {  
 	 	 c c m = 1 1 ;  
 	 	 c c y - - ;  
 	 }  
 	 c d a y f ( ) ;  
 	 p r e p c a l e n d a r ( ' ' , c c m , c c y ) ;  
 }  
  
 f u n c t i o n   c d a y f ( )   {  
 i f   ( ( c c y > s c c y ) | ( ( c c y = = s c c y ) & & ( c c m > = s c c m ) ) )  
 	 r e t u r n ;  
 e l s e   {  
 	 c c y = s c c y ;  
 	 c c m = s c c m ;  
 	 c f d = s c f d ;  
 	 }  
 } 
