/*
File : markershtml.js 
18/01/09

geolinko project
copyright : lpCom
*/

/* zoneC = zone de recherche de la consultation */
/* zoneD = zone de déplacement du service */
var html_printing;
var resultsPages;
var NB_PAGES_INDEX = 10;
var firstIndex = 1;
var lastIndex = 1;


function getIcon(file) {
if (isIE6()) return new GIcon(G_DEFAULT_ICON);
	else return new GIcon(G_DEFAULT_ICON, plainIcon(file));

var myIcon = new GIcon();
myIcon.image = plainIcon(file);
myIcon.shadow = ICON_DIR+'shadow.png';
myIcon.iconSize = new GSize(20,34);
myIcon.shadowSize = new GSize(37,34);
myIcon.iconAnchor = new GPoint(10,34);
myIcon.infoWindowAnchor = new GPoint(10,0);
//myIcon.printImage = ICON_DIR+'printImage.gif';
//myIcon.mozPrintImage = ICON_DIR+'mozPrintImage.gif';
//myIcon.printShadow = ICON_DIR+'printShadow.gif';
myIcon.transparent = ICON_DIR+'transparent.png';
myIcon.imageMap = [13,0,15,1,16,2,17,3,18,4,18,5,19,6,19,7,19,8,19,9,19,10,19,11,19,12,19,13,18,14,18,15,17,16,16,17,15,18,14,19,14,20,13,21,13,22,12,23,12,24,12,25,12,26,11,27,11,28,11,29,11,30,11,31,11,32,11,33,8,33,8,32,8,31,8,30,8,29,8,28,8,27,8,26,7,25,7,24,7,23,6,22,6,21,5,20,5,19,4,18,3,17,2,16,1,15,1,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,1,5,1,4,2,3,3,2,4,1,6,0];
return myIcon;
}

function specialChars3(str) {
	var string = str;
	string = string.replace(/\</g,'&lt;');
	string = string.replace(/\>/g,'&gt;');
	string = string.replace(/\n/g,'<br>');
	return string;
}

function heriter (destination, source) {
	for (var element in source) {
		destination[element] = source[element];
		}
}


function contactExchange(cuid, id) {
	var xhr=getHTTPObject();
	if (xhr) {	
		xhr.onreadystatechange = function() { contactExchange_rep(xhr, cuid, id); }; 
		xhr.open("GET", "dataexchange.php", true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send(null);
		}
}

function contactExchange_rep(xhr, cuid, id) {
	if (xhr.readyState==4) {
		if (xhr.status == 200) {		
			var xml = xhr.responseXML;
			var connected = XMLsuccess(xml);
			var id_exchange = XMLid_service(xml);			
			if (!connected) {
				jConfirm(ALERT_FORM_MESS18, '', function(r) {
					if (r) contact(cuid, id);
					});
				}
				else if (id_exchange){
					jConfirm(ALERT_FORM_MESS19, '', function(r) {
						if (r) contact(cuid, id, id_exchange);
						});
					}
					else contact(cuid, id);
			}
		}
}

function contact(cuid, id, id_exchange) {
	if (id_exchange)
		window.open(HTTP_SERVER+'/contact.php?cuid='+cuid+'&a_id='+id+'&id_exchange='+id_exchange, '', 'dependent=yes, directories=no, menubar=no, resizable=no, location=no, top=100,left=100, width=350, height=480, status=no, scrollbars=no');
		else window.open(HTTP_SERVER+'/contact.php?cuid='+cuid+'&a_id='+id, '', 'dependent=yes, directories=no, menubar=no, resizable=no, location=no, top=100,left=100, width=350, height=480, status=no, scrollbars=no');
}

function transmit(id) {
	window.open(HTTP_SERVER+'/transmit.php?a_id='+id, '', 'dependent=yes, directories=no, menubar=no, resizable=no, location=no, top=100,left=100, width=350, height=510, status=no, scrollbars=no');
}

function denounce(id) {
	window.open(HTTP_SERVER+'/denounce.php?a_id='+id, '', 'dependent=yes, directories=no, menubar=no, resizable=no, location=no, top=100,left=100, width=350, height=480, status=no, scrollbars=no');
}

function print_announce(typeService, id, width, height) {
	switch (mode) {
		case 1 : var mho = tabMHO[in_array(typeService, id, tabMHO)]; break;
		case 3 : var mho = selMHO[in_array(typeService, id, selMHO)]; break;
		case 4 : var mho = annMHO[in_array(typeService, id, annMHO)]; break;
		}
	var srcImage = null;
	if (width != null) srcImage = HTTP_SERVER+PICS_DIR+typeService+'-'+id+'-1.jpg';
	html_printing = getHtmlAnnounce(mho.title, mho.desco, mho.link, typeService, id, srcImage, width, height, mho.customer_id, mho.identifiant, 1);
	window.open(HTTP_SERVER+'/print.php', '', 'dependent=yes, resizable=yes, top=100,left=100, width=600, height=480, scrollbars=yes');
}

function print_selection() {
var html='<table>';
	for (var i=0; i<selMHO.length; i++)
		html += getHTML(selMHO[i].type, selMHO[i].id, selMHO[i].title, selMHO[i].desco, selMHO[i].photoListHTML, 1);
	html_printing = html + '</table>';
	window.open(HTTP_SERVER+'/print.php', '', 'dependent=yes, resizable=yes, top=100,left=100, width=600, height=480, scrollbars=yes');	
	}

function clickService(typeService, id) {
	var m;
	if (document.getElementById('resId').checked) m = getMarker(typeService, id, tabMHO);
		else if (document.getElementById('selId').checked) m = getMarker(typeService, id, selMHO);
			else m = getMarker(typeService, id, annMHO);	
	if (m) GEvent.trigger(m, "click");
}

function flashMarker(typeService, id) {
if (isIE6()) return;
	if (document.getElementById('resId').checked) t=tabMHO;
		else if (document.getElementById('selId').checked) t=selMHO;
			else t=annMHO;
	var ind = in_array(typeService, id, t);
	if (ind != -1) {
		if (!t[ind].infront) {
			for (var i=0; i<t.length; i++) {
				t[i].marker.setImage(plainIcon(t[i].ico_file));
				t[i].infront = false;
				}
			var flagWindow = t[ind].marker.InfoWindowIsOpened;
			map.removeOverlay(t[ind].marker);
			map.addOverlay(t[ind].marker);
			t[ind].infront = true;			
			if (flagWindow) clickService(typeService, id);
			}
		t[ind].marker.setImage(plainIconFlash(t[ind].ico_file));	
		}
}

function unflashMarker(typeService, id) {
if (isIE6()) return;
var t;
	if (document.getElementById('resId').checked) t=tabMHO;
		else if (document.getElementById('selId').checked) t=selMHO;
			else t=annMHO;
	var ind = in_array(typeService, id, t);
	if (ind != -1)	{
		t[ind].marker.setImage(plainIcon(t[ind].ico_file));
		}
}

function getMaxChars(str, max) {
	return str.substr(0, max);
}

function getHTML(typeService, id, title, desco, photoListHTML, printFlag) {
	var onTitle_3 = getOnTitle_3(typeService, id);
	var onTitle_4 = getOnTitle_4(typeService, id);	
	if (onTitle_3 != '')
		if (onTitle_4 != '') {
			onTitle_3 = '<span class="onTitle_3" style="width:70%">'+ onTitle_3+'</span>';
			onTitle_4 = '<span class="onTitle_4" style="width:30%">'+ onTitle_4+'</span>';
			}
		else onTitle_3 = '<span class="onTitle_3" style="width:100%">'+ onTitle_3+'</span>';
	else if (onTitle_4 != '')
			onTitle_4 = '<span class="onTitle_4" style="width:100%">'+ onTitle_4+'</span>';			
	var onTitles = onTitle_3 + onTitle_4;
	if (onTitles != '') onTitles += '<br>';
	if (printFlag)
		return '<tr><td><div class="print">'+TEXT_INFOWINDOW_REF+' '+typeService+'-'+id+' : <b><br>'+title+'</b><br>'+onTitles+photoListHTML+desco+'</div></td></tr>';
		else return '<tr><td><div class="CLASS_NAME" onmouseover="javascript:this.className=\'CLASS_NAME_hover\';flashMarker('+typeService+','+id+')" onmouseout="javascript:this.className=\'CLASS_NAME\';unflashMarker('+typeService+','+id+')" onclick="javascript:clickService('+typeService+','+id+')"><b>'+title+'</b><br>'+onTitles+photoListHTML+desco+'</div></td></tr>';
}


function getClassHTML(html) {
var class_name;
	if (mode == 4) {
		if (html == '')	html = '<tr><td>'+TEXT_NO_ANNOUNCER+'</td></tr>';
			else class_name = 'annonceur';
			}	
			else if (mode == 1) {
				if (html == '')	html = '<tr><td>'+TEXT_NO_ANNOUNCE+'</td></tr>';
					else class_name = 'results';
				}
				else {
					if (html == '')	html = '<tr><td>'+TEXT_NO_SELECTION+'</td></tr>';
						else class_name = 'selection';
					}
	var p1; var p2; var i=0;
	var classHtml = '';
	while ((p1 = html.search(/<tr>/)) != -1) {
		p2 = html.search(/<\/tr>/)
		classHtml += html.slice(p1, p2+5).replace(/CLASS_NAME/g, class_name+i);
		if (i==0) i=1; else i=0;
		html = html.slice(p2+5);
		}
	return classHtml;
}

function setResults(html) {
	resultsPages = sliceResults(getClassHTML(html));
	setResultsPageIndex(1);
}

function setResultsPageIndex(index) {
var str='';
	index = 1*index;
	if (index<=lastIndex)
		if (index>=firstIndex)
			if (resultsPages.length > NB_PAGES_INDEX)
				lastIndex = firstIndex + NB_PAGES_INDEX - 1;
				else lastIndex = firstIndex + resultsPages.length - 1;			
			else {
				firstIndex = index;
				if (resultsPages.length > NB_PAGES_INDEX)
					lastIndex = firstIndex + NB_PAGES_INDEX - 1;
					else lastIndex = firstIndex + resultsPages.length - 1;
				}
		else {
			lastIndex = index;
			firstIndex = index - NB_PAGES_INDEX + 1;
			}
	for (var i=firstIndex; (i<=lastIndex) && (i<=(firstIndex+NB_PAGES_INDEX-1)); i++)
		if (i==index) str += '<a class="pageIndexSelected" href="javascript:setResultsPageIndex('+i+')">'+i+'</a>'+' ';
			else str += '<a class="pageIndex" href="javascript:setResultsPageIndex('+i+')">'+i+'</a>'+' ';
	if (firstIndex > 1)
		str = '<a class="pageIndex" href="javascript:setResultsPageIndex(1)">1</a>... '+str;		
	if (index > 1)
		str = '<a class="pageIndex" href="javascript:setResultsPageIndex('+eval(index-1)+')"><<</a> '+str;
	if (lastIndex < resultsPages.length)
		str = str+' ...<a class="pageIndex" href="javascript:setResultsPageIndex('+resultsPages.length+')">'+resultsPages.length+'</a>';
	if (index < resultsPages.length)
		str = str +' <a class="pageIndex" href="javascript:setResultsPageIndex('+eval(index+1)+')">>></a>';			
	document.getElementById("pagesIndex").innerHTML = str;
	document.getElementById("results").innerHTML = resultsPages[index-1];
}

function sliceResults(html) {
var tab = new Array();
var i = 0;
var n = 0;
var p1;
var p2;
	tab[0] = '<table width="100%" cellspacing="0" cellpadding="0"><td>';
	while ((p1 = html.search(/<tr/)) != -1) {
		p2 = html.search(/<\/tr>/);
		tab[i] += html.slice(p1, p2+5);
		html = html.slice(p2+5);		
		n++;
		if (n == serviceNbAnnouncesPerPage(serviceShownConsultation)) {
			tab[i] += '</td></table>';
			n = 0;
			i++;
			tab[i] = '<table width="100%" cellspacing="0" cellpadding="0"><td>';
			}
		}
	if (n==0) tab.length = i;
		else tab[i] += '</td></table>';	
	return tab;
}

function showSmallInfo(typeService, id, title) {
	var m;
	if (document.getElementById('resId').checked) m = getMarker(typeService, id, tabMHO);
		else if (document.getElementById('selId').checked) m = getMarker(typeService, id, selMHO);
			else m = getMarker(typeService, id, annMHO);
	if (m && !m.InfoWindowIsOpened)
		m.openInfoWindowHtml("<table><tr><td><b>"+title+"</b></td></tr><tr><td class=\"onTitle_3\">"+getOnTitle_3(typeService, id)+"</tr><tr><tr><td class=\"infoText\"><br>"+TEXT_SMALL_INFO+"</td></tr></table>");
}

function hideSmallInfo(typeService, id) {
	var m;
	if (document.getElementById('resId').checked) m = getMarker(typeService, id, tabMHO);
		else if (document.getElementById('selId').checked) m = getMarker(typeService, id, selMHO);
			else m = getMarker(typeService, id, annMHO);
	if (m && !m.InfoWindowIsOpened)
		m.closeInfoWindow();
}

/******************************************************************************/
function MHObject(id, serviceId, xmlService, markerOptions) {
	this.id = id;
	this.type = serviceId;
	var _title = specialChars3(xmlService.getElementsByTagName('nah_title')[0].firstChild.nodeValue);
	this.title = _title;
	var _desco = specialChars3(xmlService.getElementsByTagName('nah_desco')[0].firstChild.nodeValue);
	this.desco = _desco;

	if (xmlService.getElementsByTagName('nah_link') && xmlService.getElementsByTagName('nah_link')[0])
		this.link = specialChars3(xmlService.getElementsByTagName('nah_link')[0].firstChild.nodeValue);
		else this.link = null;

	this.customer_id = xmlService.getElementsByTagName('nah_customer_id')[0].firstChild.nodeValue;
	if (xmlService.getElementsByTagName('nah_identifiant') && xmlService.getElementsByTagName('nah_identifiant')[0])	
		this.identifiant = xmlService.getElementsByTagName('nah_identifiant')[0].firstChild.nodeValue;
		else this.identifiant = null;
	
	this.marker = new GMarker(new GLatLng(xmlService.getElementsByTagName('nah_lat')[0].firstChild.nodeValue*1, xmlService.getElementsByTagName('nah_lng')[0].firstChild.nodeValue*1), markerOptions);
//	GEvent.addListener(this.marker, "mouseover", function() {flashMarker(serviceId, id);});
//	GEvent.addListener(this.marker, "mouseout", function() {unflashMarker(serviceId, id);});

	map.addOverlay(this.marker);
	this.marker.hide();
	this.infront = false;
	
	var _marker = this.marker;
	var _customer_id = this.customer_id;
	var _id = this.id;
	var _link = this.link;
	var _identifiant = this.identifiant;

	var nb_photos = 0;
	var arrayImages = new Array();
	var i = 1;
	while (xmlService.getElementsByTagName('nah_photos_w'+i)[0] && xmlService.getElementsByTagName('nah_photos_w'+i)[0].firstChild) {
		arrayImages[i] = new Array();
		arrayImages[i]['src'] = 'data/pics/'+serviceId+'-'+_id+'-'+i+'.jpg';
		arrayImages[i]['width'] = xmlService.getElementsByTagName('nah_photos_w'+i)[0].firstChild.nodeValue;
		arrayImages[i]['height'] = xmlService.getElementsByTagName('nah_photos_h'+i)[0].firstChild.nodeValue;
		i++;
		}
	nb_photos = i-1;
	
	var photoListHTML = ''; // photo vignette dans la liste des résultats
	var formatImgList;

	if (nb_photos >= 1) {
		var src = arrayImages[1]['src'];//1ère image
		var width = arrayImages[1]['width'];
		var height = arrayImages[1]['height'];
		if (width>height) {
			if (width>THUMB_LIST_WIDTH) formatImgList='width="'+THUMB_LIST_WIDTH+'"'; else formatImgList='width="'+width+'"';	
			}
			else {
				if (height>THUMB_LIST_HEIGHT) formatImgList='height="'+THUMB_LIST_HEIGHT+'"'; else formatImgList='height="'+height+'"';
				}
		photoListHTML = '<img src="'+src+'" border="0" '+formatImgList+' align="left">';
		}
	
	this.photoListHTML = photoListHTML;
//	this.html = getHTML(this.type, this.id, this.title, this.desco, this.photoListHTML);

	this.marker.InfoWindowIsOpened = false;	
	GEvent.addListener(_marker, "click",
		function() {
			_marker.InfoWindowIsOpened = true;
			visualizeInfoWindow(_marker, _title, _desco, _link, serviceId, _id, arrayImages, _customer_id, _identifiant);

			var from = markerLocalisation.getLatLng();
			var to = _marker.getLatLng();
			directions.loadFromWaypoints([from, to], {getPolyline : true});//GEvent.addListener(directions, "load"... défini dans nah_ajax.js
			}
		);
	GEvent.addListener(_marker, "infowindowclose", function() {setInfoWindowIsOpened(_marker, false);});
	GEvent.addListener(_marker, "mouseover", function() {showSmallInfo(serviceId, id, _title);});
	GEvent.addListener(_marker, "mouseout", function() {hideSmallInfo(serviceId, id);});			
}

MHObject.prototype = { inZoneSearching : function(zoneC) {
	return inZone(this.marker.getLatLng(), zoneC) ;
	}
}

function setInfoWindowIsOpened(_marker, value) {
	_marker.InfoWindowIsOpened = value;
}
/******************************************************************************/
function MHObject_service_common1(service, xmlService, itemOffre, p) {
	p.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;	
	p.ico_file = serviceIconByValue(service, p.offre);		
	if (p.offre == serviceItemValue(service, itemOffre)) {
		p.zoneD = xmlToPolyzone(xmlService, 'show_mode');
		if (show_gps_mode == '0') ; else map.addOverlay(p.zoneD);
		}
}

function MHObject_service_common2(service, xmlService, item, p) {
	p.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;	
	p.services_p2 = xmlService.getElementsByTagName('nah_services_p2')[0].firstChild.nodeValue;
	if (servicesMultiples(p.services_p2))
		p.ico_file = serviceIcon(service, '_ITEM_MULTIPLES');
		else p.ico_file = serviceIconByValue(service, log2(p.services_p2));		
	if (p.offre == serviceItemValue(service, item)) {
		p.zoneD = xmlToPolyzone(xmlService, 'show_mode');
		if (show_gps_mode == '0') ; else map.addOverlay(p.zoneD);
		}	
}

function MHObject_service_common3(service, xmlService, itemOffre, itemCherche, itemProf, itemEleve, itemProfEleve, niveau, matiere, p) {
	p.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;
	if (matiere) p.matiere = xmlService.getElementsByTagName('nah_matiere')[0].firstChild.nodeValue;			
	p.localisation_p2 = xmlService.getElementsByTagName('nah_localisation_p2')[0].firstChild.nodeValue;
	if (niveau == 1) p.niveau_p2 = xmlService.getElementsByTagName('nah_niveau_p2')[0].firstChild.nodeValue;			
	if (p.localisation_p2 & serviceItemValue_P2(service, itemProf))
		if (p.localisation_p2 & serviceItemValue_P2(service, itemEleve))
			p.ico_file = serviceIcon(service, itemProfEleve);
			else p.ico_file = serviceIcon(service, itemProf);
		else p.ico_file = serviceIcon(service, itemEleve);
	if (((p.offre == serviceItemValue(service, itemOffre))
			&& (p.localisation_p2 & serviceItemValue_P2(service, itemEleve)))
				||
		((p.offre == serviceItemValue(service, itemCherche))
			&& (p.localisation_p2 & serviceItemValue_P2(service, itemProf)))) {
		p.zoneD = xmlToPolyzone(xmlService, 'show_mode');
		if (show_gps_mode == '0') ; else map.addOverlay(p.zoneD);
		}	
}

function MHObject_service_common4(service, xmlService, itemCherche, meuble, p) {
	p.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;
	p.offreur = xmlService.getElementsByTagName('nah_offreur')[0].firstChild.nodeValue;	
	p.type_bien = xmlService.getElementsByTagName('nah_type_bien')[0].firstChild.nodeValue;	
	if (meuble) p.meuble = xmlService.getElementsByTagName('nah_meuble')[0].firstChild.nodeValue;				
	p.capacite = xmlService.getElementsByTagName('nah_capacite')[0].firstChild.nodeValue;
	p.nb_chambres = xmlService.getElementsByTagName('nah_nb_chambres')[0].firstChild.nodeValue;	
	p.equipement_p2 = xmlService.getElementsByTagName('nah_equipement_p2')[0].firstChild.nodeValue;			
	if (xmlService.getElementsByTagName('nah_prix') && xmlService.getElementsByTagName('nah_prix')[0])
		p.prix = xmlService.getElementsByTagName('nah_prix')[0].firstChild.nodeValue;
		else p.prix = null;
	p.monnaie = xmlService.getElementsByTagName('nah_monnaie')[0].firstChild.nodeValue;					
	p.ico_file = serviceIconByValue(service, p.type_bien);		
	if (p.offre == serviceItemValue(service, itemCherche)) {
		p.zoneD = xmlToPolyzone(xmlService, 'show_mode');
		if (show_gps_mode == '0') ; else map.addOverlay(p.zoneD);
		}	
}

function MHObject_service_common5(service, xmlService, itemCherche, type_bien, p) {
	p.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;			
	p.offreur = xmlService.getElementsByTagName('nah_offreur')[0].firstChild.nodeValue;
	p.location = xmlService.getElementsByTagName('nah_location')[0].firstChild.nodeValue;
	if (type_bien) {
		p.type_bien = xmlService.getElementsByTagName('nah_type_bien')[0].firstChild.nodeValue;
		p.ico_file = serviceIconByValue(service, p.type_bien);
		}
		else p.ico_file = serviceIconByValue(service, p.location);
	if (xmlService.getElementsByTagName('nah_prix') && xmlService.getElementsByTagName('nah_prix')[0])
		p.prix = xmlService.getElementsByTagName('nah_prix')[0].firstChild.nodeValue;
		else p.prix = null;
	p.monnaie = xmlService.getElementsByTagName('nah_monnaie')[0].firstChild.nodeValue;						
	if (p.offre == serviceItemValue(service, itemCherche)) {
		p.zoneD = xmlToPolyzone(xmlService, 'show_mode');
		if (show_gps_mode == '0') ; else map.addOverlay(p.zoneD);
		}
}

function MHObject_service(id, xmlService, flagAnnonceur) {
	var serviceId = xmlService.getElementsByTagName('nah_service_type')[0].firstChild.nodeValue;
	var service = serviceNameFromId(serviceId);
	switch (service) {
		case 'service_echangeReg' :
			this.type_bien = xmlService.getElementsByTagName('nah_type_bien')[0].firstChild.nodeValue;					
			this.capacite = xmlService.getElementsByTagName('nah_capacite')[0].firstChild.nodeValue;
			this.nb_chambres = xmlService.getElementsByTagName('nah_nb_chambres')[0].firstChild.nodeValue;	
			this.equipement_p2 = xmlService.getElementsByTagName('nah_equipement_p2')[0].firstChild.nodeValue;
			this.region_p2 = xmlService.getElementsByTagName('nah_region_p2')[0].firstChild.nodeValue;			
			this.ico_file = serviceIconByValue(service, this.type_bien);							
			break;		
		case 'service_colocationReg' :
			this.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;			
			this.ico_file = serviceIconByValue(service, this.offre);
			if (xmlService.getElementsByTagName('nah_prix') && xmlService.getElementsByTagName('nah_prix')[0])
				this.prix = xmlService.getElementsByTagName('nah_prix')[0].firstChild.nodeValue;
				else this.prix = null;
			this.monnaie = xmlService.getElementsByTagName('nah_monnaie')[0].firstChild.nodeValue;						
			if (this.offre == serviceItemValue(service, '_407_ITEM_CHERCHE')) {
				this.zoneD = xmlToPolyzone(xmlService, 'show_mode');
				if (show_gps_mode == '0') ; else map.addOverlay(this.zoneD);
				}		
			break;
		case 'service_parkingReg' :
			MHObject_service_common5(service, xmlService, '_404_ITEM_CHERCHE', 1, this)				
			break;		
		case 'service_terrainReg' :
			MHObject_service_common5(service, xmlService, '_403_ITEM_CHERCHE', 0, this)				
			break;
		case 'service_vacanceReg' :
			MHObject_service_common4(service, xmlService, '_405_ITEM_CHERCHE', 0, this);				
			break;			
		case 'service_venteReg' :
			MHObject_service_common4(service, xmlService, '_402_ITEM_CHERCHE', 0, this);				
			break;
		case 'service_locationReg' :
			MHObject_service_common4(service, xmlService, '_401_ITEM_CHERCHE', 1, this);				
			break;		
		case 'service_affairesReg' :
			this.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;			
			this.secteur = xmlService.getElementsByTagName('nah_secteur')[0].firstChild.nodeValue;
			if (xmlService.getElementsByTagName('nah_prix') && xmlService.getElementsByTagName('nah_prix')[0])
				this.prix = xmlService.getElementsByTagName('nah_prix')[0].firstChild.nodeValue;
				else this.prix = null;
			this.monnaie = xmlService.getElementsByTagName('nah_monnaie')[0].firstChild.nodeValue;					
			this.ico_file = serviceIconByValue(service, this.secteur);		
			if (this.offre == serviceItemValue(service, '_501_ITEM_CHERCHE')) {
				this.zoneD = xmlToPolyzone(xmlService, 'show_mode');
				if (show_gps_mode == '0') ; else map.addOverlay(this.zoneD);
				}				
			break;	
		case 'service_autres_coursReg' :
			MHObject_service_common3(service, xmlService, '_307_ITEM_OFFRE', '_307_ITEM_CHERCHE', '_307_ITEM_LOCALISATION_PROF', '_307_ITEM_LOCALISATION_ELEVE', '_307_ITEM_LOCALISATION_ELEVE_PROF', 0, 0, this);	//pas de niveau, pas de matiere
			break;		
		case 'service_informatiqueReg' :
			MHObject_service_common3(service, xmlService, '_306_ITEM_OFFRE', '_306_ITEM_CHERCHE', '_306_ITEM_LOCALISATION_PROF', '_306_ITEM_LOCALISATION_ELEVE', '_306_ITEM_LOCALISATION_ELEVE_PROF', 0, 0, this);	//pas de niveau, pas de matiere
			break;	
		case 'service_artsReg' :
			MHObject_service_common3(service, xmlService, '_305_ITEM_OFFRE', '_305_ITEM_CHERCHE', '_305_ITEM_LOCALISATION_PROF', '_305_ITEM_LOCALISATION_ELEVE', '_305_ITEM_LOCALISATION_ELEVE_PROF', 0, 1, this);	//pas de niveau
			break;		
		case 'service_theatreReg' :
			MHObject_service_common3(service, xmlService, '_304_ITEM_OFFRE', '_304_ITEM_CHERCHE', '_304_ITEM_LOCALISATION_PROF', '_304_ITEM_LOCALISATION_ELEVE', '_304_ITEM_LOCALISATION_ELEVE_PROF', 0, 1, this);	//pas de niveau		
			break;	
		case 'service_musiqueReg' :
			MHObject_service_common3(service, xmlService, '_303_ITEM_OFFRE', '_303_ITEM_CHERCHE', '_303_ITEM_LOCALISATION_PROF', '_303_ITEM_LOCALISATION_ELEVE', '_303_ITEM_LOCALISATION_ELEVE_PROF', 0, 1, this);	//pas de niveau		
			break;		
		case 'service_languesReg' :
			MHObject_service_common3(service, xmlService, '_302_ITEM_OFFRE', '_302_ITEM_CHERCHE', '_302_ITEM_LOCALISATION_PROF', '_302_ITEM_LOCALISATION_ELEVE', '_302_ITEM_LOCALISATION_ELEVE_PROF', 1, 1, this);			
			break;		
		case 'service_soutienReg' :
			MHObject_service_common3(service, xmlService, '_301_ITEM_OFFRE', '_301_ITEM_CHERCHE', '_301_ITEM_LOCALISATION_PROF', '_301_ITEM_LOCALISATION_ELEVE', '_301_ITEM_LOCALISATION_ELEVE_PROF', 1, 1, this);			
			break;		
		case 'service_animauxReg' :
			MHObject_service_common2(service, xmlService, '_206_ITEM_OFFRE', this);		
			break;		
		case 'service_bricolageReg' :
			MHObject_service_common2(service, xmlService, '_205_ITEM_OFFRE', this);		
			break;		
		case 'service_aideReg' :
			MHObject_service_common2(service, xmlService, '_203_ITEM_OFFRE', this);		
			break;		
		case 'service_menageReg' :
			MHObject_service_common2(service, xmlService, '_202_ITEM_OFFRE', this);		
			break;	
		case 'service_jardinageReg' :
			MHObject_service_common1(service, xmlService, '_204_ITEM_OFFRE', this);		
			break;
		case 'service_autres_servicesReg' :
			MHObject_service_common1(service, xmlService, '_207_ITEM_OFFRE', this);						
			break;
		case 'service_refugesReg' :
			MHObject_service_common1(service, xmlService, '_209_ITEM_CHERCHE', this);						
			break;					
		case 'service_nourricesReg' :
			MHObject_service_common1(service, xmlService, '_208_ITEM_CHERCHE', this);						
			break;	
		case 'service_neufReg' :
			MHObject_service_common1(service, xmlService, '_406_ITEM_CHERCHE', this);						
			break;			
		case 'service_baby_sittingReg' :
			this.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;
			this.home_exterior_p2 = xmlService.getElementsByTagName('nah_home_exterior_p2')[0].firstChild.nodeValue;
			if (this.home_exterior_p2 & serviceItemValue_P2(service, '_201_ITEM_HOME'))
				if (this.home_exterior_p2 & serviceItemValue_P2(service, '_201_ITEM_EXTERIOR'))
					this.ico_file = serviceIcon(service, '_201_ITEM_HOME_EXTERIOR');
					else this.ico_file = serviceIcon(service, '_201_ITEM_HOME');
				else this.ico_file = serviceIcon(service, '_201_ITEM_EXTERIOR');
			if (((this.offre == serviceItemValue(service, '_201_ITEM_OFFRE'))
					&& (this.home_exterior_p2 & serviceItemValue_P2(service, '_201_ITEM_HOME')))
						||
				((this.offre == serviceItemValue(service, '_201_ITEM_CHERCHE'))
					&& (this.home_exterior_p2 & serviceItemValue_P2(service, '_201_ITEM_EXTERIOR')))) {
				this.zoneD = xmlToPolyzone(xmlService, 'show_mode');
				if (show_gps_mode == '0') ; else map.addOverlay(this.zoneD);
				}				
			break;		
		case 'service_commercesReg' :		
			this.secteur = xmlService.getElementsByTagName('nah_secteur')[0].firstChild.nodeValue;
			this.ico_file = serviceIconDefault(service);
			break;	
		case 'service_assosReg' :
		case 'service_rencontresReg' :		
			this.secteur = xmlService.getElementsByTagName('nah_secteur')[0].firstChild.nodeValue;
			this.ico_file = serviceIconByValue(service, this.secteur);		
			break;	
		case 'service_artisansReg' :				
			this.secteur = xmlService.getElementsByTagName('nah_secteur')[0].firstChild.nodeValue;		
			this.ico_file = serviceIconDefault(service);		
			this.zoneD = xmlToPolyzone(xmlService, 'show_mode');
			if (show_gps_mode == '0') ; else map.addOverlay(this.zoneD);			
			break;
		case 'service_benevolatReg' :
			this.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;	
			this.ico_file = serviceIconByValue(service, this.offre);		
			if (this.offre == serviceItemValue(service, '_106_ITEM_OFFRE')) {
				this.zoneD = xmlToPolyzone(xmlService, 'show_mode');
				if (show_gps_mode == '0') ; else map.addOverlay(this.zoneD);
				}				
			break;				
		case 'service_emploiReg' :
			this.offre = xmlService.getElementsByTagName('nah_offre')[0].firstChild.nodeValue;
			this.type_emploi = xmlService.getElementsByTagName('nah_type_emploi')[0].firstChild.nodeValue;				
			this.secteur = xmlService.getElementsByTagName('nah_secteur')[0].firstChild.nodeValue;		
			this.ico_file = serviceIconByValue(service, this.type_emploi);		
			if (this.offre == serviceItemValue(service, '_104_ITEM_CHERCHE')) {
				this.zoneD = xmlToPolyzone(xmlService, 'show_mode');
				if (show_gps_mode == '0') ; else map.addOverlay(this.zoneD);
				}				
			break;	
		case 'service_evenementsReg' :
			this.secteur = xmlService.getElementsByTagName('nah_secteur')[0].firstChild.nodeValue;
			this.debut = xmlService.getElementsByTagName('nah_debut')[0].firstChild.nodeValue;
			this.fin = xmlService.getElementsByTagName('nah_fin')[0].firstChild.nodeValue;
			this.ico_file = serviceIconByValue(service, this.secteur);
			break;
		case 'service_perduReg' :
			this.perdu = xmlService.getElementsByTagName('nah_perdu')[0].firstChild.nodeValue;
			this.ico_file = serviceIconByValue(service, this.perdu);					
			break;
		case 'service_appelsReg' :
		case 'service_faire_partReg' :
		case 'service_barsReg' :
		case 'service_autres_vie_localeReg' :
			this.ico_file = serviceIconDefault(service);				
			break;
		}
	if (flagAnnonceur)	
		this.ico_file = serviceIconCatService(service);
//	var markerOptions = { icon: new GIcon(G_DEFAULT_ICON, plainIcon(this.ico_file))};
	var markerOptions = { icon: getIcon(this.ico_file)};
	MHObject.call(this, id, serviceId, xmlService, markerOptions);	
}

MHObject_service.prototype = { inZoneDeplacement : function (point) {
	return inZone(point, this.zoneD);
	}
};

heriter(MHObject_service.prototype, MHObject.prototype);

/******************************************************************************/
function getMarker(typeService, id, t) {
	if (t)
		for (var i=0; i<t.length; i++)
			if ((t[i].id == id) && (t[i].type == typeService)) return t[i].marker;
	return null;
}

function in_array(typeService, id, t) {
	if (t)
		for (var i=0; i<t.length; i++)
			if ((t[i].id == id) && (t[i].type == typeService)) return i;
	return -1;
}

function addTo_array(xmlService, t) {
	var id = xmlService.getElementsByTagName('nah_id')[0].firstChild.nodeValue;
	var typeService = xmlService.getElementsByTagName('nah_service_type')[0].firstChild.nodeValue;	
	if (in_array(typeService, id, t) == -1) {
		if (t == annMHO)
			t.push(new MHObject_service(id, xmlService, true));	
			else t.push(new MHObject_service(id, xmlService, false));
		t[t.length-1].html = getHTML(t[t.length-1].type, t[t.length-1].id, t[t.length-1].title, t[t.length-1].desco, t[t.length-1].photoListHTML);
		}		
}

/******************************************************************************/
var annMHO;

function hide_annMHO() {
	if (annMHO)
		for (var i=0; i<annMHO.length; i++) {
			annMHO[i].marker.hide();
			annMHO[i].marker.closeInfoWindow();
			}
	document.getElementById("suiviId").disabled = true;			
}


function addXmlTo_annMHO(xml) {
annMHO = new Array();
if (xml && xml.getElementsByTagName('nah_service')) {
	for (var i=0 ; i<xml.getElementsByTagName('nah_service').length ; i++)	{
		addTo_array(xml.getElementsByTagName('nah_service')[i], annMHO);
		}
	}
}

function display_annMHO() {
var html='';
	if (annMHO)
		for (var i=0; i<annMHO.length; i++)
			if (document.getElementById(serviceCategorie(serviceNameFromId(annMHO[i].type))).checked == true)
				html += showMHO_getHTML(annMHO[i]);
				else hideMHO(annMHO[i]);
	if (annMHO && annMHO.length>0) document.getElementById("suiviId").disabled = false;	
		else document.getElementById("suiviId").disabled = true;
	setResults(html);
}
/******************************************************************************/
var selMHO = new Array();

function hide_selMHO() {
	for (var i=0; i<selMHO.length; i++) {
		selMHO[i].marker.hide();
		selMHO[i].marker.closeInfoWindow();
		}
}

function addSelection(typeService, id) {
	var j = in_array(typeService, id, tabMHO);
	selMHO.push(tabMHO[j]);
	var m = getMarker(typeService, id, selMHO);
	if (m) GEvent.trigger(m, "click");	
}

function removeSelection(typeService, id) {
	var j = in_array(typeService, id, selMHO);
	if (j>=0) {
		var m = getMarker(typeService, id, selMHO);		
		selMHO[j].marker.closeInfoWindow();		
		if (mode==3) selMHO[j].marker.hide();		
		selMHO.splice(j, 1);
		if (mode==3) display_selMHO();
		if (m && mode!=3) GEvent.trigger(m, "click");			
		}
}

function display_selMHO() {
var html='';
	for (var i=0; i<selMHO.length; i++)
		html += showMHO_getHTML(selMHO[i]);
	setResults(html);
}

/******************************************************************************/
var tabMHO = new Array();

function showZoneDSelectedId(typeService, id) {
	var i = in_array(typeService, id, tabMHO);
	if (i != -1)
		if (tabMHO[i].zoneD) {
			map.addOverlay(tabMHO[i].zoneD);
			return true;
			}
	return false;
}

function hideZoneDSelectedId() {
	tabMHO[0].marker.hide();
	tabMHO[0].marker.closeInfoWindow();
	if (tabMHO[0].zoneD) map.removeOverlay(tabMHO[0].zoneD);
	tabMHO = new Array();
	mode = 1;
}

function hide_tabMHO() {
	for (var i=0; i<tabMHO.length; i++) {
		tabMHO[i].marker.hide();
		tabMHO[i].marker.closeInfoWindow();
		}
}

function addXmlTo_tabMHO(xml) {
if (mode == 0) hideZoneDSelectedId();
if (xml && xml.getElementsByTagName('nah_service')) {
	for (var i=0 ; i<xml.getElementsByTagName('nah_service').length ; i++)	{	
		addTo_array(xml.getElementsByTagName('nah_service')[i], tabMHO);
		}
	}
}

function cond1_display_tabMHO(service, mho, point, zoneSearching, selectedId, key_words, item1, item2) {
	return ((				
				((document.getElementById(item1).checked && (mho.offre == serviceItemValue(service, item1))
					&& mho.inZoneSearching(zoneSearching))
				||	(document.getElementById(item2).checked && (mho.offre == serviceItemValue(service, item2))
					&& mho.inZoneDeplacement(point))
				)
			&& checkboxMatched(service, serviceItemsIds(service), mho.services_p2)
			&& matchKeyWords(key_words, mho))
			|| (selectedId && (mho.id==selectedId)));
}

function cond2_display_tabMHO(service, mho, point, zoneSearching, selectedId, key_words, item1, item2) {
	return ((				
				((document.getElementById(item1).checked && (mho.offre == serviceItemValue(service, item1))
					&& mho.inZoneSearching(zoneSearching))
				||	(document.getElementById(item2).checked && (mho.offre == serviceItemValue(service, item2))
					&& mho.inZoneDeplacement(point))
				)
			&& matchKeyWords(key_words, mho))
			|| (selectedId && (mho.id==selectedId)));
}

function cond3_display_tabMHO(service, mho, point, zoneSearching, selectedId, key_words, itemOffre, itemCherche, itemProf, itemEleve, itemNiveau1, itemNiveau2, itemNiveau3, itemVal) {
	return ((((
				(document.getElementById(itemOffre).checked && (mho.offre == serviceItemValue(service, itemOffre)))
				&& (
						((mho.localisation_p2 & serviceItemValue_P2(service, itemEleve)) && document.getElementById(itemEleve).checked
							&& mho.inZoneDeplacement(point))
					|| 	((mho.localisation_p2 & serviceItemValue_P2(service, itemProf)) && document.getElementById(itemProf).checked
							&& mho.inZoneSearching(zoneSearching))
					)
			)
			||
			(
				(document.getElementById(itemCherche).checked && (mho.offre == serviceItemValue(service, itemCherche)))
				&& (
						((mho.localisation_p2 & serviceItemValue_P2(service, itemEleve)) && document.getElementById(itemEleve).checked
							&& mho.inZoneSearching(zoneSearching))
					|| 	((mho.localisation_p2 & serviceItemValue_P2(service, itemProf)) && document.getElementById(itemProf).checked
							&& mho.inZoneDeplacement(point))
					)
			))
			&& (
				(document.getElementById(itemNiveau1).checked && (mho.niveau_p2 & serviceItemValue_P2(service, itemNiveau1)))
				||
				(document.getElementById(itemNiveau2).checked && (mho.niveau_p2 & serviceItemValue_P2(service, itemNiveau2)))
				||
				(document.getElementById(itemNiveau3).checked && (mho.niveau_p2 & serviceItemValue_P2(service, itemNiveau3)))
				)
			&& (mho.matiere == document.getElementById(itemVal).value)
			&& matchKeyWords(key_words, mho))
			|| (selectedId && (mho.id==selectedId)));
}

function cond4_display_tabMHO(service, mho, point, zoneSearching, selectedId, key_words, itemOffre, itemCherche, itemProf, itemEleve, itemVal) {
	return ((((
				(document.getElementById(itemOffre).checked && (mho.offre == serviceItemValue(service, itemOffre)))
				&& (
						((mho.localisation_p2 & serviceItemValue_P2(service, itemEleve)) && document.getElementById(itemEleve).checked
							&& mho.inZoneDeplacement(point))
					|| 	((mho.localisation_p2 & serviceItemValue_P2(service, itemProf)) && document.getElementById(itemProf).checked
							&& mho.inZoneSearching(zoneSearching))
					)
			)
			||
			(
				(document.getElementById(itemCherche).checked && (mho.offre == serviceItemValue(service, itemCherche)))
				&& (
						((mho.localisation_p2 & serviceItemValue_P2(service, itemEleve)) && document.getElementById(itemEleve).checked
							&& mho.inZoneSearching(zoneSearching))
					|| 	((mho.localisation_p2 & serviceItemValue_P2(service, itemProf)) && document.getElementById(itemProf).checked
							&& mho.inZoneDeplacement(point))
					)
			))
			&& (mho.matiere == document.getElementById(itemVal).value)
			&& matchKeyWords(key_words, mho))
			|| (selectedId && (mho.id==selectedId)));
}

function cond5_display_tabMHO(service, mho, point, zoneSearching, selectedId, key_words, itemOffre, itemCherche, itemProf, itemEleve) {
	return ((((
				(document.getElementById(itemOffre).checked && (mho.offre == serviceItemValue(service, itemOffre)))
				&& (
						((mho.localisation_p2 & serviceItemValue_P2(service, itemEleve)) && document.getElementById(itemEleve).checked
							&& mho.inZoneDeplacement(point))
					|| 	((mho.localisation_p2 & serviceItemValue_P2(service, itemProf)) && document.getElementById(itemProf).checked
							&& mho.inZoneSearching(zoneSearching))
					)
			)
			||
			(
				(document.getElementById(itemCherche).checked && (mho.offre == serviceItemValue(service, itemCherche)))
				&& (
						((mho.localisation_p2 & serviceItemValue_P2(service, itemEleve)) && document.getElementById(itemEleve).checked
							&& mho.inZoneSearching(zoneSearching))
					|| 	((mho.localisation_p2 & serviceItemValue_P2(service, itemProf)) && document.getElementById(itemProf).checked
							&& mho.inZoneDeplacement(point))
					)
			))
			&& matchKeyWords(key_words, mho))
			|| (selectedId && (mho.id==selectedId)));
}

function cond6_display_tabMHO(service, mho, point, zoneSearching, selectedId, key_words, itemOffre, itemCherche, itemPrix, itemCurrencie, itemPieces, itemChambres, itemMeuble, Ids) {
	var offre = serviceItemByValue(service, mho.offre);
	var type_bien = serviceItemByValue(service, mho.type_bien);
	var offreur = serviceItemByValue(service, mho.offreur);
	var cond = ((document.getElementById(offre).checked
					&& 	document.getElementById(type_bien).checked
					&&  document.getElementById(offreur).checked					
					&& 	(mho.capacite >= document.getElementById(itemPieces).value) //on affiche les offres/recherches >= nombre demandé
					&& 	(mho.nb_chambres >= document.getElementById(itemChambres).value) //on affiche les offres/recherches >= nombre demandé
					&&  ((!isOneChecked(Ids)) || checkboxMatched(serviceShownConsultation, Ids, mho.equipement_p2))						
					&&  (document.getElementById(itemCurrencie).value == mho.monnaie)
					&&  inferieurPrixMax(mho.prix, document.getElementById(itemPrix).value, document.getElementById(itemCurrencie).value)
					&& 	(
							(document.getElementById(itemOffre).checked && mho.inZoneSearching(zoneSearching))
						||	(document.getElementById(itemCherche).checked && mho.inZoneDeplacement(point))
						))
					&& matchKeyWords(key_words, mho));
	if (itemMeuble) cond = (cond && (mho.meuble == (document.getElementById(itemMeuble).checked ? 1 : 0)));
	return (cond || (selectedId && (mho.id==selectedId)));
}

function cond7_display_tabMHO(service, mho, point, zoneSearching, selectedId, key_words, itemOffre, itemCherche, itemPrix, itemCurrencie, itemType) {
	var offre = serviceItemByValue(service, mho.offre);
	var offreur = serviceItemByValue(service, mho.offreur);
	var location = serviceItemByValue(service, mho.location);	
	var cond = ((document.getElementById(offre).checked
					&& 	document.getElementById(offreur).checked
					&&  document.getElementById(location).checked											
					&&  (document.getElementById(itemCurrencie).value == mho.monnaie)
					&&  inferieurPrixMax(mho.prix, document.getElementById(itemPrix).value, document.getElementById(itemCurrencie).value)
					&& 	(
							(document.getElementById(itemOffre).checked && mho.inZoneSearching(zoneSearching))
						||	(document.getElementById(itemCherche).checked && mho.inZoneDeplacement(point))
						))
					&& matchKeyWords(key_words, mho));
	if (itemType) {
		var type_bien = serviceItemByValue(service, mho.type_bien);
		cond = (cond && document.getElementById(type_bien).checked);
		}
	return (cond || (selectedId && (mho.id==selectedId)));
}

function inferieurPrixMax(prix, prixMax, monnaie) {
	if (!prix) return true;
	var pm = validPrice(prixMax, monnaie);
	if (pm && (prix*1 > pm*1))
		return false;
	return true;
}


function display_tabMHO(point, zoneSearching, selectedId) {
var html='';
var key_words=null;
var condition;
	if (mode == 0) hideZoneDSelectedId();
	document.getElementById('resId').checked = true;
	mode = 1;
	if (polyZoneInterventionVisibility == 1) {
		enablePolyzone(polyZoneIntervention);
		}
	if (document.getElementById('key_words')) {
		key_words = cleanKeyWords(document.getElementById('key_words').value);
		}		
	for (var i=0; i<tabMHO.length; i++) {
		switch (serviceShownConsultation) {
			case 'service_echange' :
				var Ids = new Array('_408_ITEM_EQUIPEMENT1', '_408_ITEM_EQUIPEMENT2','_408_ITEM_EQUIPEMENT3', '_408_ITEM_EQUIPEMENT4', '_408_ITEM_EQUIPEMENT5', '_408_ITEM_EQUIPEMENT6', '_408_ITEM_EQUIPEMENT7', '_408_ITEM_EQUIPEMENT8');			
				var type_bien = serviceItemByValue(serviceShownConsultation, tabMHO[i].type_bien);			
				condition = (((document.getElementById(type_bien).checked
					&& 	(tabMHO[i].capacite >= document.getElementById('_408_ITEM_CAPACITE').value) //on affiche les offres/recherches >= nombre demandé
					&& 	(tabMHO[i].nb_chambres >= document.getElementById('_408_ITEM_CHAMBRES').value) //on affiche les offres/recherches >= nombre demandé
					&&  ((!isOneChecked(Ids)) || checkboxMatched(serviceShownConsultation, Ids, tabMHO[i].equipement_p2))
					&&	((tabMHO[i].region_p2==0) || (tabMHO[i].region_p2 & Math.pow(2, document.getElementById('_408_ITEM_REGION').value)))
						)
					&& matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));
					break;		
			case 'service_colocation' :
				var offre = serviceItemByValue(serviceShownConsultation, tabMHO[i].offre);		
				condition = (((document.getElementById(offre).checked
					&&  (document.getElementById('_407_ITEM_CURRENCIE').value == tabMHO[i].monnaie)
					&&  inferieurPrixMax(tabMHO[i].prix, document.getElementById('_407_ITEM_PRIX').value, document.getElementById('_407_ITEM_CURRENCIE').value)
					&& 	(
							(document.getElementById('_407_ITEM_OFFRE').checked && tabMHO[i].inZoneSearching(zoneSearching))
						||	(document.getElementById('_407_ITEM_CHERCHE').checked && tabMHO[i].inZoneDeplacement(point))
						))
					&& matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));						
				break;			
			case 'service_neuf' :
				condition = cond2_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_406_ITEM_OFFRE', '_406_ITEM_CHERCHE');
				break;			
			case 'service_parking' :
				condition = cond7_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_404_ITEM_OFFRE', '_404_ITEM_CHERCHE', '_404_ITEM_PRIX', '_404_ITEM_CURRENCIE', 1);
				break;		
			case 'service_terrain' :
				condition = cond7_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_403_ITEM_OFFRE', '_403_ITEM_CHERCHE', '_403_ITEM_PRIX', '_403_ITEM_CURRENCIE', 0);
				break;	
			case 'service_vacance' :
				var Ids = new Array('_405_ITEM_EQUIPEMENT1', '_405_ITEM_EQUIPEMENT2','_405_ITEM_EQUIPEMENT3', '_405_ITEM_EQUIPEMENT4', '_405_ITEM_EQUIPEMENT5', '_405_ITEM_EQUIPEMENT6', '_405_ITEM_EQUIPEMENT7', '_405_ITEM_EQUIPEMENT8');
				condition = cond6_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_405_ITEM_OFFRE', '_405_ITEM_CHERCHE', '_405_ITEM_PRIX', '_405_ITEM_CURRENCIE', '_405_ITEM_CAPACITE', '_405_ITEM_CHAMBRES', null, Ids);
				break;					
			case 'service_vente' :
				var Ids = new Array('_402_ITEM_EQUIPEMENT1', '_402_ITEM_EQUIPEMENT2','_402_ITEM_EQUIPEMENT3', '_402_ITEM_EQUIPEMENT4');			
				condition = cond6_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_402_ITEM_OFFRE', '_402_ITEM_CHERCHE', '_402_ITEM_PRIX', '_402_ITEM_CURRENCIE', '_402_ITEM_PIECES', '_402_ITEM_CHAMBRES', null, Ids);
				break;		
			case 'service_location' :
				var Ids = new Array('_401_ITEM_EQUIPEMENT1', '_401_ITEM_EQUIPEMENT2','_401_ITEM_EQUIPEMENT3', '_401_ITEM_EQUIPEMENT4');			
				condition = cond6_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_401_ITEM_OFFRE', '_401_ITEM_CHERCHE', '_401_ITEM_PRIX', '_401_ITEM_CURRENCIE', '_401_ITEM_PIECES', '_401_ITEM_CHAMBRES', '_401_ITEM_MEUBLE', Ids);
				break;
			case 'service_affaires' :
				var offre = serviceItemByValue(serviceShownConsultation, tabMHO[i].offre);
				var secteur = serviceItemByValue(serviceShownConsultation, tabMHO[i].secteur);		
				condition = (((document.getElementById(offre).checked
					&& 	document.getElementById(secteur).checked
					&&  (document.getElementById('_501_ITEM_CURRENCIE').value == tabMHO[i].monnaie)
					&&  inferieurPrixMax(tabMHO[i].prix, document.getElementById('_501_ITEM_PRIX').value, document.getElementById('_501_ITEM_CURRENCIE').value)
					&& 	(
							(document.getElementById('_501_ITEM_OFFRE').checked && tabMHO[i].inZoneSearching(zoneSearching))
						||	(document.getElementById('_501_ITEM_CHERCHE').checked && tabMHO[i].inZoneDeplacement(point))
						))
					&& matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));						
				break;			
			case 'service_autres_cours' :
				condition = cond5_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_307_ITEM_OFFRE', '_307_ITEM_CHERCHE', '_307_ITEM_LOCALISATION_PROF', '_307_ITEM_LOCALISATION_ELEVE');
				break;			
			case 'service_informatique' :
				condition = cond5_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_306_ITEM_OFFRE', '_306_ITEM_CHERCHE', '_306_ITEM_LOCALISATION_PROF', '_306_ITEM_LOCALISATION_ELEVE');
				break;		
			case 'service_arts' :
				condition = cond4_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_305_ITEM_OFFRE', '_305_ITEM_CHERCHE', '_305_ITEM_LOCALISATION_PROF', '_305_ITEM_LOCALISATION_ELEVE', '_305_ITEM_ARTS');
				break;		
			case 'service_theatre' :
				condition = cond4_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_304_ITEM_OFFRE', '_304_ITEM_CHERCHE', '_304_ITEM_LOCALISATION_PROF', '_304_ITEM_LOCALISATION_ELEVE', '_304_ITEM_THEATRE');
				break;		
			case 'service_musique' :
				condition = cond4_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_303_ITEM_OFFRE', '_303_ITEM_CHERCHE', '_303_ITEM_LOCALISATION_PROF', '_303_ITEM_LOCALISATION_ELEVE', '_303_ITEM_INSTRUMENT');
				break;		
			case 'service_langues' :
				condition = cond3_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_302_ITEM_OFFRE', '_302_ITEM_CHERCHE', '_302_ITEM_LOCALISATION_PROF', '_302_ITEM_LOCALISATION_ELEVE', '_302_ITEM_NIVEAU1', '_302_ITEM_NIVEAU2', '_302_ITEM_NIVEAU3', '_302_ITEM_LANGUE');
				break;
			case 'service_soutien' :
				condition = cond3_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_301_ITEM_OFFRE', '_301_ITEM_CHERCHE', '_301_ITEM_LOCALISATION_PROF', '_301_ITEM_LOCALISATION_ELEVE', '_301_ITEM_NIVEAU1', '_301_ITEM_NIVEAU2', '_301_ITEM_NIVEAU3', '_301_ITEM_MATIERE');				
				break;			
			case 'service_animaux' :
				condition = cond1_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_206_ITEM_CHERCHE', '_206_ITEM_OFFRE');
				break;		
			case 'service_bricolage' :
				condition = cond1_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_205_ITEM_CHERCHE', '_205_ITEM_OFFRE');
				break;		
			case 'service_aide' :
				condition = cond1_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_203_ITEM_CHERCHE', '_203_ITEM_OFFRE');
				break;		
			case 'service_menage' :
				condition = cond1_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_202_ITEM_CHERCHE', '_202_ITEM_OFFRE');
				break;		
			case 'service_jardinage' :
				condition = cond2_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_204_ITEM_CHERCHE', '_204_ITEM_OFFRE');
				break;	
			case 'service_autres_services' :
				condition = cond2_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_207_ITEM_CHERCHE', '_207_ITEM_OFFRE');
				break;
			case 'service_refuges' :
				condition = cond2_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_209_ITEM_OFFRE', '_209_ITEM_CHERCHE');
				break;				
			case 'service_nourrices' :
				condition = cond2_display_tabMHO(serviceShownConsultation, tabMHO[i], point, zoneSearching, selectedId, key_words, '_208_ITEM_OFFRE', '_208_ITEM_CHERCHE');
				break;				
			case 'service_baby_sitting' :
				condition = ((((
						(document.getElementById('_201_ITEM_OFFRE').checked && (tabMHO[i].offre == serviceItemValue(serviceShownConsultation, '_201_ITEM_OFFRE')))
						&& (
								((tabMHO[i].home_exterior_p2 & serviceItemValue_P2(serviceShownConsultation, '_201_ITEM_HOME')) && document.getElementById('_201_ITEM_HOME').checked
									&& tabMHO[i].inZoneDeplacement(point))
							|| 	((tabMHO[i].home_exterior_p2 & serviceItemValue_P2(serviceShownConsultation, '_201_ITEM_EXTERIOR')) && document.getElementById('_201_ITEM_EXTERIOR').checked
									&& tabMHO[i].inZoneSearching(zoneSearching))
							)
					)
					||
					(
						(document.getElementById('_201_ITEM_CHERCHE').checked && (tabMHO[i].offre == serviceItemValue(serviceShownConsultation, '_201_ITEM_CHERCHE')))
						&& (
								((tabMHO[i].home_exterior_p2 & serviceItemValue_P2(serviceShownConsultation, '_201_ITEM_HOME')) && document.getElementById('_201_ITEM_HOME').checked
									&& tabMHO[i].inZoneSearching(zoneSearching))
							|| 	((tabMHO[i].home_exterior_p2 & serviceItemValue_P2(serviceShownConsultation, '_201_ITEM_EXTERIOR')) && document.getElementById('_201_ITEM_EXTERIOR').checked
									&& tabMHO[i].inZoneDeplacement(point))
							)
					))
					&& matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));						
				break;			
			case 'service_benevolat' :
				condition = ((				
						((document.getElementById('_106_ITEM_CHERCHE').checked && (tabMHO[i].offre == serviceItemValue(serviceShownConsultation, '_106_ITEM_CHERCHE'))
							&& tabMHO[i].inZoneSearching(zoneSearching))
						||	(document.getElementById('_106_ITEM_OFFRE').checked && (tabMHO[i].offre == serviceItemValue(serviceShownConsultation, '_106_ITEM_OFFRE'))
							&& tabMHO[i].inZoneDeplacement(point))
						)
					&& matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));						
				break;		
			case 'service_artisans' :
				condition = (((
						 	document.getElementById('_107_ITEM_TOUS_SECTEURS').checked					
						||	(document.getElementById('_107_ITEM_SECTEUR').value == tabMHO[i].secteur)
						)
					&& tabMHO[i].inZoneDeplacement(point) && matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));						
				break;		
			case 'service_rencontres' :	
				var secteur = serviceItemByValue(serviceShownConsultation, tabMHO[i].secteur);
				condition = ((document.getElementById(secteur).checked && tabMHO[i].inZoneSearching(zoneSearching) && matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId))); 
				break;			
			case 'service_commerces' :
				condition = ((					
					 	(
						 	document.getElementById('_108_ITEM_TOUS_SECTEURS').checked					
						||	(document.getElementById('_108_ITEM_SECTEUR').value == tabMHO[i].secteur)
						)
					&& tabMHO[i].inZoneSearching(zoneSearching)	&& matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));						
				break;			
			case 'service_assos' :	
				var item = serviceItemByValue(serviceShownConsultation, tabMHO[i].secteur);
				condition = ((document.getElementById(item).checked && tabMHO[i].inZoneSearching(zoneSearching) && matchKeyWords(key_words, tabMHO[i])) 
					|| (selectedId && (tabMHO[i].id==selectedId)));				
				break;		
			case 'service_evenements' :	
				var item = serviceItemByValue(serviceShownConsultation, tabMHO[i].secteur);
				condition = ((document.getElementById(item).checked && tabMHO[i].inZoneSearching(zoneSearching) && matchKeyWords(key_words, tabMHO[i])
						&& !(avant(tabMHO[i].fin, formatDate('_101_ITEM_DEBUT_ANNEE', '_101_ITEM_DEBUT_MOIS', '_101_ITEM_DEBUT_JOUR')) 
							|| (document.getElementById('_101_ITEM_FIN').checked && apres(tabMHO[i].debut, formatDate('_101_ITEM_FIN_ANNEE', '_101_ITEM_FIN_MOIS', '_101_ITEM_FIN_JOUR'))))) 
					|| (selectedId && (tabMHO[i].id==selectedId)));				
				break;
			case 'service_perdu' :	
				var perdu = serviceItemByValue(serviceShownConsultation, tabMHO[i].perdu);
				condition = ((document.getElementById(perdu).checked && tabMHO[i].inZoneSearching(zoneSearching) && matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId))) ;
				break;				
			case 'service_appels' :
			case 'service_faire_part' :
			case 'service_bars' :
			case 'service_autres_vie_locale' :			
				condition = ((tabMHO[i].inZoneSearching(zoneSearching) && matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));					
				break;
			case 'service_emploi' :
				var offre = serviceItemByValue(serviceShownConsultation, tabMHO[i].offre);
				var type_emploi = serviceItemByValue(serviceShownConsultation, tabMHO[i].type_emploi);		
				condition = (((document.getElementById(offre).checked
					&& 	document.getElementById(type_emploi).checked						
					&& 	(
						 	document.getElementById('_104_ITEM_TOUS_SECTEURS').checked					
						||	(document.getElementById('_104_ITEM_SECTEUR').value == tabMHO[i].secteur)
						)
					&& 	(
							(document.getElementById('_104_ITEM_OFFRE').checked && tabMHO[i].inZoneSearching(zoneSearching))
						||	(document.getElementById('_104_ITEM_CHERCHE').checked && tabMHO[i].inZoneDeplacement(point))
						))
					&& matchKeyWords(key_words, tabMHO[i]))
					|| (selectedId && (tabMHO[i].id==selectedId)));						
				break;	
			default :
				break;
			}
		if (condition)
			html += showMHO_getHTML(tabMHO[i]);
			else hideMHO(tabMHO[i]);		
		}
	setResults(html);
}

function log2(n) {
	for (var i=0; i<100; i++)
		if (Math.pow(2,i) == n)
			return i;
}

function servicesMultiples(n) {
	var bits_a_1 = 0
	for (var i=0; Math.pow(2, i)<n; i++)
		if (n & Math.pow(2, i))
			bits_a_1++;
	if (bits_a_1 > 1) return true;
		else return false;
}

function checkboxMatched(service, Ids, cb_p2) {
	if (document.getElementById('TEXT_ET').checked) { //ET
		for (var i=0; i<Ids.length; i++)
			if (document.getElementById(Ids[i]).checked && !(cb_p2 & Math.pow(2,serviceItemValue(service,Ids[i])))) 
				return false;
		return true;
		} else { //OU
			for (var i=0; i<Ids.length; i++)
				if (document.getElementById(Ids[i]).checked && (cb_p2 & Math.pow(2,serviceItemValue(service,Ids[i])))) 
					return true;
			return false;
			}
}


function cond(mho, zs, kw) {
	return mho.inZoneSearching(zs) && matchKeyWords(kw, mho);
}

function cleanKeyWords(words) { //à développer peut être en tenant compte des différentes langues
	var reg = new RegExp("[ ,;]+", "g");
	if (words != '') return words.split(reg); else return null;
}

function keyWordsInString(key_words, string) {
	var i = 0;
	while (i<key_words.length) {
		if (string.toUpperCase().indexOf(key_words[i].toUpperCase()) != -1) return true; else i++;
		}	
	return false;
}

function matchKeyWords(key_words, mho) { //Attention : fonction jumelle dans registration.php
	if ((!key_words) || keyWordsInString(key_words, mho.title) || keyWordsInString(key_words, mho.desco))
		return true;
	return false;
}

function showMHO_getHTML(mho) {
	mho.marker.show();
	return mho.html;
}

function hideMHO(mho) {
	mho.marker.hide();
	mho.marker.closeInfoWindow();
}


