PageSourceSearch

https://www.somfy.co.uk/dealerlocator/js/locator.js?1790250967774

js somfy.co.uk collected 2026-09-25 02:46:32 UTC 51,604 bytes, 1,642 lines download raw bytes

1// Enable trim function for IE8
2if(typeof String.prototype.trim !== 'function') {
3	String.prototype.trim = function() {
4		return this.replace(/^\s+|\s+$/g, ''); 
5	}
6}
7
8// javascript library for new dealer locator
9var selectedDealer = '';
10var selectedZIndex = 0;
11var autocomplete;
12var otherDealers = new Array();
13var selectedOtherDealerIndex = 0;
14var jsonResultVar = "";
15var mapLoaded = false;
16var windowIsLoaded = false;
17var isV6 = jQuery("#somfy.-v6").length;
18if($('#designVersion').length) {
19	var designVer = $('#designVersion').val();
20} else {
21	var designVer = '5';
22}
23
24$(window).on('load', function(){
25	windowIsLoaded = true;
26});
27
28function initAutocompleteGoogle() {
29	// Create the autocomplete object, restricting the search to geographical
30	// location types.
31	autocomplete = new google.maps.places.Autocomplete(
32		(document.getElementById('zipAndTownField')),
33		{
34			types: ['(regions)'],
35			componentRestrictions: {country: locatorConfig['country'].toLowerCase()}
36		}
37	);
38	autocomplete.setFields(['geometry','name']);
39	// When the user selects an address from the dropdown, populate the address
40	// fields in the form.
41	autocomplete.addListener('place_changed', fillInAddress);
42}
43
44function changeAutocompleteGoogleCountry() {
45	// Create the autocomplete object, restricting the search to geographical
46	// location types.
47	autocomplete = new google.maps.places.Autocomplete(
48		(document.getElementById('zipAndTownField')),
49		{
50			types: ['(regions)'],
51			componentRestrictions: {country: $("#selectCountry option:selected").attr("isocode").toLowerCase()}
52		}
53	);
54	autocomplete.setFields(['geometry','name']);
55	// When the user selects an address from the dropdown, populate the address
56	// fields in the form.
57	autocomplete.addListener('place_changed', fillInAddress);
58}
59
60// [START region_fillform]
61function fillInAddress() {
62	// Get the place details from the autocomplete object.
63	var place = autocomplete.getPlace();
64	if (!place.geometry) {
65		console.log("No geometry for this current geocode.");
66	} else {
67		document.getElementById("zipAndTownField").setCustomValidity('');
68		$("#zipAndTownField").removeClass("is-invalid");
69
70		$("#latitude").val(place.geometry.location.lat());
71		$("#longitude").val(place.geometry.location.lng());
72		$("#cityField").val(place.name);
73		$("#placeSelected").val(1);
74	}
75}
76// [END region_fillform]
77
78// [START region_geolocation]
79// Bias the autocomplete object to the user's geographical location,
80// as supplied by the browser's 'navigator.geolocation' object.
81function geolocate() {
82	if (navigator.geolocation) {
83		navigator.geolocation.getCurrentPosition(function(position) { 
84			var geolocation = {
85				lat: position.coords.latitude,
86				lng: position.coords.longitude
87			};
88			var circle = new google.maps.Circle({
89				center: geolocation,
90				radius: position.coords.accuracy
91			});
92			autocomplete.setBounds(circle.getBounds());
93		});
94	}
95}
96// [END region_geolocation]
97
98function initLocator(bProcessSearch,bShowCitySelection, translations) {
99	addKeyboardScrolling();
100
101	if(locatorConfig["autoCompleteEngine"] == 'GEONAMES') {
102		$("#zipAndTownField").autocomplete({
103			source: searchCityDL,
104			minLength: 3,
105			select: function (event, ui) {
106				document.getElementById("zipAndTownField").setCustomValidity('');
107				$("#zipAndTownField").removeClass("is-invalid");
108
109				$("#cityField").val(ui.item.town);
110				$("#cityId").val(ui.item.cityid);
111				$("#zipCodeField").val(ui.item.zip);
112				$("#latitude").val(ui.item.latitude);
113				$("#longitude").val(ui.item.longitude);
114				//console.log(ui.item);
115				$("#formValidateCity").hide();
116			},
117			open: function () {  
118				if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
119					$('.ui-autocomplete').off('menufocus hover mouseover');
120				}
121
122				$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
123			},
124			close: function () {
125				$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
126			}
127		});
128	}
129
130	/* if(designVer == '6') {
131		// enlarge the columns if there are only 3 fields (including the submit)
132		if($(".row-form-dealers-locator > .col-12").length == 3) {
133			$(".row-form-dealers-locator > .col-12").removeClass("col-3@md").addClass("col-4@md");
134		}
135	} */
136
137	if ($("#selectCountry").val() == '' || $("#selectCountry").val() == '0' || $("#selectCountry").val() == null) {
138		// hide zip town field to force country selection
139		if(designVer == '5') {
140			$("#zipAndTownField").parent().hide();
141		} else {
142			if($("#zipAndTownField").attr('type') == "text") {
143				$("#zipAndTownField").parent().parent().hide();
144				/* $("#zipAndTownField").closest(".row-form-dealers-locator").find("> .col-12").removeClass("col-3@md").addClass("col-4@md"); */
145			}
146		}
147	}
148
149	$("#selectNeed").on("invalid", function(event) {
150		document.getElementById("selectNeed").setCustomValidity($('#selectNeed').data('errormessage'));	 
151		$("#selectNeed").next("button").addClass("is-invalid");
152	});		
153	$("#selectNeed").change(function(){
154		document.getElementById("selectNeed").setCustomValidity('');
155		$("#selectNeed").next("button").removeClass("is-invalid");	 
156	});
157	
158	$("#application").on("invalid", function(event) {
159		document.getElementById("application").setCustomValidity($('#application').data('errormessage'));	 
160		$("#application").next("button").addClass("is-invalid");
161	});		
162	$("#application").change(function(){
163		document.getElementById("application").setCustomValidity('');	 
164		$("#application").next("button").removeClass("is-invalid");	 
165	});
166	
167	$("#selectCountry").on("invalid", function(event) {
168		document.getElementById("selectCountry").setCustomValidity($('#selectCountry').data('errormessage'));	
169		$("#selectCountry").next("button").addClass("is-invalid"); 
170	});		
171	$("#selectCountry").change(function(){
172		document.getElementById("selectCountry").setCustomValidity('');	 
173		$("#selectCountry").next("button").removeClass("is-invalid");	 
174	});	
175
176	$("#customerType").on("invalid", function(event) {
177		document.getElementById("customerType").setCustomValidity($('#customerType').data('errormessage'));	 
178		$("#customerType").next("button").addClass("is-invalid");
179	});		
180	$("#customerType").change(function(){
181		document.getElementById("customerType").setCustomValidity('');	
182		$("#customerType").next("button").removeClass("is-invalid");	  
183	});
184	
185	$("#zipAndTownField").focus(function () {
186		if ($("#zipAndTownField").val() == translations['zipcode']) { // "#request.cmslib.message('dealerlocator.googlemaps.zipcode')#"
187			$("#zipAndTownField").val('');
188			// clean also other fields
189			$("#cityField").val('');
190			$("#cityId").val('');
191			$("#zipCodeField").val('');
192			$("#latitude").val('');
193			$("#longitude").val('');
194			$("#placeSelected").val('0');
195		}
196		if (locatorConfig["autoCompleteEngine"] == "GOOGLE") {
197			geolocate();
198		}
199	});
200
201	if($("#zipAndTownField").attr('type') != "hidden"){
202		document.getElementById("zipAndTownField").setCustomValidity($('#zipAndTownField').data('errormessage'));	  
203	};
204
205	// error handling for SP-690 (rollback)
206	/* $("#zipAndTownField").on("invalid", function() {
207	if ($(this).attr("type") != "hidden" && $(this).is(":visible")) {
208		if($("#zipAndTownField").val() != "") {
209			this.setCustomValidity($(this).data("errorwrongvaluemessage"));
210			$("#text-zipAndTownField").text($(this).data("errorwrongvaluemessage"));
211		} else {
212			this.setCustomValidity($(this).data("errormessage"));
213			$("#text-zipAndTownField").text($(this).data("errormessage"));
214		}
215		$(this).addClass("is-invalid");
216		$(this).closest(".form-line").addClass("-error");
217	}
218	});	*/
219	$("#zipAndTownField").on("invalid", function(event) {
220		if($("#zipAndTownField").attr('type') != "hidden" && $("#zipAndTownField").is(':visible')){
221			$("#zipAndTownField").addClass("is-invalid");
222		}
223	});	
224	
225	$("#zipAndTownField").click(function () {
226		$("#zipAndTownField").removeClass('geoloc');
227		$("#zipAndTownField").val('');
228		// clean also other fields
229		$("#cityField").val('');
230		$("#cityId").val('');
231		$("#zipCodeField").val('');
232		$("#latitude").val('');
233		$("#longitude").val('');
234		$("#placeSelected").val('0');
235	});
236	
237	/* $("#zipAndTownField").blur(function () {
238		if ($("#zipAndTownField").val()=="" && !$("#zipAndTownField").parent().hasClass("-light"))
239			$("#zipAndTownField").val(translations['zipcode']); // "#request.cmslib.message('dealerlocator.googlemaps.zipcode')#"
240	}); */
241	
242	$("#zipAndTownField").keyup(function () {
243		document.getElementById("zipAndTownField").setCustomValidity('');
244		$("#zipAndTownField").removeClass("is-invalid");
245	});
246	
247	$("#addressField").focus(function () {
248		if ($("#addressField").val()==translations['address']) // "#request.cmslib.message('dealerlocator.googlemaps.address')#" 
249			$("#addressField").val('');
250	});	
251	
252	$("#addressField").blur(function () {
253		if ($("#addressField").val()=="") 
254			$("#addressField").val(translations['address']);
255	});		
256	
257	$("#stateField").focus(function () {
258		if ($("#stateField").val()==translations['state'])  // "#request.cmslib.message('dealerlocator.googlemaps.state')#"
259			$("#stateField").val('');
260	});
261
262	// add event handler to country combo
263	$("#selectCountry").change(function () {
264		if ($("#selectCountry").val() != "" && $("#selectCountry").val() != "0" && $("#zipAndTownField").attr('type') != "hidden") {
265			if (locatorConfig["autoCompleteEngine"] == 'GOOGLE') {
266				changeAutocompleteGoogleCountry();
267			}
268			if(designVer == '5') {
269				$("#zipAndTownField").parent().show();
270			} else {
271				$("#zipAndTownField").parent().parent().show();
272				/* $("#zipAndTownField").closest(".row-form-dealers-locator").find("> .col-12").removeClass("col-4@md").addClass("col-3@md"); */
273			}
274		}
275	});
276	
277	$.fn.serializeJSON=function() {
278		var json = '';
279		json=jQuery.map($(this).serializeArray(), function(n, i){
280			return ('"'+n['name']+'":"' + n['value']+'"');
281		});
282		return '{'+json.join()+'}';
283	};
284	
285	$.fn.serializeObject = function()
286	{
287		var o = {};
288		var a = this.serializeArray();
289		$.each(a, function() {
290			if (o[this.name] !== undefined) {
291				if (!o[this.name].push) {
292					o[this.name] = [o[this.name]];
293				}
294				o[this.name].push(this.value || '');
295			} else {
296				o[this.name] = this.value || '';
297			}
298		});
299		var json = '';
300		json=$.map(o, function(n, i){
301			//console.log(i +"="+n);				
302			return ('"'+i+'":"' + n+'"');
303		});
304		//console.log(json);
305		return '{'+json.join()+'}';
306	};
307	
308	
309	// support customerFinder submit
310	if(bShowCitySelection)
311		showCitySelection();		
312
313	if(bProcessSearch) {			
314		try {
315			showMap();	
316		} catch(e) {}		
317	}
318			
319	/*
320	$("#dealer_info .dealer-info-dots div.dot-right").click(function () {		
321		var currentDealer = selectedDealer;
322		var nextDealer = "";
323		
324		if( typeof currentDealer == 'undefined') {
325			nextDealer = $("li.dealerResult").first();
326		} else {
327			nextDealer = $("#"+currentDealer).next();
328		}
329		
330		if(nextDealer.length == 0) {
331			nextDealer = $("li.dealerResult").first();
332		}
333		activateDealer(nextDealer,false);
334	});	
335	
336	$("#dealer_info .dealer-info-dots div.dot-left").click(function () {
337		var currentDealer = selectedDealer;
338		var prevDealer = "";
339		if( typeof currentDealer == 'undefined') {
340			prevDealer = $("li.dealerResult").last();
341		} else {
342			prevDealer = $("#"+currentDealer).prev();
343		}
344		if(prevDealer.length == 0) {
345			prevDealer = $("li.dealerResult").last();
346		}
347		activateDealer(prevDealer,false);
348	});
349
350	$("#dealer_info .dealer-content-more-infos-button").click(function () {		
351		if($("#dealer_info").hasClass('is-open')) {
352			$("#dealer_info").removeClass('is-open');
353			$("#dealer_info div.dealer-content-more-infos").hide();
354		}
355		else {
356			$("#dealer_info").addClass('is-open');
357			$("#dealer_info div.dealer-content-more-infos").show();
358		}
359	});
360
361	$("#dealer_info_other .dealer-info-dots div.dot-right").click(function () {
362		if(otherDealers.length > selectedOtherDealerIndex + 1) {
363			showOtherDealer($(otherDealers[selectedOtherDealerIndex + 1]));
364			selectedOtherDealerIndex = selectedOtherDealerIndex + 1;
365		}
366		else if(otherDealers.length > 0){
367			// return to first
368			showOtherDealer($(otherDealers[0]));
369			selectedOtherDealerIndex = 0;
370		}
371	});
372
373	$("#dealer_info_other .dealer-info-dots div.dot-left").click(function () {
374		if(selectedOtherDealerIndex - 1 >= 0) {
375			showOtherDealer($(otherDealers[selectedOtherDealerIndex - 1]));
376			selectedOtherDealerIndex = selectedOtherDealerIndex - 1;
377		}
378		else if(otherDealers.length > 0){
379			// return to last
380			showOtherDealer($(otherDealers[otherDealers.length - 1]));
381			selectedOtherDealerIndex = otherDealers.length - 1;
382		}
383	});
384	*/
385}
386
387	
388function searchCityDL(request, response) {
389	var _countryid = 0;
390	if (typeof $("#country").val() === "undefined" || $("#country").val() == ''){
391		if(typeof $("#selectCountry").val() !== "undefined"){
392			_countryid = $("#selectCountry").val();
393		}
394	} else if(typeof $("#country").val() !== "undefined" 
395				&& isNaN($("#country").val())
396				&& typeof $("#selectCountry").val() !== "undefined" 
397				&& !(isNaN($("#selectCountry").val()))
398	){
399		_countryid =$("#selectCountry").val();
400	} else {
401		_countryid = $("#country").val();
402	}
403
404	if(_countryid == ""){
405		_countryid = 0;
406	}
407	
408	$.ajax({
409			url: locatorConfig['baseDomain']+"/"+locatorConfig['sitename']+"/ajax_handlers/dealerLocator.cfc?callback=?",
410			data: {method:"searchCityByZipAndNameJsonP", zip:request.term,cityname:request.term,countryId:_countryid, languageId:locatorConfig['language'], withGeonames:true},
411			dataType: "json",
412			crossDomain:true,
413			success: function( data ) {
414				if(!data.withGeonames) {
415					//alert('run search')
416					// lets start search
417					$("#cityId").val(data.result[0].cityid);
418					$("#cityField").val(data.result[0].town);
419					$("#zipCodeField").val(data.result[0].zip);
420					$("#latitude").val(data.result[0].latitude);
421					$("#longitude").val(data.result[0].longitude);
422					if(request.submitFormulaire)
423					{
424						if(!(typeof directCall !== 'undefined' && directCall)){
425							searchDealers(1);
426						}
427					}
428				}
429				else {
430					response( $.map( data.result, function( item ) {
431						if(locatorConfig['sitename']=='br') {
432							_label = item.name + ' (' + item.state.toUpperCase() + ')';
433						} else {
434							_label = item.zip + ' ' + item.name;
435						}
436
437						return {
438							label: _label,
439							value: _label,
440							town:  item.name,
441							zip:	item.zip,
442							cityid: item.cityId,
443							longitude: item.longitude,
444							latitude: item.latitude
445						}
446					}));
447				}
448			}
449		});
450}
451
452function showCitySelection() {
453	var translations = locatorConfig['labels'];
454	$("#formValidateCity").hide();
455	if(($("#zipAndTownField").val() !=translations['zipcode']) && $("#zipAndTownField").val() !='') {
456		var req = new Object();			
457		req.term = $("#zipAndTownField").val();
458		req.submitFormulaire = true;
459		searchCityDL(req,function(data){
460			var cityCombo = '<div class="select"><select name="selectCityId" id="selectCityId">';
461			if (data.length == 1) { // lets start search					
462				$("#cityId").val(data[0].cityid);
463				$("#cityField").val(data[0].town);							
464				$("#zipCodeField").val(data[0].zip);
465				$("#latitude").val(data[0].latitude);	
466				$("#longitude").val(data[0].longitude);	
467				if( $("#selectCityId").length == 1 ){
468					$("#zipAndTownField").val($("#selectCityId").text());					
469				}else{
470					$("#zipAndTownField").val( data[0].zip + ' ' + data[0].town );
471				}
472				if( $("#application").val() != '' ){
473					if(!(typeof directCall !== 'undefined' && directCall)){
474						searchDealers(1);
475					}
476				}								
477			}
478			else if(data.length == 0 || $("#zipAndTownField").hasClass('has-zipcode')) {
479				$("#formValidateCity").show();
480			}
481			else{
482			
483				for (var i in data) {
484					var city = data[i];
485					cityCombo += getCityOption(city.cityid, city.label);															
486				}
487				cityCombo += '</select>';
488				cityCombo += '<div class="curseur_select"></div></div>';
489				var msgSelectCity = '<span id="formValidateSelectCity" style="color:#FF0000;padding-bottom:10px;margin-left:13px;">';
490				msgSelectCity += translations['citytochoose']; //"#request.cmslib.message('dealerlocator.googlemaps.citytochoose')#";
491				msgSelectCity += '</span><br/>';
492				$("#citySelectionDiv").html(msgSelectCity + cityCombo);
493				if(designVer == '5') {
494					$("#zipAndTownField").parent().hide();
495				} else {
496					$("#zipAndTownField").parent().parent().hide();
497				}
498				$("#citySelectionDiv").show();
499			}
500		});	
501		
502		// add event handler to city combo
503		$("#selectCityId").change(function () {
504			//alert($("#selectCityId").val());
505			if ($("#selectCityId").val() != "") {
506				//alert($("#selectCityId").val());
507				$("#cityId").val($("#selectCityId").val());
508			}
509		});
510				
511	}	
512		
513}
514	
515function getCityOption(pValue,pLabel) {
516	return '<option value="'+pValue+'">'+pLabel+'</option>';
517}
518
519function showFormDatas() {
520	var spanContent = "";
521	spanContent += $('#findCustomersForm input[name="customerType"]:checked').siblings("label").html() + " : ";
522	var strCity = $('#zipAndTownField').val();
523	if(strCity.trim()=="") strCity = $('#zipCodeField').val() + ' ' + $('#cityField').val();
524	spanContent += strCity + ' : ';
525	
526	var appList = "";
527	if (designVer == '5' || designVer == '6'){
528		if (designVer == '5') {
529			var arrayTexts = $(".tc_event_search_appli .filter-option .filter-option-inner-inner").text();
530		} else {
531			var arrayTexts = $(".tc_event_search_appli").parent().find("#application-current").text();
532		}
533		var arrayTexts = arrayTexts.split(",");
534		var appCodeList = [];
535
536		for (var i = 0; i < arrayTexts.length; i++) {
537			var value = arrayTexts[i].trim();
538			
539			appCodeList.push($("select.tc_event_search_appli option:contains('"+ value +"')").val());
540		}
541		var appCodeList = appCodeList.join(",");
542	}else{
543		var appList2 = "";
544		var appCodeList = "";
545		$('#findCustomersForm input[name="application"]:checked').each(function() {
546			if(appList.length>0) appList += ", ";
547			appList += $(this).siblings("label").html();
548			if(appList2.length>0) appList2 += ", ";
549			appList2 += $(this).siblings("label").data('label');
550			if(appCodeList.length>0) appCodeList += ",";
551			appCodeList += $(this).siblings("label").data('code');
552			
553		});
554	}
555	
556	spanContent += appList;
557	$(".subtitle_resultats").html(spanContent);
558	
559	
560	// tag commander data layer
561	
562	if(tc_vars) {
563		var catVarsRequest = {dataType:"json", url:pageAjaxURL+"?targetFunction=getCatVars&targetComponent=ajax&sitename="+pageSitename+"&plugin=TagCommander&listapp="+appCodeList,method:"POST"};
564		catVarsRequest.success = function(data) { 
565			if(data) {   	    	 
566				//console.log(data);
567				var stringGlobal = data.GLOBAL;
568				var stringLocal = data.LOCAL;
569				var isocode = '';
570				if(typeof  $("select[name='selectCountry'] option[value="+$('#selectCountry').val()+"]").attr("isocode") !== "undefined"){
571					isocode = $("select[name='selectCountry'] option[value="+$('#selectCountry').val()+"]").attr("isocode").toUpperCase();
572				}else{
573					isocode = $("input[name='selectCountry']").data("country");
574				}
575				
576				tc_vars["search_country"]		= isocode;
577				tc_vars["search_city"]			= $('#cityField').val();
578				tc_vars["search_postcode"]		= $('#zipCodeField').val();
579				
580				if (designVer == '5'){
581					if ($("select.tc_event_search_service").length){
582						tc_vars["search_service"] = $("select.tc_event_search_service option:contains('"+$(".tc_event_search_service .filter-option .filter-option-inner-inner").text()+"')").val().toUpperCase();
583					}
584				}else{
585					if($('#findCustomersForm input[name="customerType"]:checked').length > 0){
586						tc_vars["search_service"]		= $('#findCustomersForm input[name="customerType"]:checked').val().toUpperCase();
587					}
588				}
589					
590				tc_vars["search_product"]		= stringGlobal;
591				tc_vars["page_cat_name"]		= stringGlobal;
592				tc_vars["page_cat_name_local"]	= stringLocal;
593				tc_vars["env_section"]			= "dealerLocator";
594				tc_vars["env_template"]			= "search";
595				if(typeof tC !== 'undefined') {
596					console.log('tagCommander reload 1');
597					try {
598						//Reload - Header A/B testing container - 20
599						if (typeof tC !== 'undefined' && typeof tC.executeTag100_3887_20 === 'function') {
600							tC.executeTag100_3887_20({ target: {} }, {});
601						} else {
602							console.log('Cannot execute: tC.executeTag100_3887_20 is not defined');
603						}
604						tC.container.reload();
605						tC.event.all(this,{});
606					}catch (e){
607						console.log('tagCommander reload error' + e );
608					}
609					console.log('tagCommander reload done');
610				}
611				
612				addTCJavaScript();
613
614				setDealerLocatorSearchEvents();
615			}
616		};
617		catVarsRequest.error = function(err) { 
618		//console.log(err);
619		};
620		jQuery.ajax(catVarsRequest);
621		
622		
623	}else{
624		console.log("tc_vars not defined");
625	}
626	
627	
628	
629}
630function searchPartnershops(){
631	$(".content-loader").show();
632	
633	var maxResults = 3;
634	var linkLabel = locatorConfig['labels']['gotoshop'];
635	var distUnit = locatorConfig['distanceUnit'];
636	var userCity = ($("#cityField").val() == "") ? $("#zipAndTownField").val() : $("#cityField").val();
637
638	$.ajax({
639		url: locatorConfig['baseDomain']+"/"+locatorConfig['sitename']+"/ajax_handlers/dealerLocator.cfc",
640		data: {
641			method: "findClosestDealers",
642			zip: $("#zipCodeField").val(),
643			cityname: userCity,
644			countryId: $("#selectCountry").val(),
645			applications:"",
646			applicationFilterAllApp: false,
647			languageId: locatorConfig['language'],
648			latitude: $("#latitude").val(),
649			longitude: $("#longitude").val(),
650			withShopURL: 'yes',
651			isAcceptLeadsOnly: false
652		},
653		dataType: "json",
654		crossDomain: true,
655		success: function(data){
656			console.log(data);
657			if(data.resultType == 'none') {
658				nbRes = 0;
659			} else {
660				nbRes = Math.min(maxResults,data.result.DEALERS.length)
661			}
662			
663			// Show subtitle
664			$("#results_title").html( $("#results_title").data("original").replace("#n#",nbRes).replace("#loc#",userCity) );
665			
666			// Show results
667			$("#results_dealers").html("");
668			if(nbRes > 0) {
669				_divClass = $("#results_dealers").data("childdivclass");
670				for (i=0; i<nbRes; i++) {
671					var _dl = data.result.DEALERS[i];
672					if($('#version').val() !== 'undefined'){
673						var _div = $("<li></li>").addClass('col-12 col-3@md');
674						var _divcontent = $("<div></div>").addClass("partnershops -bg-white -border").attr('data-viewport.once','fade-up');
675						_divcontent.append( $("<h4></h4>").addClass("partnershops-title h6").html(_dl.name) );
676						_divcontent.append( $("<span></span>").addClass("partnershops-distance").html("("+_dl.distance+" "+distUnit+")") );
677						_divcontent.append( $("<p></p>").addClass("partnershops-address").html(_dl.address1+"<br />"+_dl.zipcode+" "+_dl.city) );
678						if(_dl.shop_url != "") {
679							_divcontent.append( $("<p></p>").addClass("link -arrow").append( $("<a></a>").attr("href",_dl.shop_url).html(linkLabel) ) );
680						}
681						_div.append(_divcontent);
682
683					} else {
684						var _div = $("<div></div>").addClass(_divClass);
685						_div.append( $("<p></p>").addClass("subtitle_2").html(_dl.name) );
686						_div.append( $("<p></p>").addClass("text_small").html("("+_dl.distance+" "+distUnit+")") );
687						_div.append( $("<p></p>").addClass("text_small").html(_dl.address1+"<br />"+_dl.zipcode+" "+_dl.city) );
688						if(_dl.shop_url != "") {
689							_div.append( $("<p></p>").addClass("link_medium").append( $("<a></a>").attr("href",_dl.shop_url).html(linkLabel) ) );
690						}
691					}
692					
693					
694					$("#results_dealers").append(_div);
695				}
696			}
697			
698			$(".content-loader").hide();
699			$(".partnershops_results").slideDown();
700		},
701		error: function(er){
702			$("#results_title").html( $("#results_title").data("original").replace("#n#",0).replace("#loc#",userCity) );
703			$("#results_dealers").html("");
704			$(".content-loader").hide();
705			$(".partnershops_results").slideDown();
706			console.log(er);
707		}
708	});
709}
710
711function searchDealersRP(){
712	if(locatorConfig['useAjax']) {
713		var $form = $("#findCustomersFormRP");
714		var args =$form.serializeObject();
715
716			$.ajax({
717		type: "GET",
718		url: locatorConfig['baseDomain']+"/"+locatorConfig['sitename']+"/ajax_handlers/dealerLocator.cfc?callback=?",
719		data: {method:"dealersLSCookie", args:args},
720		dataType: "text",
721		crossDomain:true,
722		success: function( data ) {
723			try {
724				//var jsonObj = JSON.parse(data);
725
726				var d = new Date();
727				d.setTime(d.getTime() + (30*60*1000)); //30min cookie duration
728				setCookie('LS', data.trim(), d);
729
730				var _country = typeof $("#selectCountry").data("country") !== "undefined" ? $("#selectCountry").data("country") : $("#selectCountry").find(":selected").text();
731
732				setBlocConverstionEvents("dealerlocator", $("#findCustomersFormRP"), "dealerlocator", "", _country, $("#zipAndTownField").val());
733
734				window.location.href = $form.attr("action");
735			}catch(e) {
736				console.log(e);
737			}
738		},
739		error: function (XMLHttpRequest, textStatus, errorThrown) {
740			console.log("XMLHttpRequest_searchDealers : "+XMLHttpRequest);
741			console.log("textStatus_searchDealers : "+textStatus);
742			console.log("errorThrown_searchDealers : "+errorThrown);
743			}
744		});
745	}else {
746		document.getElementById('findCustomersFormRP').submit();
747	}
748}
749
750function searchDealers(offset) {
751
752	console.log('>> searchDealers');
753
754	if(locatorConfig['useAjax']) {
755		if (!($('#has_showroom_fld').val() === undefined)) {
756			if ($('input[name="has_showroom_fld"]:checked').length > 0) {
757				$('#has_showroom').val(1);
758			} else {
759				$('#has_showroom').val(0);
760			}
761		} else {
762			$('#has_showroom').val(0);
763		}
764		if (!($('#sort_option_fld').val() === undefined)) {
765			$('#dealers-order').val($('#sort_option_fld').val());
766		}
767
768		var $form = $("#findCustomersForm");
769
770		contact_dealer(false);
771
772		if ($("#message_success").length) {
773			$("#message_success").hide();
774		}
775
776		if (typeof isV4 != 'undefined' && isV4) {
777			showFormDatas();
778		}
779
780		if (offset) $("#offset").val(offset);
781		var args = $form.serializeObject();
782		/* Loading 100% CSS */
783		$("#ajaxSearchLoading").html("<div class='spinnerLoopContainer'><div class='center40px'><div class='spinnerLoop'><div class='dot1'></div><div class='dot2'></div></div></div></div>");
784		$('.content-loader').show();
785		if ($("#dealer_info").length > 0) {
786			$("#dealer_info").hide();
787		}
788
789		$.ajax({
790			type: "GET",
791			url: locatorConfig['baseDomain'] + "/" + locatorConfig['sitename'] + "/ajax_handlers/dealerLocator.cfc?callback=?",
792			data: {method: "findDealersJsonP", args: args},
793			dataType: "json",
794			crossDomain: true,
795			/*timeout:5000,*/
796			success: function (data) {
797				try {
798					// v5: returning json object
799					var jsonObj = JSON.parse(data);
800					var content = $(jsonObj.html);
801					var messageRes = "";
802					if (jsonObj.LS != undefined) {
803						var d = new Date();
804						d.setTime(d.getTime() + (30*60*1000)); //30min cookie duration
805						setCookie('LS', jsonObj.LS, d);
806					}
807					mapLoaded = false;
808					$("#ajaxSearchLoading").empty();
809					$(".content-loader").hide();
810					$(".transparency-msg").hide();
811					$("#dealers_locator").addClass("has-dealers");
812					/*$( "#ajaxSearchResult" ).css("display","flex");*/
813					if($.trim(jsonObj.resultTitle) != '') {
814						if (designVer == '6'){
815							$(".dealers-locator-top h3").html(jsonObj.resultTitle);
816						} else {
817							$(".dealers-locator-top h3.title_2").html(jsonObj.resultTitle);
818						}
819					}
820					$("#ajaxSearchResult").empty().append(content);
821					initClickEvent(); 
822
823					if($(".dealers-customform-contact-confirm").length) {
824						$(".dealers-customform-contact-confirm").show();
825						/* $('html, body').animate({
826							scrollTop: $('.dealers-locator-content').offset().top
827						}, 1000); */
828						$(".dealers-customform-contact-confirm").get(0).scrollIntoView({behavior: 'smooth'});
829						setTimeout(function() {
830							$('.dealers-customform-contact-confirm').fadeOut();
831						}, 5000);
832					}
833
834					//$('.dealers-locator-content').slideDown();
835
836					if(designVer == '5') {
837						jQuery("select:not([accesskey]):not(.no-bootstrap)").each(function () {
838							if ($(this).parents('.form_assembly .wFormContainer').length == 0) {
839								$(this).selectpicker({
840									"size": 5,
841									"showIcon": false,
842									"showTick": false,
843									"tickIcon": ''
844								});
845							}
846						});
847					}
848
849					//console.log("jsonObj :");
850					//console.log(jsonObj);
851
852					//$("#sort-options")
853					//highlightDealers();
854					jsonResultVar = jsonObj;
855
856					// remove $(".toSticky").hasClass("mapActive") because class is never set
857					if ($("#map").css("display") != "none" && jQuery(window).width() > 991) {
858
859						$("#dealers_locator").addClass("show-map");
860						initializeMap(jsonObj.dealers, jsonObj.partnerships, jsonObj.numberOfDealers, jsonObj.googleMapResult);
861
862					} else if(jQuery(window).width() <= 991) {
863						if(isV6) {
864							initializeMap(jsonObj.dealers, jsonObj.partnerships, jsonObj.numberOfDealers, jsonObj.googleMapResult);
865						} else {
866							// do not display map for this resolution
867							// Scroll to results
868							_searchWrapperMargins = 100;
869							_formHeight = $("#findCustomersForm").innerHeight();
870							_headerHeight = $("#header").innerHeight() + 1;
871
872							$('html, body').animate({
873								scrollTop: _searchWrapperMargins + _formHeight + _headerHeight
874							}, 1000);
875						}
876					} /*else {
877						//$("#dealers_locator").addClass("show-map");
878						initializeMap(jsonObj.dealers, jsonObj.partnerships, jsonObj.numberOfDealers);
879
880
881						//$("#dealers_locator").removeClass("show-map");
882					}*/
883					//showMap(jsonObj.dealers,jsonObj.partnerships,jsonObj.numberOfDealers);
884					// todo: test what this does
885					/* $("#citySelectionDiv").hide();
886					$("#zipAndTownField").parent().show();
887					$("#level_expert_explanation").show(); */
888					if ($("#dealers_locator").length > 0) {
889
890						if (jsonObj.numberOfDealers > 0) {
891							messageRes = jsonObj.numberOfDealers + ' ' + locatorConfig['labels']['dealersfound'];
892							// show first dealer on mobile
893							/*var firstDealer = jsonObj.dealers.result.DEALERS[0];
894							activateDealer($("#" + firstDealer.id), false);
895
896							try {
897								zoomDealer(firstDealer);
898							} catch (e) {
899							}
900
901							if (jsonObj.hasOtherDealers == true)
902								showOtherDealers();
903							*/
904						} else {
905							noResultsClickEvents();
906							messageRes = "";//locatorConfig['labels']['noresult'];
907						}
908						if (messageRes != "") {
909							$("#dealers_locator ul.breadcrumb li.breadcrumb-item.searchDone").show();
910							if ($("#dealers_locator ul.breadcrumb li.breadcrumb-item").length == 1) {
911								$("#dealers_locator ul.breadcrumb").append('<li class="breadcrumb-item searchDone"><a>' + messageRes + '</a></li>');
912							} else {
913								$("#dealers_locator ul.breadcrumb li.breadcrumb-item.searchDone a").html(messageRes);
914							}
915						} else {
916							$("#dealers_locator ul.breadcrumb li.breadcrumb-item.searchDone").hide();
917						}
918
919					}
920				} catch (e) {
921					console.log(e);
922
923					// not a json object in data => v4 version
924					var content = $(data);
925					$("#ajaxSearchLoading").empty();
926					$("#ajaxSearchResult").empty().append(content);
927					//highlightDealers();
928					if ($(".toSticky").hasClass("mapActive")) {
929						$("#dealers_locator").addClass("show-map");
930					}
931					//showMap();
932					$("#citySelectionDiv").hide();
933					if(designVer == '5') {
934						$("#zipAndTownField").parent().show();
935					} else {
936						$("#zipAndTownField").parent().parent().show();
937					}
938					$("#level_expert_explanation").show();
939					//scrollToAnchor('ajaxSearchResult');
940				}
941
942
943			},
944			error: function (XMLHttpRequest, textStatus, errorThrown) {
945
946				console.log("XMLHttpRequest_searchDealers : " + XMLHttpRequest);
947				console.log("textStatus_searchDealers : " + textStatus);
948				console.log("errorThrown_searchDealers : " + errorThrown);
949			}
950		});
951
952	}
953	else {
954		document.getElementById('findCustomersForm').submit();
955	}
956}
957
958
959	
960function highlightDealers(){
961	/*$("li.dealerResult").mouseover(function(){
962		$(this).addClass("hover");			
963	});
964	$("li.dealerResult").mouseout(function(){
965		$(this).removeClass("hover");
966	});
967	$("li.dealerResult a.show_on_map").click(function(e,data){
968		e.preventDefault();
969		var source = 'list_click';
970		if (typeof(data) != "undefined") {
971			source = data.source;
972		}
973		activateDealer($(this).parents('.dealerResult'),true,source)
974	});
975
976	$(".adresse a").click(dealerLocatorTracking);
977	*/
978}
979
980function activateDealer(obj, displayMoreInfo, source) {
981	try {
982		// method not always defined
983		mapClickEvents(obj.attr("id"), source+"_click");
984	}
985	catch(e) {}
986	setCookie('LD',obj.attr("id"));
987
988	$.ajax({
989		type: "GET",
990		url: "/"+pageSitename+"/ajax_handlers/dealerLocator.cfc",	
991		data: {method:"logActivity", code: obj.attr("partnerid"), activity: 'display_locator', rd: Math.random()},
992		dataType: "json",
993		crossDomain:true,				
994		success: function(msg){},
995		error: function (XMLHttpRequest, textStatus, errorThrown) {}
996	});	
997
998	if(source == 'map') {
999		document.getElementById(obj.attr("id")).scrollIntoView({behavior: "smooth"});
1000	}
1001	
1002	/* Not used in V5
1003	if(selectedDealer==obj.attr("id")) {
1004		// check if we must reopen info window (can be closed on mobile
1005		if(displayMoreInfo){
1006			$("#dealer_info").show();
1007			$("#dealer_info").addClass('is-open');
1008		}else{
1009			$("#dealer_info").hide();
1010			$("#dealer_info").removeClass('is-open');
1011		}
1012		showDetails(obj,displayMoreInfo);
1013
1014		initClickEvent(); 
1015
1016		return false;
1017	}
1018	obj.addClass("selected");
1019	obj.find("a").addClass('is-active');
1020	if(typeof displayMoreInfo == 'undefined') {
1021		displayMoreInfo = true;
1022	}
1023	*/
1024	
1025	//google.maps.event.trigger(gMarkers[obj.attr("id")],"click"); - do not trigger  > infinite loop
1026
1027	$("#map").addClass("dealerOpen");
1028	
1029	if(selectedDealer!='' && ( typeof selectedDealer != 'undefined')){
1030		//gMarkers[selectedDealer].infowindow.close();
1031		//close other infowindow 
1032		try {
1033			gOpenMarkers.forEach(function(marker) {
1034				if(typeof marker.infowindow !== 'undefined'){
1035					marker.infowindow.close(map, marker);
1036				}					
1037			});
1038		}catch(e) {}
1039		$("#"+selectedDealer).removeClass("selected");
1040		$("#"+selectedDealer + " a").removeClass("is-active");
1041		gMarkers[selectedDealer].setIcon(getMarkerIcon());
1042		gMarkers[selectedDealer].setZIndex(selectedZIndex);
1043		console.log('gMarkers>>>');
1044		console.log(gMarkers[selectedDealer]);
1045	}
1046	selectedDealer = obj.attr("id");
1047
1048	var activeMarker = gMarkers[obj.attr("id")];
1049	gOpenMarkers[0] = activeMarker;
1050	// Change marker icon
1051	activeMarker.setIcon(getMarkerIcon("active",obj.attr("hasShowroom")));
1052	try {
1053		if(typeof activeMarker.infowindow !== 'undefined')
1054			activeMarker.infowindow.open(map,activeMarker );
1055	} catch(e) {}
1056	selectedZIndex = activeMarker.getZIndex();
1057	activeMarker.setZIndex(1000+selectedZIndex);
1058	// Show detail in mobile        		
1059	if(jQuery(window).width() <= 991) {
1060		$("#dealers_list li").removeClass('active');
1061		$("#"+selectedDealer).addClass('active');    	
1062	}
1063		
1064	//showDetails(obj,displayMoreInfo);
1065
1066
1067	showClusteredMarker(activeMarker);
1068	map.panTo(activeMarker.position);
1069	
1070}
1071
1072function showClusteredMarker(marker) {
1073	var clusters = markerCluster.clusters_;
1074
1075	for (var i = 0; i < clusters.length; i++) {
1076		var markers = clusters[i].markers_;
1077		if(markers.indexOf(marker) >= 0)  {
1078			//console.log(i);
1079			//console.log(markers);
1080			//console.log("marker in cluster");
1081			map.fitBounds(clusters[i].getBounds());
1082			map.setZoom(15);
1083			return;
1084		} else {
1085			//console.log(clusters[i]);
1086		}
1087	}
1088
1089	//console.log("marker not in cluster > zoom to 5");
1090	var bounds = new google.maps.LatLngBounds();
1091	// if not in cluster set bounds to 5 nearest
1092	closest = findClosestN(marker.position, 5);
1093	//console.log(closest);
1094	for(i = 0; i < closest.length; i++) {
1095		bounds.extend(closest[i].position);
1096	}
1097	bounds.extend(marker.position);
1098	map.fitBounds(bounds);
1099
1100	map.setZoom(15);
1101
1102}
1103		
1104function showDetails(dealerObj,displayMoreInfo) {
1105	// use content to show details
1106	/*console.log(dealerObj.find(".dealer-pic-somfy-expert img").attr("src"));
1107	console.log(dealerObj.find("header"));
1108	console.log(dealerObj.find("address"));
1109	console.log(dealerObj.find("div.dealer-content-more-infos"));*/
1110	/*
1111	window.somfy.els.$dealersLocator.data('instance').handleCloseContact();
1112	$("#dealer_info header").html("");
1113	
1114	var _header = dealerObj.find("header").html();
1115	var _logos = dealerObj.find(".logos")[0].innerHTML;
1116	var _address = dealerObj.find("address")[0].outerHTML;
1117	var _moreInfos = dealerObj.find("div.dealer-content-more-infos")[0].outerHTML
1118	
1119	$("#dealer_info header").append(_logos);
1120	$("#dealer_info header").append(_header);
1121	
1122	if($("#dealer_info address").length == 0) {
1123		$("#dealer_info .dealer-content").append(_address);
1124	}
1125	else {
1126		$("#dealer_info address").html(_address);
1127	}
1128	
1129	if($("#dealer_info .dealer-content div.dealer-content-more-infos").length == 0) {
1130		$("#dealer_info .dealer-content").append(_moreInfos);
1131	}
1132	else {
1133		$("#dealer_info div.dealer-content-more-infos").html(_moreInfos);
1134	}
1135	if(displayMoreInfo)
1136		$("#dealer_info div.dealer-content-more-infos").show();
1137	
1138	window.somfy.els.$dealersLocator.data('instance').handleContact();
1139	*/
1140}
1141
1142function showOtherDealers() {
1143	if($("#dealer_info_other").length > 0 && $(".assigned-dealer-container").length > 0) {
1144		otherDealers = $(".assigned-dealer-container");
1145		selectedOtherDealerIndex = 0;
1146		showOtherDealer($(otherDealers[selectedOtherDealerIndex]));
1147
1148		// manage controls
1149		if($(".assigned-dealer-container").length == 1) {
1150			$("#dealer_info_other .dealer-info-dots .dot").hide();
1151		}
1152		else {
1153			$("#dealer_info_other .dealer-info-dots .dot").show();
1154		}
1155
1156		$("#dealer_info_other").show();
1157	}
1158}
1159
1160function showOtherDealer(dealerObj) {
1161	//var _header = dealerObj.find("header").html();
1162	try {
1163		var _title = dealerObj.find(".dealer-content-title")[0].outerHTML;
1164		var _logo = dealerObj.find(".dealer-pic img")[0].outerHTML;
1165		var _address = dealerObj.find("address")[0].outerHTML;
1166
1167
1168		$("#dealer_info_other .dealer-content-logos .dealer-content-logos-somfy-expert").html(_logo);
1169		if($("#dealer_info_other .dealer-content-title").length == 0) {
1170			$("#dealer_info_other .dealer-description").append(_title);
1171		}
1172		else {
1173			$("#dealer_info_other .dealer-content-title").html(_title);
1174		}
1175		$("#dealer_info_other header .dealer-content-title").html(_title);
1176		if($("#dealer_info_other address").length == 0) {
1177			$("#dealer_info_other .dealer-description").append(_address);
1178		}
1179		else {
1180			$("#dealer_info_other address").html(_address);
1181		}
1182
1183
1184	}
1185	catch(e) {
1186	}
1187}
1188
1189function validateLocatorForm(noAppsCheck){
1190
1191	console.log('>> validate');
1192
1193	//return true;
1194	var translations = locatorConfig['labels'];
1195	var valZip = $("#zipAndTownField").val();
1196	var valApplication = false;
1197	if(noAppsCheck) valApplication=true;
1198	var valType = false;
1199	var valCityId = $("#cityId").val();
1200	var valLatitude = $("#latitude").val();
1201	var valLongitude = $("#longitude").val();
1202	var ajaxRunning = false;
1203
1204	if ($("#cityId").val() == "" && $("#selectCityId").val() != "") {
1205		$("#cityId").val($("#selectCityId").val());
1206		valCityId = $("#cityId").val();
1207	}
1208
1209	if(locatorConfig['countryActive']== 'true' &&  !($("#zipAndTownField").hasClass('geoloc')) ) {
1210		var valCountry=$("#selectCountry").val();
1211		if(valCountry!="")
1212		{
1213			if(designVer != '6') {
1214				$("#selectCountry").next("button").removeClass("is-invalid");
1215			}
1216		}
1217		else
1218		{
1219			if(designVer != '6') {
1220				$("#selectCountry").next("button").addClass("is-invalid");
1221			}
1222			return false;
1223		}
1224	}
1225	
1226	if(locatorConfig['countryActive']== 'true' &&  ($("#zipAndTownField").hasClass('geoloc')) && $("#selectCountry").val() == "" ) {
1227		try{
1228			_isocountry = locatorConfig['country'].toLowerCase();
1229			if ($('#selectCountry option[isocode=' + _isocountry +']').val() != 'undefined'){
1230				_vv = $('#selectCountry option[isocode=' + _isocountry +']').val() ;
1231				$('#selectCountry option[value='+ _vv +']').attr('selected', 'selected');
1232			} else {
1233				$("#selectCountry option[value='']").val("0");
1234				$("#selectCountry option[value='0']").attr('selected', 'selected');
1235			}
1236			
1237		} catch(e){
1238			$("#selectCountry option[value='']").val("0");
1239			$("#selectCountry option[value='0']").attr('selected', 'selected');
1240		}
1241	}
1242
1243	if( ((valZip!="") && (valZip!=null) && (valZip!=translations['zipcode'])) || $("#zipAndTownField").hasClass('geoloc') )
1244	{
1245		if(designVer != '6') {
1246			/* document.getElementById("zipAndTownField").setCustomValidity('');
1247			$("#zipAndTownField").removeClass("is-invalid"); */
1248		}
1249	}
1250	else
1251	{
1252		if($("#zipAndTownField").attr('type') != "hidden"){
1253			if(designVer != '6') {
1254				document.getElementById("zipAndTownField").setCustomValidity($('#zipAndTownField').data('errormessage'));
1255				$("#zipAndTownField").addClass("is-invalid");
1256				setTimeout(function(){
1257				$('.search_dealers button[type=submit]').click();
1258				}, 10);	
1259			}  
1260			return false;
1261		}	
1262	}
1263
1264	if ($("select[name='customerType']").val() == "") {
1265		if(designVer != '6') {
1266			$("select[name='customerType']").next("button").addClass("is-invalid");
1267		}
1268		
1269		return false;
1270	}
1271	else {
1272		if(designVer != '6') {
1273			$("select[name='customerType']").next("button").removeClass("is-invalid");
1274		}
1275	}
1276
1277	if (!noAppsCheck) {
1278
1279		valApplication = ($("select[name='application']").val().length > 0);
1280
1281		if (!valApplication) {
1282			if(designVer != '6') {
1283				$("select[name='application']").next("button").addClass("is-invalid");
1284			}
1285			return false;
1286		}
1287		else {
1288			if(designVer != '6') {
1289				$("select[name='application']").next("button").removeClass("is-invalid");
1290			}
1291		}
1292	}
1293
1294	if(locatorConfig["autoCompleteEngine"] == 'GOOGLE') {
1295		if ($("#placeSelected").val() == "0" &&  valLatitude == '' && valLongitude == '' ) {
1296			if(designVer == '6') {
1297				document.getElementById("zipAndTownField").setCustomValidity($('#zipAndTownField').data('errormessage'));
1298				setTimeout(function(){
1299					$('#zipAndTownField').closest('.form-line').addClass('-error');
1300					}, 100);	
1301				return false;
1302			}
1303			if(designVer != '6') {
1304				document.getElementById("zipAndTownField").setCustomValidity($('#zipAndTownField').data('errormessage'));
1305				$("#zipAndTownField").addClass("is-invalid");		
1306				setTimeout(function(){
1307				$('.search_dealers button[type=submit]').click();
1308				}, 10);	    
1309				return false;
1310			} 
1311		} else {
1312			if(designVer != '6') {
1313				document.getElementById("zipAndTownField").setCustomValidity('');
1314				$("#zipAndTownField").removeClass("is-invalid");
1315			}
1316		}
1317	}
1318
1319	if(locatorConfig["autoCompleteEngine"] == 'GEONAMES') {
1320		if (
1321			(valCityId != '' && valCityId != '0') || // check if city is set after clicking on autocomplete suggestion
1322			(valLatitude != '' && valLongitude != '') ||
1323			$("#zipAndTownField").attr('type') === "hidden"
1324			)
1325		{
1326			if(designVer != '6') {
1327				document.getElementById("zipAndTownField").setCustomValidity('');
1328				$("#zipAndTownField").removeClass("is-invalid");
1329			}		
1330		} else if($("#zipAndTownField").val() != '') { // check if field zipAndTownField is not empty
1331			if($("#selectCountry").length) {
1332				var valCountry = $("#selectCountry").val();			
1333			} else {
1334				var valCountry = ""
1335			}
1336			if($("#stateField").length) {
1337				var valStateField = $("#stateField").val();			
1338			} else {
1339				var valStateField = ""
1340			}
1341			ajaxRunning = true;
1342			$('.content-loader').show();
1343			$.ajax({
1344				type: "GET",
1345				url: "/"+pageSitename+"/ajax_handlers/dealerLocator.cfc",	
1346				data: {method:"checkValidZip", zip: $("#zipAndTownField").val(), country: valCountry, state: valStateField },
1347				dataType: "json",
1348				crossDomain:true,	
1349				context: $(this),
1350				success: function(isValidZip){
1351					if(isValidZip === false) {
1352						$('.content-loader').hide();
1353						// error handling for SP-690 (rollback)
1354						/* $("#text-zipAndTownField").text($("#zipAndTownField").data("errormessage")); */
1355						document.getElementById("zipAndTownField").setCustomValidity($('#zipAndTownField').data('errormessage'));
1356						setTimeout(function(){
1357							$('#zipAndTownField').closest('.form-line').addClass('-error');
1358						}, 100);	
1359						return false;
1360					} else {
1361						searchDealers(1);
1362						return true;
1363					}
1364				},
1365				error: function (XMLHttpRequest, textStatus, errorThrown) { console.log('err:' + errorThrown) }
1366			});
1367		}else{
1368			if(typeof directCall === 'undefined' || !directCall) {
1369				if(designVer != '6') {
1370					document.getElementById("zipAndTownField").setCustomValidity($('#zipAndTownField').data('errormessage'));
1371					$("#zipAndTownField").addClass("is-invalid");
1372					setTimeout(function(){
1373					$('.search_dealers button[type=submit]').click();
1374					}, 10);			
1375				}	else {
1376					document.getElementById("zipAndTownField").setCustomValidity($('#zipAndTownField').data('errormessage'));
1377					setTimeout(function(){
1378						$('#zipAndTownField').closest('.form-line').addClass('-error');
1379						}, 100);	
1380					
1381				}
1382				return false;
1383			}
1384		}
1385	}
1386
1387	if(ajaxRunning == false) {
1388		return true;
1389	}
1390}
1391
1392function validatefindCustomersForm(noAppsCheck){
1393	var translations = locatorConfig['labels'];
1394	var valZip = $("#zipAndTownField").val();
1395	var valApplication = false;
1396	if(noAppsCheck) valApplication=true;
1397	var valType = false;
1398	var valCityId = $("#cityId").val();
1399	
1400	if ($("#cityId").val() == "" && $("#selectCityId").val() != "") {
1401		$("#cityId").val($("#selectCityId").val());
1402		valCityId = $("#cityId").val();
1403	}
1404
1405	$("input[name='customerType']").each(function(){
1406		if(this.checked) {
1407			valType = true;
1408		}
1409	});	    
1410	if (!valType) {
1411		$("#formValidateType").css('display', 'block');
1412		return false;
1413	}
1414	else {
1415		$("#formValidateType").css('display', 'none');
1416	}
1417	
1418	if (!noAppsCheck) {
1419	
1420		$(".cb_app").each(function(){
1421			if (this.checked) {
1422				valApplication = true;
1423			}
1424		});
1425		
1426		if (!valApplication) {
1427			$("#formValidateApplication").css('display', 'block');
1428			return false;
1429		}
1430		else {
1431			$("#formValidateApplication").css('display', 'none');
1432		}
1433	}
1434	
1435	if(locatorConfig['userEmailActive'] == '1') {
1436		var userMail=$("#user_email").val();
1437		if(userMail.length==0) { 
1438			$("#formValidateEmailMsg").css('display','block');
1439			return false;
1440		}
1441		else
1442		{
1443			if(userMail.indexOf("@") == -1) {
1444				$("#formValidateEmailMsg").css('display','block');
1445				return false;
1446			}
1447			else
1448			{
1449				dotPos=userMail.lastIndexOf(".");
1450				if((dotPos == (userMail.length-3)) || (dotPos == (userMail.length-4))) {
1451					$("#formValidateEmailMsg").css('display','none');
1452					//return true;
1453					if ( ( document.findCustomersForm.radioNewsletter[0].checked == false )
1454					&& ( document.findCustomersForm.radioNewsletter[1].checked == false ) )
1455					{
1456						$("#formValidateEmailNewsLetter").css('display','block');
1457						return false;
1458					}
1459					else	{
1460						$("#formValidateEmailNewsLetter").css('display','none');							
1461					}
1462						
1463				}		
1464				else {
1465					$("#formValidateEmailMsg").css('display','block');
1466					return false;
1467				}
1468			}
1469		}
1470
1471		
1472	}
1473	
1474	if(locatorConfig['countryActive']== '1') {
1475		var valCountry=$("#selectCountry").val();			
1476		if(((valZip!="")&&(valZip!=null) && (valZip!=translations['zipcode'])) && (valCountry!="0"))
1477		{				
1478			$("#formValidateMsg").css('display','none');				
1479		}
1480		else
1481		{	
1482			if($("#zipAndTownField").attr('type') != "hidden"){
1483				$("#formValidateMsg").css('display','block');
1484				return false;
1485			}
1486		}	
1487	} 
1488	else {		
1489		if((valZip!="")&&(valZip!=null)&&(valZip!=translations['zipcode']))
1490		{	
1491			$("#formValidateMsg").css('display','none');				
1492		}
1493		else
1494		{	
1495			if($("#zipAndTownField").attr('type') != "hidden"){
1496				$("#formValidateMsg").css('display','block');
1497				return false;
1498			}
1499		}		
1500	}
1501
1502
1503	if(locatorConfig["autoCompleteEngine"] == 'GOOGLE') {
1504		if ($("#placeSelected").val() == "0") {
1505			$("#formValidateSelectCity_GM").show();
1506			return false;
1507		} else {
1508			$("#formValidateSelectCity_GM").hide();
1509		}
1510	}
1511
1512	if(locatorConfig["autoCompleteEngine"] == 'GEONAMES') {
1513		if ((valCityId == '' || valCityId == '0') && $("#zipAndTownField").attr('type') != "hidden") {
1514			showCitySelection();
1515			return false;
1516
1517		}
1518	}
1519	return true;
1520	
1521}
1522
1523function contact_dealer(show, id_dealer, name){
1524	if(show){
1525		if(jQuery("section#module_form_locator div#contact input[name=\"dealer_id\"]").val() != "" &&
1526			jQuery("section#module_form_locator div#contact input[name=\"dealer_id\"]").val() != id_dealer) {
1527			//jQuery("section#module_form_locator div#contact input[name=\"subject\"]").val("");
1528			jQuery("section#module_form_locator div#contact input[name=\"email\"]").val("");
1529			jQuery("section#module_form_locator div#contact textarea[name=\"message\"]").val("");
1530			jQuery("#back_dealers").show();
1531		}
1532		jQuery("section#module_form_locator div#contact span.dealer_name").html(name);
1533		jQuery("section#module_form_locator div#contact input[name=\"dealer_id\"]").val(id_dealer);
1534		jQuery("section#module_form_locator div#contact input[name=\"dealer_name\"]").val(name);
1535		jQuery("div#ajaxSearchResult").slideUp();
1536		jQuery("section#module_form_locator div#contact").slideDown();
1537	} else {
1538		jQuery("section#module_form_locator div#contact").slideUp();
1539		jQuery("div#ajaxSearchResult").slideDown();
1540		jQuery(".non_rempli").removeClass("non_rempli");
1541		jQuery("#message_erreur").hide();
1542	}
1543}
1544
1545function addKeyboardScrolling() {
1546	var scrollTopPadding = 8;
1547	$(document).ready(function(){
1548		var originalSize = $(window).width() + $(window).height(),
1549			oldScroll = 0;
1550		$(window).resize(function(){
1551			//keyboard open
1552			if($(window).width() + $(window).height() != originalSize){
1553				oldScroll = $('main').scrollTop();
1554				if($('#zipAndTownField').is(':focus')) {
1555					var elementTop = $('#zipAndTownField').offset().top;
1556					$('main').animate({ scrollTop: elementTop - scrollTopPadding }, 300);
1557				}
1558			//keyboard closed
1559			} else {
1560				$('main').animate({ scrollTop: oldScroll }, 300);
1561
1562			}
1563		});
1564	});
1565}
1566
1567
1568function sortByDist(a, b) {
1569	return (a.distance - b.distance)
1570}
1571
1572function findClosestN(pt, numberOfResults) {
1573	var closest = [];
1574	for (var i in gMarkers) {
1575		// console.log(i);
1576		gMarkers[i].distance = google.maps.geometry.spherical.computeDistanceBetween(pt, gMar
1576kers[i].getPosition());
1577		closest.push(gMarkers[i]);
1578	}
1579	closest.sort(sortByDist);
1580	return closest.splice(0,numberOfResults);
1581}
1582
1583function initClickEvent(){
1584	const array = ["click_phoneto", "click_email", "click_website"]
1585	array.forEach(function (item, index) {
1586		$('.'+item).each(function( index ) {				
1587			$(this).get(0).addEventListener('click', null);
1588			$(this).on('click', function() {
1589				if(typeof $(this).attr('data-action') == 'undefined') {
1590					// Event already sent
1591				} else {
1592					partnerid = '';
1593					if( $(this).parents(".dealer-container").length != 0 ) { 
1594						partnerid = $(this).parents(".dealer-container").attr('partnerid'); 
1595					}
1596					$.ajax({
1597						type: "GET",
1598						url: "/"+pageSitename+"/ajax_handlers/dealerLocator.cfc",	
1599						data: {method:"logActivity", code: partnerid, activity: item, rd: Math.random()},
1600						dataType: "json",
1601						crossDomain:true,	
1602						context: $(this),
1603						success: function(msg){	
1604							$(this).removeAttr("data-action");
1605							console.log(item + ' logged')
1606						},
1607						error: function (XMLHttpRequest, textStatus, errorThrown) { console.log('err') }
1608					});
1609				}
1610			});						
1611		});		
1612	});
1613}
1614
1615function setCookie(name, value, expire) {   
1616	document.cookie = name + "=" + escape(value)   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + ";path=/";
1617}
1618
1619function getCookie(Name) {
1620	var search = Name + "=";
1621	if (document.cookie.length > 0)
1622	{ // if there are any cookies
1623		offset = document.cookie.indexOf(search);
1624		if (offset != -1)
1625		{ // if cookie exists
1626			offset += search.length;
1627			// set index of beginning of value
1628			end = document.cookie.indexOf(";", offset);
1629			// set index of end of cookie value
1630			if (end == -1)
1631			{
1632				end = document.cookie.length;
1633			}
1634		return unescape(document.cookie.substring(offset, end));
1635	}
1636	}
1637}
1638
1639function reCaptchaDataCallback() {
1640	$("#dealer_contact .form-group.captcha").removeClass("is-invalid");
1641}
1642

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.