var distmks=[],distlines=null,mapjob,rdiv,ux,uy,uzoom,showinfo,map,gdir;function ForDight(a,c){return a=Math.round(a*Math.pow(10,c))/Math.pow(10,c)}function explode(a,c){return c.toString().split(a.toString())}function getWindowHeight(){if(window.self&&self.innerHeight)return self.innerHeight;if(document.documentElement&&document.documentElement.clientHeight)return document.documentElement.clientHeight;return 0}
function mapresize(){gh=getWindowHeight()-180;th=getWindowHeight()-130;document.getElementById("map").style.height=th+"px";document.getElementById("guidediv").style.height=gh+"px"}window.onresize=function(){mapresize()};if(top.location!=self.location)top.location=self.location;
function drawdist(){if(distlines){map.removeOverlay(distlines);distlines=null}if(distmks.length>1){for(var a=[],c=0,d=0;d<distmks.length;d++){var e=distmks[d].getPoint();a.push(e);if(d>0){b=distmks[d-1].getPoint();e=distab(b.lng(),b.lat(),e.lng(),e.lat());c+=e}}distlines=new GPolyline(a);map.addOverlay(distlines);a="";a=c>1E3?"\u5f53\u524d\u957f\u5ea6:"+ForDight(c/1E3,3)+"\u516c\u91cc":"\u5f53\u524d\u957f\u5ea6:"+ForDight(c,0)+"\u7c73";cjout(a)}else distmks.length==1&&cjout("\u8bf7\u9009\u62e9\u7ed3\u675f\u70b9")}
function distab(a,c,d,e){c=c*Math.PI/180;e=e*Math.PI/180;a=2*Math.asin(Math.sqrt(Math.pow(Math.sin((c-e)/2),2)+Math.cos(c)*Math.cos(e)*Math.pow(Math.sin((a*Math.PI/180-d*Math.PI/180)/2),2)));a*=6378137;return a=Math.round(a*1E4)/1E4}
function ceju(a){if(mapjob=="distance"){if(distlines){map.removeOverlay(distlines);distlines=null}for(var c=distmks.length-1;c>=0;c--)map.removeOverlay(distmks[c]);distmks=[];if(a!=1){cjout("",1);mapjob=""}else cjout("\u8bf7\u9009\u62e9\u8d77\u59cb\u70b9")}else{map.openInfoWindowHtml(map.getCenter(),'<div style="width:339px; word-break:break-all;">\u6d4b\u8ddd\u6a21\u5f0f\u5df2\u5f00\u542f-\u8bf7\u70b9\u51fb\u8d77\u59cb\u70b9\u5f00\u59cb\u6d4b\u8ddd<br /><br />\u652f\u6301\u4e24\u70b9\u6216\u591a\u70b9\u95f4\u7684\u6d4b\u8ddd\uff0c\u6d4b\u91cf\u7ed3\u679c\u663e\u793a\u5728\u5730\u56fe\u7684\u53f3\u4e0b\u89d2\u3002<br />\u60a8\u53ef\u4ee5\u968f\u610f\u62d6\u52a8\u5730\u56fe\u4e0a\u7684\u6d4b\u91cf\u70b9\uff0c\u4fee\u6b63\u540e\u7684\u8ddd\u79bb\u4f1a\u81ea\u52a8\u7ed9\u51fa\u3002</div><br />');
cjout("\u8bf7\u9009\u62e9\u8d77\u59cb\u70b9");mapjob="distance"}}function mapclick(a,c){if(mapjob=="distance"&&c!=null){var d=new GMarker(c,{draggable:true});distmks.push(d);map.addOverlay(d);GEvent.addListener(d,"dragend",function(){drawdist()});drawdist()}}
function cjout(a,c){if(map){if(rdiv==null){rdiv=document.createElement("div");rdiv.style.position="absolute";map.getContainer().appendChild(rdiv)}rdiv.innerHTML=c!=1?'<span class="distance">'+a+'<br /><a href="javascript:void(0)" onclick="return ceju(1)" title="\u6e05\u9664\u6240\u6709\u6807\u8bb0\uff0c\u8ddd\u79bb\u5f52\u96f6">\u91cd\u7f6e\u5f52\u96f6</a> <a href="javascript:void(0)" onclick="return ceju()" title="\u9000\u51fa\u6d4b\u8ddd\u6a21\u5f0f">\u7ed3\u675f\u6d4b\u8ddd</a></span>':a;rdiv.style.left=
map.getSize().width-160+"px";rdiv.style.top=map.getSize().height-100+"px"}}
function showguide(a,c,d){if(d>100){a=explode("+",a);if(a.length<3){alert("\u51fa\u9519\u5566\uff01\u60a8\u5fc5\u987b\u6b63\u786e\u8f93\u51653\u4e2a\u6216\u4ee5\u4e0a\u7684\u5730\u70b9\u624d\u80fd\u4f7f\u7528\u591a\u70b9\u8def\u7ebf\u67e5\u8be2\u529f\u80fd\u3002");return false}if(d==101)gdir.loadFromWaypoints(a,{travelMode:G_TRAVEL_MODE_DRIVING});else d==103?gdir.loadFromWaypoints(a,{avoidHighways:true}):gdir.loadFromWaypoints(a,{travelMode:G_TRAVEL_MODE_WALKING})}else if(d==1)gdir.load("from: "+
a+" to: "+c,{travelMode:G_TRAVEL_MODE_DRIVING});else d==3?gdir.load("from: "+a+" to: "+c,{avoidHighways:true}):gdir.load("from: "+a+" to: "+c,{travelMode:G_TRAVEL_MODE_WALKING})}
function handleErrors(){if(gdir.getStatus().code==G_GEO_UNKNOWN_ADDRESS)alert("\u51fa\u9519\u5566\uff01\u5730\u7406\u6570\u636e\u5e93\u4e2d\u65e0\u6cd5\u627e\u5230\u60a8\u6240\u6307\u5b9a\u7684\u5730\u5740\uff0c\u8bf7\u68c0\u67e5\u5730\u5740\u662f\u5426\u6709\u8bef\u5e76\u6362\u7528\u5176\u4ed6\u5730\u5740\u91cd\u8bd5\u3002");else if(gdir.getStatus().code==G_GEO_SERVER_ERROR)alert("\u8fde\u63a5GEO\u670d\u52a1\u5668\u9519\u8bef\uff01");else if(gdir.getStatus().code==G_GEO_MISSING_QUERY)alert("\u5730\u5740\u8f93\u5165\u6709\u8bef\uff0c\u8bf7\u68c0\u67e5\uff01");
else if(gdir.getStatus().code==G_GEO_BAD_KEY)alert("\u4e34\u65f6\u6027\u9519\u8bef\uff0c\u539f\u56e0\uff1aBAD_KEY");else gdir.getStatus().code==G_GEO_BAD_REQUEST?alert("\u51fa\u9519\u5566\uff01GEO\u670d\u52a1\u5668\u65e0\u6cd5\u5904\u7406\u67e5\u8be2\u8bf7\u6c42\u3002"):alert("\u53d1\u751f\u672a\u77e5\u9519\u8bef\uff01")}
function showmgd(){map.openInfoWindowHtml(map.getCenter(),'<div style="width:300px;"><center><b>\u591a\u5730\u70b9\u8def\u7ebf\u67e5\u8be2\u6a21\u5f0f</b><br /><br /><form action="http://www.ditu6.com/" method="post">\u8bf7\u8f93\u5165\u5730\u540d\u6216\u5730\u5740\uff0c\u4e0d\u540c\u5730\u5740\u4e4b\u95f4\u7528\u52a0\u53f7\u5206\u9694<br /><input type="text" size="36" name="sp" value="" /><br /><select name="mode"><option value="101">\u9a7e\u8f66\u8def\u7ebf(\u9ad8\u901f\u4f18\u5148)</option><option value="103">\u9a7e\u8f66\u8def\u7ebf(\u907f\u5f00\u9ad8\u901f)</option><option value="102">\u9a91\u8f66\u6216\u5f92\u6b65\u8def\u7ebf</option></select> <input type="submit" value="\u63d0\u4ea4\u67e5\u8be2" /><input type="hidden" name="ep" value="A" /></form></center><br /><b>\u4f7f\u7528\u5e2e\u52a9\uff1a</b>\u6b64\u6a21\u5f0f\u53ef\u4ee5\u67e5\u8be2\u591a\u4e2a\u5730\u70b9\u4e4b\u95f4\u7684\u8def\u7ebf\u5730\u56fe\uff0c\u4e0d\u540c\u5730\u5740\u4e4b\u95f4\u8bf7\u7528\u52a0\u53f7\u5206\u9694\uff0c\u4f8b\u5982\u5982\u679c\u60a8\u60f3\u67e5\u8be2\u4ece\u5357\u4eac\u51fa\u53d1\uff0c\u9014\u7ecf\u65e0\u9521\u3001\u82cf\u5dde\u3001\u4e0a\u6d77\uff0c\u518d\u5230\u676d\u5dde\u7684\u8def\u7ebf\u5730\u56fe\uff0c\u60a8\u53ef\u4ee5\u8f93\u5165\u201c\u5357\u4eac\u5e02+\u65e0\u9521\u5e02+\u82cf\u5dde\u5e02+\u4e0a\u6d77\u5e02+\u676d\u5dde\u5e02\u201d\uff0c\u7136\u540e\u70b9\u51fb\u63d0\u4ea4\u5373\u53ef\u3002</div>')}
function load(){if(GBrowserIsCompatible()){mapresize();map=new GMap2(document.getElementById("map"));gdir=new GDirections(map,document.getElementById("guidediv"));map.addControl(new GLargeMapControl);map.addControl(new GMapTypeControl);map.addControl(new GScaleControl);geocoder=new GClientGeocoder;geocoder.setBaseCountryCode("CN");GEvent.addListener(gdir,"error",handleErrors);GEvent.addListener(map,"click",function(a,c){mapclick(a,c)});showguide(sp,ep,mo)}};

