ÿþ/ / J a v a s c r i p t  
  
 / *  
 F u n c t i o n :   b u i l d S e a r c h S t r i n g  
 D e s c r i p t i o n :   E x a m i n e s   s t r I n p u t ,   r e m o v e s   i l l e g a l   c h a r a c t e r s   a n d   s e l e c t e d   k e y w o r d s .  
 	 	 	 	 	 	   B u i l d s   a n d   r e t u r n s   a   V e r i t y   f o r m a t t e d   s e a r c h   s t r i n g .  
 * /  
 f u n c t i o n   b u i l d S e a r c h S t r i n g ( s e a r c h S t r i n g ,   k e y w o r d s T o R e m o v e )   {  
     v a r   k e y W o r d s ;  
     v a r   v e r i t y S e a r c h S t r i n g ;  
  
 	 / /   R e m o v e   i l l e g a l   c h a r a c t e r s  
 	 / /   F e b   0 9   2 0 0 9   -   B O B M A   -   s w a p p e d   o u t   a n   i t e r a t i v e   f u n c t i o n   u s e d   i n   v e r s i o n   1   f o r   t h i s   r e p l a c e   c a l l .  
 	 s e a r c h S t r i n g   =   s e a r c h S t r i n g . r e p l a c e ( / [ ' = ( ) . > < ! ` @ { } * , _ ~ ; : ^ + / \ \ | & # [ \ ] ] / g i ,   " " ) ;  
  
     / /   R e m o v e s   a n y   u n m a t c h i n g   d o u b l e   q u o t e s  
     s e a r c h S t r i n g   =   r e m o v e E x t r a Q u o t e s ( s e a r c h S t r i n g ) ;  
  
     / /   R e t u r n s   a n   a r r a y   c o n t a i n i n g   k e y W o r d s   a n d   q u o t e d   p h r a s e s  
     / /   F e b   0 9   2 0 0 9   -   B O B M A   -   s w a p p e d   o u t   a   v e r y   i t e r a t i v e   f u n c t i o n   f o r   t h i s   r e g u l a r   e x p r e s s i o n   u s e .  
     k e y W o r d s   =   s e a r c h S t r i n g . m a t c h ( / \ b \ S + \ b | " [ ^ " ] * " / g i ) ;  
  
     / /   B u i l d s   a   V e r i t y   b a s e d   s e a r c h   s t r i n g   b a s e d   u p o n   a n  
     / /   a r r a y   o f   k e y w o r d s  
     v e r i t y S e a r c h S t r i n g   =   b u i l d V e r i t y S e a r c h S t r i n g ( k e y W o r d s ,   k e y w o r d s T o R e m o v e ) ;  
  
     r e t u r n   v e r i t y S e a r c h S t r i n g ;  
 }  
  
 / *  
 F u n c t i o n   :   b u i l d V e r i t y S e a r c h S t r i n g  
 D e s c r i p t i o n   :   B u i l d s   a   V e r i t y   s e a r c h   s t r i n g   b a s e d   u p o n   a n   a r r a y   o f   k e y w o r d s .  
 * /  
 f u n c t i o n   b u i l d V e r i t y S e a r c h S t r i n g ( k e y W o r d s ,   k e y w o r d s T o R e m o v e )   {  
 	 v a r   b a s i c V e r i t y C l a u s e   =   " < M A N Y > < T H E S A U R U S > x x x x   < A C C R U E >   < M A N Y > < S T E M > y y y y "  
     v a r   n e w C l a u s e   =   " " ;  
     v a r   n e w S e a r c h S t r i n g   =   " " ;  
     v a r   q u o t e   =   " \ " " ;  
     v a r   k e y W o r d   =   " " ;  
     v a r   i g n o r e d R e g E x p   =   G e t I g n o r e d K e y w o r d s R e g E x p ( k e y w o r d s T o R e m o v e ) ;  
  
 	 / /   L o o p   t h r o u g h   t h e   k e y W o r d s   a r r a y   a n d   b u i l d   a   v e r i t y   s e a r c h   c l a u s e   f o r   e a c h  
     / /   k e y W o r d   t h a t   i s   n o t   e n c l o s e d   i n   d o u b l e   q u o t e s .  
     / /   I f   t h e   k e y W o r d   i s   e n c l o s e d   i n   d o u b l e   q u o t e s ,   j u s t   a p p e n d   t h e   k e y W o r d   t o   t h e   v e r i t y   s e a r c h   s t r i n g .  
     f o r   ( i   =   0   ;   i   <   k e y W o r d s . l e n g t h   ;   i + + )   {  
     	 k e y W o r d   =   k e y W o r d s [ i ] ;  
  
     	 i f   (   k e y W o r d . i n d e x O f ( q u o t e )   = =   - 1   )   {  
  
 	 	 	 / / F e b   0 9   2 0 0 9   -   B O B M A   -   d o   n o t   i n c l u d e   s p e c i f i e d   w o r d s   i n   v e r i t y   s e a r c h   s t r i n g  
             i f   ( ! i g n o r e d R e g E x p . t e s t ( k e y W o r d ) )   {  
             	 / /   S p e c i a l   c a s e   i f   k e y W o r d   i s   ' a n d ' ,   ' o r ' ,   o r   ' n o t ' .   I t   m u s t   b e   w r a p p e d   i n   s i n g l e   q u o t e s   t o   c o o p e r a t e   w i t h   < a c c r u e > .  
                 i f   ( k e y W o r d   = =   " a n d "   | |   k e y W o r d   = =   " o r "   | |   k e y W o r d   = =   " n o t " )   {  
                 	 k e y W o r d   =   " ' "   +   k e y W o r d   +   " ' " ;  
                 }  
                 n e w C l a u s e   =   b a s i c V e r i t y C l a u s e . r e p l a c e ( " x x x x " ,   k e y W o r d ) ;  
                 n e w C l a u s e   =   n e w C l a u s e . r e p l a c e ( " y y y y " ,   k e y W o r d ) ;  
                 n e w S e a r c h S t r i n g   =   A p p e n d S e a r c h S t r i n g ( n e w S e a r c h S t r i n g ,   n e w C l a u s e ) ;  
 	 	 	 }  
         }   e l s e   {  
         	 / / t h i s   i s   a   q u o t e d   p h r a s e   s o   a d d   i t   a s   i s .  
             n e w S e a r c h S t r i n g   =   A p p e n d S e a r c h S t r i n g ( n e w S e a r c h S t r i n g ,   k e y W o r d ) ;  
         }  
     }  
  
     r e t u r n   n e w S e a r c h S t r i n g ;  
 }  
  
 / *  
 F u n c t i o n   :   A p p e n d S e a r c h S t r i n g  
 D e s c r i p t i o n   :   r e t u r n s   t h e   s e a r c h   s t r i n g   w i t h   t h e   n e w   c l a u s e   j o i n e d   b y   t h e   " A C C R U E "   v e r i t y   o p p e r a t o r .  
 * /  
 f u n c t i o n   A p p e n d S e a r c h S t r i n g ( s e a r c h S t r i n g ,   n e w C l a u s e )   {  
 	 i f   ( s e a r c h S t r i n g . l e n g t h   >   0 )  
 	 	 s e a r c h S t r i n g   + =   "   < A C C R U E >   " ;  
 	 	 	 	 	  
 	 r e t u r n   s e a r c h S t r i n g   + =   n e w C l a u s e ;  
 }  
  
  
 / *  
 F e b   0 9   2 0 0 9   -   B O B M A  
 F u n c t i o n   :   G e t I g n o r e d K e y w o r d s R e g E x p  
 D e s c r i p t i o n   :   C r e a t e s   t h e   r e g u l a r   e x p r e s s i o n   f o r   m a t c h c i n g   a g a i n s t   s u p p l i e d   k e y w o r d s  
 P a r a m e t e r s :   C o m m a   s e p e r a t e d   l i s t   o f   w o r d s  
 * /  
 f u n c t i o n   G e t I g n o r e d K e y w o r d s R e g E x p ( k e y w o r d s )   {  
 	 v a r   p a t t e r n   =   " " ;  
  
 	 i f   ( k e y w o r d s   = =   n u l l   | |   k e y w o r d s . l e n g t h   < =   0 )  
 	 	 r e t u r n   n e w   R e g E x p ( " ^ $ " ) ; 	 / / w e   d o n ' t   w a n t   t o   m a t c h   a n y t h i n g   i n   t h i s   c a s e .  
  
 	 / / l o o p   t h r o u g h   e a c h   o f   t h e   k e y w o r d s   a n d   c r e a t e   t h e   a p p r o p r i a t e   r e g   e x p   m a t c h  
 	 v a r   w o r d s   =   k e y w o r d s . s p l i t ( " , " ) ;  
 	 f o r   ( i = 0 ;   i < w o r d s . l e n g t h ;   i + + )   {  
 	 	 p a t t e r n   + =   ( i   = =   0   ?   " "   :   " | " )   +   " \ \ b "   +   w o r d s [ i ] . t r i m ( )   +   " \ \ b " ;  
 	 }  
 	  
 	 r e t u r n   n e w   R e g E x p ( p a t t e r n ,   " g i " ) ;  
 }  
  
  
 / *  
 F u n c t i o n   :   r e m o v e E x t r a Q u o t e s  
 D e s c r i p t i o n :   R e m o v e s   u n m a t c h e d   d o u b l e   q u o t e s   w i t h i n   a   s t r i n g .   I f   s t r I n p u t   c o n t a i n s    
 a n   o d d   n u m b e r   o f   d o u b l e   q u o t e s   ( " ) ,   t h i s   f u n c t i o n   w i l l   r e m o v e   t h e   l a s t   d o u b l e   q u o t e    
 f r o m   t h e   s t r i n g .  
 * /  
 f u n c t i o n   r e m o v e E x t r a Q u o t e s ( s t r I n p u t )   {  
  
     v a r   d s   =   n e w   A r r a y ( ) ;  
     v a r   d i   =   0 ;  
     v a r   q u o t e   =   " \ " " ;  
     v a r   p o s   =   0 ;  
     v a r   s t a r t   =   0 ;  
     v a r   n u m b e r O f E l e m e n t s   =   0 ;  
     v a r   n e w S t r i n g   =   " " ;  
  
     / /   G e t   t h e   p o s i t i o n   o f   t h e   f i r s t   d o u b l e   q u o t e  
     p o s   =   s t r I n p u t . i n d e x O f ( q u o t e ,   s t a r t ) ;  
  
     / /   A d d   a n   e l e m e n t   t o   a r r a y   d s   t h a t   c o n t a i n s   t h e   p o s i t i o n   o f   e v e r y   d o u b l e   q u o t e  
     / /   i n   t h e   s t r i n g   s t r I n p u t  
     w h i l e   ( p o s   ! =   - 1 )   {  
         d s [ d i + + ]   =   p o s ;  
         s t a r t   =   p o s   +   1 ;  
         p o s   =   s t r I n p u t . i n d e x O f ( q u o t e ,   s t a r t ) ;  
     }  
  
     n u m b e r O f E l e m e n t s   =   d s . l e n g t h ;  
  
     / /   I f   t h e r e   i s   a n   o d d   n u m b e r   o f   e l e m e n t s   i n   d s ,   t h e n   r e m o v e   t h e   l a s t   d o u b l e   q u o t e  
     / /   f r o m   s t r i n g   s t r I n p u t ,   o t h e r w i s e   r e t u r n   t h e   s t r i n g   u n c h a n g e d  
     i f   (   ( n u m b e r O f E l e m e n t s   %   2 )   ! =   0   )   {  
         p o s   =   d s [ n u m b e r O f E l e m e n t s   -   1 ] ;  
         n e w S t r i n g   =   s t r I n p u t . s u b s t r i n g ( 0 ,   p o s )   +   s t r I n p u t . s u b s t r i n g ( p o s   +   1 ) ;  
     }   e l s e   {  
         n e w S t r i n g   =   s t r I n p u t ;  
     }  
  
     r e t u r n   n e w S t r i n g ;  
 }  
  
  
 / *  
 F u n c t i o n   :   s e a r c h H e l p  
 D e s c r i p t i o n :   O p e n s   a   n e w   b r o w s e r   w i n d o w   w i t h   a   U R L   b a s e d   o n   t h e   i n c o m i n g   v a l u e .  
 * /  
 f u n c t i o n   s e a r c h H e l p ( l o c a t i o n )   {  
     v a r   h e l p W i n d o w   =   n u l l ;  
  
     h e l p W i n d o w   =   w i n d o w . o p e n ( ' ' + l o c a t i o n + ' ' , ' ' ,   ' w i d t h = 5 7 5 , h e i g h t = 2 0 0 , l e f t = 2 5 0 , t o p = 2 5 0 , t o o l b a r = 0 , l o c a t i o n = 0 , d i r e c t o r i e s = 0 , s t a t u s = 0 , r e s i z a b l e = 1 , s c r o l l b a r s = 1 , m e n u b a r = 0 ' )  
 }  
  
  
 / *  
 F u n c t i o n   :   t r i m  
 D e s c r i p t i o n :   H e l p e r   f u n c t i o n   t o   r e m o v e   s p a c e s   a r o u n d   a   s t r i n g  
 * /  
 S t r i n g . p r o t o t y p e . t r i m   =   f u n c t i o n ( )   {  
     r e t u r n   t h i s . r e p l a c e ( / ^ \ s + | \ s + $ / g ,   " " ) ;  
 }  
 
