var gmap_common=new gmap_common();var ajax_file="get_minfo.php";var entry_cat="";var order=1;var get_search='';var gmarkers=new Array();var list=new Array();var page_info='';var polyPoints=Array();var sarea_flg = true;var openh = "";var openm = "";function init_searchmap() {if(document.getElementsByName("s_area")[0].checked) {sarea_flg=true;}else{sarea_flg=false;}GEvent.addListener(map, "moveend", function(){ if(!sarea_flg){getMarker(ajax_file);}});getMarker(ajax_file);gmap_common.set_center_marker();}function setMode(mode) {switch(mode) {case 'town/sale/index.html':case 'town/event/index.html':case 'town/ticket/index.html':ajax_file = "get_entry.php";entry_cat = $('entry_cat').value;break;case 'town/coupon/index.html':ajax_file = "get_coupon.php";break;case 'town/delivery/index.html':ajax_file = "get_deli.php";break;case 'town/openclose/index.html':ajax_file = "get_open.php";break;case 'kankou/index.html':case 'town/index.html':default:ajax_file = "get_minfo.php";break;}}function goSearch(mode){get_search = '';switch (mode) {case "cate":get_search = "&m=" + mode;get_search += "&c1="+$("c1code").value+"&c2="+$("c2code").value+"&c3="+$("c3code").value;getMarker(ajax_file);break;case "word":var word_el = $("free_word");if(word_el.value == "") {alert("フリーワードを入力してください。");} else {get_search = "&m=" + mode;get_search += "&w=" + encodeURIComponent(word_el.value);getMarker(ajax_file);}break;case "kana":get_search = "&m=" + mode;get_search += "&w=" + encodeURIComponent(goSearch.arguments[1]);getMarker(ajax_file);break;case "image":get_search = "&m=" + mode;get_search += "&w=" + encodeURIComponent(goSearch.arguments[1]);getMarker(ajax_file);break;default:get_search = "";getMarker(ajax_file);break;}}function getMarker(ajax_file){$('gmap_msg').style.display = "block";var map_bounds = map.getBounds();var sw = map_bounds.getSouthWest();var ne = map_bounds.getNorthEast();var from = 1;if(getMarker.arguments.length != 1) {from = getMarker.arguments[1];}if(!order) {order = "1";}date = new Date();var min = date.getTime();var file = "/ajax_php/" + ajax_file;var str = "entry_cat="+entry_cat;if(!sarea_flg) {str +="&min_lat=" + sw.lat() + "&min_lng=" + sw.lng()+ "&max_lat=" + ne.lat() + "&max_lng=" + ne.lng()+ "&center="+map.getCenter();} else {str +="&center="+(new GLatLng($('dlat').value,$('dlng').value));}str += "&order=" + order +"&type="+$('ctype').value+"&from="+from+ "&date=" + min+ "&entry_cat="+entry_cat;if(openh!='' && openm!='') {str+= "&openh="+openh+"&openm="+openm;}if(get_search != null) {str+= get_search;}new Ajax.Request(file,{method: 'get',parameters: str,onComplete: setMarker});}function setMarker(httpObj){var res = httpObj.responseXML;var item_n = res.getElementsByTagName("item");var item_ln = item_n.length;var page_n = res.getElementsByTagName("page");var page_ln = page_n.length;map.clearOverlays();gmarkers = new Array();list = new Array();page_info = null;var minlat = 150;var minlng = 150;var maxlat = -150;var maxlng = -150;if( item_ln > 0) {for(var i=0; i<item_ln; i++) {t = item_n[i].getAttribute("minfo_mark_type");id= item_n[i].getAttribute("minfo_id");var clat = item_n[i].getAttribute("clat");var clng = item_n[i].getAttribute("clng");if(t == 0) {createMarker(id, item_n[i].getAttribute("clat"), item_n[i].getAttribute("clng"), item_n[i].getAttribute("marker_image"), item_n[i].getAttribute("minfo_name"), item_n[i].getAttribute("bdri_code"));} else if(t == 1) {dispPolyLine(id,item_n[i].getAttribute("minfo_polygon"), item_n[i].getAttribute("minfo_line_color"), item_n[i].getAttribute("minfo_thickness"), item_n[i].getAttribute("minfo_line_alpha"));} else if(t == 2) {dispPolygon(id,item_n[i].getAttribute("minfo_polygon"), item_n[i].getAttribute("minfo_line_color"), item_n[i].getAttribute("minfo_thickness"), item_n[i].getAttribute("minfo_line_alpha"), item_n[i].getAttribute("minfo_plain_color"), item_n[i].getAttribute("minfo_plain_alpha"));}list.push(new Array(id, item_n[i].getAttribute("minfo_catchname"), item_n[i].getAttribute("minfo_name"),  item_n[i].getAttribute("minfo_note"), item_n[i].getAttribute("thmimg_path"), item_n[i].getAttribute("bdri_code")));if(minlat>clat) minlat=clat;if(minlng>clng) minlng=clng;if(maxlat<clat) maxlat=clat;if(maxlng<clng) maxlng=clng;}page_info = new Array(page_n[0].getAttribute("current"),   page_n[0].getAttribute("total"),   page_n[0].getAttribute("pageS"),  page_n[0].getAttribute("pageE"),  page_n[0].getAttribute("numpages"),  page_n[0].getAttribute("prev_link"),  page_n[0].getAttribute("next_link"),  page_n[0].getAttribute("range_s"),  page_n[0].getAttribute("range_e"));if(sarea_flg) {var bounds = new GLatLngBounds(new GLatLng(minlat,minlng), new GLatLng(maxlat,maxlng));map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));}createList();writeMarker();} else { $('page').innerHTML = "";$('list').innerHTML = '<div class="blkTownMapMapSearchResultList"><table cellspacing="0" cellpadding="0" border="0"><tr><td><p id="maplisterr"><br/>表示中のエリア内に該当する情報はありませんでした。<br/>表示エリアを広くするか、検索条件を変更してください。</p></td></tr></table></div>';$('result').innerHTML = "";}$('gmap_msg').style.display = "none";}function createMarker(code, lat, lng, icn, name, entryid){if(icn != "") {cg = new GIcon();cg.image ="/global-image/icon/"+icn;cg.iconSize =new GSize(20, 32);cg.iconAnchor=new GPoint(10, 32);var marker=new GMarker(new GLatLng(lat,lng), cg);} else {var marker=new GMarker(new GLatLng(lat,lng));}GEvent.addListener(marker, "click", function(){ moveList(code);borderList(code);});GEvent.addListener(marker, "dblclick", function(){ moveList(code);borderList(code);showGB(name,code,entryid);});gmarkers.push(marker);return true;}function dispPolygon(code,latlng,info_line_color,info_thickness,info_line_alpha,info_plain_color,info_plain_alpha){var points = new Array();latlng = latlng.match(/\d+\.\d+/g);if(latlng != null) {var t = 0;for(i=0; i<latlng.length; i+=2) {points[t] = new Array();points[t].lat = latlng[i];points[t].lon = latlng[i+1];t++;}var polygon = createEncodedPolygon(points,info_line_color,info_thickness,info_line_alpha,info_plain_color,info_plain_alpha);GEvent.addListener(polygon,'click',function(){moveList(code);borderList(code);});GEvent.addListener(polygon,'mouseover',function(){moveList(code);borderList(code);});gmarkers.push(polygon);}return true;}function dispPolyLine(code,latlng,info_line_color,info_thickness,info_line_alpha){var points = new Array();latlng = latlng.match(/\d+\.\d+/g);if(latlng != null) {var t = 0;for(i=0; i<latlng.length; i+=2) {points[t] = new Array();points[t].lat = latlng[i];points[t].lon = latlng[i+1];t++;}var polyline = createEncodedPolyline(points,info_line_color,info_thickness,info_line_alpha);GEvent.addListener(polyline,'click',function(){moveList(code);borderList(code);});GEvent.addListener(polyline,'mouseover',function(){moveList(code);borderList(code);});gmarkers.push(polyline);}return true;}function writeMarker() {for(var i=0;i<gmarkers.length;i++){map.addOverlay(gmarkers[i]);}return true;}function createList(){var spot_cnt = list.length;var html = "";if(page_info[4] > 1) {html +="<ul>";if(page_info[5] == "1") {html+= "<li class=\"pagePrev\"><a href=\"#noscript\" onclick=\"getMarker('" + ajax_file + "'," + eval(parseInt(page_info[0]) - 1) + ")\" title=\"previous page\">PREV</a>|</li>";}for(var i = parseInt(page_info[7]); i <= parseInt(page_info[8]); i++) {if(i == page_info[0]) {html += "<li class=\"pageNum\"><span class=\"pageNum\">" + i + "</span></li>";} else {html += "<li class=\"pageNum\"><a hrf=\"#noscript\" onclick=\"getMarker('" + ajax_file + "'," + i + ")\">" + i + "</a></li>";}}if(page_info[6] == "1") {html += "<li class=\"pageNext\">|<a href=\"#noscript\" onclick=\"getMarker('" + ajax_file + "'," + eval(parseInt(page_info[0]) + 1) + ")\">NEXT</a></li>";}html +="</ul>";}$('page').innerHTML = html;html = "";if(spot_cnt > 0) {for(var i = 0; i < spot_cnt; i++) {html += "<div id=\"block[" + list[i][0] + "]\" class=\"blkTownMapMapSearchResultList\">";html += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";html += "<tr>";html += "<th>";url = "/map/detail.html?sum=1&i="+list[i][0];if(list[i][4] != null && list[i][4] != '') {html += "<a href=\"#noscript\" onclick=\"showGB('"+escape(list[i][2])+"',"+list[i][0]+","+list[i][5]+");borderList(" + list[i][0] + ");\"><img src=\"/global-image/themeimg/" + list[i][0] + "/" + list[i][4] + "\" width=\"48\" height=\"36\" /></a>";} else {html += "<a href=\"#noscript\" onclick=\"showGB('"+escape(list[i][2])+"',"+list[i][0]+","+list[i][5]+");borderList(" + list[i][0] + ");\"><img src=\"/common-img/dummy-img/dummy-list-photo.jpg\" width=\"48\" height=\"36\" /></a>";}html += "<p><a href=\"#noscript\" onclick=\"showGB('"+escape(list[i][2])+"',"+list[i][0]+","+list[i][5]+");borderList(" + list[i][0] + ");\">" + list[i][2] + "</a></p>";html += "</th>";html += "<td>";if(list[i][1] != null && list[i][1] !='') {html += "<p>" + list[i][1] + "</p>";}html += "<h6><a href=\"#noscript\" onclick=\"showGB('"+escape(list[i][2])+"',"+list[i][0]+","+list[i][5]+");borderList(" + list[i][0] + ");\">" + list[i][2] + "</a></h6>";html += "</td></tr></table></div>";}}$('list').innerHTML = html;html = "";html += "検索結果：&nbsp;&nbsp;&nbsp;<span>" + page_info[1] + "</span>件中 <span>" + page_info[2] + "\uFF5E" + page_info[3] + "</span>件を表示";$('result').innerHTML = html;}function moveList(code){var mv = $("scroll");var mx = mv.scrollTop + mv.style.height;var scrl = mv.scrollHeight / list.length;var count = 0;for (i = 0; i < list.length; i++) {    if(list[i][0] == code) {    count = i;    break;    }}if((count * scrl) >= mx || (count * scrl) < mv.scrollTop) {mv.scrollTop = (count * scrl);}}function borderList(c){for (i = 0; i < list.length; i++) {var le = $("block[" + list[i][0] + "]");    if(list[i][0] == c) {    le.setAttribute('className', 'blkTownMapMapSearchResultListActive');    le.setAttribute('class', 'blkTownMapMapSearchResultListActive');    listno = i;    } else {    le.setAttribute('className', 'blkTownMapMapSearchResultList');    le.setAttribute('class', 'blkTownMapMapSearchResultList');    }}}function showGB(str,c,bc) {url = "/map/index.html?i="+c;if(!isNaN(bc)) {url += "&bdri_code="+bc;}GB_showCenter(unescape(str), url, 530, 820, null);}function set_order(val) {order = val;$("order1").setAttribute("className", "");$("order1").setAttribute("class", "");$("order2").setAttribute("className", "");$("order2").setAttribute("class", "");$("order" + val).setAttribute("className", "sortActive");$("order" + val).setAttribute("class", "sortActive");getMarker(ajax_file);}function chngmapSize(mode){switch(mode) {case 'mid':var map_size = $("map_size");map_size.setAttribute("className", "blkTownMapMapGmapMedium");map_size.setAttribute("class", "blkTownMapMapGmapMedium");var map_resize = $("map_resize");map_resize.setAttribute("className", "blkTownMapMapResize blkTownMapActiveMedium");map_resize.setAttribute("class", "blkTownMapMapResize blkTownMapActiveMedium");var scroll = $("scroll");scroll.setAttribute("className", "blkTownMapMapSrMedium");scroll.setAttribute("class", "blkTownMapMapSrMedium");map.checkResize();getMarker(ajax_file);break;case 'tall':var map_size = $("map_size");map_size.setAttribute("className", "blkTownMapMapGmapLarge");map_size.setAttribute("class", "blkTownMapMapGmapLarge");var map_resize = $("map_resize");map_resize.setAttribute("className", "blkTownMapMapResize blkTownMapActiveLarge");map_resize.setAttribute("class", "blkTownMapMapResize blkTownMapActiveLarge");var scroll = $("scroll");scroll.setAttribute("className", "blkTownMapMapSrLarge");scroll.setAttribute("class", "blkTownMapMapSrLarge");map.checkResize();getMarker(ajax_file);break;case 'small':var map_size = $("map_size");map_size.setAttribute("className", "blkTownMapMapGmapSmall");map_size.setAttribute("class", "blkTownMapMapGmapSmall");var map_resize = $("map_resize");map_resize.setAttribute("className", "blkTownMapMapResize blkTownMapActiveSmall");map_resize.setAttribute("class", "blkTownMapMapResize blkTownMapActiveSmall");var scroll = $("scroll");scroll.setAttribute("className", "blkTownMapMapSrSmall");scroll.setAttribute("class", "blkTownMapMapSrSmall");map.checkResize();getMarker(ajax_file);break;}gmap_common.set_center_marker();}function MoveArea() {var area = ($("area").value).match(/\d+\.\d+/g);var lat=area[0];var lng=area[1];map.panTo(new GLatLng(lat,lng));$('dlat').value = lat;$('dlng').value = lng;}function load_detail(lat, lng, zl, t){if(gmap_common.loadMap(lat, lng, zl)) {ctrl2 = new GSmallMapControl();map.removeControl(ctrl1);map.addControl(ctrl2);latlng = (document.getElementsByName("minfo_polygon")[0].value).match(/\d+\.\d+/g);if(latlng != null) {for(i=0; i<latlng.length; i+=2) {var point = new GLatLng(parseFloat(latlng[i]), parseFloat(latlng[i+1]));var mapNormalProj = G_NORMAL_MAP.getProjection();var mapZoom = map.getZoom();if(t=='0') {polyPoints = Array();polyPoints.push(point);} else if(t=='1') {polyPoints.push(point);} else if(t=='2') {if(polyPoints.length > 1) {polyPoints.pop();polyPoints.push(point);polyPoints.push(polyPoints[0]);} else {polyPoints.push(point);polyPoints.push(point);}}}draw(t);}}}function draw(t){map.clearOverlays();var m = null;if(t=='0') {m = new GMarker(polyPoints[polyPoints.length -1]);}if (t=='1') {m = new GPolyline(polyPoints,$('minfo_line_color').value,$('minfo_thickness').value,$('minfo_line_alpha').value);map.setZoom(map.getBoundsZoomLevel(m.getBounds()));} else if(t=='2') {m = new GPolygon(polyPoints,$('minfo_line_color').value,$('minfo_thickness').value,$('minfo_line_alpha').value,$('minfo_plain_color').value,$('minfo_plain_alpha').value);map.setZoom(map.getBoundsZoomLevel(m.getBounds()));}map.addOverlay(m);}function chgSarea(t) {if(t==1) {sarea_flg = false;} else {sarea_flg = true;}getMarker(ajax_file);}function set_time() {openh = $('openh').value;openm = $('openm').value;}
