    //<![CDATA[
 var map;
     var pstion=null; //div elem of position finder
	 var lns=null;  // measure line
	 var lnsA = Array(); // measure line array
	 var op="";  // operate mark
	 var marker=null;

function setop (newop)
{
if (op=="")
{
op=newop;
if (op=="ps"){document.getElementById("ps").innerHTML="Position Finder <font color=red>[X]</font>"}
if (op=="ms"){document.getElementById("ms").innerHTML="Distance Measurement <font color=red>[X]</font>"}
}
else 
{
if (op==newop){
if (op=="ps"){document.getElementById("ps").innerHTML="Position Finder"}
if (op=="ms"){document.getElementById("ms").innerHTML="Distance Measurement"}
op=""
} else { 
if (op=="ps"){document.getElementById("ps").innerHTML="Position Finder"; document.getElementById("ms").innerHTML="Distance Measurement <font color=red>[X]</font>";}
if (op=="ms"){document.getElementById("ps").innerHTML="Position Finder  <font color=red>[X]</font>"; document.getElementById("ms").innerHTML="Distance Measurement";}
op=newop;
}
}

map.clearOverlays();
lnsA = new Array();
lns = null;
marker = null;
if (pstion==null){}else
{pstion.style.visibility="hidden";
map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(pstion);
}
}


   function load(x,y,z) {
      if (GBrowserIsCompatible()) {
	    map = new GMap2(document.getElementById("map"),{draggableCursor: 'crosshair', draggingCursor: 'pointer'});
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.addMapType(G_PHYSICAL_MAP);
		map.setCenter(new GLatLng(x,y),z,G_NORMAL_MAP);
        document.getElementById("ll").innerHTML = 'Lon.:  ' + map.getCenter().lng() + '<br>Lat.:  ' + map.getCenter().lat() + '<br>';
		document.getElementById("t").innerHTML = "Map Center";
		//map.addControl(new GOverviewMapControl()) ;
		//geocoder = new GClientGeocoder();
		//geocoder.setBaseCountryCode("CN");
		
//	 myicon = new GIcon();
//     myicon.shadow = "";
   //  myicon.iconSize = new GSize(10, 10);
  //   myicon.iconAnchor = new GPoint(0, 0);
    // myicon.infoWindowAnchor = new GPoint(0, 0);
     //myicon.infoShadowAnchor = new GPoint(0, 0);
     //myicon.image = "/images/red-10-10.png" ;

		
	 GEvent.addListener(map, "move", function() {
      if ((op=="" || lns== null) && (marker==null))
	  {
	    var center = map.getCenter();
        lx=center.lng();
		ly=center.lat();
        var latLngStr = 'Lon.:' + lx + '<br>Lat.:' + ly + '<br>';
        document.getElementById("ll").innerHTML = latLngStr;
		document.getElementById("t").innerHTML = "Map Center";
		}
      });

      	 	 
///// position finder.

GEvent.addListener(map,"click",function(overlay,latlng)
{

if (op=="ps")
{
	 map.clearOverlays();
   	 marker = new GMarker(latlng, {draggable: false});
     map.addOverlay(marker);
	 var lx = map.fromLatLngToDivPixel(marker.getLatLng()).x;
	 var ly = map.fromLatLngToDivPixel(marker.getLatLng()).y;
	 var latLngStr = 'Lon.:' + latlng.lng() + '<br>Lat.:' + latlng.lat() + '<br>';
		//var latLngStr = 'LONG.:  ' + lx + '<br>LAT.:  ' + ly + '<br>';
    document.getElementById("ll").innerHTML = latLngStr;
	document.getElementById("t").innerHTML = "Current Position";
if (pstion==null){
pstion=document.createElement("div"); }
pstion.style.position="absolute";
pstion.style.fontFamily="Arial, Helvetica, sans-serif";
pstion.style.fontSize="12px";
pstion.style.color="#333333";
pstion.style.float="right";
pstion.style.borderStyle="solid";
pstion.style.borderWidth="1px";
pstion.style.backgroundColor="#ffffff";
pstion.style.marginRight="auto";
pstion.style.marginLeft="auto";
pstion.style.visibility="visible";
//.getContainer().appendChild(pstion)
pstion.innerHTML=latLngStr;
pstion.style.left=(lx+3) +"px";
pstion.style.top=(ly+3)+"px";
map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(pstion);
//map.addOverlay(pstion);
//pstion.style.left="100px";
//pstion.style.top="200px";
}

//////-- measurement
if (op=="ms")
{
//map.removeOverlay();
//map.setDraggableCursor("crosshair");
marker = new GMarker(latlng, {draggable: false});
map.addOverlay(marker);
var lx = map.fromLatLngToDivPixel(marker.getLatLng()).x;
var ly = map.fromLatLngToDivPixel(marker.getLatLng()).y;
//var latLngStr = 'Lon.:' + latlng.lng() + '<br>Lat.:' + latlng.lat() + '<br>';
lnsA.push(new GLatLng(latlng.lat(),latlng.lng()))

	if (lnsA.length > 1)	{
		lns = new GPolyline(lnsA,  "#ff0000",  2, 0.5, "geodesic");
		if (pstion==null){
pstion=document.createElement("div"); }
pstion.style.position="absolute";
pstion.style.fontFamily="Arial, Helvetica, sans-serif";
pstion.style.fontSize="12px";
pstion.style.color="#333333";
pstion.style.float="right";
pstion.style.borderStyle="solid";
pstion.style.borderWidth="1px";
pstion.style.backgroundColor="#ffffff";
pstion.style.marginRight="auto";
pstion.style.marginLeft="auto";
//.getContainer().appendChild(pstion)
document.getElementById("t").innerHTML = "Distance";
if (lns.getLength()>1609)
{
document.getElementById("ll").innerHTML = Math.round(lns.getLength())/1000+ "km<br>" + Math.round(lns.getLength()/1.609)/1000 + "mi";
pstion.innerHTML= Math.round(lns.getLength())/1000+ "km<br>" + Math.round(lns.getLength()/1.609)/1000 + "mi";
}
else
{
document.getElementById("ll").innerHTML = Math.round(lns.getLength())+ "m<br>" + Math.round(lns.getLength()/0.3048) + "ft";
pstion.innerHTML= Math.round(lns.getLength()*1000)/1000+ "m<br>" + Math.round(lns.getLength()*1000/0.3048)/1000 + "ft";
}

pstion.style.left=(lx+3) +"px";
pstion.style.top=(ly+3)+"px";
pstion.style.visibility="visible";
map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(pstion);
//map.addOverlay(pstion);
//pstion.style.left="100px";
//pstion.style.top="200px";
	}
	if (lnsA.length == 1)
	{
	document.getElementById("t").innerHTML = "Start point";
	document.getElementById("ll").innerHTML = "Lon.:" + marker.getLatLng().lng()+ "<br>Lat.: " + marker.getLatLng().lat();
	}
map.addOverlay(lns);
}
     });
      }
	  else
    {
     document.getElementById("map").innerHTML = "Sorry your browser not compatible with Google Maps" ;
    }
    }
		//function DisMeasure(){
		//var polyOptions = {geodesic:true};
        //var polyline = new GPolyline([
        //new GLatLng(26, 103.974609375),
        //new GLatLng(38.13455657705411, 113.115234375)
        //], "#ff0000", 2, 1, polyOptions);
        //map.addOverlay(polyline);
        //map.addOverlay(createLengthMarker(new GLatLng(37, 107)));
		//}

    //]]>
