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