
    //if (GBrowserIsCompatible()) {



    var map;
    var geo;
    var reasons=[];
    function load() {
//      map = new GMap(document.getElementById("map"));
//      map.addControl(new GLargeMapControl());
//      map.addControl(new GMapTypeControl());
//      map.setCenter(new GLatLng(20,0),2);
      
      // ====== Create a Client Geocoder ======
      geo = new GClientGeocoder(); 

      // ====== Array for decoding the failure codes ======
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
    }


    // ===== list of words to be standardized =====
    var standards = [   ["road","rd"],   
                        ["street","st"], 
                        ["avenue","ave"], 
                        ["av","ave"], 
                        ["drive","dr"],
                        ["saint","st"], 
                        ["north","n"],   
                        ["south","s"],    
                        ["east","e"], 
                        ["west","w"],
                        ["expressway","expy"],
                        ["parkway","pkwy"],
                        ["terrace","ter"],
                        ["turnpike","tpke"],
                        ["highway","hwy"],
                        ["lane","ln"]
                     ];

    // ===== convert words to standard versions =====
    function standardize(a) {
      for (var i=0; i<standards.length; i++) {
        if (a == standards[i][0])  {a = standards[i][1];}
      }
      return a;
    }

    // ===== check if two addresses are sufficiently different =====
    function different(a,b) {
      // only interested in the bit before the first comma in the reply
      var c = b.split(",");
      b = c[0];
      // convert to lower case
      a = a.toLowerCase();
      b = b.toLowerCase();
      // remove apostrophies
      a = a.replace(/'/g ,"");
      b = b.replace(/'/g ,"");
      // replace all other punctuation with spaces
      a = a.replace(/\W/g," ");
      b = b.replace(/\W/g," ");
      // replace all multiple spaces with a single space
      a = a.replace(/\s+/g," ");
      b = b.replace(/\s+/g," ");
      // split into words
      awords = a.split(" ");
      bwords = b.split(" ");
      // perform the comparison
      var reply = false;
      for (var i=0; i<bwords.length; i++) {
        //GLog.write (standardize(awords[i])+"  "+standardize(bwords[i]))
        if (standardize(awords[i]) != standardize(bwords[i])) {reply = true}
      }
      //GLog.write(reply);
      return (reply);
    }

    var rawUrl = "";
    var distance = 0;
      // ====== Plot a marker after positive reponse to "did you mean" ======
      function place(lat,lng,texta) {
        var point = new GLatLng(lat,lng);
        map.setCenter(point,14); 
        map.addOverlay(new GMarker(point));
        document.getElementById("message").innerHTML = "";
        
      }

      function setdefaultLocation(lat, lng) {
          var point = new GLatLng(lat, lng);
          map.setCenter(point, 4);
          map.clearOverlays();
          document.getElementById("message").innerHTML = "";
      }
      
      function place2(lat, lng, result) {

          var txtSearch = jQuery('#store-locator').find('input[id$=txtPostcode]');
          var txtSearchId = jQuery('#store-locator').find('input[id$=txtPostcode]').attr("id"); 
          var btnSearchStore = jQuery('#store-locator').find('input[id$=btnSearchStore]');
          var arresult= result.split(',');
          if (arresult.length > 0) {
              result = arresult[0];
          }
          jQuery(txtSearch).val(result);
          var ddl = jQuery('#store-locator').find('select[id$=ddlkm]').attr("id");

          findLocations(txtSearchId, ddl, rawUrl);
      }

      function place3(result) {
          var txtSearch = jQuery('#store-locator').find('input[id$=txtPostcode]');
          var txtSearchId = jQuery('#store-locator').find('input[id$=txtPostcode]').attr("id");
          var btnSearchStore = jQuery('#store-locator').find('input[id$=btnSearchStore]');
          jQuery(txtSearch).val(result);
          var ddl = jQuery('#store-locator').find('select[id$=ddlkm]').attr("id");

          findLocations(txtSearchId, ddl, rawUrl);
      }
      // ====== Geocoding ======
      function showAddress(hfValue) {
          
          load();
          var search = hfValue;  //document.getElementById("search").value;
        // ====== Perform the Geocoding ======
          geo.getLocations(search, function(result) {
              //map.clearOverlays();
              if (result.Status.code == G_GEO_SUCCESS) {
                  var message = jQuery('#store-locator').find('#errormessage');
                  //var spnLocation = jQuery('#store-locator').find('#spnLocation');
                  // ===== If there was more than one result, "ask did you mean" on them all =====
                  if (result.Placemark.length > 1) {
                      jQuery(message).hide();

                      var isTrue = false;
                      document.getElementById("message").innerHTML = "<span class='did-you-mean'>Did you mean ?</span><br/>";
                      // Loop through the results
                      var srno=0;
                      for (var i = 0; i < result.Placemark.length; i++) {
                          var p = result.Placemark[i].Point.coordinates;
                          var searchText = result.Placemark[i].address;

                          isTrue = IsCheckDuplicateResult(searchText, search);

                          if (isTrue) {
                          srno=srno+1;
                          document.getElementById("message").innerHTML += "<br>" + (srno) + ": <a href='javascript:place2(" + p[1] + "," + p[0] + ",\"" + searchText + "\")'>" + result.Placemark[i].address + "<\/a>";
                          }
                      }
                      if (isTrue) {
                          setGoogleMapDisplay(true);
                      }
                      else {
                          jQuery(message).show();
                          //spnLocation.text(search);
                          document.getElementById("message").innerHTML = "";
                          setGoogleMapDisplay(false);
                      }
                  }
                  // ===== If there was a single marker, is the returned address significantly different =====
                  else {
                      document.getElementById("message").innerHTML = "";
                      if (different(search, result.Placemark[0].address)) {
                          jQuery(message).hide();
                          setGoogleMapDisplay(true);
                          document.getElementById("message").innerHTML = "<span class='did-you-mean'>Did you mean ?</span><br/>";
                          var p = result.Placemark[0].Point.coordinates;
                          var searchText = result.Placemark[0].address;
                          var isTrue = IsCheckDuplicateResult(searchText, search);

                          if (isTrue) {
                              document.getElementById("message").innerHTML += "<a href='javascript:place2(" + p[1] + "," + p[0] + ",\"" + searchText + "\")'>" + result.Placemark[0].address + "<\/a>";
                          }
                          else {
                              jQuery(message).show();
                              //spnLocation.text(search);
                              document.getElementById("message").innerHTML = '';
                              setGoogleMapDisplay(false);
                          }
                      }

                      else if (!different(search, result.Placemark[0].address)) {
                      jQuery(message).show();
                      //spnLocation.text(search);
                          setGoogleMapDisplay(false);
                          document.getElementById("message").innerHTML = "";
                      }
                      else {
                          //var p = result.Placemark[0].Point.coordinates;
                          //place(p[1], p[0]);
                      }
                  }
              }
              // ====== Decode the error status ======
              else {
                  var reason = "Code " + result.Status.code;
                  if (reasons[result.Status.code]) {
                      reason = reasons[result.Status.code]
                  }
                  alert('Could not find "' + search + '" ' + reason);
              }
          }
        );
      }
    //}
    
    // display a warning if the browser was not compatible
    //else {
      //alert("Sorry, the Google Maps API is not compatible with this browser");
      //}
    

      var root = "/";

      function findLocations(search, killometer, url) {
          
          var pagePath = root + "get-data/get-locations.aspx";
          var text = jQuery('#' + search).val();
          var km = jQuery('#' + killometer).val();
          text = $.trim(text);
          if (text.length<=0) {
              alert('Please enter postcode or suburb.');
              jQuery('#' + search).val('');
              return false;
          }

          if (url.indexOf('?') > 0) {
              rawUrl = url.substring(0, url.indexOf('?'));
          }
          else {
              rawUrl = url;
          }

          distance = km;
          
        jQuery.ajax
        ({
        url: pagePath + '?locationstore=' + text + '&killometer=' + km + '&',
            data: '',
            type: 'post',
            datatype: 'html',
            success: successLocationFn,
            error: errorLocationFn
        });
        return false;
      }

      function successLocationFn(result) {
          
          if (result != "") {
              var SearchMessage = jQuery('#store-locator').find("span[id$='lblSearchMessage']");
              var gridviewList = jQuery('#store-locator').find(".storeList");
              
              var txtSearch = jQuery('#store-locator').find('input[id$=txtPostcode]');
              var hfSearch = jQuery('#store-locator').find('input[id$=hfPostcode]');

              var Searchtxt = jQuery(txtSearch).val();
              var resultList = result.split("$$");

              if (resultList[0] == 'false' && resultList.length == 1) {

                  jQuery(hfSearch).val(Searchtxt);
                  showAddress(Searchtxt);
                  jQuery(SearchMessage).hide();
                  jQuery(gridviewList).hide();
                  setdefaultLocation(defaultLatitude, defaultLongitude);
              }
              else if (resultList[0] == 'false' && resultList.length == 2) {
              document.getElementById("message").innerHTML = "<span class='did-you-mean'>Did you mean ?</span><br/>";
              document.getElementById("message").innerHTML += resultList[1];
              setGoogleMapDisplay(true);
              }
              else {
                  jQuery(hfSearch).val(Searchtxt);
                  location.href = rawUrl + "?postcode=" + Searchtxt + '&distance=' + distance;
                  //__doPostBack('__Page', '');
              }
          }
      }

      function errorLocationFn() {
          alert('Error in processing the request. Please try again');
      }


      function SubmitQuickSearch(evt, btnSubmit) {
          var k;
          if (evt.which)
              k = evt.which;
          else
              k = evt.keyCode;

          if (k == 13) {
              document.getElementById(btnSubmit).focus();
              return true;
          }
          else {
              return true;
          }
      }


      $(document).ready(function() {
      setGoogleMapDisplay(false);
      
      })

      function setGoogleMapDisplay(isGoogleResult) {

          var google_map = jQuery('#store-locator').find('#google-map');
          var google_result = jQuery('#store-locator').find('#google-result');
          var map = jQuery('#store-locator').find('#map');
          var border = jQuery('#store-locator').find('#border');
          var search_result_height = jQuery(google_result).innerHeight();
          var google_map_height = jQuery(google_map).innerHeight();
          var search_area_text_message = jQuery('#store-locator').find('.search-area-text-message');
          
          if (isGoogleResult) {

              //google map main  
              jQuery(google_map).addClass("google-map-main-result");
              jQuery(google_map).removeClass("google-map-main-noresult");
              
              //google map control
              jQuery(map).addClass("google-map-result");
              jQuery(map).removeClass("google-map-noresult");

              //google search result
              jQuery(google_result).addClass("google-result");
              jQuery(google_result).removeClass("google-noresult");

              //display border and set height
              jQuery(border).addClass("display-border");
              jQuery(border).removeClass("hide-border");


              jQuery(search_area_text_message).addClass("search-area-text-message-padding");
              
              if (search_result_height < google_map_height) {
                  jQuery(border).css('height',google_map_height-5);
              }
              else {
                  jQuery(border).css('height',search_result_height);
              }
              
              
          }
          else {

              //google map main
             
              jQuery(google_map).removeClass("google-map-main-result");
              jQuery(google_map).addClass("google-map-main-noresult");

              // google map control
              jQuery(map).removeClass("google-map-result");
              jQuery(map).addClass("google-map-noresult");

              //google search result
              jQuery(google_result).removeClass("google-result");
              jQuery(google_result).addClass("google-noresult");

              //hide border
              jQuery(border).removeClass("display-border");
              jQuery(border).addClass("hide-border");

              jQuery(search_area_text_message).removeClass("search-area-text-message-padding");
          }
      }


      function IsCheckDuplicateResult(searchText, searchValue) {
          
          var aresult = searchText.split(',');
          if (aresult.length > 0) {
              var result = aresult[0].toLowerCase();
              if (searchValue.toLowerCase() == result) {
                  return false;
              }
              else {
                  return true;
              }
          }
          else {
              return true;
          }
      }