    var map;
    var geocoder;
    var searchLat;
    var searchLng;
    var directions;
    //toggle visibility of search results and directions panels
    function toggleDirSearchPanelsSD()
    {
       directions.clear();
       toggleDirSearchPanels(false);
    }
    function toggleDirSearchPanels(showDir)
    {
        if(showDir == true)
        {
            $get("divDirResult").style.zIndex = "1";
            $get("divSearchResult").style.zIndex = "2";
            //$get("my_textual_div").style.zIndex = "1";
           
            $get("divDirResult").style.display = "block" ;
            $get("divSearchResult").style.display = "none" ;
        }
        else
        {
            
            $get("divDirResult").style.zIndex = "2";
            $get("divSearchResult").style.zIndex = "1";
            //$get("my_textual_div").style.zIndex = "1";

            $get("divDirResult").style.display = "none" ;
            $get("divSearchResult").style.display = "block" ;
        }
        
//           setTimeout("var cTest = $get('my_textual_div');alert(cTest.innerHTML);",1000);
    }
    //initializes map objects
    
  	function initialize() {
  	
		geocoder = new google.maps.ClientGeocoder();
		
        map = new google.maps.Map(document.getElementById("map"));
        map.addControl(new google.maps.SmallMapControl());
        map.addControl(new google.maps.MapTypeControl());
        map.setCenter(new google.maps.LatLng(32.503276,-83.322144), 7);
        $get("divDirResult").style.display = "none" ;
        $get("divSearchResult").style.display = "none" ;
        $get("txtAddress").focus();
	}
    //Marker options for custom icon and naming
    function getMyMarkerOptions(i)
    {
        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        var baseIcon = new google.maps.Icon(G_DEFAULT_ICON);
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new google.maps.Size(20, 34);
        baseIcon.shadowSize = new google.maps.Size(37, 34);
        baseIcon.iconAnchor = new google.maps.Point(9, 34);
        baseIcon.infoWindowAnchor = new google.maps.Point(9, 2);
                
        var letter = String.fromCharCode("A".charCodeAt(0) + i);
        var letteredIcon = new google.maps.Icon(baseIcon);
        letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
        // Set up our GMarkerOptions object
        markerOptions = { icon:letteredIcon };
        return markerOptions;
    }
    //Shows directions between input address and selected payment center
    function showDirections(toLat, toLng)
    {
        var directionsPanel = document.getElementById("my_textual_div");
        if(directions == null) 
        {
            directions = new google.maps.Directions(map, directionsPanel);
        }
        else
        {
           directions.clear();
        }
        dirQuery = "from: " + searchLat + ","+ searchLng + " to: " + toLat + "," + toLng;
        //$get("my_textual_div").innerHTML = "";
        setTimeout("directions.load(dirQuery);",50);
        setTimeout("toggleDirSearchPanels(true);",100);
    }
    //Shows payment location on the map
    function showPayLocation(ind, lat, lng, name, address, city, state, phone, showHtmlWin)
    {
        if(showHtmlWin == null) showHtmlWin = false;
        var point = new google.maps.LatLng(eval(lat), eval(lng))
        map.panTo(point, 13);
        markerOptionsResult = getMyMarkerOptions(ind);                
        
        if(phone.length > 0)
        {
            phone = "<br/>Phone: " + phone;
        }
        else
        {
            phone = "";
        }

        var marker = new google.maps.Marker(point, markerOptionsResult);
        map.addOverlay(marker);

        var addressHtml = "<table width=\"250px\" border=\"0\"><tr><td><b>" 
            + name + "</b><br/>" 
            + address + "<br/>" 
            + city + ", " 
            + state + phone + "<br/><br/></td></tr></table>"
            + "<a href=\"javascript:void();\" onclick=\"showDirections('" 
            + lat + "','" 
            +  lng + "');\" >Get Directions</a>";
        if(showHtmlWin == true)
        {
            marker.openInfoWindowHtml(addressHtml);
        }
        google.maps.Event.addListener(marker, 'click', function() {
                    marker.openInfoWindowHtml(addressHtml);
                          });
    }
    //Generates Payment center left navigation buttons
    function generatePayLocs(arrPL)
    {
            var strResult = "";
            var optPhone = "";
            map.clearOverlays();
            for(i=0; i<arrPL.length;i++)
            {
                if(arrPL[i].Phone.length > 0 ) 
                {
                    optPhone = "<br/>Phone: " + arrPL[i].Phone;
                }
                else
                {
                    optPhone = "";
                }
                strResult += "<li id=\"Li2\" onclick=\"" 
                    + "showPayLocation('" + i + "','" + arrPL[i].Latitude + "','" 
                    +  arrPL[i].Longitude + "','" + arrPL[i].Name +  "','" 
                    +  arrPL[i].Address + "','" + arrPL[i].City +  "','" 
                    +  arrPL[i].State + "','" +  arrPL[i].Phone +  "',true);\">" 
                    +"<div class=\"resulttext vcard hcard\">"
                    +"<span class=\"letter\">" + String.fromCharCode(65+i) +"</span>"
                    +"<h3 class=\"fn n org storename\">" + arrPL[i].Name +"</h3>"
                    +"<span class=\"adr\">"
                    +"<span class=\"street-address\">" + arrPL[i].Address +"</span>"
                    +", <span class=\"locality\">" + arrPL[i].City + "</span>"
                    +", <span class=\"region\">" + arrPL[i].State +"</span>"
                    +" <span class=\"postal-code\"></span>"
                    +"</span><span class=\"tel\">" + optPhone +"</span>"
                    +"<div class=\"cap bottom\"></div>"
                    +"</div></li>";
                var point = new google.maps.LatLng(eval(arrPL[i].Latitude), eval(arrPL[i].Longitude))
                map.setCenter(point, 13);
                
                showPayLocation(i, arrPL[i].Latitude, arrPL[i].Longitude , arrPL[i].Name, 
                    arrPL[i].Address, arrPL[i].City, arrPL[i].State, arrPL[i].Phone, false);
                
            }
            document.getElementById("snDynamicResult").innerHTML = strResult ;
    }
	//Callback function for getTop10NearestPayLocations() function when succeeded
    function successCallback(serviceResult)
    {
        //Display if success
        if(serviceResult != '')
        {
            generatePayLocs(serviceResult);
            var pointStart = new google.maps.LatLng(serviceResult[0].Latitude, serviceResult[0].Longitude)
            map.panTo(pointStart, 13);
        }
    }
    //Callback function for getTop10NearestPayLocations() function when failed
    function failedCallback(serviceError)
    {
       // Display error message
       alert("Oops!, unable to find payment centers in this address");
    }    
    //gets top 10 nearest payment centers by calling GetTopTenNearestPL web method using web service.
    function getTop10NearestPayLocations(pLat, pLng)
    {
        searchLat = pLat;
        searchLng = pLng;
        GasSouthWebApp.LocationLocatorWebService.GetTopTenNearestPL(pLat, pLng, successCallback, failedCallback);
        return false;
    }
    //Find Address by appending GA, USA
    function findNearestPLs2(addr)
    {
    geocoder.getLocations( addr, 
            function (response) {
                if (!response || response.Status.code != 200)
                {
	                alert("Sorry, we were unable to find this address - " + addr);
                    $get("divPayLocSearchSummary").innerHTML = "Unable to locate address : " + addr + ".";
                    map.clearOverlays();
                    $get("snDynamicResult").innerHTML = "";
                    toggleDirSearchPanels(false);
                }
                else
                {
                    place = response.Placemark[0];
                    getTop10NearestPayLocations(
                    place.Point.coordinates[1],place.Point.coordinates[0]);
                    $get("divPayLocSearchSummary").innerHTML = "Gas South payment centers near " + addr + ":";
                    toggleDirSearchPanels(false);
                }
            });
    }
    //Perform find operation by using address details given by user or uses default address(Atlanta).
    function findNearestPLs(valAddress, valCity, valZip)
    {
        if(valAddress == null || valAddress == "" || valAddress == "Street Address" ) valAddress = ""; 
        if(valCity == null || valCity == "" || valCity == "City") valCity = ""; 
        if(valZip == null || valZip == "" || valZip == "Zip Code") valZip = ""; 
        
        
        var  addr = valAddress ;
        
        if( addr == "")
        {   
            if( valCity != "" ) addr =  valCity + ",GA,USA";
        }
        else
        {
            if( valCity != "" ) 
            {
                addr = addr + "," + valCity + ",GA,USA";
            }
            else
            {
                addr = addr + ",GA,USA";
            }
        }
        
        if(addr == "")
        {
          addr = "Atlanta,GA,USA";
          //$get("txtCity").value = "Atlanta";
        }
        
        addr = addr.replace(/,/gi,", ");
        var  addrWithOut =  addr.replace(/, GA, USA/gi," ");
        if(valZip != "")
        {
            addr = "GA " + valZip + ", USA";
            $get("txtCity").value = "";
            $get("txtAddress").value = "";
            addrWithOut = valZip;
        }

        //Find Address without GA, USA
        
        geocoder.getLocations( addrWithOut, 
        function (response) {
            if (!response || response.Status.code != 200)
            {
                $get("divPayLocSearchSummary").innerHTML = "Unable to locate address : " + addrWithOut + ".";
                map.clearOverlays();
                $get("snDynamicResult").innerHTML = "";
                toggleDirSearchPanels(false);
                alert("Sorry, we were unable to find this address - " + addrWithOut);
            }
            else
            {
                //Find Address with GA, USA
//                place = response.Placemark[0];
//               alert("place.AddressDetails.Country.CountryNameCode:"+place.AddressDetails.Country.CountryNameCode);
               
                findNearestPLs2(addr);
            }
        });
    }	
    //handler for locate button click
    function locateClicked()
    {
        findNearestPLs($get("txtAddress").value,$get("txtCity").value,$get("txtZip").value);   
    }
