<?php

function mp_filter_drop_down($key, &$filter) {
	/*
			onfocusin="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')"
			onclick="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')"
			onfocus="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')"
				onclick="filter_show_only_selection(this, '.json_encode(array()).', '."'".$key."'".')"
			onchange="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')"

			onchange="filter_show_only_selection(this, '.json_encode(array()).', '."'".$key."'".')"
			onchange="filter_event(this, this.options[this.selectedIndex], \''.$key.'\')"
	*/
	$menu_name_class = 'filter_menu_'.str_replace(" ", "_", $key).'';
		$id = "filter_"
			. $key
			. "_"
			. $key
		;
	$content = '
		<select
			form="ljdp_form"
			class="filter_menu filter_menu_drop"
			onchange="filter_show_only(this.options[this.selectedIndex], \''.$key.'\')"
		>
			<option
				selected
				id="'.$id.'"
				class="filter_menu_item '.$menu_name_class.'"
				data-menu_index="menu_name"
			>
				'.$key.'
			</option>
	';
	foreach ($filter as $key_filter => $value) {
		$id = "filter_"
			. $key
			. "_"
			. str_replace( " ", "_", $value->_name)
		;
		$content .= '
			<option
				id="'.$id.'"
				class="filter_menu_item '.$menu_name_class.'"
				data-menu_index="'.$key_filter.'"
			>
				'.$value->_name.'
			</option>
		';
	}
	$content .= '
		</select>
	';

	return $content;
};

function mp_filter_buttons($key, &$filter) {

/*
				onclick="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".', true)"
*/
	$menu_name_class = 'filter_menu_'.str_replace(" ", "_", $key).'';
	$content = '';
	foreach ($filter as $key_filter => $value) {
		$id = "filter_"
			. $key
			. "_"
			. str_replace( " ", "_", $value->_name)
		;
		$content .= '
			<input
				type="checkbox"
				form="ljdp_form"
				id="'.$id.'"
				class="filter_menu_checkbox filter_menu_item '.$menu_name_class.'"
				onclick="filter_show_only(this, \''.$key.'\')"
				style="display:none;"
				data-menu_index="'.$key_filter.'",
			>
			<label
				for="'.$id.'"
				class="filter_menu filter_menu_checkbox"
			>
				<p>'.$value->_name.'</p>
			</label>
		';
	}

	return $content;
};

function mp_create_div(&$filters) {
	$mp_map_div  = '
		<div id="ljdp_map_wrapper">
			<form id="ljdp_form" style="display:none;"></form>
			<div id="ljdp_map_filters">
	';

	foreach ($filters as $key => $filter) {

		if ($key == "mode")
			$mp_map_div .= mp_filter_buttons($key, $filter);
		else
			$mp_map_div .= mp_filter_drop_down($key, $filter);
	};

	$mp_map_div .= '
				<input
					type="reset"
					form="ljdp_form"
					id="filter_menu_reset"
					class="filter_menu_button"
					onclick="filter_show_all()"
					style="display:none;"
				>
				<label
					for="filter_menu_reset"
					class="filter_menu filter_menu_reset"
				>
					<p>Effacer</p>
				</label>
	';

	$mp_map_div .= '
			</div>
			<div id="ljdp_map"></div>
		</div>
	';

	return $mp_map_div;
};


?>
