// JavaScript Document
// TextualZoomControl 是一种 GControl 控件，可以显示文本＂放大＂和＂缩小＂按钮。
    // （取代Google 地图上对应的图标按钮）
	
	var map;

    function TextualZoomControl() {
    }
    TextualZoomControl.prototype = new GControl();

    // 为每个按钮创建一个 DIV，并将其放在容器 DIV 中，
    // 然后返回容器 DIV 作为我们的控件元素。将该控件添加到
    // 地图容器中，并将其返回，以便地图类能正确地放置它。
    TextualZoomControl.prototype.initialize = function(map) {
      var container = document.createElement("div");

      var zoomInDiv = document.createElement("div");
      this.setButtonStyle_(zoomInDiv);
      container.appendChild(zoomInDiv);
      zoomInDiv.appendChild(document.createTextNode("放大"));
      GEvent.addDomListener(zoomInDiv, "click", function() {
        map.zoomIn();
      });

      var zoomOutDiv = document.createElement("div");
      this.setButtonStyle_(zoomOutDiv);
      container.appendChild(zoomOutDiv);
      zoomOutDiv.appendChild(document.createTextNode("缩小"));
      GEvent.addDomListener(zoomOutDiv, "click", function() {
        map.zoomOut();
      });

      map.getContainer().appendChild(container);
      return container;
    }

    // 默认情况下，该控件将在地图的左上角显示，边距为 7 像素。
    TextualZoomControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
    }

    // 设置给定按钮元素的正确 CSS。
    TextualZoomControl.prototype.setButtonStyle_ = function(button) {
      button.style.textDecoration = "underline";
      button.style.color = "#0000cc";
      button.style.backgroundColor = "white";
      button.style.font = "small Arial";
      button.style.border = "1px solid black";
      button.style.padding = "2px";
      button.style.marginBottom = "3px";
      button.style.textAlign = "center";
      button.style.width = "6em";
      button.style.cursor = "pointer";
    }
	


var depart_xy = {
		c0000:[22.543177, 114.056168],
		c8078:[22.822217, 113.687706],  
		c8031:[23.022325, 113.748905],
		c8022:[23.102564, 113.310138],
		c8024:[22.941532, 113.380153],
		c8023:[23.131429, 113.283007],
		c8021:[23.134793, 113.309887],
		c8030:[23.139069, 113.328836],
		c8026:[23.125554, 113.261767],
		c8054:[26.074824,119.302876],
		c8068:[20.036052,110.336300], 
		c8028:[22.596491,113.101668], 
		c8055:[24.804196,118.572366], 
		c8059:[28.685571,115.899604],
		c8071:[22.552953,114.133388],
		c8074:[22.556472,113.889905],
		c8073:[22.524688,113.950503],
		c8069:[22.554189,114.121038],
		c8086:[22.728447,113.829562],
		c8072:[22.53864,114.053486],
		c8070:[22.540596,114.090631],
		c8025:[22.834843,113.262294],
		c8088:[22.862303,113.128072],
		c8075:[21.26899,110.372971],
		c8095:[21.438844,110.775446],
		c8027:[22.535856,113.384689],
		c8029:[22.239223,113.573133],
		c8019:[31.778625,119.958653],
		c8087:[31.423155,119.491741],
		c8063:[30.278245,120.153831],
		c8098:[31.885042,117.469869],
		c8064:[31.854366,117.286602],
		c8018:[33.591729,119.025923],
		c8082:[33.948284,118.295178],
		c8014:[32.084347,118.783257],
		c8013:[32.037196,118.778920],
		c8015:[31.99976,120.855521],
		c8084:[32.309855,121.192576],
		c8009:[31.207358,121.526054],
		c8012:[31.202928,121.431822],
		c8007:[31.219128,121.483799],
		c8008:[31.263462,121.479005],
		c8006:[31.230877,121.466162],
		c8011:[31.260239,121.495851],
		c8010:[31.237348,121.444122],
		c8016:[31.299943,120.606636],
		c8083:[30.907233,120.65614],
		c8020:[31.911811,120.273031],
		c8080:[32.426139,119.575037],
		c8017:[32.396155,119.433765],
		c8081:[32.281278,119.173436],
		c8004:[39.994534,116.407268],
		c8003:[39.915837,116.486135],
		c8001:[39.864178,116.434715],　
		c8002:[39.907033,116.299066],　
		c8005:[40.977537,117.936223],
		c8047:[36.650131,117.037113],　
		c8046:[34.663717,112.394988],　
		c8049:[36.067975,120.379083],
		c8058:[37.877261,112.5622],　
		c8093:[39.708324,117.303908],
		c8092:[39.256599,117.808215],
		c8091:[40.050511,117.419435],
		c8051:[39.092671,117.223565],
		c8053:[39.146752,117.158652],
		c8096:[38.939934,116.918435],
		c8052:[39.120708,117.186284],
		c8097:[39.380587,117.05231],
		c8048:[37.50409,122.116906],
		c8090:[34.454377,113.03745],
		c8045:[34.770952,113.733296],
		c8044:[34.755294,113.622901],
		c8040:[41.103251,122.992605],　
		c8062:[43.890168,125.334388],　
		c8061:[38.924214,121.641005],
		c8094:[45.532642,127.083437],
		c8056:[45.772771,126.667543],　
		c8057:[45.77901,126.623807],
		c8037:[41.805657,123.446811],
		c8038:[41.775259,123.427759],
		c8039:[42.280639,123.844438],
		c8060:[28.200407,112.984542],
		c8079:[30.446123,112.696195],
		c8043:[30.422584,112.891295],
		c8042:[30.601588,114.288905],
		c8041:[30.581413,114.355015],　
		c8032:[30.68471,104.0727],　
		c8089:[30.823499,104.167421],　
		c8033:[29.560865,106.581333],
		c8065:[26.573687,106.71785],
		c8034:[31.463131,104.746515],
		c8085:[30.755993,105.704176],
		c8035:[30.50007,105.582045],
		c8036:[29.348672,104.768473],
		c8066:[34.241683,108.955632],
		c8067:[36.629421,101.768844],
		c8076:[36.392805,94.910018],
		c8077:[21.871047,112.008432],
		c16701:[40.117356,94.590445],
		c8100:[22.719274,114.234654],
		c8101:[22.654928,114.027261]
}


var provinceAgent = ['c8004', 'c8071', 'c8059', 'c8062', 'c8009', 'c8022', 'c8014', 'c8047', 'c8056', 'c8058', 'c8033', 'c8054',
'c8063', 'c8045', 'c8060', 'c8051', 'c8068', 'c8064', 'c8037', 'c8032', 'c8065', 'c8066', 'c8067'];

function queryDepartInfo(code, marker){
	var url = '/web001/depart/branchQuery.php';
	new Ajax.Request(
		url,
		{
			method:'get',
			parameters:{code:code},
			onSuccess:function(transport){
				var response = transport.responseText.evalJSON(true);
				var tips = "<div class='title'>-name-</div>"+
				  "<div class='section1'><p> 编号：-code- <br>  名称：-name- <br> 地址：-address- <br> 邮编：-mailcode- <br> 电话：-telephone- <br> </p></div>"+
				  "";
				tips = tips.replace('-name-', response.name);
				tips = tips.replace('-code-', response.code);
				tips = tips.replace('-name-', response.name);
				tips = tips.replace('-address-', response.address);
				tips = tips.replace('-mailcode-', response.mailcode);
				tips = tips.replace('-telephone-', response.telephone);
				marker.openExtInfoWindow(
				  map, 
				  "custom_info_window_red",
				  tips,
				  {beakOffset: 3}
                 );
			},
			onFailure:function()
			{
			 	alert("系统忙，请稍后再试！");
			}
		}
	);
}
	
var curCode;
var curMarker;

function geoNav(code){
	map.clearOverlays();
	map.closeExtInfoWindow();
	var latlng = new GLatLng(depart_xy[code][0], depart_xy[code][1]);
	
	map.setCenter(latlng, 15);   
	marker = new GMarker(latlng);
	map.addOverlay(marker);	
	queryDepartInfo(code.substr(1), marker);
	
	curCode = code;
	curMarker = marker;
	GEvent.addListener(marker, "click", function() {
            queryDepartInfo(curCode.substr(1), curMarker);
    });
	
}

var centerTips = "<div class='title'>中投证券总部（深圳）</div>"+
				  "<div class='section1'><p> 名称：中国建银投资证券有限公司 <br> 地址：深圳福田区益田路6003号荣超商务中心A座18-21层  <br> 邮编：518048 <br> 电话：4006-008-008（全国统一客服热线） 国外用户拨打：0755-33960588 <br> <a href=\"http://www.cjis.cn\" target=\"_blank\">网站首页</a> <a href=\"http://www.cjis.cn/soft/download.html\" target=\"_blank\">软件下载</a> <a href=\"http://www.cjis.cn/info/zjzx.jsp\" target=\"_blank\">专家在线</a> <a href=\"https://etrade.cjis.cn/websales/homepage.html\" target=\"_blank\">网上营业厅</a> <br> </p></div>"+
				  "";

function geoCenter(code){
	map.clearOverlays();
	map.closeExtInfoWindow();
	var latlng = new GLatLng(depart_xy[code][0], depart_xy[code][1]);
	
	map.setCenter(latlng, 15);   
	marker = new GMarker(latlng);
	map.addOverlay(marker);	
	
				
		marker.openExtInfoWindow(
				  map, 
				  "custom_info_window_red",
				  centerTips,
				  {beakOffset: 3}
         );
		 
		 GEvent.addListener(marker, "click", function() {
            geoCenter('c0000');
    });
		 

}
 
function initialize() {      
	if (GBrowserIsCompatible()) 
	{        
		//地图初始化及属性设置
		map = new GMap2(document.getElementById("map_canvas"));  
		map.setCenter(new GLatLng(38.08, 104.46), 4); 
		map.addControl(new TextualZoomControl());
		
		for(var i = 0; i < provinceAgent.length; i++){
			var polyline = new GPolyline([
  		    new GLatLng(depart_xy['c0000'][0], depart_xy['c0000'][1]),

  		    new GLatLng(depart_xy[provinceAgent[i]][0], depart_xy[provinceAgent[i]][1])
		], "#ff0000", 1);
		map.addOverlay(polyline);
		}
		
		var latlng = new GLatLng(depart_xy['c0000'][0], depart_xy['c0000'][1]);
		marker = new GMarker(latlng);
		
		
				
		marker.openExtInfoWindow(
				  map, 
				  "custom_info_window_red",
				  centerTips,
				  {beakOffset: 3}
         );
		 map.addOverlay(marker);	
		 
		  GEvent.addListener(marker, "click", function() {
            geoCenter('c0000');
    });
	}
}    