
var App;var G_PageNo=3;var G_defLat=null;var G_defLng=null;var G_ldmkid=-1;var mapConfig={"id":"map3","defalutLat":35.674206,"defaultLng":139.755707,"defaultZoom":14}
var im=null;function onLoad(){im=new IconManager();im.get("5",bybusInit);}
function bybusInit(){App=new ByBusWebApp3();var dlg=new WaitDialog();dlg.show("しばらくお待ちください");var AjaxRequest=new Ajax.Request("/calta/servlet/CaltaSessionServlet?action=login&account=guest&password="+MD5_hexhash("mizube2006"),{method:'post',onComplete:function(request){dlg.close();if(G_ldmkid!=1){var url="/calta/servlet/BusStopInfo?ldmkid="+ldmkid;var ajax=new Ajax.Request(url,{method:"post",onComplete:function(request){var bus=eval("("+request.responseText+")");$('bsname').value=bus.name;$('description').value=bus.description;$('highway').checked=bus.iconid==21||bus.iconid==1?false:true;$('roof').checked=bus.roof=="true"?true:false;$('parking').checked=bus.parking=="true"?true:false;$('bicycle').checked=bus.bicycle=="true"?true:false;$('bench').checked=bus.bench=="true"?true:false;G_ldmkid=bus.ldmkid;Element.hide("btupdate");$('opmessage').innerHTML="";Element.hide("btmove");Element.hide("btupcancel");Element.show("btok");Element.show("btcancel");}});}},onTimeout:function(req,ajaxComponent){dlg.close();alert("タイムアウトが発生しました");}});}
function getGmap(){if(App.gmap!=null){return App.gmap.map;}
return null;}
var ByBusWebApp3=Class.create();ByBusWebApp3.prototype={initialize:function(){App=this;this.gmap=null;this.busStopInfoList=null;this.iconManager=im;this.cursor=null;inputInit();$('spotsearch').value="";$('bsname').value="";$('description').value="";$('highway').checked=false;$('roof').checked=false;$('parking').checked=false;$('bicycle').checked=false;$('bench').checked=false;if(GBrowserIsCompatible()){this.gmap=new ByBusMap();}
window.onunload=function(){var cookie=new Cookie();try{var point=getGmap().getCenter();cookie.set("BYBUS_LAT",point.y,365);cookie.set("BYBUS_LNG",point.x,365);cookie.set("BYBUS_ZOOM",getGmap().getZoom(),365);}
catch(e){}};}}
var beforeZoom=null;var beforePoint=null;var ByBusMap=Class.create();ByBusMap.prototype={initialize:function(){this.map=new GMap2($(mapConfig.id));App.gmap=this;this.clickLister=null;var objtypes=new Array(5);this.pointMarker=null;this.showStop=false;this.landMarkManger=new LandMarkManager();this.map.enableDoubleClickZoom();this.map.enableContinuousZoom();this.map.contorol=new GLargeMapControl();this.map.addControl(this.map.contorol);this.map.addControl(new GScaleControl());this.map.addControl(new GMapTypeControl());this.zoomendlistener=GEvent.addListener(this.map,'zoomend',function(){map.show();});var map=this;this.moveendlistener=GEvent.addListener(this.map,'moveend',function(){map.show();});var cookie=new Cookie();var lat=cookie.get("BYBUS_LAT");var lng=cookie.get("BYBUS_LNG");var zoom=cookie.get("BYBUS_ZOOM");if(G_defLng!=null&&G_defLat!=null){lat=G_defLat;lng=G_defLng;}
else if(lat!=null&lng!=null){}
else{lat=mapConfig.defalutLat;lng=mapConfig.defaultLng;}
zoom=16;this.allocate();this.map.setCenter(new GLatLng(lat,lng),parseInt(zoom));this.show();},allocate:function(){},onResize:function(){},show:function(force){if(this.showStop==true)return;var point;var zoom;if(force!=true){try{point=this.map.getCenter();zoom=this.map.getZoom();if(beforePoint!=null){if(point.x==beforePoint.x&&point.y==beforePoint.y){if(zoom==beforeZoom){return;}}}}
catch(e){}}
beforeZoom=zoom;beforePoint=point;if(zoom<13)return;var url='/calta/servlet/CaltaServlet?objtype=5&ver=2';var prm=this.getAreaRangeStr();var AjaxRequest=new Ajax.Request(url+prm,{method:'post',onComplete:function(request){var xml=request.responseXML;App.gmap.landMarkManger.overlay(xml);}});},getAreaRangeStr:function(){var cObj=this.map.getBounds();var NorthEast=cObj.getNorthEast();var SouthWest=cObj.getSouthWest();return"&NorthEast_lat="+NorthEast.lat()+"&NorthEast_lng="+NorthEast.lng()
+"&SouthWest_lat="+SouthWest.lat()+"&SouthWest_lng="+SouthWest.lng()
+"&zoom="+this.map.getZoom();},moveMap:function(keyword){var geocode=new GClientGeocoder();geocode.getLatLng(keyword,function(point){var map=getGmap();if(point!=null){map.panTo(new GLatLng(point.y,point.x));}});}}
var wdlg=null;function mapSearch(){App.gmap.moveMap($('spotsearch').value);}
function bsRegist(){if($('bsname').value.length==0){alert("バス停名を入力してください");return;}
if(getGmap().getZoom()<16){alert("地図を詳細表示にします。");getGmap().setZoom(16);}
App.cursor=new IconCursor("RegistCursor");App.cursor.show("バス停の位置を地図上でクリックします。",$("highway").checked?"/calta/icons/ico_bustop_g.gif":"/calta/icons/ico_bustop_r.gif");Element.show('btcancel');App.gmap.clickLister=GEvent.addListener(getGmap(),'click',function(overray,point){if(point){GEvent.removeListener(App.gmap.clickLister);var busUpdater=new BusStopUpdater([{"param":"lat","value":point.y},{"param":"lng","value":point.x},{"param":"ldmkid","value":G_ldmkid},{"param":"name","value":$('bsname').value},{"param":"description","value":$('description').value},{"param":"parking","value":$("parking").checked},{"param":"bicycle","value":$("bicycle").checked},{"param":"roof","value":$("roof").checked},{"param":"bench","value":$("bench").checked},{"param":"objtype","value":5},{"param":"highway","value":$("highway").checked},{"param":"updaterid","value":50},{"param":"creatorid","value":50}]);busUpdater.update(function(marker){App.gmap.showStop=false;App.cursor.hide();if(marker==null)return;$('bsname').value="";$('description').value="";$('highway').checked=false;$('roof').checked=false;$('parking').checked=false;$('bicycle').checked=false;$('bench').checked=false;G_ldmkid=-1;Element.hide("btupdate");$('opmessage').innerHTML="";Element.hide("btmove");Element.hide("btupcancel");Element.show("btok");Element.hide("btcancel");App.gmap.landMarkManger.landmarkArray.push(marker);marker.addOverlay();});}});}
function bsCancel(){App.cursor.hide();GEvent.removeListener(App.gmap.clickLister);Element.hide('btcancel');}
function bsUpdate(){if($('bsname').value.length==0){alert("バス停名を入力してください");return;}
var busUpdater=new BusStopUpdater([{"param":"ldmkid","value":G_ldmkid},{"param":"name","value":$('bsname').value},{"param":"description","value":$('description').value},{"param":"parking","value":$("parking").checked},{"param":"bicycle","value":$("bicycle").checked},{"param":"roof","value":$("roof").checked},{"param":"bench","value":$("bench").checked},{"param":"highway","value":$("highway").checked},{"param":"updaterid","value":50},{"param":"creatorid","value":50}]);busUpdater.update(function(marker){App.gmap.showStop=false;if(marker==null)return;$('bsname').value="";$('description').value="";$('highway').checked=false;$('roof').checked=false;$('parking').checked=false;$('bicycle').checked=false;$('bench').checked=false;G_ldmkid=-1;Element.hide("btupdate");$('opmessage').innerHTML="";Element.hide("btmove");Element.hide("btupcancel");Element.show("btok");Element.hide("btcancel");try{App.cursor.hide();}
catch(e){}
var array=App.gmap.landMarkManger.landmarkArray;for(var i=0;i<array.length;i++){if(array[i].ldmkid==marker.ldmkid){array[i].removeOverlay();array[i]=marker;marker.addOverlay();break;}}
App.gmap.landMarkManger.allDisp();});}
function bsUpCancel(){try{App.cursor.hide();}
catch(e){}
App.gmap.landMarkManger.disableDragging(G_ldmkid);Element.hide('btcancel');App.gmap.landMarkManger.allDisp();$('bsname').value="";$('description').value="";$('highway').checked=false;$('roof').checked=false;$('parking').checked=false;$('bicycle').checked=false;$('bench').checked=false;G_ldmkid=-1;Element.hide("btupdate");$('opmessage').innerHTML="";Element.hide("btmove");Element.hide("btupcancel");Element.show("btok");Element.hide("btcancel");}
function bsMove(){App.cursor=new IconCursor("RegistCursor");App.cursor.show("バス停をドラッグして位置を移動します。",null);Element.hide("btmove");App.gmap.landMarkManger.enableDragging(G_ldmkid);}