
      function initialize_page() {
         alert_debug_f = document.forms.alert_debug.alert_debug1_f.value;
         f = document.forms.start;

         // If show_intro_f set, either go to RIDES page or reload this page.
         
         if ( f.show_intro_f.value == 1 && f.login_only_f.value != 1 ) {
            /*
            if ( f.rides_intro_f.value == 1 ) {
               if ( alert_debug_f ) {
                  alert( "go to RIDES page" );
               } else {
                  top.window.location = "rides"
               }
            }
            */
         }

         // If page not within frame, reload.  Get last part of path.

         var path = top.location.pathname;
         parts = new Array();
         parts = path.split( "/" );
         var nparts = parts.length;
         var page = parts[nparts-1];
         if ( alert_debug_f ) {
            alert( "page: " + page
                   + "\nrestart_f: " + f.restart_f.value
                   + "\nis_nav6up: X" + is_nav6up + "X"
                   + "\nagt: " + agt );
         }

         // index.php may be linked to ridematch_login_frame.php, in which case
         // page will show up as "" or "index.php".

         if (    page != "ridematch_login_frame.php" 
              && page.slice( 0, 11 ) != "admin_login" 
              && page != "" 
              && page != "index.php"                   ) {
            alert ( "Sorry, cannot access this page directly."
                    + "\nClick OK to reload." );
            top.location = "ridematch_login_frame.php";
         }

         if ( is_nav6up && is_win ) {
            f.pc_nav6up_f.value = "1";
         } else {
            f.pc_nav6up_f.value = "";
         }


         if ( f.restart_f.value == 1 ) {
            go_to_registration( 0 );
         } else if ( f.show_intro_f.value != 1 ) {
            set_initial_focus(); 
         }
      }


      function set_initial_focus() {
         f = document.forms.start;
         if ( f.site.value == "" ) {
            f.site_label.focus();
         } else if ( f.area_code.value == "" ) {
            f.area_code.focus();
         } else {
            f.PIN.focus();
         }
      }


      function go_to_registration( new_user_f ) {
         f = document.forms.start;
         var site = f.site.value;

         // If any Netscape (or others I don't know about), let
         // registration.php know, so can set larger title frame.

         if ( new_user_f == 1 ) {
            var new_user_str = "&new_user_f=1";
         } else {
            var new_user_str = "";
         }
         if ( f.promotion_code ) {
            var promotion_code = f.promotion_code.value;
         } else {
            var promotion_code = "";
         }
         pc_nav6up_f = f.pc_nav6up_f.value;
         top.window.location = "registration.php?keep_menu_f=1"
                               + "&site="           + site 
                               + "&pc_nav6up_f="    + pc_nav6up_f
                               + "&promotion_code=" + promotion_code
                               + new_user_str;
      }


      // Called from ridematch_main.js.

      function site_selected() {
         alert_debug_f = document.forms.alert_debug.alert_debug1_f.value;
         f = document.forms.start;
         var site_label_f = f.site_label_f.value;
         if ( site_label_f == 1 ) {
            var i_site_label = f.site_label.selectedIndex;
            if ( alert_debug_f ) {
               alert( "i_site_label: " + i_site_label );
            }
            if ( i_site_label >= 1 ) {
               var site = "" + ( i_site_label - 1 );
            } else {
               site = "";
            }
            return site;
         } else {
            return "0";
         }
      }


      function site_change() {
         alert_debug_f = document.forms.alert_debug.alert_debug1_f.value;
         f = document.forms.start;
         var i_site_label = f.site_label.selectedIndex;
         if ( i_site_label >= 1 ) {
            var site = "" + ( i_site_label - 1 );

            // West Oakland server.  If Dublin-Pleasanton site chosen, redirect.

            if ( site == "1" ) {
               //top.window.location 
               //          = "http://207.234.224.236/ridematch_login_frame.php";
            }
         } else {
            site = "";
         }
         f.site.value = site;
      }


      function login_button() {
         var alert_debug_f = document.forms.alert_debug.alert_debug1_f.value;
         f = document.forms.start;

         var msg = "";
         var site = f.site.value;
         if ( site == "" ) {
            msg += "\nPlease select Ride Now! service/area";
            f.site_label.focus();
         }

         var area_code = f.area_code.value;
         if ( area_code == "" )  {
            if ( msg == "" ) {
               f.area_code.focus();
            }
            msg += "\nPlease enter phone number";
         } else {

            // Check phone number in more detail.

            var prefix    = f.tel_prefix.value;
            var last_four = f.tel_last_four.value;
            if ( area_code.length != 3 || ! is_digits( area_code ) ) {
               msg += "\nPlease correct area code";
            }
            if ( prefix == "" ) {
               msg += "\nPlease enter phone number prefix";
            } else {
               if ( prefix.length != 3 || ! is_digits( prefix ) ) {
                  msg += "\nPlease correct phone number prefix";
               }
            }
            if ( prefix == "" ) {
               msg += "\nPlease enter last four digits of phone number";
            } else {
               if ( last_four.length != 4 || ! is_digits( last_four ) ) {
                  msg += "\nPlease correct last four digits of phone number";
               }
            }
         }
         if ( f.PIN.value == "" )  {
            if ( msg == "" ) {
               f.PIN.focus();
            }
            msg += "\nPlease enter PIN";
         }
         if ( msg != "" ) {
            alert( msg );
         } else {
            f.submit();
         }
      }


      function new_user_button() {

         // Require that site be selected first.

         f = document.forms.start;
         if ( f.site.value == "" ) {
            f.site_label.focus();
            alert( "Please select which Ride Now service/area you wish to "
                   + "use." );
         } else {
            go_to_registration( 1 );
         }
      }

      // Autotab - used with area code and prefix of phone numbers to go to next
      // field as soon as third digit entered.

      var isNN = (navigator.appName.indexOf("Netscape")!=-1);
      if(isNN) document.captureEvents(Event.KEYPRESS);

      function autotab( input, len, e ) {
         var keyCode = (isNN) ? e.which : e.keyCode; 
         var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
         if ( input.value.length >= len 
                                     && ! containsElement( filter, keyCode ) ) {
            input.value = input.value.slice( 0, len );
            input.form[(getIndex(input)+1) % input.form.length].focus();
            input.form[(getIndex(input)+1) % input.form.length].select();
         }

         function containsElement( arr, ele) {
            var found = false;
            var index = 0;
            while( !found && index < arr.length ) {
               if( arr[index] == ele ) {
                  found = true;
               } else {
                  index++;
               }
            }
            return found;
         }

         function getIndex(input) {
            var index = -1;
            var i = 0;
            var found = false;
            while ( i < input.form.length && index == -1 ) {
               if ( input.form[i] == input ) {
                  index = i;
               } else {
                  i++;
               }
           }
           return index;
         }

         return true;
      }


      function map( mapURL ) {
         mapWindow = window.open( mapURL, "mapwindow", 
                                  "height=570, width=450, scrollbars=yes" );
         mapWindow.focus();
      }


      function mapnote( n_note ) {
         f = document.forms.match_request;
         var tmsg = "";
         var url = "";
         if( n_note == -1 ) {
            tmsg = "1/4 mile north of Redwood Parkway.  Can also "
                   + "be reached from I-37/Columbus Parkway.";
         } else if ( n_note == 1 ) {
            url = "maps_i80/fairgrounds-sereno.htm";
         }

         if( n_note == -2 ) {
            tmsg = "About 3/4 mile west of I-80 on Curtola Parkway.";
         } else if ( n_note == 2 ) {
            url = "maps_i80/curtola-solano.htm";
         }

         if( n_note == -3 ) {
            tmsg = "Just east of I-80, on the south side of Willow, between "
                   + "the stores and the apartment complex.";
         } else if ( n_note == 3 ) {
            url = "maps_i80/willow-cambridge.htm";
         }

         if( n_note == -4 ) {
            tmsg = "On San Pablo, 1/2 mile south of Hercules Transit Center "
                   + "(John Muir Parkway / Highway 4 exit).";
         } else if ( n_note == 4 ) {
            url = "maps_i80/san_pablo-hercules.htm";
         }

         if( n_note == -5 ) {
            tmsg = "Just west of I-80 - Pinole Valley Road exit.";
         } else if ( n_note == 5 ) {
            url = "maps_i80/pinole_valley-henry.htm";
         }

         if( n_note == -6 ) {
            tmsg = "3/4 mile north of I-80.  Appian Way exit.";
         } else if ( n_note == 6 ) {
            url = "maps_i80/san_pablo-appian.htm";
         }

         if( n_note == -7 ) {
            tmsg = "Hilltop Park and Ride.  Just east of I-80, on north side "
                   + "of Hilltop.";
         } else if ( n_note == 7 ) {
            url = "maps_i80/hilltop-i-80.htm";
         }

         if( n_note == -8 ) {
            tmsg = "Just east of I-80";
         } else if ( n_note == 8 ) {
            url = "maps_i80/el_portal.htm";
         }

         if( n_note == -9 ) {
            tmsg = "1/4 mile west of I-80 on El Portal.";
         } else if ( n_note == 9 ) {
            url = "maps_i80/el_portal.htm";
         }

         if( n_note == -10 ) {
            tmsg = "1/2 mile from I-80 (west from McBryde exit or north from "
                   + "San Pablo Ave exit)";
         } else if ( n_note == 10 ) {
            url = "maps_i80/san_pablo-garvin-solano.htm";
         }

         if( n_note == -11 ) {
            tmsg = "1/2 mile from I-80 (west from McBryde exit or north from "
                   + "San Pablo Ave exit)";
         } else if ( n_note == 11 ) {
            url = "maps_i80/san_pablo-garvin-solano.htm";
         }

         if( n_note == -12 ) {
            tmsg = "Just west of I-80 (Potrero or Barrett exits)";
         } else if ( n_note == 12 ) {
            url = "maps_i80/san_pablo-macdonald.htm";
         }

         if( n_note == -13 ) {
            tmsg = "1/2 mile east of I-80";
         } else if ( n_note == 13 ) {
            url = "maps_i80/belmont-yosemite-central.htm";
         }

         if( n_note == -14 ) {
            tmsg = "1/2 mile east of I-80";
         } else if ( n_note == 14 ) {
            url = "maps_i80/belmont-yosemite-central.htm";
         }

         if( n_note == -15 ) {
            tmsg = "Just east of  I-80, on Pierce between Buchanan and Central";
         } else if ( n_note == 15 ) {
            url = "maps_i80/pierce-washington.htm";
         }

         if( n_note == -16 ) {
            tmsg = "Just east of  I-80, on Pierce between Buchanan and Central";
         } else if ( n_note == 16 ) {
            url = "maps_i80/pierce-washington.htm";
         }

         if ( tmsg != "" ) {
            write_note( tmsg );
            note_stack++;
         }
         if ( url != "" ) {
            map( url );
         }
      }

      // Check if same note is still there before do reset.  If a new note is
      // there (another helpnote has been clicked), then don't erase it.

      var note_stack = 0;
      function reset_note() {
         if ( note_stack <= 1 ) {
            reset_title();
            note_stack = 0;
         }
         note_stack--;
      }


      var title_note_f = false;
      function write_note( lmsg ) {
         alert_debug_f = document.forms.alert_debug.alert_debug1_f.value;
         t = top.frames[0].document;

         if ( false ) {

      // Netscape Navigator 4 (and everything else I don't know about): 
      // use TEXTAREA.

      // No, NS4 seems to work.

            f = document.forms.tnote_form;

      // Put message in form on this page and submit.
      // Netscape 4 has to use php so I can use wordwrap() to break into lines,
      // since Netscape Navigator 4 doesn't wrap.

            f.tnote.value = lmsg;
            f.submit();
         } else {

      // Known to work with Netscape 6 and 6.1 and Internet Explorer 5.0 and 
      // 5.5.

            t.open();
            t.write( "<HEAD><TITLE>window title</TITLE></HEAD>" );
            t.write( "<BODY BGCOLOR=\"FFFF33\">" );
            t.write( "<P><FONT SIZE=-1>" + lmsg + "</FONT>" );
            t.write( "</BODY>" ); 
            t.close();
         }
         title_note_f = true;
      }

      function reset_title() {
         top.frames[0].location = "ridematch_title.php?site=x";
      }
      

      // Resubmit login frame with flag set to show introductory material.
      // Also set form variable so if go elsewhere and come back will get
      // introductory material.

      function show_intro() {
         f = document.forms.main_pass_data;
         f.show_intro_f.value = 1;
         top.window.location = "ridematch_login_frame.php?show_intro_f=1"
      }


      function new_window( url ) {
         newWindow = window.open( url, "newwindow", 
                              "height=350, width=500, scrollbars=yes, "
                              + "resizable=yes" );
         newWindow.focus();
      }


      function is_digits( str ) {
         var len = str.length;
         for ( var i=0; i<len; i++ ) {
            ichar = str.charAt( i );
            if ( ichar < '0' || ichar > '9' ) {
               return false;
            }
         }
         return true;
      }


