﻿// JavaScript Document
var map;
var superPoint;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("ggmap") );
//map.removeMapType(G_SATELLITE_MAP);
if (tx_MapType=="地图")
{
map.setCenter(new GLatLng(tx_lat, tx_lng), tx_ZoomLevel);
}
else
{
map.setCenter(new GLatLng(tx_lat, tx_lng), tx_ZoomLevel, G_HYBRID_MAP);
}
//var mapControl = new GMapTypeControl();
//map.addControl(mapControl);
//map.addControl(new TextualZoomControl());

//map.setCenter(new GLatLng(39.91737289576941,116.39019012451172), 12, G_HYBRID_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl()); 
		map.enableDragging();
		map.enableDoubleClickZoom();
		map.enableContinuousZoom();
		//map.enableScrollWheelZoom();
		enableMarker(true);

      //var WINDOW_HTML = '<div style="width: 210px; padding-right: 10px"><h3>'+tx_subject+'</h3><a href="/scenery_album.asp" target=_blank>实景图</a>　<a href="/ditu.html" target=_blank>全屏</a>　<a href="javascript:tj();">分享</a>　<a href="javascript:window.external.AddFavorite(\'http://www.52maps.com/mapsmarker_show.asp?id='+tx_MapID+'\', \''+ tx_subject+'卫星地图\')">收藏</a>　<a href="/help.asp" target="_blank">帮助</a></div>'
	  var WINDOW_HTML = '<div style="width: 260px; padding-right: 10px"><h3>'+tx_subject+'</h3>　　　　　 <a href="/TravelMap.asp?id='+tx_MapID+'" target=_blank>实景图</a>　<a href="/ditu.html?lat='+tx_lat+'&lng='+tx_lng+'&zoom='+tx_ZoomLevel+'" target=_blank>全屏</a>　<a href="/mapdown.asp?js" target="_blank">下载高清地图</a></div>'
	  //var WINDOW_HTML = '<div style="width: 210px; padding-right: 10px"><h3>'+tx_subject+'</h3></div>'
	  var marker = new GMarker(new GLatLng(tx_lat, tx_lng));
      map.addOverlay(marker);
      GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(WINDOW_HTML);
      });
	  
      marker.openInfoWindowHtml(WINDOW_HTML);
	 }
//GEvent.addListener(map, 'click', function(overlay, point) {
//		if (overlay) {
//			// nothing
//		} else {
//			map.clearOverlays();
//			superPoint = point;
//	  		document.getElementById("x_zb").value = point.x + "," + point.y;
//	  		document.getElementById("x_lng").value = point.x;
//	  		document.getElementById("x_lat").value = point.y;
//	  		document.getElementById("x_ZoomLevel").value = map.getZoom();
//	  		document.getElementById("x_MapType").value = map.getCurrentMapType().getName();
//			var marker = map.addOverlay(new GMarker(point));
//			var html = '<div style="width:200px;"><input type=button onclick="javascript: marker.style.display=\'block\';" value=标注该位置><br><br>如果您熟悉红球所指的位置，请点击“标注该位置”按钮标识该位置，以便让其他网友所知晓！<br>您可以在地图熟悉的位置上单击鼠标左键，重新选择标注点！<br><a href=http://www.nanpengyou.com/ target=_blank>点这里，在该地区找老乡</a></div>';
//			//var html = '暂停标注';
//			map.openInfoWindowHtml(point, html);
//		}
//	});

    }


// A TextualZoomControl is a GControl that displays textual "Zoom In"
    // and "Zoom Out" buttons (as opposed to the iconic buttons used in
    // Google Maps).
    function TextualZoomControl() {
    }
    TextualZoomControl.prototype = new GControl();

    // Creates a one DIV for each of the buttons and places them in a container
    // DIV which is returned as our control element. We add the control to
    // to the map container and return the element for the map class to
    // position properly.
    TextualZoomControl.prototype.initialize = function(map) {
      var container = document.createElement("div");

//	  var tuDiv = document.createElement("div");
//      this.setButtonStyle_(tuDiv);
//      container.appendChild(tuDiv);
//      tuDiv.appendChild(document.createTextNode("实景图"));
//      GEvent.addDomListener(tuDiv, "click", function() {
//        window.location="http://www.nanpengyou.com/wallpaper_Album.asp";
//      }
//	  );
	  
      var zoomOutDiv = document.createElement("div");
      this.setButtonStyle_(zoomOutDiv);
      container.appendChild(zoomOutDiv);
      zoomOutDiv.appendChild(document.createTextNode("+"));
      GEvent.addDomListener(zoomOutDiv, "click", function() {
        map.zoomIn();
      });
	  
	  var zoomInDiv = document.createElement("div");
      this.setButtonStyle_(zoomInDiv);
      container.appendChild(zoomInDiv);
      zoomInDiv.appendChild(document.createTextNode("-"));
      GEvent.addDomListener(zoomInDiv, "click", function() {
        map.zoomOut();
      });
	  
	  var moveLeftDiv = document.createElement("div");
      this.setButtonStyle_(moveLeftDiv);
      container.appendChild(moveLeftDiv);
      moveLeftDiv.appendChild(document.createTextNode("<-"));
      GEvent.addDomListener(moveLeftDiv, "click", function() {
		map.panDirection(2, 0)
      });
	  var moveRightDiv = document.createElement("div");
      this.setButtonStyle_(moveRightDiv);
      container.appendChild(moveRightDiv);
      moveRightDiv.appendChild(document.createTextNode("->"));
      GEvent.addDomListener(moveRightDiv, "click", function() {
		map.panDirection(-2, 0)
      });
	  	  var moveTopDiv = document.createElement("div");
      this.setButtonStyle_(moveTopDiv);
      container.appendChild(moveTopDiv);
      moveTopDiv.appendChild(document.createTextNode("↑"));
      GEvent.addDomListener(moveTopDiv, "click", function() {
		map.panDirection(0, 2)
      });
	  	  var moveXiaDiv = document.createElement("div");
      this.setButtonStyle_(moveXiaDiv);
      container.appendChild(moveXiaDiv);
      moveXiaDiv.appendChild(document.createTextNode("↓"));
      GEvent.addDomListener(moveXiaDiv, "click", function() {
		map.panDirection(0, -2)
      });	  

//	  var quanDiv = document.createElement("div");
//      this.setButtonStyle_(quanDiv);
//      container.appendChild(quanDiv);
//      quanDiv.appendChild(document.createTextNode("全屏"));
//      GEvent.addDomListener(quanDiv, "click", function() {
//        window.location="/ditu.asp";
//      }
//	  );

	  
      map.getContainer().appendChild(container);
      return container;
    }

    // By default, the control will appear in the top left corner of the
    // map with 7 pixels of padding.
    TextualZoomControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
    }

    // Sets the proper CSS for the given button element.
    TextualZoomControl.prototype.setButtonStyle_ = function(button) {
      button.style.textDecoration = "none";
      button.style.color = "#000000";
      button.style.backgroundColor = "white";
      button.style.font = "small Arial";
      button.style.border = "1px solid black";
      button.style.padding = "1px";
      button.style.marginBottom = "3px";
      button.style.textAlign = "center";
      button.style.width = "18px";
      button.style.cursor = "pointer";
    }

	function enableMarker(bool){
	if (bool==true)
	{
	myEventListener=GEvent.addListener(map, 'click', function(overlay, point) {
		if (overlay) {
			// nothing
		} else {
			map.clearOverlays();
			superPoint = point;
	  		document.getElementById("x_zb").value = point.x + "," + point.y;
	  		document.getElementById("x_lng").value = point.x;
	  		document.getElementById("x_lat").value = point.y;
	  		document.getElementById("x_ZoomLevel").value = map.getZoom();
	  		document.getElementById("x_MapType").value = map.getCurrentMapType().getName();
			//var marker = map.addOverlay(new GMarker(point));
			//var html = '<div style="width:200px; font-size:13px; line-height:1.5;"><input type=button onclick="javascript: marker.style.display=\'block\';" value=标注该位置><br><br>如果您熟悉红球所指的位置，请点击“标注该位置”按钮标识该位置，以便让其他网友所知晓！<br>您可以在地图熟悉的位置上单击鼠标左键，重新选择标注点！<br><a href=http://www.nanpengyou.com/ target=_blank>点这里，在该地区找老乡</a></div>';
			//var html = '暂停标注';
			//map.openInfoWindowHtml(point, html);
		}
	});
	}
	else
	{
	GEvent.removeListener(myEventListener);
	}
	}

function tj(){
window.clipboardData.setData("Text",tx_subject+"卫星地图：http://www.52maps.com/mapsmarker_show.asp?id="+tx_MapID);
alert('链接已复制，请粘贴发送给您的QQ或MSN好友吧');
}
//取字符串字节长度
String.prototype.getByteLength = function ()
{
  return this.replace(/[^\x00-\xff]/g,"00").length;
}


function howManyWords(inputString)
{
  return inputString.split(document.db.x_subject.value).length;
}

function Checksubmit2()
{
    if (document.db.x_subject.value=="")
    {
        msg="请填写地标名称，尽量具体，例如某省某市某建筑"
        alert(msg);
         document.db.x_subject.focus();
    return false;
    }
    if (document.db.x_subject.value.getByteLength()<=6)
    {
        msg="地标名称太短，不足以表明该地标的核心内容"
        alert(msg);
         document.db.x_subject.focus();
    return false;
    }
    if (document.db.x_category.value=="")
    {
        msg="请选择类别"
        alert(msg);
         document.db.x_category.focus();
    return false;
    }

    if (document.db.x_explain.value=="")
    {
        msg=document.db.x_subject.value + "详细说明，多多少少也介绍一点啊\n你可以从Google里搜索一点介绍，复制进来！"
        alert(msg);
         document.db.x_explain.focus();
    return false;
    }
    if (document.db.x_explain.value.getByteLength()<=10)
    {
        msg="介绍不够哦，起码也要超过10个中文字吧"
        alert(msg);
         document.db.x_explain.focus();
    return false;
    }
	
	if (howManyWords(document.db.x_explain.value)>=2)
	{
        msg="无效的说明，似乎只是在重复标题，没有意义啊，请填写一些有意义的地标说明 ^_^"
        alert(msg);
         document.db.x_explain.focus();
		 return false;
	}
	
    if (document.db.x_Username.value=="")
    {
        msg="请填写您的网名"
        alert(msg);
         document.db.x_Username.focus();
    return false;
    }

document.db.submit();
return true;
}