function ZdcEmapStorageNList (htmlStr) {
	var fafilter = document.formList.fafilter.value,
	faflg = document.formList.faflg.value,
	mefilter = document.formList.mefilter.value,
	lat = document.formList.lat.value,
	lon = document.formList.lon.value;
	sroute = document.formList.sroute.value;
	var me = ZdcStorageShop;
	var keyFa = me.keyFav;
	var keyMemo = me.keyMemo;
	var storageFa = me.getItem(keyFa);
	var storageMe = me.getItem(keyMemo);
	if (faflg == 1) displayFavoriteBoxInfo(faflg);
	$('#ZdcEmapSearchNShopList').append(htmlStr); //create temp element.
	// favorite screen.
	if (faflg == 1) {
		addMemoList(storageMe); //add memo to item.
		ZdcEmapSortFavNList(storageFa); // filter favorite list screen.
		sortable(faflg); // drag drop favorite screen
		showList(); // show 10 item and load more
	} 
	// when search route
	else if (sroute == 1) {
		addAddressCenter(lat, lon, sroute); // add address center.
		$('.ml-block-info__title').html(titleSearchRoute); // show tittle when search route
		var center = new ZDC.LatLon(ZDC.msTodeg(lat),ZDC.msTodeg(lon));
		ZdcNListFilterStorage(fafilter, mefilter, storageFa, storageMe); // filter favorite list screen.
		filterRoute(center); //filter route.
		if ($('.ml-list').find('.ml-list-item').length > 0) {
			addTimeMoveRoute(lat, lon, true, function() { // get distance and time.
				addMemoList(storageMe); //add memo to item.
				changeColorFavItem(storageFa); // change color favorite item.
				showList(); // show 10 item and load more.
			});
		} else {
			showList(); // show 10 item and load more.
		}
	}
	// when not search route
	else {
		$('.ml-block-info__title').html(titleSearchNRoute); // show tittle when search route
		addAddressCenter(lat, lon, sroute); // add address center.
		addTimeMoveNRoute(); // get distance and time.
		addMemoList(storageMe); //add memo to item.
		changeColorFavItem(storageFa); // change color favorite item.
		ZdcNListFilterStorage(fafilter, mefilter, storageFa, storageMe); // filter favorite list screen.
		showList(); // show 10 item and load more.
	}
}
function displayFavoriteBoxInfo (flg) {
	if (flg == 1) {
		$("#fbox").css('display', 'block');
	} else {
		$("#nbox").css('display', 'block');
	}
}
//open filtering modal at map screen.
function custOpenCondMap() {
	var dlg = document.getElementById("cust_cond_dlg");
	if (!dlg) return;
	dlg.style.display = "block";
	window.history.pushState('popup-open', null, '');
	window.onpopstate = function(event) {
		custCloseCondMap();
	};
	disableScrollBody();
}
//close filtering modal at map screen.
function custCloseCondMap() {
	var dlg = document.getElementById("cust_cond_dlg");
	if (!dlg) return;
	var form = document.formCond;
	if (form) form.reset();
	dlg.style.display = "none";
	enableScrollBody();
	onchangePrivateType();
}
//Re-search list screen by conditions filter.
function custCondReSearchMap() {
	var e = document.getElementById("cust_research_url");
	if (!e) return;
	var formCond = document.formCond;
	if (!formCond) return;
	hknUpdateConditionForm(formCond, true);
	var formMapTop = document.formMapTop;
	var formList = document.formList;
	if (formMapTop) custCondCheck(formCond, formMapTop);
	if (formList) custCondCheck(formCond, formList);
	var cond = ZdcEmapGetCondParm(true);
	cond += hknGetCondCustom(formCond);
	var url = e.value+cond;
	window.location.href = url;
}
//Update hidden form by filter cond form.
function custCondCheck(fCond, form) {
	for (var i = 0; i < fCond.elements.length - 1; i++) {
		var obj = fCond.elements[i];
		if (obj.type == "checkbox") {
			if (form){
				if(form.elements[i].name == obj.name){
					if (obj.checked) {
						form.elements[i].value = obj.value;
					}else{
						form.elements[i].value = "";
					}
				}
			}
		}
	}
}
//get condition filter storage favirote or memo.
function ZdcEmapGetCondStorage (item, query, esc) {
	var chk = item;
	var condparm = '';
	if (chk) {
		if ((chk.type == "checkbox" && chk.checked) || (chk.type == "hidden" && chk.value != "")) {
				condparm += ("&" + query + '=');
			if (esc) {
				condparm += encodeURIComponent(chk.value);
			} else {
				condparm += chk.value;
			}
		}
	}
	return condparm;
}
// add address to item.
function addAddressCenter(lat, lon, sroute) {
	if (lat && lon) {
		ZDC.Search.getAddrByLatLon({latlons: [new ZDC.LatLon(ZDC.msTodeg(lat),ZDC.msTodeg(lon))]},function (status, res) {
			if (status['code'] == '000' && res[0] && "address" in res[0]) {
				if (sroute == 1) {
					$('.ml-block-info__address').html('ルート中心点' + ': ' + res[0]['address']['text']);
					// $('.ml-block-info__address').css('font-size', '11px')
				}
				else{
					$('.ml-block-info__address').html('地図中心点' + ': ' + res[0]['address']['text']);
					// $('.ml-block-info__address').css('font-size', '11px')
				}
			}
			displayFavoriteBoxInfo(0);
		});
	}
	else{
		return false;
	}
}
// add time move and sort when search route
function addTimeMoveRoute(lat, lon, sroute, callback) {
	if (lat && lon) {
		var center = new ZDC.LatLon(ZDC.msTodeg(lat),ZDC.msTodeg(lon));
		var len = $('.ml-list').find('.ml-list-item').length;
		var count = 0;
		$('.ml-list').find('.ml-list-item').each(function(key, val) {
			var id = $(this).data('id');
			var latHoikuen = $(this).data('lat');
			var lonHoikuen = $(this).data('lon');
			var hoikuen = new ZDC.LatLon(ZDC.msTodeg(latHoikuen),ZDC.msTodeg(lonHoikuen));
			var option = {
				from: center,
				to: hoikuen,
				searchtype: 'dist',
				maxdist: 10,
			}
			ZDC.Search.getRouteByWalk(option, function(status,res){
				count++;
				if (status['code'] == '000') {
					var dist = res['route']['distance'];
					var html = Math.round(dist) + 'm' + '(徒歩'+Math.round(dist/(hknSpeedWalk * 1000 / 60 ))+'分/自転車'+Math.round(dist/(hknSpeedBike*1000/60))+'分)';
					var nlink = typeof res['route']['link'] == "undefined" ? 0 : res['route']['link'].length;
					$('.ml-list-item__distance[data-id="'+id+'"]').html(html);
					$('.ml-list-item[data-id="'+id+'"]').attr("data-dist", dist);
					$('.ml-list-item[data-id="'+id+'"]').attr("data-nlink", nlink);
				}
				//get all data route.
				if (count == len) {
					var list = $('.ml-list > .ml-list-item').get();
					list.sort(function (a, b) {
						a = Math.round ($(a).attr('data-dist'));
						b = Math.round ($(b).attr('data-dist'));
						if (a == b) return 0;
						return (a > b) ? 1 : -1;
					});
					$('.ml-list').html('');
					var rcount = 0;
					var max = parseInt(searchRouteMax) || 5;
					for (var el in list) {
						if (sroute) {
							if (typeof $(list[el]).attr('data-dist') == "undefined" || 
								typeof $(list[el]).attr('data-nlink') == 0)
							{ //check item can not draw route.
								continue;
							}
							rcount++;
							if (rcount > max) { //check max route.
								break;
							}
						}
						$('.ml-list').append(list[el]);
					}
					if (typeof callback == "function") {
						callback();
					}
				}
			});
		});
	}
	else{
		return false;
	}
}
// add time move and sort when not search route
function addTimeMoveNRoute() {
	$('.ml-list').find('.ml-list-item').each(function(key, val) {
		var dist = $(this).data('distnr');
		var html = Math.round(dist) + 'm' + '(徒歩'+Math.round(dist/(hknSpeedWalk * 1000 / 60 ))+'分/自転車'+Math.round(dist/(hknSpeedBike*1000/60))+'分)';
		$(this).find('.ml-list-item__distance').html(html);
	});
}
//add memo to list screen
function addMemoList(storageMe){
	if (storageMe) {
		$('.ml-list').find('.ml-list-item').each(function(key, val) {
			var id = $(this).data('id');
			for(i = 0; i < storageMe.length; i++){
				if (storageMe[i]['id'] == id) {
					var memo = storageMe[i]['data'][0]['content'];
					$(this).find('.ml-list-item__memo').html(memo.replace(/\n/g, "
")); 
				}
			}
		});
	}
	else{
		return false;
	}
}
// filter favorite list screen
function ZdcEmapSortFavNList(storageFa) {
	var listItem = [];
	if (storageFa) {
		for(i = 0; i < storageFa.length; i++){
			$('.ml-list').find('.ml-list-item').each(function(key, val) {
				var id = $(this).data('id');
				if (id == storageFa[i]['id']) {
					listItem.push($(this).get(0).outerHTML);
				}
			});
		}
	}
	
	$('.ml-list').html(listItem.join('')); //update list.
}
// drag drop favorite screen
function sortable(faflg) {
	if (faflg == 1) {
		$('.ml-text-center').show();
		$('.ml-landing-page p').show();
		$('.ml-list').toggleClass('ml-list__move');
		// use sortable to drag drop favorite hoikuen.
		$("#sortable").sortable({
			axis: 'y',
			scroll : false,
			handle: '.ml-list-ic__move',
			// get array before drag drop.
			/* start: function(event,ui) {
				var oldArray = $(this).sortable('toArray',{attribute: 'data-id'});
				$(this).attr('data-prearray', oldArray);
			}, */
			// get 2 id is swap.
			update: function(event, ui) {
				/* var oldArray = $(this).attr('data-prearray').split(',');
				for(i = 0; i < newArray.length; i++){
					if (oldArray[i] != newArray[i]) {
						oldId = oldArray[i];
						newId = newArray[i];
						break;
					}
				} */
				var newArray = $(this).sortable('toArray',{attribute: 'data-id'});
				ZdcStorageShop.sort(newArray);
			}
		});
		$( "#sortable" ).disableSelection();
	}
	else{
		$('.ml-text-left').show();
	}
}
function submitFormFilter() {
	$(".z_map_btn_locroute").submit(); // Submit the form filter
}
//support transit form list to map.
function transit2map () {
	$('.z_map_btn_nlist').submit(); // Submit the form map
}
//support transit to favorite.
function transit2favorite (url) {
	url = url || "";
	var params = '&' + serialize(document.formMapList)
	url += params;
	window.location.href = url;
}
function transit2detail(url) {
	var nlist_url = serialize(document.formMapList)
	//replace state of history session for back from to detail.
	// history.replaceState({screen: 2}, "NLIST", nlist_url);
	window.location.href = url;
}
//load more.
function showList() {
	var total = $(".ml-list-item").length;
	if (total == 0) {
		var html = '
'+msgEmptyNList+'
'; $('#ZdcEmapSearchNShopList').html(html); return; } if (total > hknstep) { $('.page-num').html('11件〜'); $('.pagination').css('display', 'block'); } $(".ml-list .ml-list-item").slice(0, hknstep).addClass('ml-show'); $(".ml-list .ml-list-item").slice(0, hknstep).removeClass('ml-hide'); $(document).delegate("#loadMore","click", function (e) { e.preventDefault(); $(".ml-hide").slice(0, hknstep).addClass('ml-show'); $(".ml-hide").slice(0, hknstep).removeClass('ml-hide'); var cur = $(".ml-show").length + 1; $('.page-num').html(cur + '件〜'); if ($(".ml-hide").length == 0) { $('.pagination').css('display', 'none'); } }); } // change color favorite item function changeColorFavItem(storageFa) { if (storageFa) { $('.ml-list').find('.ml-list-item').each(function(key, val) { var id = $(this).data('id'); for(i = 0; i < storageFa.length; i++){ if (storageFa[i]['id'] == id) { $(this).css("background-color", "rgba(255, 255, 0, 0.5)"); } } }); } else { return false; } } function ZdcNListFilterStorage (fafilter, mefilter, storageFa, storageMe) { var listKid = []; var listItemId = []; $(".ml-list .ml-list-item").each(function () { listItemId.push($(this).data('id').toString()); }); if (listItemId.length == 0) return; if (fafilter == 1 && storageFa && mefilter == 0) { for (var f in storageFa) { var kid = storageFa[f].id.toString(); if (listItemId.indexOf(kid) >= 0 && listKid.indexOf(kid) < 0) { listKid.push(kid); } } } if (mefilter == 1 && storageMe && fafilter == 0) { for (var m in storageMe) { var kid = storageMe[m].id.toString(); if (listItemId.indexOf(kid) >= 0 && listKid.indexOf(kid) < 0) { listKid.push(kid); } } } if (mefilter == 1 && storageMe && fafilter == 1 && storageFa) { for (var m in storageFa) { for (var n in storageMe){ if (storageFa[m].id.toString() == storageMe[n].id.toString()) { var kid = storageFa[m].id.toString(); if (listItemId.indexOf(kid) >= 0 && listKid.indexOf(kid) < 0) { listKid.push(kid); } } } } } if (mefilter == 1 || fafilter == 1) { if (listKid.length == 0) { $(".ml-list .ml-list-item").remove(); return false; } else { $(".ml-list .ml-list-item").each(function () { var itemid = $(this).data('id').toString(); if (listKid.indexOf(itemid) < 0) { $(this).remove(); } }) } } } //filter item route by radius. function filterRoute (center) { if ($('.ml-list').find('.ml-list-item').length == 0) return; //search route option. var radius = parseInt(searchRouteRad) || 3000; var max = parseInt(searchRouteMax) || 5; $('.ml-list').find('.ml-list-item').each(function(key, val) { var latHoikuen = $(this).data('lat'); var lonHoikuen = $(this).data('lon'); var hoikuen = new ZDC.LatLon(ZDC.msTodeg(latHoikuen),ZDC.msTodeg(lonHoikuen)); var rad = getLatLonToDistance(center, hoikuen); if (rad > radius) { $(this).remove(); } else { $(this).attr('data-rad', rad); } }) } //support calculate distance between 2 point //refer to moyori library. function getLatLonToDistance (p1, p2) { if (p1['lat'] == p2['lat'] && p1['lon'] == p2['lon']) return 0; var pi = Math.PI / 180; var R = 6370000; var a = R * Math.cos(p1['lat'] * pi) * Math.cos(p1['lon'] * pi); var b = R * Math.cos(p1['lat'] * pi) * Math.sin(p1['lon'] * pi); var c = R * Math.sin(p1['lat'] * pi); var d = R * Math.cos(p2['lat'] * pi) * Math.cos(p2['lon'] * pi); var e = R * Math.cos(p2['lat'] * pi) * Math.sin(p2['lon'] * pi); var f = R * Math.sin(p2['lat'] * pi); var g = a * d + b * e + c * f; var h = Math.acos(g / (R * R)); return Math.round(R * h * 100) / 100; };