
      /**********

          file:     help_part_2.js
          created:  15 mar 2005  by blending page_460_help_1.js with page_460_help_2.js
          topic:    support ftns for user choosing colors
          text:     Mastering JavaScript
          author:   James Jaworski
          pages:    <none>

          updates:
             31 mar 2005  Removed all tabs
             02 apr 2005  1) Allowed user to choose blue for background color
                          2) Added "<span>" tags to some create_prefs_form items
             03 apr 2005  Added the  gmt_set_color_btn  class
             07 apr 2005  Removed attempt to use rough gray background
             30 apr 2005  Removed some debugging lines
             03 June 2005  
                 1) Added blanched almond to choices for bg color
                 2) Reformatted file
             06 nov 2005  Moved file from home area to top_help_js

    
      **********/

      var  expiration_date = 
             "Tuesday, 10-Nov-20 23:12:40 GMT" ; // cookie valid until 10 nov 2020


      function name_is_defined ( ck, nam )
         {
             var ss    = remove_blanks( ck ) ;
             var pairs = ss.split( ";" ) ;
             for( var j=0; j<pairs.length; j++ )
                {
                    var pair_split = pairs[j].split( "=" ) ;
                    if ( pair_split[0] == nam ) 
                       {
                          return true ;
                       }
                }
             return false ;

         } // name_is_defined

      function remove_blanks ( ss )
         {
            var temp = "" ;
            for( var j=0; j<ss.length; j++ ) 
               {
                  var cc = ss.charAt( j ) ;
                  if ( cc != " " )
                     {
                        temp += cc ;
                     }
               }
            return temp ;
        
          } // remove_blanks
       
       function get_cookie_value ( kk, n )
          {
              var ss = remove_blanks( kk ) ;
              var pairs = ss.split( ";" ) ;
              for( var j=0; j<pairs.length; j++ )
                 {
                    var pair_split = pairs[j].split( "=" ) ;
                    if ( pair_split[0] == n )
                       {
                          return pair_split[ 1 ] ;
                       }
                 }
              return "" ;
       
           } // get_cookie_value

        function read_cookie() 
           {
               //// alert( "Hello from top of read_cookie " ) ;

               var cookie = document.cookie ;

               part_2_text_color = "black" ;

               if ( name_is_defined( cookie, "part_2_background" )) 
                  {
                      part_2_background = get_cookie_value ( cookie, "part_2_background" ) ;
                  }
               else
                  {
                      part_2_background = "white" ;  // added on 02 march 2005
                  }
       
               if ( name_is_defined( cookie, "part_2_text_color" )) 
                  {
                      part_2_text_color = get_cookie_value ( cookie, "part_2_text_color" ) ;
                  }
      
            } // read_cookie

         function setCookie() 
            {
        
                var new_cookie_1 = "part_2_background=" + part_2_background ;

                //// alert( "Start of   new_cookie_1 is " +  new_cookie_1 ) ;

                new_cookie_1 += "; expires="  +  expiration_date ; 
       
                window.document.cookie = new_cookie_1 ;
       
                var new_cookie_2 = "part_2_text_color=" + part_2_text_color ;
       
                new_cookie_2 += "; expires="  +  expiration_date ; 
         
                window.document.cookie = new_cookie_2 ;
       
                window.location="craps_part_2.htm"

            } // setCookie

         function set_prefs () 
            {
                //// alert( "Hello from top of set_prefs " ) ;
        
                bg_field     = window.document.my_prefs_form.my_bg ;
                bg_index     = bg_field.selectedIndex ;
       
                if ( bg_field.options[bg_index].text == "light gray" )     
                   {
                       part_2_background = "#eeeeee" ;  // smooth light gray
                   }
                else if ( bg_field.options[bg_index].text == "blanched almond" )
                   {
                       part_2_background = "blanchedalmond" ; 
                   }
                else
                   {
                       part_2_background  = bg_field.options[bg_index].text ;
                   }
     
                fg_field     = window.document.my_prefs_form.my_fg ;
                fg_index     = fg_field.selectedIndex ;
                part_2_text_color  = fg_field.options[fg_index].text ;
                setCookie() ;
       
            } // set_prefs

         function create_prefs_form () 
            {
                document.writeln( '<form   name="my_prefs_form">' ) ;

                document.writeln( "<span  class='gmt_choose_color' >"  +
                                  "&nbsp;&nbsp;&nbsp;&nbsp;   Background color: </span>" ) ;

                document.writeln( '<select  name="my_bg" size="1" >' ) ;
                document.writeln( '<option>aqua' ) ;

                document.writeln( '<option>blanched almond' ) ;
                document.writeln( '<option>blue' ) ;

                document.writeln( '<option>black' ) ;
                          //// document.writeln( '<option>rough_gray' ) ;        
                document.writeln( '<option>light gray' ) ;              
                document.writeln( '<option>lime' ) ;
                document.writeln( '<option>orange' ) ;
                document.writeln( '<option>red' ) ;
                document.writeln( '<option>tan' ) ;
                document.writeln( '<option SELECTED >white' ) ;  
                document.writeln( '<option>yellow' ) ;        
                document.writeln( '</select >' ) ;

                //// document.writeln( ' Text color: ' ) ;

                document.writeln( "<span  class='gmt_choose_color' >"  +
                                  "&nbsp Text color: </span>" ) ;

                document.writeln( '<select  name="my_fg" size="1" >' ) ;
                document.writeln( '<option>aqua' ) ;        
                document.writeln( '<option SELECTED >black' ) ;
                document.writeln( '<option>blue' ) ;  
                document.writeln( '<option>gray' ) ;  
                document.writeln( '<option>green' ) ; 
                document.writeln( '<option>lime' ) ;        
                document.writeln( '<option>orange' ) ;
                document.writeln( '<option>red' ) ;
                document.writeln( '<option>silver' ) ;                    
                document.writeln( '<option>tan' ) ;
                document.writeln( '<option>white' ) ;
                document.writeln( '<option>yellow' ) ;        
                document.writeln( '</select >' ) ;
                document.write( ' &nbsp; &nbsp; ' ) ;  // two spaces     
                document.writeln( "<input   "                  +
                                  "class='gmt_set_color_btn'"  +
                                  "type='button'"              +
                                  "value='Set Colors'"         +
                                  "onClick='set_prefs()'" ) ;
                document.writeln( '</form>' ) ;

            } // create_prefs_form

