ÿþ 
 / *   k d a t e . j s   -   K a l u a c h   J a v a s c r i p t   H e b r e w   d a t e   r o u t i n e s  
   *       V e r s i o n   0 . 0 3   ( b e t a   r e l e a s e )  
   *   C o p y r i g h t   ( C )   5 7 6 0   ( 2 0 0 0   C E ) ,   b y   A b u   M a m i   a n d   Y i s r a e l   H e r s c h .  
   *       A l l   R i g h t s   R e s e r v e d .  
   *       A l l   c o p y r i g h t   n o t i c e s   i n   t h i s   s c r i p t   m u s t   b e   l e f t   i n t a c t .  
   *   B a s e d   o n   t h e   f o r m u l a   b y   G a u s s  
   *   T e r m s   o f   u s e :  
   *       -   P e r m i s s i o n   w i l l   b e   g r a n t e d   t o   u s e   t h i s   s c r i p t   o n   p e r s o n a l  
   *           w e b   p a g e s .   A l l   t h a t ' s   r e q u i r e d   i s   t h a t   y o u   p l e a s e   a s k .  
   *           ( O f   c o u r s e   i f   y o u   w a n t   t o   s e n d   a   f e w   d o l l a r s ,   t h a t ' s   O K   t o o   : - )  
   *       -   U s e   o n   c o m m e r c i a l   w e b   s i t e s   r e q u i r e s   a   $ 5 0   p a y m e n t .  
   *   w e b s i t e :   h t t p : / / w w w . k a l u a c h . n e t  
   *   e m a i l :   a b u - m a m i @ k a l u a c h . n e t  
   * /  
  
 f u n c t i o n   m a k e A r r a y ( )   {  
 	 t h i s [ 0 ]   =   m a k e A r r a y . a r g u m e n t s . l e n g t h ;  
 	 f o r   ( i   =   0 ;   i   <   m a k e A r r a y . a r g u m e n t s . l e n g t h ;   i   =   i   +   1 )  
 	 	 t h i s [ i + 1 ]   =   m a k e A r r a y . a r g u m e n t s [ i ] ;  
 }  
  
 v a r   h e b M o n t h   =   n e w   m a k e A r r a y (  
 	 ' àÙáß' ,   ' ÐÙÙè' ,   ' áÙÕß' ,   ' êÞÕÖ' ,   ' ÐÑ' ,   ' ÐÜÕÜ' ,  
 	 ' êéèÙ' ,   ' ×éÕß' ,   ' ÛáÜÕ' ,   ' ØÑê' ,   ' éÑØ' ,  
 	 ' ÐÓè' ,   ' ÐÓè  Ð' ,   ' ÐÓè  Ñ' ) ;  
  
 v a r   c i v M o n t h   =   n e w   m a k e A r r a y (  
 	 ' J a n u a r y ' ,   ' F e b r u a r y ' ,   ' M a r c h ' ,   ' A p r i l ' ,   ' M a y ' ,   ' J u n e ' ,  
 	 ' J u l y ' ,   ' A u g u s t ' ,   ' S e p t e m b e r ' ,   ' O c t o b e r ' ,   ' N o v e m b e r ' ,   ' D e c e m b e r ' ) ;  
  
 v a r   w e e k D a y   =   n e w   m a k e A r r a y (  
 	 ' S u n ' ,   ' M o n ' ,   ' T u e s ' ,   ' W e d ' ,   ' T h u r ' ,   ' F r i ' ,   ' S h a b b a t ' ) ;  
  
 f u n c t i o n   G a u s s ( y e a r )   {  
 	 v a r   a , b , c ;  
 	 v a r   m ;  
 	 v a r 	 M a r ; 	 / /   " d a y   i n   M a r c h "   o n   w h i c h   P e s a c h   f a l l s   ( r e t u r n   v a l u e )  
  
 	 a   =   M a t h . f l o o r ( ( 1 2   *   y e a r   +   1 7 )   %   1 9 ) ;  
 	 b   =   M a t h . f l o o r ( y e a r   %   4 ) ;  
 	 m   =   3 2 . 0 4 4 0 9 3 1 6 1 1 4 4   +   1 . 5 5 4 2 4 1 7 9 6 6 2 1 2   *   a   +     b   /   4 . 0   -   0 . 0 0 3 1 7 7 7 9 4 0 2 2 0 9 2 3   *   y e a r ;  
 	 i f   ( m   <   0 )  
 	 	 m   - =   1 ;  
 	 M a r   =   M a t h . f l o o r ( m ) ;  
 	 i f   ( m   <   0 )  
 	 	 m + + ;  
 	 m   - =   M a r ;  
  
 	 c   =   M a t h . f l o o r ( ( M a r   +   3   *   y e a r   +   5   *   b   +   5 )   %   7 ) ;  
 	 i f ( c   = =   0   & &   a   >   1 1   & &   m   > =   0 . 8 9 7 7 2 3 7 6 5 4 3 2 1 0   )  
 	 	 M a r + + ;  
 	 e l s e   i f ( c   = =   1   & &   a   >   6   & &   m   > =   0 . 6 3 2 8 7 0 3 7 0 3 7 0 3 7 )  
 	 	 M a r   + =   2 ;  
 	 e l s e   i f ( c   = =   2   | |   c   = =   4   | |   c   = =   6 )  
 	 	 M a r + + ;  
  
 	 M a r   + =   M a t h . f l o o r ( ( y e a r   -   3 7 6 0 )   /   1 0 0 )   -   M a t h . f l o o r ( ( y e a r   -   3 7 6 0 )   /   4 0 0 )   -   2 ;  
 	 r e t u r n   M a r ;  
 }  
  
 f u n c t i o n   l e a p ( y )   {  
 	 r e t u r n   ( ( y   %   4 0 0   = =   0 )   | |   ( y   %   1 0 0   ! =   0   & &   y   %   4   = =   0 ) ) ;  
 }  
  
 f u n c t i o n   c i v M o n t h L e n g t h ( m o n t h ,   y e a r )   {  
 	 i f ( m o n t h   = =   2 )  
 	 	 r e t u r n   2 8   +   l e a p ( y e a r ) ;  
 	 e l s e   i f ( m o n t h   = =   4   | |   m o n t h   = =   6   | |   m o n t h   = =   9   | |   m o n t h   = =   1 1 )  
 	       r e t u r n   3 0 ;  
 	 e l s e  
 	 	 r e t u r n   3 1 ;  
 }  
  
 f u n c t i o n   c i v 2 h e b ( d a y ,   m o n t h ,   y e a r )   {  
 	 v a r   d   =   d a y ;  
 	 v a r 	 m   =   m o n t h ;  
 	 v a r   y   =   y e a r ;  
 	 v a r   h y ;  
 	 v a r   p e s a c h ;  
 	 v a r   a n c h o r ;  
 	 v a r   a d a r T y p e ;  
  
 	 m   - =   2 ;  
 	 i f   ( m   < =   0 )   {   / /   J a n   o r   F e b  
 	 	 m   + =   1 2 ;  
 	 	 y   - =   1 ;  
 	 }  
  
 	 d   + =   M a t h . f l o o r ( 7   *   m   /   1 2   +   3 0   *   ( m   -   1 ) ) ;   / /   d a y   i n   M a r c h  
 	 h y   =   y   +   3 7 6 0 ; 	 / /   g e t   H e b r e w   y e a r  
 	 p e s a c h   =   G a u s s ( h y ) ;  
 	 i f   ( d   < =   p e s a c h   -   1 5 )   {   / /   b e f o r e   1   N i s a n  
 	 	 a n c h o r   =   p e s a c h ;  
 	 	 d   + =   3 6 5 ;  
 	 	 i f ( l e a p ( y ) )  
 	 	 	 d + + ;  
 	 	 y   - =   1 ;  
 	 	 h y   - =   1 ;  
 	 	 p e s a c h   =   G a u s s ( h y ) ;  
 	 }  
 	 e l s e  
 	 	 a n c h o r   =   G a u s s ( h y   +   1 ) ;  
  
 	 d   - =   p e s a c h   -   1 5 ;  
 	 a n c h o r   - =   p e s a c h   -   1 2 ;  
 	 y + + ;  
 	 i f ( l e a p ( y ) )  
 	 	 a n c h o r + + ;  
  
 	 f o r ( m   =   0 ;   m   <   1 1 ;   m + + )   {  
 	 	 v a r   d a y s ;  
 	 	 i f ( m   = =   7   & &   a n c h o r   %   3 0   = =   2 )  
 	 	 	 d a y s   =   3 0 ;   / /   C h e s h v a n  
 	 	 e l s e   i f ( m   = =   8   & &   a n c h o r   %   3 0   = =   0 )  
 	 	 	 d a y s   =   2 9 ;   / /   K i s l e v  
 	 	 e l s e  
 	 	 	 d a y s   =   3 0   -   m   %   2 ;  
 	 	 i f ( d   < =   d a y s )  
 	 	 	 b r e a k ;  
 	 	 d   - =   d a y s ;  
 	 }  
  
 	 a d a r T y p e   =   0 ; 	 	 	 / /   p l a i n   o l d   A d a r  
 	 i f   ( m   = =   1 1   & &   a n c h o r   > =   3 0 )   {  
 	 	 i f   ( d   >   3 0 )   {  
 	 	 	 a d a r T y p e   =   2 ; 	 / /   A d a r   2  
 	 	 	 d   - =   3 0 ;  
 	 	 }  
 	 	 e l s e  
 	 	 	 a d a r T y p e   =   1 ; 	 / /   A d a r   1  
 	 }  
  
 	 i f ( m   > =   6 ) 	 	 / /   T i s h r e i   o r   a f t e r ?  
 	 	 h y + + ; 	 	 / /   t h e n   b u m p   u p   y e a r  
  
 	 i f ( m   = =   1 1 ) 	 	 	 / /   A d a r ?  
 	 	 m   + =   a d a r T y p e ; 	 / /   a d j u s t   f o r   A d a r s  
  
 	 r e t u r n   ( d   +   '   '   +   m   +   '   '   +   h y ) ;  
 }  
  
  
 f u n c t i o n   E a s t e r ( Y )   {  
 	 / /   b a s e d   o n   t h e   a l g o r i t h m   o f   O u d i n  
         v a r   C   =   M a t h . f l o o r ( Y   /   1 0 0 ) ;  
         v a r   N   =   Y   -   1 9   *   M a t h . f l o o r ( Y   /   1 9 ) ;  
         v a r   K   =   M a t h . f l o o r ( ( C   -   1 7 )   /   2 5 ) ;  
         v a r   I   =   C   -   M a t h . f l o o r ( C   /   4 )   -   M a t h . f l o o r ( ( C   -   K )   /   3 )   +   1 9   *   N   +   1 5 ;  
         I   =   I   -   3 0 * M a t h . f l o o r ( ( I   /   3 0 ) ) ;  
         I   =   I   -   M a t h . f l o o r ( I   /   2 8 )   *   ( 1   -   M a t h . f l o o r ( I   /   2 8 )   *   M a t h . f l o o r ( 2 9   /   ( I   +   1 ) )   *   M a t h . f l o o r ( ( 2 1   -   N )   /   1 1 ) ) ;  
         v a r   J   =   Y   +   M a t h . f l o o r ( Y   /   4 )   +   I   +   2   -   C   +   M a t h . f l o o r ( C   /   4 ) ;  
         J   =   J   -   7   *   M a t h . f l o o r ( J   /   7 ) ;  
         v a r   L   =   I   -   J ;  
         v a r   M   =   3   +   M a t h . f l o o r ( ( L   +   4 0 )   /   4 4 ) ;  
         v a r   D   =   L   +   2 8   -   3 1   *   M a t h . f l o o r ( M   /   4 ) ;  
  
 	 v a r   r e t   =   n e w   O b j e c t ( ) ;  
 	 r e t [ 1 ]   =   M ;  
 	 r e t [ 2 ]   =   D ;  
 	 r e t u r n   r e t ;  
 }  
  
 f u n c t i o n   D O W ( d a y , m o n t h , y e a r )   {  
 	 v a r   a   =   M a t h . f l o o r ( ( 1 4   -   m o n t h ) / 1 2 ) ;  
 	 v a r   y   =   y e a r   -   a ;  
 	 v a r   m   =   m o n t h   +   1 2 * a   -   2 ;  
 	 v a r   d   =   ( d a y   +   y   +   M a t h . f l o o r ( y / 4 )   -   M a t h . f l o o r ( y / 1 0 0 )   +  
 	 	 	 M a t h . f l o o r ( y / 4 0 0 )   +   M a t h . f l o o r ( ( 3 1 * m ) / 1 2 ) )   %   7 ;  
 	 r e t u r n   d   +   1 ;  
 }  
  
 f u n c t i o n   N t h D O W ( n t h , w e e k d a y , m o n t h , y e a r )   {  
 	 i f   ( n t h   >   0 )  
 	 	 r e t u r n   ( n t h   -   1 )   *   7   +   1   +   ( 7   +   w e e k d a y   -   D O W ( ( n t h   -   1 )   *   7   +   1 ,   m o n t h ,   y e a r ) )   %   7 ;  
 	 v a r   d a y s   =   c i v M o n t h L e n g t h ( m o n t h ,   y e a r ) ;  
 	 r e t u r n   d a y s   -   ( D O W ( d a y s ,   m o n t h ,   y e a r )   -   w e e k d a y   +   7 )   %   7 ;  
 }  
  
 f u n c t i o n   h o l i d a y s ( c d a y ,   c m o n t h ,   c y e a r )   {  
 	 / /   A m e r i c a n   c i v i l   h o l i d a y s   a n d   s o m e   m a j o r   r e l i g i o u s   h o l i d a y  
 	 i f   ( c m o n t h   = =   1   & &   c d a y   = =   1 )  
 	 	 r e t u r n   " N e w   Y e a r ' s   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   2   & &   c d a y   = =   1 2 )  
 	 	 r e t u r n   " L i n c o l n ' s   B i r t h d a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   2   & &   c d a y   = =   1 4 )  
 	 	 r e t u r n   " V a l e n t i n e ' s   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   2   & &   c d a y   = =   N t h D O W ( 3 ,   2 ,   2 ,   c y e a r ) )  
 	 	 r e t u r n   " P r e s i d e n t ' s   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   3   & &   c d a y   = =   1 7 )  
 	 	 r e t u r n   " S t .   P a t r i c k ' s   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   3   | |   c m o n t h   = =   4 )   {  
 	 	 v a r   e   =   E a s t e r ( c y e a r ) ;  
 	         i f   ( c m o n t h   = =   e [ 1 ]   & &   c d a y   = =   e [ 2 ] )  
 	 	 	 r e t u r n   " E a s t e r " ;  
 	 }  
 	 e l s e   i f   ( c m o n t h   = =   5   & &   c d a y   = =   N t h D O W ( 2 ,   1 ,   5 ,   c y e a r ) )  
 	 	 r e t u r n   " M o t h e r ' s   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   5   & &   c d a y   = =   N t h D O W ( 3 ,   7 ,   5 ,   c y e a r ) )  
 	 	 r e t u r n   " A r m e d   F o r c e s   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   5   & &   c d a y   = =   N t h D O W ( 0 ,   2 ,   5 ,   c y e a r ) )  
 	 	 r e t u r n   " M e m o r i a l   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   6   & &   c d a y   = =   1 4 )  
 	 	 r e t u r n   " F l a g   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   6   & &   c d a y   = =   N t h D O W ( 3 ,   1 ,   6 ,   c y e a r ) )  
 	 	 r e t u r n   " F a t h e r ' s   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   7   & &   c d a y   = =   4 )  
 	 	 r e t u r n   " I n d e p e n d e n c e   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   9   & &   c d a y   = =   N t h D O W ( 1 ,   2 ,   9 ,   c y e a r ) )  
 	 	 r e t u r n   " L a b o r   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   1 0   & &   c d a y   = =   N t h D O W ( 2 ,   2 ,   1 0 ,   c y e a r ) )  
 	 	 r e t u r n   " C o l u m b u s   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   1 0   & &   c d a y   = =   3 1 )  
 	 	 r e t u r n   " H a l l o w e e n " ;  
 	 e l s e   i f   ( c m o n t h   = =   1 1   & &   c d a y   = =   1 1 )  
 	 	 r e t u r n   " V e t e r a n s '   D a y " ;  
 	 e l s e   i f   ( c m o n t h   = =   1 1   & &   c d a y   = =   N t h D O W ( 4 ,   5 ,   1 1 ,   c y e a r ) )  
 	 	 r e t u r n   " T h a n k s g i v i n g " ;  
 	 e l s e   i f   ( c m o n t h   = =   1 2   & &   c d a y   = =   2 5 )  
 	 	 r e t u r n   " C h r i s t m a s " ;  
  
 	 r e t u r n   " " ;  
 }  
  
 f u n c t i o n   m o a d i m ( c d a y ,   c m o n t h ,   c y e a r ,   h d a y ,   h m o n t h ,   d o w )   {  
 	 i f ( h m o n t h   = =   6 )   {  
 	 	 i f ( h d a y   = =   1   | |   h d a y   = =   2 )  
 	 	 	 r e t u r n   " R o s h   H a s h a n a "  
 	 	 e l s e   i f ( h d a y   = =   3   & &   d o w   ! =   7 )  
 	 	 	 r e t u r n   " F a s t   o f   G e d a l i a " ;  
 	 	 e l s e   i f ( h d a y   = =   4   & &   d o w   = =   1 )  
 	 	 	 r e t u r n   " F a s t   o f   G e d a l i a " ;  
 	 	 e l s e   i f ( h d a y   = =   1 0 )  
 	 	 	 r e t u r n   " Y o m   K i p p u r "  
 	 	 e l s e   i f ( h d a y   > =   1 5   & &   h d a y   < =   2 2 )  
 	 	 	 r e t u r n   " S u k k o t "  
 	 	 e l s e   i f ( h d a y   = =   2 3 )  
 	 	 	 r e t u r n   " S u k k o t   ( d ) "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   8 )   {  
 	 	 i f ( h d a y   > =   2 5 )  
 	 	 	 r e t u r n   " C h a n u k k a h "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   9 )   {  
 	 	 i f ( h d a y   < =   2 )   {  
 	 	 	 r e t u r n   " C h a n u k k a h "  
 	 	 }  
 	 	 e l s e   i f ( h d a y   = =   3 )   {  
 	 	 	 / /   K i s l e v   c a n   b e   m a l e i   o r   c h a s e r  
 	 	 	 i f ( c d a y   = =   1 )   {  
 	 	 	 	 c d a y   =   2 9 ;  
 	 	 	 	 c m o n t h   =   1 1 ;  
 	 	 	 }  
 	 	 	 e l s e   i f ( c d a y   = =   2 )   {  
 	 	 	 	 c d a y   =   3 0 ;  
 	 	 	 	 c m o n t h   =   1 1 ;  
 	 	 	 }  
 	 	 	 e l s e  
 	 	 	 	 c d a y   - =   3 ;  
 	 	 	 v a r   h d a t e   =   c i v 2 h e b ( c d a y ,   c m o n t h ,   c y e a r ) ;  
 	 	 	 h d   =   e v a l ( h d a t e . s u b s t r i n g ( 0 ,   h d a t e . i n d e x O f ( '   ' ) ) ) ;  
 	 	 	 i f ( h d   = =   2 9 )  
 	 	 	 	 r e t u r n   " C h a n u k k a h "  
 	 	 }  
 	 	 e l s e   i f ( h d a y   = =   1 0 )  
 	 	 	 r e t u r n   " F a s t   o f   T e v e t "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   1 0 )   {  
 	 	 i f ( h d a y = = 1 5 )  
 	 	 	 r e t u r n   " T u   b ' S h v a t "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   1 1   | |   h m o n t h   = =   1 3 )   {  
 	 	 i f ( h d a y   = =   1 1   & &   d o w   = =   5 )  
 	 	 	 r e t u r n   " T a a n i t   E s t h e r "  
 	 	 e l s e   i f ( h d a y   = =   1 3   & &   d o w   ! =   7 )  
 	 	 	 r e t u r n   " T a a n i t   E s t h e r "  
 	 	 e l s e   i f ( h d a y   = =   1 4 )  
 	 	 	 r e t u r n   " P u r i m "  
 	 	 e l s e   i f ( h d a y   = =   1 5 )  
 	 	 	 r e t u r n   " S h u s h a n   P u r i m "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   0 )   {  
  
 	 	 i f ( h d a y   = =   1 2   & &   d o w   = =   5 )  
 	 	 	 r e t u r n   " T a a n i t   B e c h o r o t "  
 	 	 e l s e   i f ( h d a y   = =   1 4   & &   d o w   ! =   7 )  
 	 	 	 r e t u r n   " T a a n i t   B e c h o r o t "  
 	 	 e l s e   i f ( h d a y   > =   1 5   & &   h d a y   < =   2 1 )  
 	 	 	 r e t u r n   " P e s a c h "  
 	 	 e l s e   i f ( h d a y   = =   2 2 )  
 	 	 	 r e t u r n   " P e s a c h   ( d ) "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   1 )   {  
 	 	 i f ( h d a y   = =   3   & &   d o w   = =   5 )  
 	 	 	 r e t u r n   " Y o m   H a ' A t z m a u t "  
 	 	 e l s e   i f ( h d a y   = =   4   & &   d o w   = =   5 )  
 	 	 	 r e t u r n   " Y o m   H a ' A t z m a u t "  
 	 	 e l s e   i f ( h d a y   = =   5   & &   d o w   ! =   6   & &   d o w   ! =   7 )  
 	 	 	 r e t u r n   " Y o m   H a ' A t z m a u t "  
 	 	 i f ( h d a y   = =   1 4 )  
 	 	 	 r e t u r n   " P e s a h   s h e n i "  
 	 	 e l s e   i f ( h d a y   = =   1 8 )  
 	 	 	 r e t u r n   " L a g   B ' O m e r "  
 	 	 i f ( h d a y   = =   2 8 )  
 	 	 	 r e t u r n   " Y o m   Y e r u s h a l a y i m "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   2 )   {  
 	 	 i f ( h d a y   = =   6 )  
 	 	 	 r e t u r n   " S h a v u o t "  
 	 	 e l s e   i f ( h d a y   = =   7 )  
 	 	 	 r e t u r n   " S h a v u o t   ( d ) "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   3 )   {  
 	 	 i f ( h d a y   = =   1 7   & &   d o w   ! =   7 )  
 	 	 	 r e t u r n   " F a s t   o f   T a m m u z "  
 	 	 i f ( h d a y   = =   1 8   & &   d o w   = =   1 )  
 	 	 	 r e t u r n   " F a s t   o f   T a m m u z "  
 	 }  
 	 e l s e   i f ( h m o n t h   = =   4 )   {  
 	 	 i f ( h d a y   = =   9   & &   d o w   ! =   7 )  
 	 	 	 r e t u r n   " T i s h a   B ' A v "  
 	 	 i f ( h d a y   = =   1 0   & &   d o w   = =   1 )  
 	 	 	 r e t u r n   " T i s h a   B ' A v "  
 	 	 i f ( h d a y   = =   1 5 )  
 	 	 	 r e t u r n   " T u   B ' A v "  
 	 }  
  
 	 r e t u r n   " " ;  
 }  
 
