﻿/*
 * Finds the location the user entered into the Find Location text box. This method completes
 * asynchronously.
 */
function FindLocation()
{
    // Get the location text out of the text box
    var LocationText = $get('txtFindLocation').value;
    
    // Look up the location. This is an asynchronous method and we'll pass a completion handler
    geocoder.getLocations(LocationText,FindLocationCompletionHandler);
    
    //FadeAllTopMenus();
}

/*
 * This is the completion method for the geocoder.getLocations method.
 */
function FindLocationCompletionHandler(response)
{
    // Figure out if the response succeeded or failed
    if (!response || response.Status.code != 200) 
    {
        // There was a problem with the geocode request
        alert('Unable to find the location you entered. Try entering a complete address.');
    }
    else
    {
        // Take the first match
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
    
        // If we're still on zoom level 2, why not help the user out by zooming in to the location they just found
        if(map.getZoom()<=5)
            map.setZoom(15);
        
        // Move to the position
        map.panTo(point);
        
        ToggleSlider_Nav('FindLocation');
        
    }
}
