
var App;var G_PageNo=7;var G_defLat=null;var G_defLng=null;var G_ldmkid=-1;var mapConfig={"id":"map7","defalutLat":35.674206,"defaultLng":139.755707,"defaultZoom":14}
var im=null;function onLoad(){im=new IconManager();im.get("13",bybusInit);}
var dlg=null;function bybusInit(){App=new ByBusWebApp7();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();},onTimeout:function(req,ajaxComponent){dlg.close();alert("タイムアウトが発生しました");}});$('spotsearch').value="";$('spotname').value="";$('spotdescription').value="";$('spoturl').value="http://";$('photokey').value="";}
function getGmap(){if(App.gmap!=null){return App.gmap.map;}
return null;}
var ByBusWebApp7=Class.create();ByBusWebApp7.prototype={initialize:function(){App=this;this.gmap=null;this.busStopInfoList=null;this.iconManager=im;this.cursor=null;inputInit();this.iconselector=new IconSelector('icoselect');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.addControl(new GScaleControl());this.map.addControl(new GMapTypeControl());var contorol=new GLargeMapControl();this.map.addControl(contorol,new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,30)));this.map.addControl(new Photodiv());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=13&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(){spotUpCancel();App.gmap.moveMap($('spotsearch').value);}
function spotCancel(){App.cursor.hide();GEvent.removeListener(App.gmap.clickLister);Element.hide('btcancel');}
function spotUpdate(){if($('spotname').value.length==0){alert("スポット名を入力してください");return;}
var spotUpdater=new SpotUpdater([{"param":"ldmkid","value":G_ldmkid},{"param":"name","value":$('spotname').value},{"param":"description","value":$('spotdescription').value},{"param":"objtype","value":13},{"param":"iconid","value":App.iconselector.getIconid()},{"param":"updaterid","value":50},{"param":"creatorid","value":50},{"param":"imageurl","value":$('spoturl').value=="http://"?"":$('spoturl').value}]);spotUpdater.update(function(marker){App.gmap.showStop=false;try{App.cursor.hide();}
catch(e){}
if(marker==null)return;$('spotname').value="";$('spotdescription').value="";G_ldmkid=-1;Element.hide("btupdate");$('opmessage').innerHTML="";Element.hide("btmove");Element.hide("btupcancel");Element.show("btok");Element.hide("btcancel");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();$('spotphotodiv').innerHTML="";});}
function spotRegist(){if($('spotname').value.length==0){alert("スポット名を入力してください");return;}
if(getGmap().getZoom()<16){alert("地図を詳細表示にします。");getGmap().setZoom(16);}
App.cursor=new IconCursor("RegistCursor");App.cursor.show("スポットの位置を地図上でクリックします。",App.iconselector.getIcon().icon.image);Element.show('btcancel');App.gmap.clickLister=GEvent.addListener(getGmap(),'click',function(overray,point){if(point){GEvent.removeListener(App.gmap.clickLister);var spotUpdater=new SpotUpdater([{"param":"lat","value":point.y},{"param":"lng","value":point.x},{"param":"ldmkid","value":G_ldmkid},{"param":"name","value":$('spotname').value},{"param":"description","value":$('spotdescription').value},{"param":"objtype","value":13},{"param":"iconid","value":App.iconselector.getIconid()},{"param":"updaterid","value":50},{"param":"creatorid","value":50},{"param":"zoommax","value":999},{"param":"zoommin","value":14},{"param":"imageurl","value":$('spoturl').value=="http://"?"":$('spoturl').value}]);spotUpdater.update(function(marker){App.gmap.showStop=false;App.cursor.hide();if(marker==null)return;$('spotname').value="";$('spotdescription').value="";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();$('spotphotodiv').innerHTML="";});}});}
function spotUpCancel(){try{App.cursor.hide();}
catch(e){}
App.gmap.landMarkManger.disableDragging(G_ldmkid);Element.hide('btcancel');App.gmap.landMarkManger.allDisp();$('spotname').value="";$('spotdescription').value="";$('spoturl').value="http://";$('photokey').value="";G_ldmkid=-1;Element.hide("btupdate");$('opmessage').innerHTML="";Element.hide("btmove");Element.hide("btupcancel");Element.show("btok");Element.hide("btcancel");$('spotphotodiv').innerHTML="";}
function getPhoto(){var key=$('photokey').value;var url="/calta/servlet/GetPhotozo?type=photo&keyword="+key;url=encodeURI(url);var dlg=new WaitDialog();dlg.show("フォト蔵から"+key+"の写真を検索中・・");var ajax=new Ajax.Request(url,{method:"post",onComplete:function(request){dlg.close();var xml=request.responseXML;dispSpotPhoto(xml);}});}
function dispSpotPhoto(xml){photodialog=new PhotoList();photodialog.show();var photos=xml.getElementsByTagName("photo");for(var i=0;i<photos.length;i++){var div=document.createElement("div");div.className="spotphoto";var a=document.createElement("a");a.href=photos[i].getElementsByTagName("url")[0].firstChild.nodeValue;a.target="_blank";var img=document.createElement("img");img.src=photos[i].getElementsByTagName("thumbnail_image_url")[0].firstChild.nodeValue;img.alt=photos[i].getElementsByTagName("photo_title")[0].firstChild.nodeValue;img.title=photos[i].getElementsByTagName("photo_title")[0].firstChild.nodeValue;;img.border="0";a.appendChild(img);div.appendChild(a);var p=document.createElement("p");a=document.createElement("a");a.href="#";a.setAttribute("link",photos[i].getElementsByTagName("thumbnail_image_url")[0].firstChild.nodeValue);a.onclick=function(){$('spoturl').value=this.getAttribute("link");$('spotphotodiv').innerHTML='<img src=\"'+this.getAttribute("link")+'\"/>';photodialog.close();}
a.appendChild(document.createTextNode("選択"));p.align="center";p.className="photoselect"
p.appendChild(document.createTextNode("[ "));p.appendChild(a);p.appendChild(document.createTextNode(" ]"));div.appendChild(p);$('photolist').appendChild(div);}
var fotter=document.createElement("div");fotter.className="photofotter";fotter.appendChild(document.createTextNode($('photokey').value+"に関連した画像　"));var a=document.createElement('a');a.href="http://photozou.jp";a.target="_blank";var img=document.createElement('img');img.src="http://photozou.jp/img/photozou_logo.gif";img.alt="フォト蔵";img.align="middle";img.border="0";a.appendChild(img);fotter.appendChild(a);var input=document.createElement("input");input.type="button";input.onclick=function(){photodialog.close();return false;}
input.value="閉じる";fotter.appendChild(input);$('photodlg').appendChild(fotter);}
var photodialog;function setPhotoKey(){$('photokey').value=$('spotname').value;}
var PhotoList=Class.create();PhotoList.prototype={initialize:function(){this.div=null;this.width=800;this.height=330;this.overlay=null;},show:function(msg){if(this.div!=null){this.close();}
this.div=document.createElement("div");this.div.className="photodlg";this.div.id="photodlg";this.div.style.height=this.height+"px";this.div.style.width=this.width+"px";var potolist=document.createElement("div");potolist.className="photolist";potolist.id="photolist";this.div.appendChild(potolist);var body=document.getElementsByTagName("body");var x;var y;var wy;if(isIE()){wy=(document.body.scrollTop||document.documentElement.scrollTop);y=wy+100;x=document.body.clientWidth/2-this.width/2;}
else{wy=window.pageYOffset;y=wy+100;x=window.innerWidth/2-this.width/2;}
this.div.style.top=y+"px";this.div.style.left=x+"px";var w;var h;if(isIE()){h=document.body.clientHeight;w=document.body.clientWidth;}
else{h=window.innerHeight;w=window.innerWidth;}
this.overlay=document.createElement("div");this.overlay.className="photoverlay";this.overlay.style.width=(w-50)+"px";this.overlay.style.height=h+"px";this.overlay.style.top=wy+"px";body[0].appendChild(this.div);body[0].appendChild(this.overlay);},close:function(){var body=document.getElementsByTagName("body");body[0].removeChild(this.div);body[0].removeChild(this.overlay);this.div=null;}}
function spotMove(){App.cursor=new IconCursor("RegistCursor");App.cursor.show("スポットをドラッグして位置を移動します。",null);Element.hide("btmove");App.gmap.landMarkManger.enableDragging(G_ldmkid);}
var IconSelector=Class.create();IconSelector.prototype={initialize:function(id){this.id=id;this.mydivid="_icondiv";var cnt=0;var div=document.createElement("div");div.id=this.mydivid;var frm=document.createElement("form");frm.name="iconForm";frm.id="iconForm";var inputStr="";for(var i=0;i<App.iconManager.iconArray.length;i++){var ico=App.iconManager.iconArray[i];if(ico.objtype!=13)continue;if(ico.iconid>=251&&ico.iconid<=254){continue;}
if(cnt==0){inputStr+='<input checked type="radio" name="iconradio" value="'+ico.iconid+'"/>';}
else{inputStr+='<input type="radio" name="iconradio" value="'+ico.iconid+'"/>';}
inputStr+='<img src="'+ico.icon.image+'" alt="'+ico.name+'" title="'+ico.name+'"/>';cnt++;if(cnt%4==0){inputStr+="<br/>";}
else{inputStr+="　";}}
frm.innerHTML=inputStr;div.appendChild(frm);$(id).appendChild(div);},getIconid:function(){var radios=$('iconForm').iconradio;for(var i=0;i<radios.length;i++){if(radios[i].checked)return radios[i].value;}
return radios[0].value;},getIcon:function(){var id=this.getIconid();return App.iconManager.getAt(id);},selectIcon:function(iconid){var radios=document.forms['iconForm'].iconradio;for(var i=0;i<radios.length;i++){if(radios[i].value==iconid){radios[i].checked=true;return;}}
radios[0].checked=true;}}
function unlinkPhoto(){$('spotphotodiv').innerHTML="";$('spoturl').value="";}
function Photodiv(){}
Photodiv.prototype=new GControl();Photodiv.prototype.initialize=function(map){var container=document.createElement("div");var customPanel=document.createElement("div");container.appendChild(customPanel);var panelContent='<div id="spotphotodiv"></div>';customPanel.innerHTML=panelContent;map.getContainer().appendChild(container);return container;}
Photodiv.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(0,0));}