ÿþv a r   c _ y e a r T i m e U n i t   =   3 9 ;  
  
 f u n c t i o n   i n i t ( )   {  
         a c t i v F i e l d ( ' S u m R e q u i r e d ' ) ;  
         i n i t E l e m e n t s ( )  
 }  
  
 f u n c t i o n   n e x t ( )   {  
 	 i f   ( ! n e x t C o m m o n ( ) )   {  
 	 	 r e t u r n ;  
 	 }  
  
         v a r   l e a d   =   d o c u m e n t . g e t E l e m e n t B y I d ( ' l e a d ' ) ;  
         l e a d . H y p o t h e c I n c o m e C u r r e n c y . v a l u e   =   l e a d . S u m C u r r e n c y . v a l u e ;  
         l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d C u r r e n c y . v a l u e   =   l e a d . S u m C u r r e n c y . v a l u e ;  
         l e a d . R e f i n a n c i n g D e b t C u r r e n c y . v a l u e   =   l e a d . S u m C u r r e n c y . v a l u e ;  
 	  
 	 v a r   f i e l d ;  
 	 i f   ( l e a d . A i m . v a l u e   = =   ' 1 ' )   {  
 	         s t e p   =   ' s t e p H y p o t h e c ' ;  
 	         f i e l d   =   ' H y p o t h e c R e a l t y T y p e ' ;  
 	 }   e l s e   {  
 	 	 s t e p   =   ' s t e p R e f i n a n c i n g ' ;  
 	 	 f i e l d   =   ' R e f i n a n c i n g B a n k ' ;  
 	 }  
 	  
 	 d o c u m e n t . g e t E l e m e n t B y I d ( s t e p ) . s t y l e . d i s p l a y   =   ' i n l i n e ' ;  
 	 a c t i v F i e l d ( f i e l d ) ;  
 }  
  
 f u n c t i o n   c h a n g e M a r k e t ( f i e l d )   {  
 i f   ( 8   = =   f i e l d . v a l u e   | |   1 0   = =   f i e l d . v a l u e   | |   1 1   = =   f i e l d . v a l u e )   {  
         d o c u m e n t . g e t E l e m e n t B y I d ( ' H y p o t e c M a r k e t B l o c k 1 ' ) . s t y l e . v i s i b i l i t y   =   ' v i s i b l e ' ;  
         d o c u m e n t . g e t E l e m e n t B y I d ( ' H y p o t e c M a r k e t B l o c k 2 ' ) . s t y l e . v i s i b i l i t y   =   ' v i s i b l e ' ;  
         d o c u m e n t . g e t E l e m e n t B y I d ( ' H y p o t e c M a r k e t B l o c k 0 ' ) . s t y l e . v i s i b i l i t y   =   ' v i s i b l e ' ;  
         }  
         e l s e   {  
         d o c u m e n t . g e t E l e m e n t B y I d ( ' H y p o t e c M a r k e t B l o c k 1 ' ) . s t y l e . v i s i b i l i t y   =   ' h i d d e n ' ;  
         d o c u m e n t . g e t E l e m e n t B y I d ( ' H y p o t e c M a r k e t B l o c k 2 ' ) . s t y l e . v i s i b i l i t y   =   ' h i d d e n ' ;  
         d o c u m e n t . g e t E l e m e n t B y I d ( ' H y p o t e c M a r k e t B l o c k 0 ' ) . s t y l e . v i s i b i l i t y   =   ' h i d d e n ' ;  
         t o g g l e ( ' H y p o t h e c M a r k e t ' ,   d o c u m e n t . g e t E l e m e n t B y I d ( ' H y p o t e c M a r k e t B l o c k 0 ' ) )  
         }  
 }  
  
 f u n c t i o n   c h e c k _ o n b l u r ( f i e l d )   {  
         v a r   v   =   v a l i d a t e ( f i e l d ) ;  
         i f   ( v   ! =   n u l l   & &   g e t H i g h l i g h t E r r o r ( f i e l d ) )   {  
                 c a l l S e r v e r ( f i e l d . i d   +   ' | '   +   f i e l d . v a l u e ,   n u l l )  
         }  
         s e t R e d E r r o r ( f i e l d , v ) ;  
 }  
  
 f u n c t i o n   v a l i d a t e ( f i e l d )   {  
 	 v a r   v a r t y p e   =   f i e l d . g e t A t t r i b u t e ( ' v a r t y p e ' ) ;  
 	 v a r   m i n   =   f i e l d . g e t A t t r i b u t e ( ' m i n ' ) ;  
 	 v a r   m a x   =   f i e l d . g e t A t t r i b u t e ( ' m a x ' ) ;  
  
 	 i f   ( v a r t y p e   = =   u n d e f i n e d )   r e t u r n   n u l l ;  
  
 	 v a r   v a l u e   =   f i e l d . v a l u e . r e p l a c e ( / ^ \ s + / ,   ' ' ) . r e p l a c e ( / \ s + $ / ,   ' ' ) ;  
 	 v a r   a l l o w e m p t y   =   f i e l d . g e t A t t r i b u t e ( ' a l l o w e m p t y ' ) ;  
 	  
 	 i f   ( v a l u e   = =   ' ' )   {  
 	         i f   ( a l l o w e m p t y   = =   ' T r u e ' )   r e t u r n   n u l l ;  
 	         e l s e   i f   ( v a r t y p e   = =   ' i n t '   & &   m i n   = =   ' 0 ' )   v a l u e   =   ' 0 ' ;  
 	         e l s e   r e t u r n   c _ e m p t y ;  
 	 }  
 	  
 	 v a r   l e a d   =   d o c u m e n t . g e t E l e m e n t B y I d ( ' l e a d ' ) ;  
 	 i f   ( f i e l d . i d   = =   ' R e f i n a n c i n g T e r m '   & &   l e a d . R e f i n a n c i n g T e r m U n i t s . v a l u e   = =   c _ y e a r T i m e U n i t )   {  
                 v a l u e   =   ' '   +   v a l u e . r e p l a c e ( / , / ,   ' . ' )   *   1 2 ;  
         }  
 	 i f   ( f i e l d . i d   = =   ' R e f i n a n c i n g R e m a i n i n g '   & &   l e a d . R e f i n a n c i n g R e m a i n i n g U n i t s . v a l u e   = =   c _ y e a r T i m e U n i t )   {  
 	         v a l u e   =   ' '   +   v a l u e . r e p l a c e ( / , / ,   ' . ' )   *   1 2 ;  
 	 }  
 	  
 	 i f   ( f i e l d . i d   = =   ' R e f i n a n c i n g T e r m '   | |   f i e l d . i d   = =   ' R e f i n a n c i n g R e m a i n i n g ' )  
 	 {  
 	         v a r   r e s u l t   =   c h e c k I n t ( v a l u e ,   m i n ,   m a x ) ;  
 	         i f   ( n u l l   = =   r e s u l t )      
 	                 r e t u r n   r e f i n a n c i n g C h e c k ( ) ;  
 	         e l s e   r e t u r n   r e s u l t ;  
 	 }  
 	  
 	 i f   ( f i e l d . i d   = =   ' R e f i n a n c i n g D e b t ' )  
 	 {  
 	         r e t u r n   c h e c k I n t ( v a l u e ,   m i n ,   m a x ) ;  
 	 }  
  
 	 i f   ( f i e l d . i d   = =   ' H y p o t h e c I n c o m e '   | |   f i e l d . i d   = =   ' H y p o t h e c I n c o m e U n c o n f i r m e d ' )  
 	 {  
 	         v a r   r e s u l t   =   c h e c k I n t ( v a l u e ,   m i n ,   m a x ) ;  
 	         i f   ( n u l l   = =   r e s u l t )      
 	                 r e t u r n   i n c o m e S u m C h e c k ( ) ;  
 	         e l s e   r e t u r n   r e s u l t ;  
 	 }  
 	  
 	 r e t u r n   v a l i d a t e C o m m o n ( v a r t y p e ,   m i n ,   m a x ,   v a l u e ) ;  
 }  
  
 f u n c t i o n   r e f i n a n c i n g C h e c k ( )  
 {  
         v a r   r e s u l t   =   n u l l ;  
         v a r   v a l u e 1   =   0 ;  
 	 v a r   l e a d   =   d o c u m e n t . g e t E l e m e n t B y I d ( ' l e a d ' ) ;  
 	 i f   ( l e a d . R e f i n a n c i n g T e r m U n i t s . v a l u e   = =   c _ y e a r T i m e U n i t )   {  
                 v a l u e 1   =   l e a d . R e f i n a n c i n g T e r m . v a l u e . r e p l a c e ( / , / ,   ' . ' )   *   1 2 ;  
         }  
         e l s e   v a l u e 1   =   l e a d . R e f i n a n c i n g T e r m . v a l u e  
          
         v a r   v a l u e 2   =   0 ;  
 	 i f   ( l e a d . R e f i n a n c i n g R e m a i n i n g U n i t s . v a l u e   = =   c _ y e a r T i m e U n i t )   {  
 	         v a l u e 2   =   l e a d . R e f i n a n c i n g R e m a i n i n g . v a l u e . r e p l a c e ( / , / ,   ' . ' )   *   1 2 ;  
 	 }  
 	 e l s e   v a l u e 2   =   l e a d . R e f i n a n c i n g R e m a i n i n g . v a l u e  
  
 	 i f   ( v a l u e 1   <   v a l u e 2 )  
 	 {  
 	         r e s u l t   =   c _ i n c o r r e c t ;  
 	 }  
 	  
 	 s e t R e d E r r o r ( l e a d . R e f i n a n c i n g T e r m , r e s u l t ) ;  
         s e t R e d E r r o r ( l e a d . R e f i n a n c i n g R e m a i n i n g , r e s u l t ) ;  
 	  
 	 r e t u r n   r e s u l t ;  
 }  
  
 f u n c t i o n   i n c o m e S u m C h e c k ( )  
 {  
         v a r   l e a d   =   d o c u m e n t . g e t E l e m e n t B y I d ( ' l e a d ' ) ;  
          
         v a r   i n c 1   =   l e a d . H y p o t h e c I n c o m e . v a l u e . r e p l a c e ( / [ . , '   ] / g ,   ' ' )   *   1 ;  
         v a r   i n c 2   =   l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d . v a l u e . r e p l a c e ( / [ . , '   ] / g ,   ' ' )   *   1 ;  
         v a r   r e s u l t   =   n u l l ;  
          
         i f   ( i n c 1   +   i n c 2   <   1 0 0 )  
         {  
                 r e s u l t   =   c _ i n c o r r e c t ;  
         }  
  
         i f   ( n u l l = = r e s u l t )  
         {  
  
                 v a r   m i n I n c   =   l e a d . H y p o t h e c I n c o m e . g e t A t t r i b u t e ( ' m i n ' ) ;  
         	 v a r   m a x I n c   =   l e a d . H y p o t h e c I n c o m e . g e t A t t r i b u t e ( ' m a x ' ) ;  
         	 v a r   v a l u e I n c   =   p r e V a l i d a t e ( l e a d . H y p o t h e c I n c o m e ) ;       	  
  
                 v a r   m i n I n c U n c   =   l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d . g e t A t t r i b u t e ( ' m i n ' ) ;  
         	 v a r   m a x I n c U n c   =   l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d . g e t A t t r i b u t e ( ' m a x ' ) ;  
         	 v a r   v a l u e I n c U n c   =   p r e V a l i d a t e ( l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d ) ;  
         	       	  
                 i f   ( v a l u e I n c U n c   = =   n u l l   & &   i n c 1   > =   1 0 0 )  
         	 {  
         	         s e t R e d E r r o r ( l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d , n u l l ) ;  
         	         s e t R e d E r r o r ( l e a d . H y p o t h e c I n c o m e , c h e c k I n t ( v a l u e I n c , m i n I n c , m a x I n c ) ) ;    
         	         r e t u r n   n u l l ;  
         	 }  
         	 i f   ( v a l u e I n c   = =   n u l l   & &   i n c 2   > =   1 0 0 )  
         	 {  
         	         s e t R e d E r r o r ( l e a d . H y p o t h e c I n c o m e , n u l l ) ;    
         	         s e t R e d E r r o r ( l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d , c h e c k I n t ( v a l u e I n c U n c , m i n I n c U n c , m a x I n c U n c ) ) ;  
         	         r e t u r n   n u l l ;  
         	 }  
         	  
         	 s e t R e d E r r o r ( l e a d . H y p o t h e c I n c o m e , c h e c k I n t ( v a l u e I n c , m i n I n c , m a x I n c ) ) ;  
                 s e t R e d E r r o r ( l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d , c h e c k I n t ( v a l u e I n c U n c , m i n I n c U n c , m a x I n c U n c ) ) ;          
         }  
         e l s e  
         {  
                 s e t R e d E r r o r ( l e a d . H y p o t h e c I n c o m e , r e s u l t ) ;  
                 s e t R e d E r r o r ( l e a d . H y p o t h e c I n c o m e U n c o n f i r m e d , r e s u l t ) ;  
         }    
          
          
         r e t u r n   r e s u l t ;  
 }  
  
  
 
