<!--

var nPause    =  20;
var nRePause  =  20;
var nMxPause  = 125;

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}
//-------------------------------------------------------
//-------------------------------------------------------
function route_instantiate( results, status ) { //v3

    var state   = '';
    var city    = '';
    var addr    = '';
    var country = '';
          
    if (! results) {
      alert("Google Maps did not return a valid response");
      addr= 'No Location info for the spot you clicked.';
      document.getElementById("spot_address" ).innerHTML = addr;
      return;
    } 
    
    if (status != google.maps.GeocoderStatus.OK) { 
        alert("Google Maps  did not return a valid response");
        addr= 'No Location info for the spot you clicked.';
        document.getElementById("spot_address" ).innerHTML = addr;
    } 
           
    var latlng = results[0].geometry.location; 
    geoCode  = adx_geocode( results );      
    var addr = geoCode[9];
    
    aData = [ addr, geoCode[7], geoCode[5], geoCode[2] ];
    
    Route_Points( 0 );
}

//-------------------------------------------------------
function Init_Route_Points(){

    var xlat   = Route_MX[0].mlat;
    var xlng   = Route_MX[0].mlng;
    var latlng = new google.maps.LatLng( xlat, xlng );
    
    
    var request = { 'location': latlng };
    my_geocoder.geocode( request, route_instantiate );
    
    //Route_Points( 0 );

}
//-------------------------------------------------------
var nByPass = 0;
function Route_Points( ndx ){

// ndx is Zero Based while MX_Ndx is the Number of Point Object
// For example, 50 point objects, ndx = 0,1,2,...49 and MX_Ndx=50

    if( ndx >= MX_Ndx  ){
        standby_overlay.setVisible( false );
        return;
    }
     
    var prv_latlng      = null;
    var polyline        = null;
    var poly_pts        = new Array(2); 
    var bb_Avoid_Hwys   = 0;
    var bb_Walking      = 0;
    var b_Follow_Roads  = 0;
    var meters          = 0;

    var xlat   = Route_MX[ndx].mlat;
    var xlng   = Route_MX[ndx].mlng;
    var latlng = new google.maps.LatLng( xlat, xlng );

    if( ndx != 0 ){
        xlat = Route_MX[ndx-1].mlat;
        xlng = Route_MX[ndx-1].mlng;
        prv_latlng = new google.maps.LatLng( xlat, xlng );
    }

    nPoints = ndx + 1;
    display_route_npoints();
    
    obj_Map_UI = new Map_Data_UI( nPoints, 0, null, 1, 1, latlng,  prv_latlng, latlng, 0, 0, 0 );
        
    if( ndx == 0 ){
    
        remove_jump_marker();
        Map_UI[ndx] = obj_Map_UI;
        pt_marker_disp_v3( 1, Start_marker, latlng );
        Route_Points( ndx+1 );
        
    }else{
    
        iOpts         = Route_MX[ndx].mopts;
        bb_Avoid_Hwys = Route_MX[ndx].mHwy;
        bb_Walking    = Route_MX[ndx].mWalk;

        Map_UI[ndx] = obj_Map_UI;
                
        if( iOpts == 1  ){//  || ndx < 2  iOpts == 1 => Follow Roads is TRUE
            Follow_Roads( Map_UI[ndx], ndx, 2 );// 3rd parameter tells Follow_Roads to call back this routine             
        }else{ //Follow_Points......
          
            poly_pts[0] = obj_Map_UI.mLxL_Prv;
            poly_pts[1] = obj_Map_UI.mLxL;
    
            polyline = gx_polyline( poly_pts, '#ff0000' );
                        
            try{
              //meters = google.maps.geometry.spherical.computeLength( poly_pts[0], poly_pts[1] );
                meters = google.maps.geometry.spherical.computeDistanceBetween( poly_pts[0], poly_pts[1] );
            }
            catch(e){
                alert('computeDistanceBetween error: '+e.message);
            }
                        
            Map_UI[ndx].mpoly  = polyline;
            Map_UI[ndx].mdist  = meters;     
            Map_UI[ndx].mEndPt = poly_pts[1];       
            Map_UI[ndx].mopts  = 0;
            Map_UI[ndx].mHwy   = 0;
            
            plength += meters;
            display_distance( plength );
                        
            if( b_Markers_ON == 1 ){
                Dist_Marks( 0, ndx, poly_pts, 0 );
                Dist_Marks( 1, ndx, poly_pts, 0 );
            }
            
            pt_marker_disp_v3( 1, EndRt_marker, Map_UI[ndx].mEndPt );
            Route_Points( ndx+1 );
        }
    }
    
    display_start_button( nPoints );
}
//-----------------------------------------------------------------------------
function Re_Route_Points( ndx ){

// ndx is Zero Based while Map_UI.length is the Number of Point Objects
// For example for 50 point objects, ndx = 0,1,2,...49 and MX_Ndx=50
        
    if( ndx >= Map_UI.length  ){
        return;
    }
            
    var prv_latlng = null;
    var poly_pts   = new Array(2);

    nPoints = ndx + 1;
    display_route_npoints();
          
    if( ndx == 0 ){        
        remove_jump_marker();
        latlng = Map_UI[0].mLxL;
    ////Reset_Direction_Start( latlng );
        pt_marker_disp_v3( 1, Start_marker, latlng );
        Re_Route_Points( ndx+1 );
        
    }else{
            
        iOpts = Map_UI[ndx].mopts;

        if( iOpts == 1 ){// iOpts == 1 => Follow Roads is TRUE          
            Follow_Roads( Map_UI[ndx], ndx, 1 );// 3rd parameter tells Follow_Roads to call back this routine            
        }else{ //Follow_Points......          
            poly_pts[0] = Map_UI[ndx].mLxL_Prv;
            poly_pts[1] = Map_UI[ndx].mLxL;
            
            var polyline = gx_polyline( poly_pts, '#ff0000' );
            var meters   = google.maps.geometry.spherical.computeDistanceBetween( poly_pts[0], poly_pts[1] );
            
            Map_UI[ndx].mpoly  = polyline;
            Map_UI[ndx].mdist  = meters;
            Map_UI[ndx].mEndPt = poly_pts[1];
            Map_UI[ndx].mopts  = 0;
            Map_UI[ndx].mHwy   = 0;
            
            plength += meters;
            display_distance( plength );
            
            if( b_Markers_ON == 1 ){
                Dist_Marks( 0, ndx, poly_pts, 0 );
                Dist_Marks( 1, ndx, poly_pts, 0 );
            }
            pt_marker_disp_v3( 1, EndRt_marker, Map_UI[ndx].mEndPt );
                        
            Re_Route_Points( ndx+1 );
        }
    } 
    
}
//-----------------------------------------------------------------------------
// -->
