function cpAutocomplete(){ if($("#cp, #cpHeader, #cpProduit, #cpCustom").length > 0){ $("#cp, #cpHeader, #cpProduit, #cpCustom").autocomplete({ source: function( request, response ) { $.ajax({ url: "http://ws.geonames.net/postalCodeSearchJSON", dataType: "jsonp", data: { username: 'bndm', featureClass: "P", style: "full", maxRows: 12, country: 'FR,MC,NC,MQ,GP,YT,GF,PM,RE,PF', placename_startsWith: request.term }, success: function( data ) { response( $.map( data.postalCodes, function( item ) { return { label: item.postalCode + " " + item.placeName + (item.adminName2 ? ", " + item.adminName2 : ""), value: item.postalCode, name: item.placeName, latitude: item.lat, longitude: item.lng } })); } }); }, minLength: 2, select: function( event, ui ) { var input = $(this); $.ajax({ url: "/index.php?action=catchCoordinates", dataType: "json", data: { latitude: ui.item.latitude, longitude: ui.item.longitude, cp: ui.item.value, ville: ui.item.name }, success: function() { } }); } }); } } function delVille(){ if($(".delVille").length > 0){ $(".delVille").live('click', function () { $.ajax({ url: "/index.php?action=delVille", dataType: "html", async: false, success: function() { if($('#customRevendeurs').length > 0) { $('#magasins').html(""); $('#magasins').before( '

' +'' +'' +'
+ de 300 magasins près de chez vous' +'

'); cpAutocomplete(); } else { window.location.href = window.location.href; } } }); }); } } $(document).ready(function(){ cpAutocomplete(); delVille(); });