/*
 * Handles methods and properties for Google Map search
 * @author David Galvis
 * @date 23.11.2008
 */


function Geocoder (idInput, options) {

    var _this = this;
    if (GBrowserIsCompatible()) {
		jQuery.extend(this, options);

        this.autocomplete = new HomeSearch(idInput, {align:'left'});
        this.input = jQuery("#" + idInput);
        
        this.suggestions = jQuery("<div class='suggestion'></div>");
        this.suggestionsTitle = jQuery("<div class='geocoder-suggestion-title'>" + trad_address_will_be + "</div>");
        this.suggestionsBody = jQuery("<div></div>");
        //alert(GLanguage.getLanguage());
        //this.input.after(this.suggestions);
        this.suggestions.append(this.suggestionsTitle);
        this.suggestions.append(this.suggestionsBody);
        
		this.geocoder = new GClientGeocoder();
        this.geocoder.setCache(new CapitalCitiesCache());
       // this.geocoder.setViewPort(new CapitalCitiesCache());

        //var pointSW = new GLatLng(42.1331639, -5.9820520);
        //var pointNE = new GLatLng(50.0380022, 10.4095500);

        //var pointSW = new GLatLng(45.7361562, 4.7702990);
        //var pointNE = new GLatLng(45.7984244, 4.8983584);
        //this.geocoder.setViewport(new GLatLngBounds(pointSW, pointNE));

        this.geocoder.setBaseCountryCode('fr');

        // Modifing input name to hide browser autocomplete
        if (this.name == null)
            this.input.attr('name', Math.random()*Math.random());
        else
            this.input.attr('name', this.name);
        /**
         * Events
         */
        this.input.focus(function(){
            if(_this.input.val().length > 0)
                _this.autocomplete.sendRequest();
            //_this.input.select();
        });

        this.autocomplete.sendRequest = function()
        {
            this.input.attr('name', Math.random()*Math.random());

            try{
              clearTimeout(requestTimeout);
            } catch(e){}
            requestTimeout = setTimeout(function()
            {
                if(_this.input.val().length == 0){
                    //_this.invalidLocation();
                    _this.autocomplete.results.hide();
                    return false;
                }
                var location = _this.input.val();
               if (_this.allowedCountries.length == 1)
                   location += ', ' + _this.allowedCountries[0];

                _this.geocoder.getLocations(location, function(response){
                //console.log(jQuery.toJSON(response));

                    try{
                       var responseHTML = [];
                       for(var i=0; i<response.Placemark.length; i++)
                       {
                            var countryCode = '';
                            if (typeof response.Placemark[i].AddressDetails.Country != 'undefined')
                                countryCode = response.Placemark[i].AddressDetails.Country.CountryNameCode;
       
                            for (var j=0; j<_this.allowedCountries.length; j++){
                                
                                var countryCodeIsOk = false;
                                if (countryCode == _this.allowedCountries[j]){
                                    countryCodeIsOk = true;
                                    //_this.placemark = response.Placemark[i];
                                    //console.log(response.Placemark[i]);n
                                    var item = jQuery('<p class="item">' + response.Placemark[i].address + '</p>');
                                    item.Placemark = response.Placemark[i];
                                    /*item.click(function(){
                                        console.log(this);
                                        //_this.placemark = this.Placemark;
                                        //_this.input.val(this.Placemark.address);
                                    });*/
                                    responseHTML.push(item);

                                    //_this.suggestionsBody.html("<img src='/images/map_go.png' style='top:0'/>" + response.Placemark[i].address);
                                    _this.address = true;
                                    //break;
                                }
                            }
                            //if (countryCodeIsOk && _this.address)
                            //    break;
                            // Response doesent's match with our countries'
                            //if (!countryCodeIsOk)
                            //    
                       }
                       //console.log(responseHTML);
                        
                        
                    } catch (e){;}

                    // Address not know by google service
                    //console.log(response.Status.code);
                    if (response.Status.code == 602 || typeof response.Placemark == 'undefined' || !_this.address || responseHTML.length == 0){
                        responseHTML.push(_this.invalidLocation());
                        _this.address = false;
                        //console.log(response.Status.code);
                    }
                    _this.autocomplete.results.empty();
                    _this.autocomplete.results.hide();
                    jQuery(responseHTML).each(function(){
                        _this.autocomplete.results.append(this);
                        var placemark = this.Placemark;

                        // User click on item
                        this.click(function(){
                            _this.placemark = placemark;
                            _this.input.val(placemark.address);
                        });

                        _this.input.blur(function(event)
                        {
                            if (_this.autocomplete.selected == null)
                                _this.autocomplete.moveFirst();

                                _this.autocomplete.selected.trigger('click');
                            //_this.autocomplete.hide();
                        });
                    });
                    //_this.autocomplete.results.html(responseHTML);
                    try{
                      clearTimeout(hideTimeout);
                    } catch(e){}
                    hideTimeout = setTimeout(function(){
                        _this.autocomplete.results.slideDown('slow');
                    },20);
                    var offset = _this.autocomplete.input.offset();

                    // Aligning horizontally the result box
                    var left;
                    if (_this.autocomplete.align == 'left')
                        left = offset.left;
                    else if (_this.autocomplete.align == 'xRight')
                        left = offset.left + _this.autocomplete.input.width()+ 20;
                    else
                        left = offset.left - (_this.autocomplete.results.width()-_this.autocomplete.input.width());

                    // Aligning vertically the result box
                    var top;
                    if (_this.autocomplete.vAlign == 'middle')
                        top = offset.top - (_this.autocomplete.results.height()/2);
                    else
                        top = offset.top + _this.autocomplete.input.height()+10;

                    // Position if the result box
                    _this.autocomplete.results.css({
                        zIndex:99000,
                        top: top,
                        left: left,
                        textAlign:'left'
                    });

                    jQuery(function(){
                        _this.autocomplete.addItemEffects();
                        _this.autocomplete.items = _this.autocomplete.results.find(".item");
                        _this.autocomplete.moveFirst();
                    });
                });
            },120);
        };
        /*this.input.select(function(){
            _this.geocode();
        });*/
        //this.input.blur = this.input.keyup;
	}
}

Geocoder.prototype =
{
   spinner : '/images/itaste-loader.gif',
   address : false,
   city : null,
   country : null,
   name : null,
   defaultText : null,
   placemark :[],

   /**
    * This is the field of the placemark that will be displayed as an item on the autocomple
    */
   displayKey : ['address'],

   /** Allowed country codes */
   allowedCountries : ['CH','FR','IT','BE','ES','MT','GB','US'],

   getAddress : function(){
       try {
           return this.findKey('ThoroughfareName', this.placemark);
       } catch(e){
           return '';
       }
   },

   getPostalCode : function(){
       
       try {
           return this.findKey('PostalCodeNumber', this.placemark);
       }catch(e){
           return '';
       }
   },

   getCity : function(){
       return this.findCity(this.placemark);
   },

   getCountry : function(){
       if (!this.address)
           return '';
       try{
           return this.placemark.AddressDetails.Country.CountryName;
       }catch(e){
           return '';
       }
   },

   getCountryCode : function(){
       try {
           if (!this.address)
               return '';
           if (typeof this.placemark.AddressDetails.Country.CountryNameCode != 'undefined')
               return this.placemark.AddressDetails.Country.CountryNameCode;
           else {
               return '';
           }
       }catch(e){
           return '';
       }
   },

   getBounds : function() {
       if (typeof this.placemark.ExtendedData != 'undefined')
           return this.placemark.ExtendedData.LatLonBox;
       else return '';
   },

   getGeocodedAddress : function(){
       return this.placemark.address;
   },

   setAllowedCountries : function(allowedCountries){
       this.allowedCountries = allowedCountries;
       this.placemark = [];
       this.address = false;
       this.input.val('');
   },

   setDisplayKey : function(displayKey){
       this.displayKey = displayKey;
   },

   isValid : function (){
       return this.address;
   },

   invalidLocation : function(){
       this.address = false;
       return jQuery('<p class="geocoder-suggestion-error">' + trad_wrong_address + '</p>');
       //this.suggestionsBody.html('<span class="geocoder-suggestion-error">' + trad_wrong_address + '</span>');
   },

   show : function (){
       this.suggestions.show();
   },

   hide : function(){
       this.suggestions.hide();
   },

   geocode : function(fnc){
       var _this = this;
       var location;

       if (typeof this.defaultText != null){
           location = _this.defaultText.getText();
           
       }else
           location = _this.input.val();
       
       if (this.allowedCountries.length == 1)
           location += ', ' + this.allowedCountries[0];

       _this.geocoder.getLocations(location, function(response){
           _this.placemark = response.Placemark[0];
           _this.address = true;
           if (typeof fnc != 'undefined')
               fnc();
       });
   },

   findKey : function (key,obj,value){
       var _this = this;
       jQuery.each(obj,function(k, v){
           if (k == key){
               value = v;
           }if (typeof v == 'object')
               value = _this.findKey(key, v, value);
       });
       if (typeof value == 'undefined')
           return '';
       return value;
   },

   findCity : function(placemark)
   {
       try{
           var LocalityName = this.findKey('LocalityName', placemark);
           if (LocalityName != '')
               return LocalityName;

           var DependentLocalityName = this.findKey('DependentLocalityName', placemark);
           if (DependentLocalityName != '')
               return DependentLocalityName;

           var AddressLine = this.findKey('AddressLine', placemark);
           if (AddressLine != '')
               return AddressLine[0];

       } catch (e){
           return '';
       }
       return '';
   },

   submitOnReturn : function(bool){
       this.autocomplete.submitOnReturn = bool;
   }
};

// CapitalCitiesCache is a custom cache that extends the standard GeocodeCache.
  // We call apply(this) to invoke the parent's class constructor.
  function CapitalCitiesCache() {
    GGeocodeCache.apply(this);
  }

  // Assigns an instance of the parent class as a prototype of the
  // child class, to make sure that all methods defined on the parent
  // class can be directly invoked on the child class.
  CapitalCitiesCache.prototype = new GGeocodeCache();

  // Override the reset method to populate the empty cache with
  // information from our array of geocode responses for capitals.
  CapitalCitiesCache.prototype.reset = function() {
    GGeocodeCache.prototype.reset.call(this);
    for (var i in city) {
      this.put(city[i].name, city[i]);
    }
  };

/**
 * Cached sities
 */

 var montreuil = [
    {"id": "p1", "address": "93100 Montreuil, France", "AddressDetails": {"Country": {"CountryNameCode": "FR", "CountryName": "France", "AdministrativeArea": {"AdministrativeAreaName": "Ile-de-France", "SubAdministrativeArea": {"SubAdministrativeAreaName": "Seine-Saint-Denis", "Locality": {"LocalityName": "Montreuil", "PostalCode": {"PostalCodeNumber": "93100"}}}}}, "Accuracy": 5}, "ExtendedData": {"LatLonBox": {"north": 48.878653, "south": 48.8487397, "east": 2.4826549, "west": 2.4153292}}, "Point": {"coordinates": [2.4403634, 48.8592753, 0]}},
    {"id": "p2", "address": "Montreuil, France", "AddressDetails": {"Country": {"CountryNameCode": "FR", "CountryName": "France", "AdministrativeArea": {"AdministrativeAreaName": "Centre", "SubAdministrativeArea": {"SubAdministrativeAreaName": "Eure-et-Loir", "Locality": {"LocalityName": "Montreuil"}}}}, "Accuracy": 4}, "ExtendedData": {"LatLonBox": {"north": 48.805166, "south": 48.7562012, "east": 1.4055372, "west": 1.3556163}}, "Point": {"coordinates": [1.3665751, 48.7772512, 0]}}
];
var boulogne = [
    {"id": "p2", "address": "Boulogne-Billancourt, France", "AddressDetails": {"Country": {"CountryNameCode": "FR", "CountryName": "France", "AdministrativeArea": {"AdministrativeAreaName": "Ile-de-France", "SubAdministrativeArea": {"SubAdministrativeAreaName": "Hauts-de-Seine", "Locality": {"LocalityName": "Boulogne-Billancourt"}}}}, "Accuracy": 4}, "ExtendedData": {"LatLonBox": {"north": 48.8534246, "south": 48.8214846, "east": 2.262982, "west": 2.2228807}}, "Point": {"coordinates": [2.24333, 48.8338029, 0]}},
    {"id": "p1", "address": "Boulogne-sur-Mer, France", "AddressDetails": {"Country": {"CountryNameCode": "FR", "CountryName": "France", "AdministrativeArea": {"AdministrativeAreaName": "Nord-Pas-de-Calais", "SubAdministrativeArea": {"SubAdministrativeAreaName": "Pas-de-Calais", "Locality": {"LocalityName": "Boulogne-sur-Mer"}}}}, "Accuracy": 4}, "ExtendedData": {"LatLonBox": {"north": 50.7495665, "south": 50.7098285, "east": 1.6335091, "west": 1.5789143}}, "Point": {"coordinates": [1.6148833, 50.7256046, 0]}}
];

var paris = [
    {
    "id": "p1",
    "address": "Paris, France",
    "AddressDetails": {
        "Country": {
            "CountryNameCode": "FR",
            "CountryName": "France",
            "AdministrativeArea"
            : {
                "AdministrativeAreaName": "Ile-de-France",
                "SubAdministrativeArea": {
                    "SubAdministrativeAreaName": "Paris"
                    ,
                    "Locality": {
                        "LocalityName": "Paris"
                    }
                    }
                }
            },
        "Accuracy": 4
    },
    "ExtendedData": {
        "LatLonBox": {
            "north": 48.9153630,
            "south": 48.7979015,
            "east": 2.4790465,
            "west": 2.2229277
        }
    },
    "Point": {
        "coordinates": [ 2.3509871, 48.8566667, 0 ]
    }
}
];

var parisQuatre = [
{
    "id": "p2",
    "address": "4ème Arrondissement, Paris, France",
    "AddressDetails": {
        "Country": {
            "CountryNameCode": "FR",
            "CountryName": "France",
            "AdministrativeArea"
            : {
                "AdministrativeAreaName": "Ile-de-France",
                "SubAdministrativeArea": {
                    "SubAdministrativeAreaName": "Paris"
                    ,
                    "Locality": {
                        "LocalityName": "Paris",
                        "AddressLine":["4ème Arrondissement"]
                        }
                    }
                }
            },
        "Accuracy": 4
    },
    "ExtendedData": {
        "LatLonBox": {
            "north": 48.8619959,
            "south": 48.8461217,
            "east": 2.3691640,
            "west": 2.3446508
        }
    },
    "Point": {
        "coordinates": [ 2.3509871, 48.8566667, 0 ]
    }
}
];

var parisAll = [];

if (typeof ONLY_ARRONDISSEMENTS_PARIS == 'undefined'){
    parisAll.push({
        "id": "p1",
        "address": "Paris, France",
        "AddressDetails": {
            "Country": {
                "CountryNameCode": "FR",
                "CountryName": "France",
                "AdministrativeArea"
                : {
                    "AdministrativeAreaName": "Ile-de-France",
                    "SubAdministrativeArea": {
                        "SubAdministrativeAreaName": "Paris"
                        ,
                        "Locality": {
                            "LocalityName": "Paris"
                        }
                        }
                    }
                },
            "Accuracy": 4
        },
        "ExtendedData": {
            "LatLonBox": {
                "north": 48.9153630,
                "south": 48.7979015,
                "east": 2.4790465,
                "west": 2.2229277
            }
        },
        "Point": {
            "coordinates": [ 2.3509871, 48.8566667, 0 ]
        }
    });
} 

    parisAll.push(

     {
        "id": "p1",
        "address": "1er Arrondissement, Paris, France",
        "AddressDetails": {
            "Accuracy" : 4,
            "Country" : {
                "AdministrativeArea" : {
                "AdministrativeAreaName" : "Ile-de-France",
                "SubAdministrativeArea" : {
                    "Locality" : {
                        "AddressLine" : [ "1er Arrondissement Paris" ],
                        "LocalityName" : "Paris"
                    },
                    "SubAdministrativeAreaName" : "Paris"
                    }
                },
                "CountryName" : "France",
                "CountryNameCode" : "FR"
            }
        },
        "ExtendedData": {
            "LatLonBox": {
            "north": 48.8675803,
            "south": 48.8528986,
            "east": 2.3571752,
            "west": 2.3251604
            }
        },
        "Point": {
            "coordinates": [ 2.3411678, 48.8602400, 0 ]
        }
    },
    {
        "id": "p1",
        "address": "2ème Arrondissement, Paris, France",
        "AddressDetails": {
            "Accuracy" : 4,
            "Country" : {
                "AdministrativeArea" : {
                "AdministrativeAreaName" : "Ile-de-France",
                "SubAdministrativeArea" : {
                    "Locality" : {
                        "AddressLine" : [ "2ème Arrondissement Paris" ],
                        "LocalityName" : "Paris"
                    },
                    "SubAdministrativeAreaName" : "Paris"
                }
                },
                "CountryName" : "France",
                "CountryNameCode" : "FR"
            }
        },
        "ExtendedData": {
            "LatLonBox": {
                "north": 48.8738744,
                "south": 48.8591946,
                "east": 2.3561723,
                "west": 2.3241575
            }
        },
        "Point": {
            "coordinates": [ 2.3401649, 48.8665350, 0 ]
        }
    },
    {
    "id": "p1",
    "address": "3ème Arrondissement, Paris, France",
    "AddressDetails": {
    "Accuracy" : 4,
    "Country" : {
        "AdministrativeArea" : {
        "AdministrativeAreaName" : "Ile-de-France",
        "SubAdministrativeArea" : {
        "Locality" : {
        "AddressLine" : [ "3ème Arrondissement Paris" ],
        "LocalityName" : "Paris"
        },
        "SubAdministrativeAreaName" : "Paris"
        }
        },
        "CountryName" : "France",
        "CountryNameCode" : "FR"
        }
    },
    "ExtendedData": {
    "LatLonBox": {
        "north": 48.8710461,
        "south": 48.8563655,
        "east": 2.3771014,
        "west": 2.3450866
    }
    },
    "Point": {
        "coordinates": [ 2.3610940, 48.8637063, 0 ]
    }
    },
    {
        "id": "p1",
        "address": "4ème Arrondissement, Paris, France",
        "AddressDetails": {
            "Country": {
                "CountryNameCode": "FR",
                "CountryName": "France",
                "AdministrativeArea"
                : {
                    "AdministrativeAreaName": "Ile-de-France",
                    "SubAdministrativeArea": {
                        "SubAdministrativeAreaName": "Paris"
                        ,
                        "Locality": {
                            "LocalityName": "Paris",
                            "AddressLine":["4ème Arrondissement"]
                            }
                        }
                    }
                },
            "Accuracy": 4
        },
        "ExtendedData": {
            "LatLonBox": {
                "north": 48.8619959,
                "south": 48.8461217,
                "east": 2.3691640,
                "west": 2.3446508
            }
        },
        "Point": {
            "coordinates": [ 2.3509871, 48.8566667, 0 ]
        }
    },
      {
            "id": "p1",
    "address": "5ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "5ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
    "ExtendedData": {
      "LatLonBox": {
    "north": 48.8528038,
    "south": 48.8381179,
    "east": 2.3605252,
    "west": 2.3285104
      }
    },
    "Point": {
      "coordinates": [ 2.3445178, 48.8454614, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "6ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "6ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8578442,
    "south": 48.8431597,
    "east": 2.3487761,
    "west": 2.3167613
      }
    },
    "Point": {
      "coordinates": [ 2.3327687, 48.8505025, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "7ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "7ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8653153,
    "south": 48.8506330,
    "east": 2.3311645,
    "west": 2.2991497
      }
    },
    "Point": {
      "coordinates": [ 2.3151571, 48.8579747, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "8ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "8ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8851240,
    "south": 48.8704475,
    "east": 2.3323585,
    "west": 2.3003437
      }
    },
    "Point": {
      "coordinates": [ 2.3163511, 48.8777863, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "9ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "9ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
    "ExtendedData": {
      "LatLonBox": {
    "north": 48.8801634,
    "south": 48.8654855,
    "east": 2.3564836,
    "west": 2.3244688
      }
    },
    "Point": {
      "coordinates": [ 2.3404762, 48.8728250, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "10ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "10ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8790756,
    "south": 48.8643973,
    "east": 2.3732082,
    "west": 2.3411934
      }
    },
    "Point": {
      "coordinates": [ 2.3572008, 48.8717370, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "11ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "11ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8660766,
    "south": 48.8513945,
    "east": 2.3945637,
    "west": 2.3625489
      }
    },
    "Point": {
      "coordinates": [ 2.3785563, 48.8587361, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "12ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "12ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
    "ExtendedData": {
      "LatLonBox": {
    "north": 48.8701579,
    "south": 48.8114085,
    "east": 2.4527748,
    "west": 2.3247154
      }
    },
    "Point": {
      "coordinates": [ 2.3887451, 48.8407918, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "13ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "13ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8466042,
    "south": 48.8172243,
    "east": 2.3878699,
    "west": 2.3238403
      }
    },
    "Point": {
      "coordinates": [ 2.3558551, 48.8319164, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "14ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "14ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8473979,
    "south": 48.8180184,
    "east": 2.3569275,
    "west": 2.2928979
      }
    },
    "Point": {
      "coordinates": [ 2.3249127, 48.8327103, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "15ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "15ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8563896,
    "south": 48.8270155,
    "east": 2.3316300,
    "west": 2.2676004
      }
    },
    "Point": {
      "coordinates": [ 2.2996152, 48.8417047, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "16ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "16ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8933249,
    "south": 48.8346027,
    "east": 2.3414192,
    "west": 2.2133598
      }
    },
    "Point": {
      "coordinates": [ 2.2773895, 48.8639724, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "17ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "17ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8979555,
    "south": 48.8686058,
    "east": 2.3512629,
    "west": 2.2872333
      }
    },
    "Point": {
      "coordinates": [ 2.3192481, 48.8832828, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "18ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "18ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8997165,
    "south": 48.8850443,
    "east": 2.3609848,
    "west": 2.3289700
      }
    },
    "Point": {
      "coordinates": [ 2.3449774, 48.8923809, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "19ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "19ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8971382,
    "south": 48.8677879,
    "east": 2.4146207,
    "west": 2.3505911
      }
    },
    "Point": {
      "coordinates": [ 2.3826059, 48.8824652, 0 ]
        }
      },
      {
            "id": "p1",
    "address": "20ème Arrondissement, Paris, France",
    "AddressDetails": {
       "Accuracy" : 4,
       "Country" : {
      "AdministrativeArea" : {
     "AdministrativeAreaName" : "Ile-de-France",
     "SubAdministrativeArea" : {
    "Locality" : {
       "AddressLine" : [ "20ème Arrondissement Paris" ],
       "LocalityName" : "Paris"
    },
    "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
       }
    },
        "ExtendedData": {
      "LatLonBox": {
    "north": 48.8794457,
    "south": 48.8500850,
    "east": 2.4306067,
    "west": 2.3665771
      }
    },
    "Point": {
      "coordinates": [ 2.3985919, 48.8647675, 0 ]
        }
      }

     );

var marseille = [{
    "id": "p1",
    "address": "Marseille, France",
    "AddressDetails": {
        "Country": {
            "CountryNameCode": "FR",
            "CountryName": "France",
            "AdministrativeArea"
            : {
                "AdministrativeAreaName": "Provence-Alpes-Côte d'Azur",
                "SubAdministrativeArea": {
                    "SubAdministrativeAreaName"
                    : "Bouches-du-Rhône",
                    "Locality": {
                        "LocalityName": "Marseille"
                    }
                    }
                }
            },
        "Accuracy": 4
    },
    "ExtendedData": {
        "LatLonBox": {
            "north": 43.3625250,
            "south": 43.2325922,
            "east": 5.5091013,
            "west": 5.2529825
        }
    },
    "Point": {
        "coordinates": [ 5.3810419, 43.2975933, 0 ]
    }
}];

var london = [{
    "id": "p1",
    "address": "Londres, Royaume Uni",
    "AddressDetails": {
   "Accuracy" : 4,
   "Country" : {
      "AdministrativeArea" : {
         "AdministrativeAreaName" : "Londres",
         "SubAdministrativeArea" : {
            "Locality" : {
               "LocalityName" : "Londres"
            },
            "SubAdministrativeAreaName" : "Westminster"
         }
      },
      "CountryName" : "Royaume Uni",
      "CountryNameCode" : "GB"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 51.5140423,
        "south": 51.4862583,
        "east": -0.0942214,
        "west": -0.1582510
      }
    },
    "Point": {
      "coordinates": [ -0.1262362, 51.5001524, 0 ]
    }
  }];

var lyon = [{
    "id": "p1",
    "address": "Lyon, France",
    "AddressDetails": {
        "Country": {
            "CountryNameCode": "FR",
            "CountryName": "France",
            "AdministrativeArea"
            : {
                "AdministrativeAreaName": "Rhône-Alpes",
                "SubAdministrativeArea": {
                    "SubAdministrativeAreaName": "Rhône",
                    "Locality": {
                        "LocalityName": "Lyon"
                    }
                    }
                }
            },
        "Accuracy": 4
    },
    "ExtendedData": {
        "LatLonBox": {
            "north": 45.7984244,
            "south": 45.7361562,
            "east": 4.8983584,
            "west": 4.7702990
        }
    },
    "Point": {
        "coordinates": [ 4.8343287, 45.7672990, 0 ]
    }
}];

var nyon = [
{
    "id": "p1",
    "address": "Nyon, Suisse",
    "AddressDetails": {
        "Country": {
            "CountryNameCode": "CH",
            "CountryName": "Suisse",
            "AdministrativeArea"
            : {
                "AdministrativeAreaName": "Vaud",
                "SubAdministrativeArea": {
                    "SubAdministrativeAreaName": "Nyon",
                    "Locality"
                    : {
                        "LocalityName": "Nyon"
                    }
                    }
                }
            },
        "Accuracy": 4
    },
    "ExtendedData": {
        "LatLonBox": {
            "north": 46.3962258,
            "south": 46.3654359,
            "east": 6.2704058,
            "west": 6.2063762
        }
    },
    "Point": {
        "coordinates": [ 6.2383910, 46.3808330, 0 ]
    }
},
{
    "id": "p1",
    "address": "Nyons, France",
    "AddressDetails": {
        "Country": {
            "CountryNameCode": "FR",
            "CountryName": "France",
            "AdministrativeArea": {
                "AdministrativeAreaName": "Rhône-Alpes",
                "SubAdministrativeArea": {
                    "SubAdministrativeAreaName": "Drôme",
                    "Locality": {
                        "LocalityName": "Nyons"
                    }
                    }
                }
            },
        "Accuracy": 4
    },
    "ExtendedData": {
        "LatLonBox": {
            "north": 44.3923331,
            "south": 44.3285133,
            "east": 5.2040086,
            "west": 5.0759492
        }
    },
    "Point": {
        "coordinates": [ 5.1399789, 44.3604319, 0 ]
    }
}
];

var geneve = [{
"id": "p1",
    "address": "Genève, Suisse",
    "AddressDetails": {
    "Country": {
        "CountryNameCode": "CH","CountryName": "Suisse","AdministrativeArea": {
            "AdministrativeAreaName": "Genève",
            "SubAdministrativeArea": {
                    "SubAdministrativeAreaName": "Genève",
                    "Locality"
                    : {
                        "LocalityName": "Genève"
                    }
                    }
                }
                },"Accuracy"
        : 2
        },
        "ExtendedData": {
    "LatLonBox": {
        "north": 46.3413947,
            "south": 46.0943420,
            "east": 6.3778113,
            "west": 5.8655737
            }
        },
        "Point": {

    "coordinates": [ 6.1216925, 46.2180073, 0 ]
        }
        }];

var stutzheim_offenheim = [{
    "id": "p1",
    "address": "Stutzheim-Offenheim, France",
    "AddressDetails": {
        "Country": {
            "CountryNameCode": "FR",
            "CountryName": "France",
            "AdministrativeArea"
            : {
                "AdministrativeAreaName": "Alsace",
                "SubAdministrativeArea": {
                    "SubAdministrativeAreaName": "Bas-Rhin"
                    ,
                    "Locality": {
                        "LocalityName": "Stutzheim-Offenheim"
                    }
                    }
                }
            },
        "Accuracy": 4
    },
    "ExtendedData": {
        "LatLonBox": {
            "north": 48.6431845,
            "south": 48.6136854,
            "east": 7.6555870,
            "west": 7.5915574
        }
    },
    "Point": {
        "coordinates": [ 7.6235722, 48.6284371, 0 ]
    }
}];

var cully = [{
    "id": "p1",
    "address": "Cully, Suisse",
    "AddressDetails": {
   "Accuracy" : 4,
   "Country" : {
      "AdministrativeArea" : {
         "AdministrativeAreaName" : "Vaud",
         "SubAdministrativeArea" : {
            "Locality" : {
               "LocalityName" : "Cully"
            },
            "SubAdministrativeAreaName" : "Lavaux"
         }
      },
      "CountryName" : "Suisse",
      "CountryNameCode" : "CH"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 46.5189247,
        "south": 46.4574661,
        "east": 6.7943390,
        "west": 6.6662796
      }
    },
    "Point": {
      "coordinates": [ 6.7303093, 46.4882041, 0 ]
    }
  },
  {
    "id": "p2",
    "address": "14480 Cully, France",
    "AddressDetails": {
   "Accuracy" : 4,
   "Country" : {
      "AdministrativeArea" : {
         "AdministrativeAreaName" : "Basse-Normandie",
         "SubAdministrativeArea" : {
            "Locality" : {
               "LocalityName" : "Cully"
            },
            "SubAdministrativeAreaName" : "Calvados"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 49.2652890,
        "south": 49.2361555,
        "east": -0.5027128,
        "west": -0.5667424
      }
    },
    "Point": {
      "coordinates": [ -0.5347276, 49.2507244, 0 ]
    }
  }
];

var lampertheim = [{
    "id": "p1",
    "address": "67450 Lampertheim, France",
    "AddressDetails": {
   "Accuracy" : 4,
   "Country" : {
      "AdministrativeArea" : {
         "AdministrativeAreaName" : "Alsace",
         "SubAdministrativeArea" : {
            "Locality" : {
               "LocalityName" : "Lampertheim"
            },
            "SubAdministrativeAreaName" : "Bas-Rhin"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 48.6651974,
        "south": 48.6357113,
        "east": 7.7324168,
        "west": 7.6683872
      }
    },
    "Point": {
      "coordinates": [ 7.7004020, 48.6504565, 0 ]
    }
  }];

var suisse = [{
    "id": "p1",
    "address": "Suisse",
    "AddressDetails": {
   "Accuracy" : 1,
   "Country" : {
      "CountryName" : "Suisse",
      "CountryNameCode" : "CH"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 47.7866679,
        "south": 45.8319448,
        "east": 10.2764622,
        "west": 5.9701401
      }
    },
    "Point": {
      "coordinates": [ 8.2275120, 46.8181880, 0 ]
    }
}];

var paris8 = [ {
    "id": "p1",
    "address": "8ème Arrondissement Paris, France",
    "AddressDetails": {
   "Accuracy" : 5,
   "Country" : {
      "AdministrativeArea" : {
         "AdministrativeAreaName" : "Ile-de-France",
         "SubAdministrativeArea" : {
            "Locality" : {
               "LocalityName" : "Paris",
               "PostalCode" : {
                  "PostalCodeNumber" : "75008"
               }
            },
            "SubAdministrativeAreaName" : "Paris"
         }
      },
      "CountryName" : "France",
      "CountryNameCode" : "FR"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 48.8834113,
        "south": 48.8630386,
        "east": 2.3271679,
        "west": 2.2950669
      }
    },
    "Point": {
      "coordinates": [ 2.3176432, 48.8718722, 0 ]
    }
} ];

var city = [
    {
        "name": "montreuil",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": montreuil,
        "__shared": undefined
    },
    {
        "name": "montreui",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": montreuil,
        "__shared": undefined
    },
    {
        "name": "boulogne",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": boulogne,
        "__shared": undefined
    },
    {
        "name": "13000",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": marseille,
        "__shared": undefined
    },
    {
        "name": "pari",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisAll,
        "__shared": undefined
    },
    {
        "name": "75000",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": paris,
        "__shared": undefined
    },
    {
        "name": "paris 4",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "paris 4e",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "paris 04",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "paris 4em",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "paris 4eme",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "4ème Arrondissement, Paris, France",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "paris 4è",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "paris 04",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "paris 4èm",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "paris 4ème",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisQuatre,
        "__shared": undefined
    },
    {
        "name": "69000",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": lyon,
        "__shared": undefined
    },
    {
        "name": "nyo",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": nyon,
        "__shared": undefined
    },
    {
        "name": "nyon",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": nyon,
        "__shared": undefined
    },
    {
        "name": "genève",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": geneve,
        "__shared": undefined
    },
    {
        "name": "geneve",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": geneve,
        "__shared": undefined
    },
    {
        "name": "gene",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": geneve,
        "__shared": undefined
    },
    {
        "name": "genè",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": geneve,
        "__shared": undefined
    },
    {
        "name": "genèv",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": geneve,
        "__shared": undefined
    },
    {
        "name": "Genève, Suisse",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": geneve,
        "__shared": undefined
    },
    {
        "name": "67370",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": stutzheim_offenheim,
        "__shared": undefined
    },
    {
        "name": "stutzheim",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": stutzheim_offenheim,
        "__shared": undefined
    },
    {
        "name": "67450",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": lampertheim,
        "__shared": undefined
    },
    {
        "name": "lampertheim",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": lampertheim,
        "__shared": undefined
    },
    {
        "name": "suisse",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": suisse,
        "__shared": undefined
    },
    {
        "name": "suiss",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": suisse,
        "__shared": undefined
    },
    {
        "name": "cully",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": cully,
        "__shared": undefined
    },
    {
        "name": "paris",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": parisAll,
        "__shared": undefined
    },
    {
        "name": "8ème Arrondissement Paris, France",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": paris8,
        "__shared": undefined
    },
    {
        "name": "londres",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": london,
        "__shared": undefined
    },
    {
        "name": "london",
        "Status": {
            "code": 200, "request": "geocode"
        },
        "Placemark": london,
        "__shared": undefined
    }
];
