//lienObtenirMunicipalites doit être défini avant de charger ce script
var lienControleMunicipalites = lienObtenirMunicipalites;
var langueModuleRecherche;


$(document).ready(function () {
	langueModuleRecherche = $('#HiddenFieldLanguage').val();

	/* Set the default search button */
	chBtnFond('PROVPROVQC');

	/* ****************************************************************************** */
	/* ANIMATION CARTE ************************************************************** */
	/* ****************************************************************************** */

	// Preload des images
	; (function ($) { var h = $.preload = function (c, d) { if (c.split) c = $(c); d = $.extend({}, h.defaults, d); var f = $.map(c, function (a) { if (!a) return; if (a.split) return d.base + a + d.ext; var b = a.src || a.href; if (typeof d.placeholder == 'string' && a.src) a.src = d.placeholder; if (b && d.find) b = b.replace(d.find, d.replace); return b || null }), data = { loaded: 0, failed: 0, next: 0, done: 0, total: f.length }; if (!data.total) return finish(); var g = $(Array(d.threshold + 1).join('<img/>')).load(handler).error(handler).bind('abort', handler).each(fetch); function handler(e) { data.element = this; data.found = e.type == 'load'; data.image = this.src; data.index = this.index; var a = data.original = c[this.index]; data[data.found ? 'loaded' : 'failed']++; data.done++; if (d.enforceCache) h.cache.push($('<img/>').attr('src', data.image)[0]); if (d.placeholder && a.src) a.src = data.found ? data.image : d.notFound || a.src; if (d.onComplete) d.onComplete(data); if (data.done < data.total) fetch(0, this); else { if (g && g.unbind) g.unbind('load').unbind('error').unbind('abort'); g = null; finish() } }; function fetch(i, a, b) { if (a.attachEvent && data.next && data.next % h.gap == 0 && !b) { setTimeout(function () { fetch(i, a, 1) }, 0); return !1 } if (data.next == data.total) return !1; a.index = data.next; a.src = f[data.next++]; if (d.onRequest) { data.index = a.index; data.element = a; data.image = a.src; data.original = c[data.next - 1]; d.onRequest(data) } }; function finish() { if (d.onFinish) d.onFinish(data) } }; h.gap = 14; h.cache = []; h.defaults = { threshold: 2, base: '', ext: '', replace: '' }; $.fn.preload = function (a) { h(this, a); return this } })(jQuery);

	var basePath = '/home/images/modRecherche/Theme1/';
	jQuery(function ($) {
		var urls = [basePath + '/carte/grande/GSGS4211.gif',
					 basePath + '/carte/grande/GSGS4212.gif',
					 basePath + '/carte/grande/GSGS4621.gif',
					 basePath + '/carte/grande/GSGS4622.gif',
					 basePath + '/carte/grande/GSGS4623.gif',
					 basePath + '/carte/grande/GSGS4624.gif',
					 basePath + '/carte/grande/GSGS4625.gif',
					 basePath + '/carte/grande/RARA01.gif',
					 basePath + '/carte/grande/RARA02.gif',
					 basePath + '/carte/grande/RARA03.gif',
					 basePath + '/carte/grande/RARA04.gif',
					 basePath + '/carte/grande/RARA05.gif',
					 basePath + '/carte/grande/RARA07.gif',
					 basePath + '/carte/grande/RARA08.gif',
					 basePath + '/carte/grande/RARA09.gif',
					 basePath + '/carte/grande/RARA10.gif',
					 basePath + '/carte/grande/RARA11.gif',
					 basePath + '/carte/grande/RARA12.gif',
					 basePath + '/carte/grande/RARA14.gif',
					 basePath + '/carte/grande/RARA15.gif',
					 basePath + '/carte/grande/RARA16.gif',
					 basePath + '/carte/grande/RARA17.gif',
					 basePath + '/carte/grande/REGIONMTL.gif',
					 basePath + '/carte/grande/REGIONQC.gif',

					 basePath + '/boutons/' + langueModuleRecherche + '/GSGS4211.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/GSGS4212.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/GSGS4621.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/GSGS4622.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/GSGS4623.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/GSGS4624.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/GSGS4625.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA01.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA02.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA03.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA04.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA05.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA07.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA08.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA09.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA10.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA11.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA12.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA14.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA15.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA16.jpg',
					 basePath + '/boutons/' + langueModuleRecherche + '/RARA17.jpg',

					 basePath + '/carte/GSGS4211.gif',
					 basePath + '/carte/GSGS4212.gif',
					 basePath + '/carte/GSGS4621.gif',
					 basePath + '/carte/GSGS4622.gif',
					 basePath + '/carte/GSGS4623.gif',
					 basePath + '/carte/GSGS4624.gif',
					 basePath + '/carte/GSGS4625.gif',
					 basePath + '/carte/RARA01.gif',
					 basePath + '/carte/RARA02.gif',
					 basePath + '/carte/RARA03.gif',
					 basePath + '/carte/RARA04.gif',
					 basePath + '/carte/RARA05.gif',
					 basePath + '/carte/RARA07.gif',
					 basePath + '/carte/RARA08.gif',
					 basePath + '/carte/RARA09.gif',
					 basePath + '/carte/RARA10.gif',
					 basePath + '/carte/RARA11.gif',
					 basePath + '/carte/RARA12.gif',
					 basePath + '/carte/RARA14.gif',
					 basePath + '/carte/RARA15.gif',
					 basePath + '/carte/RARA16.gif',
					 basePath + '/carte/RARA17.gif'
					];
		$.preload(urls, {
			base: '',
			ext: '',
			onFinish: function () {
				$('#preloader').animate({ opacity: 0 }, function () {
					$('#preloader').css({ display: 'none' });
				});
			}
		});
	});

	// Détection de IE6 pour gérer bug input select par dessus div des municipalités
	if ($.browser.msie && $.browser.version == "6.0") { var browserIE6 = true; } else { var browserIE6 = false; }

	var zoomCarte = 0;
	var zoomProvince = '';

	// Assigne texte des labels FR/EN
	if (langueModuleRecherche == 'fr') { labelRetourProvince = 'Province<br />de Qu&eacute;bec'; }
	else { labelRetourProvince = 'Province<br />of Qu&eacute;bec'; }
	if (langueModuleRecherche == 'fr') { labelProvinceQuebec = 'Province de Qu&eacute;bec'; }
	else { labelProvinceQuebec = 'Province of Qu&eacute;bec'; }
	if (langueModuleRecherche == 'fr') { labelNbMuniSelect = 'municipalit&eacute;s s&eacute;lectionn&eacute;es'; }
	else { labelNbMuniSelect = 'selected municipalities'; }
	if (langueModuleRecherche == 'fr') { labelTouteMuniSelect = 'MUNICIPALIT&Eacute;S - TOUTES'; }
	else { labelTouteMuniSelect = 'MUNICIPALITIES - ALL'; }
	if (langueModuleRecherche == 'fr') { labelSelectSecteur = 'Choisissez un secteur'; }
	else { labelSelectSecteur = 'Choose a area'; }
	if (langueModuleRecherche == 'fr') { labelRetour = 'Retour'; }
	else { labelRetour = 'Back'; }
	if (langueModuleRecherche == 'fr') { labelChargement = 'Chargement...'; }
	else { labelChargement = 'Loading...'; }
	if (langueModuleRecherche == 'fr') { labelDepuis = 'Depuis...'; }
	else { labelDepuis = 'Since...'; }

	/* Tableau contenant le nom des régions FR/EN */
	labelProvince = new Array();
	if (langueModuleRecherche == 'fr') {
		labelProvince["PROVPROVQC"] = "Province de Québec";
		labelProvince["RARA08"] = "Abitibi-Témiscamingue";
		labelProvince["RARA01"] = "Bas-Saint-Laurent";
		labelProvince["RARA03"] = "Capitale-Nationale";
		labelProvince["RARA17"] = "Centre-du-Québec";
		labelProvince["RARA12"] = "Chaudière-Appalaches";
		labelProvince["RARA09"] = "Côte-Nord";
		labelProvince["RARA05"] = "Estrie";
		labelProvince["RARA11"] = "Gaspésie/Îles-de-la-Madeleine";
		labelProvince["GSGS4621"] = "Île de<br />Montréal";
		labelProvince["RARA14"] = "Lanaudière";
		labelProvince["RARA15"] = "Laurentides";
		labelProvince["GSGS4622"] = "Laval";
		labelProvince["RARA04"] = "Mauricie";
		labelProvince["RARA16"] = "Montérégie";
		labelProvince["RARA10"] = "Nord-du-<br />Québec";
		labelProvince["RARA07"] = "Outaouais";
		labelProvince["GSGS4623"] = "Rive-Nord de Montréal";
		labelProvince["GSGS4211"] = "Rive-Nord de Québec";
		labelProvince["GSGS4624"] = "Rive-Sud de Montréal";
		labelProvince["GSGS4212"] = "Rive-Sud de Québec";
		labelProvince["RARA02"] = "Saguenay/<br />Lac-Saint-Jean";
		labelProvince["GSGS4625"] = "Vaudreuil-Soulanges";
	}
	else {
		labelProvince["PROVPROVQC"] = "Province of Quebec";
		labelProvince["RARA08"] = "Abitibi-Témiscamingue";
		labelProvince["RARA01"] = "Bas-Saint-Laurent";
		labelProvince["RARA03"] = "Capitale-Nationale";
		labelProvince["RARA17"] = "Centre-du-Québec";
		labelProvince["RARA12"] = "Chaudière-Appalaches";
		labelProvince["RARA09"] = "Côte-Nord";
		labelProvince["RARA05"] = "Estrie";
		labelProvince["RARA11"] = "Gaspésie/Îles-de-la-Madeleine";
		labelProvince["GSGS4621"] = "Île de Montréal";
		labelProvince["RARA14"] = "Lanaudière";
		labelProvince["RARA15"] = "Laurentides";
		labelProvince["GSGS4622"] = "Laval";
		labelProvince["RARA04"] = "Mauricie";
		labelProvince["RARA16"] = "Montérégie";
		labelProvince["RARA10"] = "Nord-<br />du-<br />Québec";
		labelProvince["RARA07"] = "Outaouais";
		labelProvince["GSGS4623"] = "North Shore of Montréal";
		labelProvince["GSGS4211"] = "North Shore of Québec";
		labelProvince["GSGS4624"] = "South Shore of Montréal";
		labelProvince["GSGS4212"] = "South Shore of Québec";
		labelProvince["RARA02"] = "Saguenay/<br />Lac-Saint-Jean";
		labelProvince["GSGS4625"] = "Vaudreuil-Soulanges";
	}

	labelPrefixProvince = new Array();
	if (langueModuleRecherche == 'fr') {
		labelPrefixProvince["PROVPROVQC"] = "la";
		labelPrefixProvince["RARA08"] = "l'";
		labelPrefixProvince["RARA01"] = "le";
		labelPrefixProvince["RARA03"] = "la";
		labelPrefixProvince["RARA17"] = "le";

		labelPrefixProvince["RARA09"] = "la";
		labelPrefixProvince["RARA05"] = "l'";
		labelPrefixProvince["RARA11"] = "la";

		labelPrefixProvince["RARA15"] = "les";

		labelPrefixProvince["RARA04"] = "la";
		labelPrefixProvince["RARA16"] = "la";
		labelPrefixProvince["RARA10"] = "le";
		labelPrefixProvince["RARA07"] = "l'";
		labelPrefixProvince["GSGS4623"] = "la";
		labelPrefixProvince["GSGS4211"] = "la";
		labelPrefixProvince["GSGS4624"] = "la";
		labelPrefixProvince["GSGS4212"] = "la";
		labelPrefixProvince["RARA02"] = "le";
	}

	$('#retourCarteProvince').html(labelRetourProvince);
	$('#provinceListeTexteDetail').html(labelProvince["PROVPROVQC"]);

	cliqueCarte = 0;
	/* Survol zoneMap */
	$('#imagemap area, #imagemapMontreal area, #imagemapQuebec area').mouseover(function () {
		$('#provinceListeTexte').html($(this).attr('rel'));
		$('#provinceListeTexteDetail').html('');

		var idProvinceSelect = $(this).attr('id').split('_');
		$('#imageMin_' + idProvinceSelect[1]).stop().fadeTo(200, 1);
	}).mouseout(function () {
		$('.imageMin').stop().fadeTo(200, 0);

		if (cliqueCarte != 1) {
			$('#provinceListeTexte').html(labelProvince["PROVPROVQC"]);
		}
		else {
			$('#provinceListeTexte').html("");
		}
	});

	var tm1;

	/* Click zoneMap  */
	$('#imagemap area, #imagemapMontreal area, #imagemapQuebec area').click(function () {
		clearTimeout(tm1);
		cliqueCarte = 1;
		$('#listeRegionsDIV').html($(this).attr('rel'));
		idProvinceSelect = $(this).attr('id').split('_');
		idProvince = idProvinceSelect[1];

		animateCarte(idProvince);

		regionLabelActive = 0; $('#listeRegions').css({ display: 'none' });
		municipalitesLabelActive = 0; $('#div_select').css({ display: 'none' });
		categorieLabelActive = 0; $('#listeCategories').css({ display: 'none' });

		//fix pour faire disparaitre la zone de sélection de l'imagemap lorsqu'on clique (dans ie)
		$('html').focus();
	});


	var autoAnimateON = 1;
	/* Hover sur Ile Montreal & Ile de Quebec */
	$('area#areaCarte_REGIONMTL, area#areaCarte_REGIONQC').mouseover(function () {
		if (autoAnimateON) {
			var idProvinceSelect = $(this).attr('id').split('_');
			var idProvince = idProvinceSelect[1];
			tm1 = setTimeout(function () { cliqueCarte = 1; animateCarte(idProvince) }, 2000);
		}
	}).mouseout(function () {
		if (autoAnimateON) {
			clearTimeout(tm1);
		}
	});


	/* Click lien retour province  */
	$('a#retourCarteProvince').click(function () {
		cliqueCarte = 0;
		$('#listeRegionsDIV').html(labelProvinceQuebec);
		reinitCarteProvince();
		idProvince = 0;
		chBtnFond('PROVPROVQC');
		changeRegion('PROVPROVQC');
		autoAnimateON = 1;
	});


	/* Click lien retour region */
	$('a#retourCarteRegion').click(function () {
		$('#masqueInactif').css({ left: 0 });
		//$('#retourCarteProvince').css({opacity: 1});
		$('.imageFull').animate({ opacity: 0 });

		if (zoomProvince == 'MTL') {
			$('#imageFull_REGIONMTL').animate({ opacity: 1, width: 248, height: 142 }, function () {
				$('#masqueInactif').css({ left: -1000 });
			});
			$('#framePrincipal').attr('usemap', '#mapRegionMontreal');
		}
		else if (zoomProvince == 'QC') {
			$('#imageFull_REGIONQC').animate({ opacity: 1, width: 248, height: 142 }, function () {
				$('#masqueInactif').css({ left: -1000 });
			});
			$('#framePrincipal').attr('usemap', '#mapRegionQuebec');
		}

		$('.imageMin').animate({ opacity: 0 });
		$('#retourCarteRegion').animate({ opacity: 0 });
		$('#retourCarteRegion').css({ right: -1000 });
		$('#choixSecteurTexte').html('Choisissez un secteur');
		$('#provinceListeTexteDetail').html('');
		$('#retourCarteProvince').animate({ opacity: 1 }, 1000);

		zoomCarte = 2;
	});


	// Initialise le datePicker
	$("#ContentHolder_controlSearch_dateDepuis").datepicker({
		altFormat: "dd/mm/yy",
		dateFormat: "dd/mm/yy",
		showOtherMonths: true,
		showOn: "both",
		buttonImage: "/home/images/modRecherche/Theme1/cal.gif",
		buttonImageOnly: true,
		buttonText: labelDepuis
	});


	function changeRegion(idProvince, appelerFonctionExterne) {
		if (typeof appelerFonctionExterne == 'undefined') { appelerFonctionExterne = true; }
		/* Ajax page externe pour sauvegarde cookie et charger liste municipalités */
		$('#municipalitesLabel').html(labelChargement);

		$.ajax({
			type: "GET",
			url: lienControleMunicipalites,
			data: "region=" + idProvince,
			success: function (data) {
				$('#listeMunicipalite').html(data);
				nbMunicipaliteCheck();
			}
		});

		//appel d'une fonction externe (si elle existe) lors d'un changement de région
		if (typeof changementRegionZoneRecherche == 'function' && appelerFonctionExterne == true) {
			changementRegionZoneRecherche(idProvince);
		}
	}


	function chBtnFond(provinceID) {
		$('#ContentHolder_controlSearch_lancerRecherche').css('background-image', 'url(/home/images/modRecherche/Theme1/boutons/' + langueModuleRecherche + '/' + provinceID + '.jpg)');
	}

	function animateCarte(idProvince, appelerFonctionExterne) {
		if (typeof appelerFonctionExterne == 'undefined') { appelerFonctionExterne = true; }

		/* Set a 0 l'opacité de toutes les images pour utilisation 
		par liste déroulantes des municipalités */
		$('.imageFull').css({ opacity: 0 });

		/* Div par dessus pour empecher interactivité avec la carte pendant animation */
		$('#masqueInactif').css({ left: 0 });

		$('#carteProvince').animate({ opacity: 0, width: 496, height: 284 });

		// Si ID n'est pas REGIONMTL ou REGIONQC zoom nv1 | sinon zoom nv2
		if (idProvince == 'REGIONMTL' || idProvince == 'REGIONQC' || zoomCarte == 2) {
			if (zoomCarte != 2) {
				if (idProvince == 'REGIONMTL') {
					$('#framePrincipal').attr('usemap', '#mapRegionMontreal');
					$('#provinceListeTexte').html('');
					zoomProvince = 'MTL';
					$('#retourCarteProvince').animate({ opacity: 1 }, 1000);
				}
				else if (idProvince == 'REGIONQC') {
					$('#framePrincipal').attr('usemap', '#mapRegionQuebec');
					$('#provinceListeTexte').html('');
					zoomProvince = 'QC';
					$('#retourCarteProvince').animate({ opacity: 1 }, 1000);
				}
				$('#choixSecteurTexte').html(labelSelectSecteur);
				$('#retourCarteRegion').css({ right: -1000 });
				zoomCarte = 2;
			}
			else {
				if (zoomProvince == 'MTL') {
					$('#retourCarteProvince').css({ opacity: 0 });
					$('#framePrincipal').attr('usemap', '');
					$('#imageFull_REGIONMTL').animate({ opacity: 0, width: 496, height: 284 });
				}
				else if (zoomProvince == 'QC') {
					$('#retourCarteProvince').css({ opacity: 0 });
					$('#framePrincipal').attr('usemap', '');
					$('#imageFull_REGIONQC').animate({ opacity: 0, width: 496, height: 284 });
				}
				$('#retourCarteRegion').html(labelRetour);
				$('#retourCarteRegion').animate({ opacity: 1 });
				$('#retourCarteRegion').css({ right: 5 });
				$('#choixSecteurTexte').html('');
				chBtnFond(idProvince);

				//on désactive l'animation automatique lors du hover sur région de mtl ou qc
				autoAnimateON = 0;
			}
		}
		else {
			$('#retourCarteProvince').animate({ opacity: 1 }, 1000);
			$('#framePrincipal').attr('usemap', '');
			zoomCarte = 1;
			chBtnFond(idProvince);
		}

		$('#provinceListeTexteDetail').html(labelProvince[idProvince]);
		$('#provinceListeTexte').html('');
		$('.imageMin').css({ opacity: 0, display: 'none' });
		$('#imageFull_' + idProvince).fadeTo(200, 1, function () {
			$('#masqueInactif').css({ left: -1000 });
		});

		changeRegion(idProvince, appelerFonctionExterne);
	}

	function reinitCarteProvince() {
		zoomCarte = 1;
		zoomProvince = '';
		var idProvince = 0;
		$('#masqueInactif').css({ left: 0 });

		$('#retourCarteProvince').css({ opacity: 0 });
		$('#carteProvince').animate({ opacity: 1, width: 248, height: 142 }, function () {
			$('#masqueInactif').css({ left: -1000 });
		});
		$('#imageFull_REGIONMTL, #imageFull_REGIONQC').css({ opacity: 0, width: 248, height: 142 });
		$('#retourCarteRegion').css({ right: 1000 });
		$('#framePrincipal').attr('usemap', '#map');

		$('.imageFull').animate({ opacity: 0 });
		$('#provinceListeTexte').html('');
		$('#choixSecteurTexte').html('');
		$('#provinceListeTexteDetail').html(labelProvince["PROVPROVQC"]);
	}

	/* ****************************************************************************** */
	/* FORMULAIRE ******************************************************************* */
	/* ****************************************************************************** */

	/* Préselectionne région dans la liste déroulante */
	$('#imagemap area, #imagemapMontreal area, #imagemapQuebec area').click(function () {
		var idProvinceSelect = $(this).attr('id').split('_');
		$('#listeRegions option').each(function (index) {
			if ($(this).val() == idProvinceSelect[1]) {
				$(this).attr('selected', 'selected');
			}
		});
	});


	/* onChange liste des municipalités */
	$('#listeRegions').change(function () {
		chBtnFond($(this).val());
		if ($(this).val() == 'PROVPROVQC') {
			zoomCarte = 0;
			reinitCarteProvince();
			idProvince = 0;
			$("#listeRegions option:selected").each(function () {
				$('#listeRegionsDIV').html($(this).text());
			});
		}
		else {
			animateCarte($(this).val());
			chBtnFond($(this).val());
			idProvince = $(this).val();

			$("#listeRegions option:selected").each(function () {
				$('#listeRegionsDIV').html($(this).text());
			});

		}
		regionLabelActive = 0;
		$(this).css({ display: 'none' });
	});

	/* onChange liste des catégories */
	$('#listeCategories').change(function () {
		$("#listeCategories option:selected").each(function () {
			$('#listeCategorieDIV').html($(this).text());
		});
		categorieLabelActive = 0;
		$(this).css({ display: 'none' });
	});

	/* Ouvre la boite des régions */
	var regionLabelActive = 0;
	$('#listeRegionsDIV').click(function (event) {
		event.stopPropagation();
		if (!regionLabelActive) {
			$('#listeRegions').css({ display: 'block' });
			regionLabelActive = 1;
			$('html').bind('click', function () {
				$('#listeRegions').css({ display: 'none' });
				regionLabelActive = 0;
				$('html').unbind('click');
			});
		}
		else {
			$('#listeRegions').css({ display: 'none' });
			regionLabelActive = 0;
		}
		municipalitesLabelActive = 0; $('#div_select').css({ display: 'none' });
		categorieLabelActive = 0; $('#listeCategories').css({ display: 'none' });
	});

	/* workaround pour IE */
	var municipalitesLabelActive = 0;
	$('#municipalitesLabel').click(function (event) {
		event.stopPropagation();
		//if ($(this).attr('id') == 'municipalitesLabel'){		
		if (!municipalitesLabelActive) {
			$('#div_select').css({ display: 'block' });
			if (browserIE6) { $('#listeCategories').css({ visibility: 'hidden' }); }
			municipalitesLabelActive = 1;
			$('html').bind('click', function () {
				$('#div_select').css({ display: 'none' });
				municipalitesLabelActive = 0;
				nbMunicipaliteCheck();
				$('html').unbind('click');
			});
		}
		else {
			$('#div_select').css({ display: 'none' });
			if (browserIE6) { $('#listeCategories').css({ visibility: 'visible' }); }
			municipalitesLabelActive = 0;
		}
		regionLabelActive = 0; $('#listeRegions').css({ display: 'none' });
		categorieLabelActive = 0; $('#listeCategories').css({ display: 'none' });

		//}
	});

	$('#listeMunicipalite').click(function (event) {
		event.stopPropagation();
	});

	/* Ouvre boite des catégories */
	var categorieLabelActive = 0;
	$('#listeCategorieDIV').click(function (event) {
		event.stopPropagation();
		if (!categorieLabelActive) {
			$('#listeCategories').css({ display: 'block' });
			categorieLabelActive = 1;
			$('html').bind('click', function () {
				$('#listeCategories').css({ display: 'none' });
				categorieLabelActive = 0;
				$('html').unbind('click');
			});
		}
		else {
			$('#listeCategories').css({ display: 'none' });
			categorieLabelActive = 0;
		}
		regionLabelActive = 0; $('#listeRegions').css({ display: 'none' });
		municipalitesLabelActive = 0; $('#div_select').css({ display: 'none' });
		event.stopPropagation();
	});


	$('a#deselectionnerTout').click(function () {
		$('#div_select input').each(function (index) {
			$(this).attr('checked', '');
		});
	});

	//		$('#formulaireCentris').submit(function () {
	$('input#ContentHolder_controlSearch_lancerRecherche').click(function () {
		if ($('#ContentHolder_controlSearch_prixDeForm').val() == 'PRIX DE' || $('#prixDe-form').val() == 'PRICE FROM') {
			$('#ContentHolder_controlSearch_prixDeForm').attr('value', '');
		}

		var splitPrixA = $('#ContentHolder_controlSearch_prixAForm').val().split(' ');
		if (splitPrixA[0] == 'PRIX' || splitPrixA[0] == 'PRICE') {
			$('#ContentHolder_controlSearch_prixAForm').attr('value', '');
		}

		if ($('#ContentHolder_controlSearch_dateDepuis').val() == 'DEPUIS' || $('#ContentHolder_controlSearch_dateDepuis').val() == 'SINCE') {
			$('#ContentHolder_controlSearch_dateDepuis').attr('value', '');
		}

		$('#ContentHolder_controlSearch_HiddenFieldCategory').attr('value', $('#listeCategories').val());

		var sel = "";
		$('#listeMunicipalite input').each(function (index) {
			var ch = $(this).attr('checked');
			if (ch == true) {
				var id = $(this).attr('id');
				sel = sel + id + ",";
			}
		});
		$('#ContentHolder_controlSearch_HiddenFieldMunicipalites').attr('value', sel);
	});

	function nbMunicipaliteCheck() {
		var municipaliteCheckBox = 0;
		$('#div_select input').each(function (index) {
			if ($(this).is(':checked')) { municipaliteCheckBox++; }
		});

		if (municipaliteCheckBox) {
			$('#municipalitesLabel').html(municipaliteCheckBox + ' ' + labelNbMuniSelect);
		}
		else {
			$('#municipalitesLabel').html(labelTouteMuniSelect);
		}
	}

	//initialisation du module de recherche en fonction de la région sélectionnée
	var regionSelectionnee = $('#ContentHolder_controlSearch_hiddenFieldRegion').val();
	//var regionSelectionnee = $('#listeRegions').val();
	if (regionSelectionnee == 'PROVPROVQC' || regionSelectionnee == undefined) {
		reinitCarteProvince();
		changeRegion('PROVPROVQC');
	}
	else {
		animateCarte(regionSelectionnee, false);
		if (labelPrefixProvince[regionSelectionnee] == null) { labelPrefixProvince[regionSelectionnee] = ""; }
		var surOn = ''; if (langueModuleRecherche == 'fr') { surOn = 'sur'; } else { surOn = 'on'; }
		$('#menu_gauche_region').text(surOn + " " + labelPrefixProvince[regionSelectionnee] + " " + labelProvince[regionSelectionnee].replace(/<.*?>/g, '')); ;
	}

	$("#listeRegions option:selected").each(function () {
		$('#listeRegionsDIV').html($(this).text());
	});

	//seulement chiffres permis dans prix de/à
	$("#ContentHolder_controlSearch_prixDeForm, #ContentHolder_controlSearch_prixAForm").keydown(function (event) {
		// Allow only backspace and delete
		if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9) {  //. Backspace Tab
			// let it happen, don't do anything
		}
		else {
			// Ensure that it is a number and stop the keypress
			if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {

				event.preventDefault();
			}
		}
		maskNumber(this, ' ');

	}).keyup(function () {
		maskNumber(this, ' ');
	});

	function maskNumber(control, separator) {
		var value = control.value;
		var valueFormat = value.replace(/ /g, '');
		if (valueFormat.toString().length > 3) {
			valueFormat = addSpacesNumber(valueFormat, separator);
			var valueShow = valueFormat;
			control.value = valueShow;
		}
	}

	function addSpacesNumber(value, separator) {
		var parts = new Array();
		for (var i = 0; i < value.toString().length / 3; ++i) {
			parts[i] = value.toString().substring(value.toString().length - ((i + 1) * 3), value.toString().length - ((i + 1) * 3) + 3);
		}
		var valueWithSpaces = parts[0];
		for (var i = 1; i < value.toString().length / 3; ++i) {
			valueWithSpaces = parts[i] + separator + valueWithSpaces;
		}
		return valueWithSpaces;
	}

	/* ****************************************************************************** */
});

