GPolygon.prototype.Contains = function(point) {
  var j=0;
  var oddNodes = false;
  var x = point.lng();
  var y = point.lat();
  for (var i=0; i < this.getVertexCount(); i++) {
    j++;
    if (j == this.getVertexCount()) {j = 0;}
    if (((this.getVertex(i).lat() < y) && (this.getVertex(j).lat() >= y))
    || ((this.getVertex(j).lat() < y) && (this.getVertex(i).lat() >= y))) {
      if ( this.getVertex(i).lng() + (y - this.getVertex(i).lat())
      /  (this.getVertex(j).lat()-this.getVertex(i).lat())
      *  (this.getVertex(j).lng() - this.getVertex(i).lng())<x ) {
        oddNodes = !oddNodes
      }
    }
  }
  return oddNodes;
};
GPolygon.prototype.Area = function() {
  var a = 0;
  var j = 0;
  var b = this.Bounds();
  var x0 = b.getSouthWest().lng();
  var y0 = b.getSouthWest().lat();
  for (var i=0; i < this.getVertexCount(); i++) {
    j++;
    if (j == this.getVertexCount()) {j = 0;}
    var x1 = this.getVertex(i).distanceFrom(new GLatLng(this.getVertex(i).lat(),x0));
    var x2 = this.getVertex(j).distanceFrom(new GLatLng(this.getVertex(j).lat(),x0));
    var y1 = this.getVertex(i).distanceFrom(new GLatLng(y0,this.getVertex(i).lng()));
    var y2 = this.getVertex(j).distanceFrom(new GLatLng(y0,this.getVertex(j).lng()));
    a += x1*y2 - x2*y1;
  }
  return Math.abs(a * 0.5);
};
GPolygon.prototype.Distance = function() {
  var dist = 0;
  for (var i=1; i < this.getVertexCount(); i++) {
    dist += this.getVertex(i).distanceFrom(this.getVertex(i-1));
  }
  return dist;
};
GPolygon.prototype.Bounds = function() {
  var bounds = new GLatLngBounds();
  for (var i=0; i < this.getVertexCount(); i++) {
    bounds.extend(this.getVertex(i));
  }
  return bounds;
};
GPolygon.prototype.GetPointAtDistance = function(metres) {
  // some awkward special cases
  if (metres == 0) return this.getVertex(0);
  if (metres < 0) return null;
  var dist=0;
  var olddist=0;
  for (var i=1; (i < this.getVertexCount() && dist < metres); i++) {
    olddist = dist;
    dist += this.getVertex(i).distanceFrom(this.getVertex(i-1));
  }
  if (dist < metres) {return null;}
  var p1= this.getVertex(i-2);
  var p2= this.getVertex(i-1);
  var m = (metres-olddist)/(dist-olddist);
  return new GLatLng( p1.lat() + (p2.lat()-p1.lat())*m, p1.lng() + (p2.lng()-p1.lng())*m);
};
GPolygon.prototype.GetPointsAtDistance = function(metres) {
  var next = metres;
  var points = [];
  // some awkward special cases
  if (metres <= 0) return points;
  var dist=0;
  var olddist=0;
  for (var i=1; (i < this.getVertexCount()); i++) {
    olddist = dist;
    dist += this.getVertex(i).distanceFrom(this.getVertex(i-1));
    while (dist > next) {
      var p1= this.getVertex(i-1);
      var p2= this.getVertex(i);
      var m = (next-olddist)/(dist-olddist);
      points.push(new GLatLng( p1.lat() + (p2.lat()-p1.lat())*m, p1.lng() + (p2.lng()-p1.lng())*m));
      next += metres;    
    }
  }
  return points;
};
GPolygon.prototype.GetIndexAtDistance = function(metres) {
  // some awkward special cases
  if (metres == 0) return this.getVertex(0);
  if (metres < 0) return null;
  var dist=0;
  var olddist=0;
  for (var i=1; (i < this.getVertexCount() && dist < metres); i++) {
    olddist = dist;
    dist += this.getVertex(i).distanceFrom(this.getVertex(i-1));
  }
  if (dist < metres) {return null;}
  return i;
};
GPolygon.prototype.Bearing = function(v1,v2) {
  if (v1 == null) {
    v1 = 0;
    v2 = this.getVertexCount()-1;
  } else if (v2 ==  null) {
    v2 = v1+1;
  }
  if ((v1 < 0) || (v1 >= this.getVertexCount()) || (v2 < 0) || (v2 >= this.getVertexCount())) {
    return;
  }
  var from = this.getVertex(v1);
  var to = this.getVertex(v2);
  if (from.equals(to)) {
    return 0;
  }
  var lat1 = from.latRadians();
  var lon1 = from.lngRadians();
  var lat2 = to.latRadians();
  var lon2 = to.lngRadians();
  var angle = - Math.atan2( Math.sin( lon1 - lon2 ) * Math.cos( lat2 ), Math.cos( lat1 ) * Math.sin( lat2 ) - Math.sin( lat1 ) * Math.cos( lat2 ) * Math.cos( lon1 - lon2 ) );
  if ( angle < 0.0 ) angle  += Math.PI * 2.0;
  angle = angle * 180.0 / Math.PI;
  return parseFloat(angle.toFixed(1));
};
GPolyline.prototype.Contains             = GPolygon.prototype.Contains;
GPolyline.prototype.Area                 = GPolygon.prototype.Area;
GPolyline.prototype.Distance             = GPolygon.prototype.Distance;
GPolyline.prototype.Bounds               = GPolygon.prototype.Bounds;
GPolyline.prototype.GetPointAtDistance   = GPolygon.prototype.GetPointAtDistance;
GPolyline.prototype.GetPointsAtDistance  = GPolygon.prototype.GetPointsAtDistance;
GPolyline.prototype.GetIndexAtDistance   = GPolygon.prototype.GetIndexAtDistance;
GPolyline.prototype.Bearing              = GPolygon.prototype.Bearing;





var BlueWalkerMarker = function(){
   this.id=new Date().getTime()+"";
   this.lat ="";
   this.lng ="";
   this.title ="";
   this.desc ="";
   this.icon="/images/bmarker.gif";
   this.innerMark =null;
   this.readonly = false;
}; 
BlueWalkerMarker.prototype.getViewInfoHtml = function()
{
	var html='<div><table width="400" border="0" cellspacing="0" cellpadding="0" class="commitform">'+
	         ' <tr>'+
             '  <td width="17%"  align="right" class="bold">Title：</td>'+
             '  <td align="left">'+this.title+'</td>'+
             '</tr>'+
			 ' <tr>'+
             '  <td align="left" valign="top" class="bold">Description：</td>'+
             '  <td align="left" class="bold">'+this.desc+'</td>'+
             '</tr>'+
			 '</table></div>';
	 return html;
};
BlueWalkerMarker.prototype.getInfoHtml = function()
{
	var html='<div><table width="400" border="0" cellspacing="0" cellpadding="0" class="commitform">'+
	         ' <tr>'+
             '  <td width="17%"  align="right" class="bold">Title：</td>'+
             '  <td align="left"><input type="text" id="txtBlueTitle"  tabindex="1" size="40" value="'+ encodeURIComponent(this.title) +'" /></td>'+
             '</tr>'+
			 ' <tr>'+
             '  <td align="left" valign="top" class="bold">Description：</td>'+
             '  <td align="left" class="bold"><textarea id="txtBlueDesc"  rows="6" tabindex="8" cols="40" >'+encodeURIComponent(this.desc)+'</textarea></td>'+
             '</tr>'+
			 '<tr>'+
             '<td colspan="2" align="center">'+
			 '  <input type="button" value="Save" onclick="javascript:expatMap.SaveBlueMarker(\''+this.id+'\');" />'+
             '  <input type="button" value="Remove" onclick="javascript:expatMap.RemoveBlueMarker(\''+this.id+'\');" /></td>'+
             '</tr></table></div>';
	 return html;
};
var BlueWalkerPolyon = function(){
   this.id=new Date().getTime()+"";
   this.clat ="";
   this.clng ="";
   this.color ="#FF00FF";
   this.desc ="";
   this.points=[];
   this.opacity =0.9;
   this.title ="";
   this.innerPolyon =null;
    this.readonly = false;
}; 
BlueWalkerPolyon.prototype.getViewInfoHtml = function()
{
	var html='<div><table width="400" border="0" cellspacing="0" cellpadding="0" class="commitform">'+
	         ' <tr>'+
             '  <td width="17%"  align="right" class="bold">Title：</td>'+
             '  <td align="left">'+this.title+'</td>'+
             '</tr>'+
			 ' <tr>'+
             '  <td align="left" valign="top" class="bold">Description：</td>'+
             '  <td align="left" class="bold">'+this.desc+'</td>'+
             '</tr>'+
			 '</table></div>';
	 return html;
};
BlueWalkerPolyon.prototype.getInfoHtml = function()
{
	var html='<div><table width="400" border="0" cellspacing="0" cellpadding="0" class="commitform">'+
	         ' <tr>'+
             '  <td width="17%"  align="right" class="bold">Title：</td>'+
             '  <td align="left" ><input type="text" id="txtBluePolyTitle"  tabindex="1" size="40" value="'+ encodeURIComponent(this.title) +'" /></td>'+
             '</tr>'+
			 ' <tr>'+
             '  <td align="left" valign="top" class="bold">Description：</td>'+
             '  <td align="left" class="bold"><textarea id="txtBluePolyDesc"  rows="4" tabindex="8" cols="40" >'+encodeURIComponent(this.desc)+'</textarea></td>'+
             '</tr>'+
			 '<tr>'+
             '<td colspan="2" align="center">'+
			 '  <input type="button" value="Save" onclick="javascript:expatMap.SaveBluePolyon(\''+this.id+'\');" />'+
             '  <input type="button" value="Remove" onclick="javascript:expatMap.RemoveBluePolyon(\''+this.id+'\');" /></td>'+
             '</tr></table></div>';
	 return html;
};
var BlueWalkerPolyline = function(){
   this.id=new Date().getTime()+"";
   this.clat ="";
   this.clng ="";
   this.color ="#FF00FF";
   this.desc ="";
   this.points="";
   this.opacity =0.9;
   this.title ="";
   this.innerPolyline =null;
    this.readonly = false;
}; 
BlueWalkerPolyline.prototype.getViewInfoHtml = function()
{
	var html='<div><table width="400" border="0" cellspacing="0" cellpadding="0" class="commitform">'+
	         ' <tr>'+
             '  <td width="17%"  align="right" class="bold">Title：</td>'+
             '  <td align="left" >'+this.title+'</td>'+
             '</tr>'+
			 ' <tr>'+
             '  <td align="left" valign="top" class="bold">Description：</td>'+
             '  <td align="left" class="bold">'+this.desc+'</td>'+
             '</tr>'+
			 '</table></div>';
	 return html;
};
BlueWalkerPolyline.prototype.getInfoHtml = function()
{
	var html='<div><table width="400" border="0" cellspacing="0" cellpadding="0" class="commitform">'+
	         ' <tr>'+
             '  <td width="17%"  align="right" class="bold">Title：</td>'+
             '  <td align="left" ><input type="text" id="txtBluePolyTitle"  tabindex="1" size="40" value="'+ encodeURIComponent(this.title) +'" /></td>'+
             '</tr>'+
			 ' <tr>'+
             '  <td align="left" valign="top" class="bold">Description：</td>'+
             '  <td align="left" class="bold"><textarea id="txtBluePolyDesc"  rows="4" tabindex="8" cols="40" >'+encodeURIComponent(this.desc)+'</textarea></td>'+
             '</tr>'+
			 '<tr>'+
             '<td colspan="2" align="center">'+
			 '  <input type="button" value="Save" onclick="javascript:expatMap.SaveBluePolyline(\''+this.id+'\');" />'+
             '  <input type="button" value="Remove" onclick="javascript:expatMap.RemoveBluePolyline(\''+this.id+'\');" /></td>'+
             '</tr></table></div>';
	 return html;
}; 
function LabeledMarker(latlng, opt_opts) {
  this.opts_ = opt_opts;

  this.labelText_ = opt_opts.labelText || "";
  this.labelClass_ = opt_opts.labelClass || "LabeledMarker_markerLabel";
  this.labelOffset_ = opt_opts.labelOffset || new GSize(0, 0);

  this.clickable_ = opt_opts.clickable || true;
  this.title_ = opt_opts.title || "";
  this.labelVisibility_ = true;
  this.ownVisibility_ = true;

  this.div_ = document.createElement("div");
  this.div_.className = this.labelClass_;
  this.div_.innerHTML = this.labelText_;
  this.div_.style.position = "absolute";
  this.div_.style.cursor = "pointer";
  this.div_.title = this.title_;

  if (opt_opts.draggable) {
    opt_opts.draggable = false;
  }

  GMarker.apply(this, arguments);
};
 
LabeledMarker.prototype = new GMarker(new GLatLng(0, 0));
 
LabeledMarker.prototype.initialize = function (map) {
  // Do the GMarker constructor first.
  GMarker.prototype.initialize.apply(this, arguments);

  this.map_ = map;

  if (!this.ownVisibility_) {
    this.hide();
  }
  this.applyLabelVisibility_();
  map.getPane(G_MAP_MARKER_PANE).appendChild(this.div_);

  if (this.clickable_) {
    var eventPassthrus = ['click', 'dblclick', 'mousedown', 'mouseup',
                          'mouseover', 'mouseout'];
    for (var i = 0; i < eventPassthrus.length; i++) {
      var name = eventPassthrus[i];
      GEvent.addDomListener(this.div_, name,
                            GEvent.callback(GEvent, GEvent.trigger,
                                            this, name, this.getLatLng()));
    }
  }
};
 
LabeledMarker.prototype.redraw = function (force) {
  GMarker.prototype.redraw.apply(this, arguments);
  this.redrawLabel_();
};
 
LabeledMarker.prototype.redrawLabel_ = function () {
  var p = this.map_.fromLatLngToDivPixel(this.getLatLng());
  var z = GOverlay.getZIndex(this.getLatLng().lat());
  if(this.div_ ==null)
     return;
 
  this.div_.style.left = (p.x + this.labelOffset_.width) + "px";
  this.div_.style.top = (p.y + this.labelOffset_.height) + "px";
  this.div_.style.zIndex = z; // in front of the marker
};
 
LabeledMarker.prototype.remove = function () {
  GEvent.clearInstanceListeners(this.div_);
  if (this.div_.outerHTML) {
    this.div_.outerHTML = ""; //prevent pseudo-leak in IE
  }
  if (this.div_.parentNode) {
    this.div_.parentNode.removeChild(this.div_);
  }
  this.div_ = null;
  GMarker.prototype.remove.apply(this, arguments);
};
 
LabeledMarker.prototype.copy = function () {
  var newMarker = new LabeledMarker(this.getLatLng(), this.opts_);
  // copy visibility properties as they are not controlled by opts_
  newMarker.labelVisibility_ = this.labelVisibility_;
  newMarker.ownVisibility_ = this.ownVisibility_;
  return newMarker;
};
 
LabeledMarker.prototype.show = function () {
  GMarker.prototype.show.apply(this, arguments);
  this.ownVisibility_ = true;
  this.applyLabelVisibility_();
};
 
LabeledMarker.prototype.hide = function () {
  GMarker.prototype.hide.apply(this, arguments);
  this.ownVisibility_ = false;
  this.applyLabelVisibility_();
};
 
LabeledMarker.prototype.setLabelVisibility = function (visibility) {
  this.labelVisibility_ = visibility;
  this.applyLabelVisibility_();
};
 
LabeledMarker.prototype.getLabelVisibility = function () {
  return this.labelVisibility_;
};
 
LabeledMarker.prototype.applyLabelVisibility_ = function () {
  if ((!this.isHidden()) && this.labelVisibility_) {
    this.div_.style.display = 'block';
  } else {
    this.div_.style.display = 'none';
  }
};
 
LabeledMarker.prototype.setLabelText = function (text) {
  this.labelText_ = text;
  this.div_.innerHTML = text;
  this.opts_.labelText = text;
};
function ELabel(point, html, classname, pixelOffset, percentOpacity,overlap,openmarkfun,overmarkerfun)
{
    this.point = point;
    this.html = html;

    // Optional parameters
    this.classname = classname || "";
    this.pixelOffset = pixelOffset || new GSize(0, 0);
    if (percentOpacity) {
        if (percentOpacity < 0) { percentOpacity = 0; }
        if (percentOpacity > 100) { percentOpacity = 100; }
    }
    this.percentOpacity = percentOpacity;
    this.overlap = overlap || false;
    this.hidden = false;
	this.openmarkfun = openmarkfun|| "";
	this.overmarkerfun = overmarkerfun|| "";
	
	this.div_ = document.createElement("div");
    this.div_.style.position = "absolute";
	this.div_.style.cursor='default';
    this.div_.innerHTML = '<div id="lablediv" class="' + this.classname + '" >' + this.html + '</div>';
};

ELabel.prototype = new GOverlay();
ELabel.prototype.initialize = function(map) 
{
    map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(this.div_);
    this.map_ = map;
    if (this.percentOpacity) {
        if (typeof (this.div_.style.filter) == 'string') { this.div_.style.filter = 'alpha(opacity:' + this.percentOpacity + ')'; }
        if (typeof (this.div_.style.KHTMLOpacity) == 'string') { this.div_.style.KHTMLOpacity = this.percentOpacity / 100; }
        if (typeof (this.div_.style.MozOpacity) == 'string') { this.div_.style.MozOpacity = this.percentOpacity / 100; }
        if (typeof (this.div_.style.opacity) == 'string') { this.div_.style.opacity = this.percentOpacity / 100; }
    }
    if (this.overlap) {
        var z = GOverlay.getZIndex(this.point.lat());
        this.div_.style.zIndex = z;
    }
    if (this.hidden) {
        this.hide();
    }
};
 
ELabel.prototype.remove = function() {
	if (this.div_.parentNode) {
		this.div_.parentNode.removeChild(this.div_);
	}
};

ELabel.prototype.copy = function() {
    return new ELabel(this.point, this.html, this.classname, this.pixelOffset, this.percentOpacity, this.overlap);
};

ELabel.prototype.redraw = function(force) {
    var p = this.map_.fromLatLngToDivPixel(this.point);
    var h = parseInt(this.div_.clientHeight);
    this.div_.style.left = (p.x + this.pixelOffset.width) + "px";
    this.div_.style.top = (p.y + this.pixelOffset.height - h) + "px";
};

ELabel.prototype.show = function() {
    if (this.div_) {
        this.div_.style.display = "";
        this.redraw();
    }
    this.hidden = false;
};

ELabel.prototype.hide = function() {
    if (this.div_) {
        this.div_.style.display = "none";
    }
    this.hidden = true;
};

ELabel.prototype.isHidden = function() {
    return this.hidden;
};

ELabel.prototype.supportsHide = function() {
    return true;
};

ELabel.prototype.setContents = function(html) {
    this.html = html;
    this.div_.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>';
    this.redraw(true);
};

ELabel.prototype.setPoint = function(point) {
    this.point = point;
    if (this.overlap) {
        var z = GOverlay.getZIndex(this.point.lat());
        this.div_.style.zIndex = z;
    }
    this.redraw(true);
};

ELabel.prototype.setOpacity = function(percentOpacity) {
    if (percentOpacity) {
        if (percentOpacity < 0) { percentOpacity = 0; }
        if (percentOpacity > 100) { percentOpacity = 100; }
    }
    this.percentOpacity = percentOpacity;
    if (this.percentOpacity) {
        if (typeof (this.div_.style.filter) == 'string') { this.div_.style.filter = 'alpha(opacity:' + this.percentOpacity + ')'; }
        if (typeof (this.div_.style.KHTMLOpacity) == 'string') { this.div_.style.KHTMLOpacity = this.percentOpacity / 100; }
        if (typeof (this.div_.style.MozOpacity) == 'string') { this.div_.style.MozOpacity = this.percentOpacity / 100; }
        if (typeof (this.div_.style.opacity) == 'string') { this.div_.style.opacity = this.percentOpacity / 100; }
    }
};

ELabel.prototype.getPoint = function() {
    return this.point;
};function MarkerManager(map, opt_opts) {
  var me = this;
  me.map_ = map;
  me.mapZoom_ = map.getZoom();
  me.projection_ = map.getCurrentMapType().getProjection();

  opt_opts = opt_opts || {};
  me.tileSize_ = MarkerManager.DEFAULT_TILE_SIZE_;

  var mapTypes = map.getMapTypes();
  var mapMaxZoom = mapTypes[0].getMaximumResolution();
  for (var i = 0; i < mapTypes.length; i++) {
    var mapTypeMaxZoom = mapTypes[i].getMaximumResolution();
    if (mapTypeMaxZoom > mapMaxZoom) {
      mapMaxZoom = mapTypeMaxZoom;
    }
  }
  me.maxZoom_  = opt_opts.maxZoom || mapMaxZoom;

  me.trackMarkers_ = opt_opts.trackMarkers;
  me.show_ = opt_opts.show || true;

  var padding;
  if (typeof opt_opts.borderPadding === "number") {
    padding = opt_opts.borderPadding;
  } else {
    padding = MarkerManager.DEFAULT_BORDER_PADDING_;
  }
  // The padding in pixels beyond the viewport, where we will pre-load markers.
  me.swPadding_ = new GSize(-padding, padding);
  me.nePadding_ = new GSize(padding, -padding);
  me.borderPadding_ = padding;

  me.gridWidth_ = [];

  me.grid_ = [];
  me.grid_[me.maxZoom_] = [];
  me.numMarkers_ = [];
  me.numMarkers_[me.maxZoom_] = 0;

  GEvent.bind(map, "moveend", me, me.onMapMoveEnd_);

  // NOTE: These two closures provide easy access to the map.
  // They are used as callbacks, not as methods.
  me.removeOverlay_ = function (marker) {
    map.removeOverlay(marker);
    me.shownMarkers_--;
  };
  me.addOverlay_ = function (marker) {
    if (me.show_) {
	  map.addOverlay(marker);
      me.shownMarkers_++;
    }
  };

  me.resetManager_();
  me.shownMarkers_ = 0;

  me.shownBounds_ = me.getMapGridBounds_();
};

// Static constants:
MarkerManager.DEFAULT_TILE_SIZE_ = 1024;
MarkerManager.DEFAULT_BORDER_PADDING_ = 100;
MarkerManager.MERCATOR_ZOOM_LEVEL_ZERO_RANGE = 256;

 
MarkerManager.prototype.resetManager_ = function () {
  var me = this;
  var mapWidth = MarkerManager.MERCATOR_ZOOM_LEVEL_ZERO_RANGE;
  for (var zoom = 0; zoom <= me.maxZoom_; ++zoom) {
    me.grid_[zoom] = [];
    me.numMarkers_[zoom] = 0;
    me.gridWidth_[zoom] = Math.ceil(mapWidth / me.tileSize_);
    mapWidth <<= 1;
  }
};
 
MarkerManager.prototype.clearMarkers = function () {
  var me = this;
  me.processAll_(me.shownBounds_, me.removeOverlay_);
  me.resetManager_();
};
 
MarkerManager.prototype.getTilePoint_ = function (latlng, zoom, padding) {
  var pixelPoint = this.projection_.fromLatLngToPixel(latlng, zoom);
  return new GPoint(
      Math.floor((pixelPoint.x + padding.width) / this.tileSize_),
      Math.floor((pixelPoint.y + padding.height) / this.tileSize_));
};
 
MarkerManager.prototype.addMarkerBatch_ = function (marker, minZoom, maxZoom) {
  var mPoint = marker.getPoint();
  marker.MarkerManager_minZoom = minZoom;
  // Tracking markers is expensive, so we do this only if the
  // user explicitly requested it when creating marker manager.
  if (this.trackMarkers_) {
    GEvent.bind(marker, "changed", this, this.onMarkerMoved_);
  }

  var gridPoint = this.getTilePoint_(mPoint, maxZoom, GSize.ZERO);

  for (var zoom = maxZoom; zoom >= minZoom; zoom--) {
    var cell = this.getGridCellCreate_(gridPoint.x, gridPoint.y, zoom);
    cell.push(marker);

    gridPoint.x = gridPoint.x >> 1;
    gridPoint.y = gridPoint.y >> 1;
  }
};
 
MarkerManager.prototype.isGridPointVisible_ = function (point) {
  var me = this;
  var vertical = me.shownBounds_.minY <= point.y &&
      point.y <= me.shownBounds_.maxY;
  var minX = me.shownBounds_.minX;
  var horizontal = minX <= point.x && point.x <= me.shownBounds_.maxX;
  if (!horizontal && minX < 0) {
    // Shifts the negative part of the rectangle. As point.x is always less
    // than grid width, only test shifted minX .. 0 part of the shown bounds.
    var width = me.gridWidth_[me.shownBounds_.z];
    horizontal = minX + width <= point.x && point.x <= width - 1;
  }
  return vertical && horizontal;
};
 
MarkerManager.prototype.onMarkerMoved_ = function (marker, oldPoint, newPoint) {
  // NOTE: We do not know the minimum or maximum zoom the marker was
  // added at, so we start at the absolute maximum. Whenever we successfully
  // remove a marker at a given zoom, we add it at the new grid coordinates.
  var me = this;
  var zoom = me.maxZoom_;
  var changed = false;
  var oldGrid = me.getTilePoint_(oldPoint, zoom, GSize.ZERO);
  var newGrid = me.getTilePoint_(newPoint, zoom, GSize.ZERO);
  while (zoom >= 0 && (oldGrid.x !== newGrid.x || oldGrid.y !== newGrid.y)) {
    var cell = me.getGridCellNoCreate_(oldGrid.x, oldGrid.y, zoom);
    if (cell) {
      if (me.removeFromArray_(cell, marker)) {
        me.getGridCellCreate_(newGrid.x, newGrid.y, zoom).push(marker);
      }
    }
    // For the current zoom we also need to update the map. Markers that no
    // longer are visible are removed from the map. Markers that moved into
    // the shown bounds are added to the map. This also lets us keep the count
    // of visible markers up to date.
    if (zoom === me.mapZoom_) {
      if (me.isGridPointVisible_(oldGrid)) {
        if (!me.isGridPointVisible_(newGrid)) {
          me.removeOverlay_(marker);
          changed = true;
        }
      } else {
        if (me.isGridPointVisible_(newGrid)) {
          me.addOverlay_(marker);
          changed = true;
        }
      }
    }
    oldGrid.x = oldGrid.x >> 1;
    oldGrid.y = oldGrid.y >> 1;
    newGrid.x = newGrid.x >> 1;
    newGrid.y = newGrid.y >> 1;
    --zoom;
  }
  if (changed) {
    me.notifyListeners_();
  }
};
 
MarkerManager.prototype.removeMarker = function (marker) {
  var me = this;
  var zoom = me.maxZoom_;
  var changed = false;
  var point = marker.getPoint();
  var grid = me.getTilePoint_(point, zoom, GSize.ZERO);
  while (zoom >= 0) {
    var cell = me.getGridCellNoCreate_(grid.x, grid.y, zoom);

    if (cell) {
      me.removeFromArray_(cell, marker);
    }
    // For the current zoom we also need to update the map. Markers that no
    // longer are visible are removed from the map. This also lets us keep the count
    // of visible markers up to date.
    if (zoom === me.mapZoom_) {
      if (me.isGridPointVisible_(grid)) {
        me.removeOverlay_(marker);
        changed = true;
      }
    }
    grid.x = grid.x >> 1;
    grid.y = grid.y >> 1;
    --zoom;
  }
  if (changed) {
    me.notifyListeners_();
  }
  me.numMarkers_[marker.MarkerManager_minZoom]--;
};
 
MarkerManager.prototype.addMarkers = function (markers, minZoom, opt_maxZoom) {
  var maxZoom = this.getOptMaxZoom_(opt_maxZoom);
  for (var i = markers.length - 1; i >= 0; i--) {
    this.addMarkerBatch_(markers[i], minZoom, maxZoom);
  }

  this.numMarkers_[minZoom] += markers.length;
};
 
MarkerManager.prototype.getOptMaxZoom_ = function (opt_maxZoom) {
  return opt_maxZoom || this.maxZoom_;
};
 
MarkerManager.prototype.getMarkerCount = function (zoom) {
  var total = 0;
  for (var z = 0; z <= zoom; z++) {
    total += this.numMarkers_[z];
  }
  return total;
};

 
MarkerManager.prototype.getMarker = function(lat, lng, zoom) { 
  var me = this; 
  var mPoint = new GLatLng(lat, lng); 
  var gridPoint = me.getTilePoint_(mPoint, zoom, GSize.ZERO); 

  var marker = new GMarker(mPoint); 
  var cellArray = me.getGridCellNoCreate_(gridPoint.x, gridPoint.y, zoom); 
  if(cellArray != undefined){ 
    for (var i = 0; i < cellArray.length; i++) 
    { 
      if(lat == cellArray[i].getLatLng().lat() && 
         lng == cellArray[i].getLatLng().lng()) 
      { 
        marker = cellArray[i]; 
      } 
    } 
  } 
  return marker; 
}; 
 
MarkerManager.prototype.addMarker = function (marker, minZoom, opt_maxZoom) {
  var me = this;
  var maxZoom = this.getOptMaxZoom_(opt_maxZoom);
  me.addMarkerBatch_(marker, minZoom, maxZoom);
  var gridPoint = me.getTilePoint_(marker.getPoint(), me.mapZoom_, GSize.ZERO);
  if (me.isGridPointVisible_(gridPoint) &&
      minZoom <= me.shownBounds_.z &&
      me.shownBounds_.z <= maxZoom) {
    me.addOverlay_(marker);
    me.notifyListeners_();
  }
  this.numMarkers_[minZoom]++;
};
 
GBounds.prototype.containsPoint = function (point) {
  var outer = this;
  return (outer.minX <= point.x &&
          outer.maxX >= point.x &&
          outer.minY <= point.y &&
          outer.maxY >= point.y);
};
 
MarkerManager.prototype.getGridCellCreate_ = function (x, y, z) {
  var grid = this.grid_[z];
  if (x < 0) {
    x += this.gridWidth_[z];
  }
  var gridCol = grid[x];
  if (!gridCol) {
    gridCol = grid[x] = [];
    return (gridCol[y] = []);
  }
  var gridCell = gridCol[y];
  if (!gridCell) {
    return (gridCol[y] = []);
  }
  return gridCell;
};
 
MarkerManager.prototype.getGridCellNoCreate_ = function (x, y, z) {
  var grid = this.grid_[z];
  if (x < 0) {
    x += this.gridWidth_[z];
  }
  var gridCol = grid[x];
  return gridCol ? gridCol[y] : undefined;
};
 
MarkerManager.prototype.getGridBounds_ = function (bounds, zoom, swPadding, nePadding) {
  zoom = Math.min(zoom, this.maxZoom_);

  var bl = bounds.getSouthWest();
  var tr = bounds.getNorthEast();
  var sw = this.getTilePoint_(bl, zoom, swPadding);
  var ne = this.getTilePoint_(tr, zoom, nePadding);
  var gw = this.gridWidth_[zoom];

  // Crossing the prime meridian requires correction of bounds.
  if (tr.lng() < bl.lng() || ne.x < sw.x) {
    sw.x -= gw;
  }
  if (ne.x - sw.x  + 1 >= gw) {
    // Computed grid bounds are larger than the world; truncate.
    sw.x = 0;
    ne.x = gw - 1;
  }
  var gridBounds = new GBounds([sw, ne]);
  gridBounds.z = zoom;
  return gridBounds;
};
 
MarkerManager.prototype.getMapGridBounds_ = function () {
  var me = this;
  return me.getGridBounds_(me.map_.getBounds(), me.mapZoom_, me.swPadding_, me.nePadding_);
};
 
MarkerManager.prototype.onMapMoveEnd_ = function () {
  var me = this;
  me.objectSetTimeout_(this, this.updateMarkers_, 0);
};
 
MarkerManager.prototype.objectSetTimeout_ = function (object, command, milliseconds) {
  return window.setTimeout(function () {
    command.call(object);
  }, milliseconds);
};

 
MarkerManager.prototype.visible = function () {
  return this.show_ ? true : false;
};
 
MarkerManager.prototype.isHidden = function () {
  return !this.show_;
};
 
MarkerManager.prototype.show = function () {
  this.show_ = true;
  this.refresh();
};
 
MarkerManager.prototype.hide = function () {
  this.show_ = false;
  this.refresh();
};
 
MarkerManager.prototype.toggle = function () {
  this.show_ = !this.show_;
  this.refresh();
};

 
MarkerManager.prototype.refresh = function () {
  var me = this;
  if (me.shownMarkers_ > 0) {
    me.processAll_(me.shownBounds_, me.removeOverlay_);
  }
  // An extra check on me.show_ to increase performance (no need to processAll_)
  if (me.show_) {
    me.processAll_(me.shownBounds_, me.addOverlay_);
  }
  me.notifyListeners_();
};
 
MarkerManager.prototype.updateMarkers_ = function () {
  var me = this;
  me.mapZoom_ = this.map_.getZoom();
  var newBounds = me.getMapGridBounds_();

  // If the move does not include new grid sections,
  // we have no work to do:
  if (newBounds.equals(me.shownBounds_) && newBounds.z === me.shownBounds_.z) {
    return;
  }

  if (newBounds.z !== me.shownBounds_.z) {
    me.processAll_(me.shownBounds_, me.removeOverlay_);
    if (me.show_) { // performance
      me.processAll_(newBounds, me.addOverlay_);
    }
  } else {
    // Remove markers:
    me.rectangleDiff_(me.shownBounds_, newBounds, me.removeCellMarkers_);

    // Add markers:
    if (me.show_) { // performance
      me.rectangleDiff_(newBounds, me.shownBounds_, me.addCellMarkers_);
    }
  }
  me.shownBounds_ = newBounds;

  me.notifyListeners_();
};

 
MarkerManager.prototype.notifyListeners_ = function () {
  GEvent.trigger(this, "changed", this.shownBounds_, this.shownMarkers_);
};
 
MarkerManager.prototype.processAll_ = function (bounds, callback) {
  for (var x = bounds.minX; x <= bounds.maxX; x++) {
    for (var y = bounds.minY; y <= bounds.maxY; y++) {
      this.processCellMarkers_(x, y,  bounds.z, callback);
    }
  }
};
 
MarkerManager.prototype.processCellMarkers_ = function (x, y, z, callback) {
  var cell = this.getGridCellNoCreate_(x, y, z);
  if (cell) {
    for (var i = cell.length - 1; i >= 0; i--) {
      callback(cell[i]);
    }
  }
};
 
MarkerManager.prototype.removeCellMarkers_ = function (x, y, z) {
  this.processCellMarkers_(x, y, z, this.removeOverlay_);
};
 
MarkerManager.prototype.addCellMarkers_ = function (x, y, z) {
  this.processCellMarkers_(x, y, z, this.addOverlay_);
};
 
MarkerManager.prototype.rectangleDiff_ = function (bounds1, bounds2, callback) {
  var me = this;
  me.rectangleDiffCoords_(bounds1, bounds2, function (x, y) {
    callback.apply(me, [x, y, bounds1.z]);
  });
};
 
MarkerManager.prototype.rectangleDiffCoords_ = function (bounds1, bounds2, callback) {
  var minX1 = bounds1.minX;
  var minY1 = bounds1.minY;
  var maxX1 = bounds1.maxX;
  var maxY1 = bounds1.maxY;
  var minX2 = bounds2.minX;
  var minY2 = bounds2.minY;
  var maxX2 = bounds2.maxX;
  var maxY2 = bounds2.maxY;

  var x, y;
  for (x = minX1; x <= maxX1; x++) {  // All x in R1
    // All above:
    for (y = minY1; y <= maxY1 && y < minY2; y++) {  // y in R1 above R2
      callback(x, y);
    }
    // All below:
    for (y = Math.max(maxY2 + 1, minY1);  // y in R1 below R2
         y <= maxY1; y++) {
      callback(x, y);
    }
  }

  for (y = Math.max(minY1, minY2);
       y <= Math.min(maxY1, maxY2); y++) {  // All y in R2 and in R1
    // Strictly left:
    for (x = Math.min(maxX1 + 1, minX2) - 1;
         x >= minX1; x--) {  // x in R1 left of R2
      callback(x, y);
    }
    // Strictly right:
    for (x = Math.max(minX1, maxX2 + 1);  // x in R1 right of R2
         x <= maxX1; x++) {
      callback(x, y);
    }
  }
};
 
MarkerManager.prototype.removeFromArray_ = function (array, value, opt_notype) {
  var shift = 0;
  for (var i = 0; i < array.length; ++i) {
    if (array[i] === value || (opt_notype && array[i] === value)) {
      array.splice(i--, 1);
      shift++;
    }
  }
  return shift;
};
var resizeFlag = false;
var loadDefault = true;

var ExpatMap = function(mapDivId) {
    this.map = null;
    this.markMgr = null;
    this.toolBar = new ExpatMapToolbar();
    this.allowedBounds = new GLatLngBounds(new GLatLng(30.5, 120.5), new GLatLng(32.0, 122.5));
    this.mapCenterLang = new GLatLng(31.224353100000,121.475915900000);

    this.polyLineArray = [];
    this.stopLocalArray = [];
    this.buspathArray = [];
	this.buspathIDArray = [];
    this.suggestAddrArray = [];
	this.sharpArray=[];

    this.currentPanel = "";
    //
    this.calLable = null;
    this.startCalPoint = null;
    this.lineTipLabel = null;

    this.centerSearchMarker = null;
    ///////////////////////
    this.invisibleIcon = null;
    this.lableStart = null;
    this.lableEnd = null;
	this.errorLable=null;
	
	 this.lableSearch = null;

    this.canResize = true;
    this.standerMarker = null;

    this.startMarker = null;
    this.endMarker = null;
	this.startMarkerId=null;
	this.endMarkerId =null;
	
    this.mapDivId = mapDivId;
    if (this.mapDivId == null || this.mapDivId == '') {
        this.mapDivId = 'mapDiv'
     }
    this.scaleControl = true;
	this.mapType = true;
	this.view = true;
	this.largMap = true;
	this.simplScale = false;
	
	this.needToolBar = true;
	this.simpleBar = false;
	
	this.viewHDivArray =["#header","#footer"];
	this.pageBarHeight = 60;
    this.fixWidth = -1;
	this.fixHeigh =-1;
	this.viewWDivArray =["#mapResult","#midBar","5"];
	
	this.logLable =null;
	this.toolBarPanel = null;
	this.errorLable =null;
	this.loadLable = null;
	
	this.toobarUrl ="/ToolBar.aspx";
	
	this.initalized = false;
};
ExpatMap.prototype.Init = function() {
    var mapDom = document.getElementById(this.mapDivId);
    if (mapDom == null)	{this.initalized=true;return;}

    this.map = new GMap2(mapDom, { googleBarOptions: { showOnLoad: false} });
    if (inLocal == null || inLocal == true) {
        G_NORMAL_MAP.getTileLayers()[0].getTileUrl = function(title, zoom) { return "/Handler/MapServer.ashx?type=map&x=" + title.x + "&y=" + title.y + "&zoom=" + zoom; }
    }
    this.map.setCenter(this.mapCenterLang,13);
    this.map.setMapType(G_NORMAL_MAP);

    if (this.mapType != false) {
        var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 30));
        this.map.addControl(new GHierarchicalMapTypeControl(), topRight);
    }
    if (this.view != false) {
        this.map.addControl(new GOverviewMapControl(new GSize(100, 100)));
    }
    if (this.largMap != false) {
        var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 30));
        var optsZomm = {
            zoomInBtnTitle: "Zoom In",
            zoomOutBtnTitle: "Zoom Out",
            moveNorthBtnTitle: "Move To North",
            moveSouthBtnTitle: "Move To South",
            moveEastBtnTitle: "Move To East",
            moveWestBtnTitle: "Move To West",
            homeBtnTitle: "Center"
        };
        var extLargeMapControl = new ExtLargeMapControl(optsZomm);
        this.map.addControl(extLargeMapControl, topLeft);
    }
    else {
        if (this.simplScale == true) {
            var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 30));
            var optsZomm = { type: "small" };
            var samllMapControl = new ExtLargeMapControl(optsZomm);
            this.map.addControl(samllMapControl, topLeft);
        }
    }
    logoContorl = new MapIcLogoControl();
    this.map.addControl(logoContorl, new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(50, 5)));
    logoContorl.setContent("<a href='http://www.icexpat.com' target='_blank' ><img src='/images/logo.png'></a>");

    this.loadLable = new MapLoadControl();
    this.map.addControl(this.loadLable, new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0)));
    this.loadLable.hide();

    this.map.enableScrollWheelZoom();

    this.AttachEvent("click", function f(overlayObj, latlngObj) { MapEvent.MapClickEvent(overlayObj, latlngObj); });
    this.AttachEvent("singlerightclick", function f(overlayObj, latlngObj) { MapEvent.MapRClickEvent(overlayObj, latlngObj); });
    this.AttachEvent("mousemove", function f(latlngObj) { MapEvent.MoveOnMapEvent(latlngObj); });
    this.AttachEvent("dblclick", function f(overlayObj, latlngObj) { MapEvent.MapDoubleClick(overlayObj, latlngObj); });
    this.AttachEvent("zoomend", function f(oldLevel, newLevel) { MapEvent.MapZoomEvent(oldLevel, newLevel); });
    this.AttachEvent("moveend", function f() { MapEvent.MapMoveendEvent(); });
    this.AttachEvent("dragend", function f() { MapEvent.MapDragendEvent(); });

    this.invisibleIcon = new GIcon(G_DEFAULT_ICON, "/images/markerTransparent.png");
    this.invisibleIcon.shadow = null;
    this.invisibleIcon.iconSize = new GSize(40, 40);

    this.markMgr = new ExpatMarkerMgr(this.map);

    $.ajaxSetup({ cache: false });
    this.canResize = true;

    this.standerMarker = null;
    this.startMarker = null;
    this.endMarker = null;
    this.ShowToolbarPanel();
	
	this.initalized =true;
	this.Resize();
};

ExpatMap.prototype.SetAllowWheel = function(allow){
	if(typeof allow !="undefined" && allow == false){ this.map.disableScrollWheelZoom();}
	else{this.map.enableScrollWheelZoom();}
};
ExpatMap.prototype.ShowToolbarPanel = function()
{
	 if(this.needToolBar==false)
	    return;
	 if (this.toolBarPanel == null) {
	 	var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
	 	this.toolBarPanel = new MapToolBarControl();
	 	this.map.addControl(this.toolBarPanel, topLeft);
		this.toolBarPanel.setContentAjax(this.toobarUrl,{'simple': this.simpleBar,'rand':Math.random()*10000},
		    function(){expatMap.toolBarPanel.setWidth(this.GetMapCanvasWidth());});
	 }
	 else {
	 	this.toolBarPanel.setWidth(this.GetMapCanvasWidth()-6);
	 }
};
ExpatMap.prototype.SearchAddressInGoogle = function(key){
	 $.getJSON("/Handler/ExpatMap.ashx",
	  {action:'gmapSearch','key':key},
	   function(resultData){
	   	 expatMap.CleanMap();
	 	 if(resultData==null){ alert("no data");return;}
		 if(resultData.status ==-1){ alert("error." + resultData.error);return;}
		 if(resultData.result.length==0){ alert("no data");return;}
		 for(var i=0;i<resultData.result.length;i++)
		 {
		 	if (i == 0) {
				expatMap.ShowStanderMarker("txtLat","txtLng",resultData.result[i].lat,resultData.result[i].lng);
			}
			else {
				expatMap.AddMarker(resultData.result[i]);
			}
		 }
		 expatMap.GetBestView(resultData.result); 
      });
};
ExpatMap.prototype.ShowLogLable=function(content)
{
	 if(this.logLable==null)
	 {
	 	var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(80,20));
	 	this.logLable =new MapLogControl();
		this.map.addControl(this.logLable,topLeft);
	 }
	 this.logLable.setContent(content);
};
ExpatMap.prototype.ShowError = function(errorInfo)
 {
 	if (errorInfo == null || errorInfo == '') {
	    if(this.errorLable != null)
		   this.errorLable.hide();
		return;
	}
 	var center = this.map.getCenter();
	if (this.errorLable == null) {
		this.errorLable = this.CreateLable(errorInfo, center.lat(), center.lng(), "errorLable", null, 80);
	}
	this.errorLable.show();
 };
 
ExpatMap.prototype.ShowStanderMarker = function(latElementId,lngElementId,lat,lng){
	 this.HideStanderMarker();
	 var xlat = $('#'+latElementId).val();
	 var xlng = $('#'+lngElementId).val();
	 var markIcon =new GIcon(G_DEFAULT_ICON, "/images/smarkerss.gif");
     markIcon.iconSize=new GSize(31,31);
     markIcon.shadow =null;
	 
	 $('#'+latElementId).val(lat);
	 $('#'+lngElementId).val(lng);
	 
	 if(lat !=null && lng !=null && lat>0 && lng >0)
	 {
	 	 var point = new GLatLng(lat,lng);
		   this.standerMarker = new GMarker(point , {
		 		icon: markIcon,
		 		draggable: true
		 	});
	 }
	 else  
	 {
		 xlat = parseFloat(xlat);
		 xlng = parseFloat(xlng);
		 var centLatLng = null;
		 if(isNaN(xlat) ||isNaN(xlng) || xlat<0.01 || xlng <0.01)
		 {
		 	 centLatLng = this.map.getCenter();
		 }
		 else 
		 {
		 	centLatLng =  new GLatLng(xlat,xlng);
		 }
	 	 this.standerMarker = new GMarker(centLatLng, {
	 		icon: markIcon,
	 		draggable: true
	 	});
	 }
	 
	 GEvent.addListener( this.standerMarker, "dragstart", function() {
	      expatMap.map.closeInfoWindow();
	 });
	
	 GEvent.addListener( this.standerMarker, "dragend", function() {
	 	 var latlng =expatMap.standerMarker.getLatLng();
		
	     $('#'+latElementId).val(latlng.lat());
		 $('#'+lngElementId).val(latlng.lng());
	 });
	 this.AddOverLayer(this.standerMarker);
	 this.SetCenter(this.standerMarker.getLatLng().lat(),this.standerMarker.getLatLng().lng());
	 this.standerMarker.openInfoWindowHtml("Drag the icon to adjust location.");
};

ExpatMap.prototype.HideStanderMarker = function(){
    this.markMgr.ClearMarkers();
    if(this.standerMarker)
	{
		this.RemoveOverLayer(this.standerMarker);
		this.standerMarker =null;
	}
};
ExpatMap.prototype.GetBestView = function(markArray) 
{
	if(markArray==null || markArray.length==0)
	{
		return;
	}
	if(markArray.length==1)
	{
		this.SetCenter(markArray[0].lat,markArray[0].lng);
		return;
	}
     var bounds = new GLatLngBounds();
	 var hasMarker = false;
     for (var i=0; i < markArray.length; i++) 
	 {
	 	if(markArray[i].lat <0.001 || markArray[i].lng<0.001)
		  continue;
       bounds.extend(new GLatLng(markArray[i].lat,markArray[i].lng));
	   hasMarker = true;
     }
	 if(hasMarker==false)
	   return;
	 var clatlng = bounds.getCenter();
	 this.SetCenter(clatlng.lat(),clatlng.lng());
	 this.AdjustView(bounds);
};

ExpatMap.prototype.AdjustView = function(objBounder)
{
	var zoomVal = this.map.getZoom();
	var mapBound = this.map.getBounds();
	if (mapBound.containsBounds(objBounder)) 
	{ 
	   return;
	}
	this.map.setZoom(17);
	while (true) {
		mapBound = this.map.getBounds();
		if (mapBound.containsBounds(objBounder)) 
		{
			break;
		}
		this.map.zoomOut();
		if (this.map.getZoom() < 10) 
			break;
	}
};
//////////////////////////////Map Function/////////////////////////////////
ExpatMap.prototype.SetCursor = function(cursorName) 
{
    $('#mapDiv').css("cursor", cursorName);
};

ExpatMap.prototype.PrepareDrawline = function(){
	this.polyLineArray = [];
	this.calLable = null;	
    this.startCalPoint = null;
	this.lineTipLabel = null;
	if (this.lineTipLabel) 
    {
        this.map.removeOverlay(this.lineTipLabel);
    }
};
ExpatMap.prototype.Reset = function() 
{
    this.SetCursor('default');
    $("#divInfo").text("");
	
	$("#clng").val('');
	$("#clat").val('');
 
    if (this.lineTipLabel) 
    {
        this.map.removeOverlay(this.lineTipLabel);
    }
	$('#txtStartStop').val('');
    $('#startlat').val('');
    $('#startlng').val('');
	$('#txtEndStop').val('');
	$('#endlat').val('');
	$('#endlng').val('');
	
	if (this.markMgr != null) {
		this.markMgr.ClearMarkers();
	}
	this.polyLineArray = [];
	this.sharpArray =[];
     
    this.stopLocalArray = [];
	this.buspathArray = [];
	this.buspathIDArray = [];
	this.suggestAddrArray=[];

    this.calLable = null;	
    this.startCalPoint = null;
	this.lineTipLabel = null;
 
    this.centerSearchMarker=null;
	if (this.map != null) {
		this.map.clearOverlays();
		this.EnableDragging();
	}
};
ExpatMap.prototype.DisableDragging = function(ployLine) {
    this.map.disableDragging();
};
ExpatMap.prototype.EnableDragging = function(ployLine) {
    this.map.enableDragging();
};
ExpatMap.prototype.SetCenter = function(lat, lng) {
     this.map.setCenter(new GLatLng(lat, lng));
};
ExpatMap.prototype.ZoomIn = function() {
    var zoom = this.map.getZoom();
	this.map.zoomIn();
	
};
ExpatMap.prototype.ZoomOut = function() {
    var zoom = this.map.getZoom();
	if(zoom >0)
	  this.map.zoomOut();
};
  
ExpatMap.prototype.SetZoom = function(zoom){
	expatMap.map.setZoom(zoom);
};

ExpatMap.prototype.ZoomHere = function(lat,lng) {
    var zoom = this.map.getZoom();
	if(zoom >16)
	   return;
	this.map.setZoom(16);
    this.SetCenter(lat,lng);
};
ExpatMap.prototype.AttachEvent = function(eName, fName) {
    GEvent.addListener(this.map, eName, fName);
};
function getTotalHeight(){
	  if(expatMap.fixHeigh != -1)
	     return expatMap.fixHeigh;
	if($.browser.msie){ return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight : document.body.clientHeight;}
	else{ return self.innerHeight;}
};
function getTotalWidth (){
	  if(expatMap.fixWidth != -1)
	     return expatMap.fixWidth;
	  if($.browser.msie){return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth : document.body.clientWidth;}
	  else{ return self.innerWidth; }
};
ExpatMap.prototype.GetMapCanvasHeight = function(){
	var fullHeight=getTotalHeight();
	for(var i=0;i< this.viewHDivArray.length;i++)
	{
		var div =this.viewHDivArray[i];
		if (div.charAt(0) != '#') {
		   var intV = parseInt(div);
		   if(!isNaN(intV)) {
		    if(intV>0)
			  fullHeight -= intV; 
			else
			  fullHeight += Math.abs(intV); 
          }
		}
		else {if ($(div).css('display') == "none") {continue;}
			var divHeight= $(div).height();
			//alert(div+":" +divWidth)
		    fullHeight-=divHeight;
		}
	}
	if ($.browser.msie) {  return fullHeight-5;}
	else {return fullHeight;}
};

ExpatMap.prototype.GetMapCanvasWidth = function(){ 
	var fullWitdth =getTotalWidth(); 
	for(var i=0;i< this.viewWDivArray.length;i++)
	{
		var div =this.viewWDivArray[i];
		if (div.charAt(0) != '#') {
		   var intV = parseInt(div);
		   if(!isNaN(intV)){
		   	if(intV>0)
			  fullWitdth -= intV; 
			else
			  fullWitdth += Math.abs(intV); 
			}
		}
		else {if ($(div).css('display') == "none") {continue;}
			var divWidth = $(div).width();
			//alert(div+":" +divWidth)
			fullWitdth -= divWidth;
		}
	}
	if ($.browser.msie) {return fullWitdth;	}
	else {return fullWitdth;}
};

ExpatMap.prototype.Resize = function(){
	if(this.map==null)
	   return;
    if(resizeFlag==true )
	   return;
	var center = this.map.getCenter();
	resizeFlag = true;
	var height=this.GetMapCanvasHeight();
	var witdth=this.GetMapCanvasWidth();
	 
	height = height<150?150:height;
	witdth = witdth<100?100:witdth;
    	
	$('#mapTable').height(height);
    $('#'+this.mapDivId).height(height+5);
	$('#'+this.mapDivId).width(witdth+5);

	if($('#fixed').height() )
	{
	   var scrollheigh =height-$('#fixed').height()-this.pageBarHeight;
	   $('#scroll').height(scrollheigh);
	}
	
	this.loadLable.setWidth(witdth+5);
	this.loadLable.setHeight(height+5);
	
	this.ShowToolbarPanel();
    this.map.checkResize();
	this.map.setCenter(center);
	resizeFlag = false;
};
  
ExpatMap.prototype.AddOverLayer= function(overLayer)
{
	this.map.addOverlay(overLayer);
};

ExpatMap.prototype.RemoveOverLayer= function(overLayer)
{
	if(overLayer==null)
	  return;
	this.map.removeOverlay(overLayer);
};

var polyObjArray =[];
var calMarkers =[];
var calLables =[];
var currentCalLine =null;
ExpatMap.prototype.DrawSharp = function()
{
    var color = COLORS.red;
    var polygon = new GPolygon([], color, 3, 0.8, color, 0.2);
    this.SaveDrawObj(polygon);
};

ExpatMap.prototype.DrawLine = function(){
    var color = COLORS.blue;
    var line = new GPolyline([], color,4, 0.7);
    this.SaveDrawObj(line);
};

ExpatMap.prototype.DrawDistance = function()
{
   this.RemoveCalObj();
   var color = COLORS.blue;
   var line = new GPolyline([], color,3, 0.7);
   currentCalLine = line;
   this.SaveDrawObj(line,false);
};

ExpatMap.prototype.SaveDrawObj = function(poly, enableEdit)
{
	var pid =new Date().getTime()+"";
	polyObjArray[pid]=poly;
	
    this.AddOverLayer(poly);
    this.polyLineArray.push(poly);
    
    poly.enableDrawing(null);
    if (enableEdit != false) 
	{
        poly.enableEditing({
            onEvent: "mouseover"
        });
        poly.disableEditing({
            onEvent: "mouseout"
        });
    }
    GEvent.addListener(poly, "endline", function(){
       expatMap.EnableDragging();
	   if (expatMap.lineTipLabel) 
		{ 
		  expatMap.RemoveOverLayer(expatMap.lineTipLabel);
		  expatMap.lineTipLabel =null;
	   }
	   if(expatMap.toolBar.drawline==true||
	      expatMap.toolBar.drawSharp==true)
	   {
	      	var pvCount = poly.getVertexCount();
			var html ="<div class='lineWin'>" + '<a href="javascript:expatMap.RemoveLineObj(\'' +pid + '\')" >Remove</a></div>';
			expatMap.map.openInfoWindowHtml(poly.getVertex(pvCount-1),html);
	   }
	   if(expatMap.toolBar.cal==true)
	   {    
	   	     var pvCount = poly.getVertexCount();
	         var marker = new ExpatMarker();
			 marker.lat=poly.getVertex(pvCount-1).lat();
             marker.lng=poly.getVertex(pvCount-1).lng();
	   	     marker.iconWidth = 15;
             marker.iconHeight = 15;
             marker.iconArchorX = 25;
             marker.iconArchorY = 8;
			 marker.clickMethod =function(){ 
			  if(confirm("Do you really want to delete it?")==false) return;
			   expatMap.RemoveCalObj();
			 };
			 marker.iconUrl="/images/x.gif";
             expatMap.AddMarker(marker);
			 calMarkers.push(marker);
	   }
	   expatMap.toolBar.drawline=false;
	   expatMap.toolBar.drawSharp=false;
	   expatMap.toolBar.cal = false;
    });
    GEvent.addListener(poly, "click", function()
	{
       if (currentCalLine == poly) {
	   	  return;
	   }
        if (expatMap.toolBar.removeFlag == true) 
		{
            this.RemoveLineObj();
        }
		else{
			var pvCount = poly.getVertexCount();
			var html ="<div class='lineWin'>" + '<a href="javascript:expatMap.RemoveLineObj(\'' +pid + '\')" >Remove</a></div>';
			expatMap.map.openInfoWindowHtml(poly.getVertex(pvCount-1),html);
		}
    });
};
ExpatMap.prototype.RemoveLineObj = function(pid){
    if(confirm("Do you really want to delete it?")==false)  return;
	 var poly = polyObjArray[pid];
	 if(poly ==null)
	    return;
	 polyObjArray.removeArrayByElementKey(pid);
     expatMap.RemoveOverLayer(poly);
	 expatMap.map.closeInfoWindow();
	 currentCalLine =null;
}
ExpatMap.prototype.RemoveCalObj = function(){
	if(typeof currentCalLine !='undefined' && currentCalLine != null)
	{
		expatMap.RemoveOverLayer(currentCalLine);
		currentCalLine = null;
	}
	for(var i=0;i<calMarkers.length;i++)
	{
		expatMap.markMgr.RemoveMarker(calMarkers[i].id);
	}
	calMarkers =[];
	for(var i=0;i<calLables.length;i++)
	{
		expatMap.RemoveOverLayer(calLables[i]);
	}
	calLables =[];
};

var totalDistance =0;
var prevTotalDisance =0;

ExpatMap.prototype.Drawing = function(latlng)
{
	if (this.toolBar.drawline == true || this.toolBar.drawSharp == true) {
		if (!this.lineTipLabel) {
			this.lineTipLabel = this.CreateLable("Double click exit.",latlng.lat(),latlng.lng(),"drawTipStyle") ;
  			this.lineTipLabel.show();
		}
		else {
			this.RemoveOverLayer(this.lineTipLabel);
			this.lineTipLabel.setPoint(latlng);
			this.AddOverLayer(this.lineTipLabel);
		}
	}
	else if (this.toolBar.cal == true && this.calLable) 
	{
			this.RemoveOverLayer(this.calLable);
			this.calLable.setPoint(latlng);
			var distance = this.CalDistance(this.startCalPoint, latlng);
			if(distance <0.001)
			   return;
			totalDistance = prevTotalDisance + parseFloat(distance.toString());
			totalDistance = new Number( parseFloat(totalDistance.toString()));
			this.calLable.setContents(distance + "/" + totalDistance.toFixed(2) +" km.");
			this.AddOverLayer(this.calLable);
			calLables.push(this.calLable);
	}
	else if(this.toolBar.fromHere == true||this.toolBar.fromHere2 == true)
	{
		if (this.lableStart == null) {
			var content = "<img src='/img/icon_a.gif'/>";
			this.lableStart =this.CreateLable(content,latlng.lat(),latlng.lng(),"cursorStyle",new GSize(-18,5));
			this.lableStart.show();
		}
		else {
			this.RemoveOverLayer(this.lableStart);
			this.lableStart.setPoint(latlng);
			this.AddOverLayer(this.lableStart);
		}
	}
	else if(this.toolBar.toHere==true||this.toolBar.toHere2==true)
	{
		if (this.lableEnd == null) {
			var content = "<img src='/img/icon_b.gif'/>";
			this.lableEnd = this.CreateLable(content,latlng.lat(),latlng.lng(),"cursorStyle",new GSize(-18,5));
			this.lableEnd.show();
		}
		else {
			this.RemoveOverLayer(this.lableEnd);
			this.lableEnd.setPoint(latlng);
			this.AddOverLayer(this.lableEnd);
		}
	}
	else if(this.toolBar.searchFlag==true||this.toolBar.searchFlag2==true)
	{
		if (this.lableSearch == null) {
			var content = "<img src='/images/label.gif'/>";
			this.lableSearch = this.CreateLable(content,latlng.lat(),latlng.lng(),"cursorStyle",new GSize(-11,5));
			this.lableSearch.show();
		}
		else {
			this.RemoveOverLayer(this.lableSearch);
			this.lableSearch.setPoint(latlng);
			this.AddOverLayer(this.lableSearch);
		}
	}
 };

ExpatMap.prototype.CalDist = function(point) 
{
	if(this.toolBar.cal==false)
	    return;
     var content = "0";
	 this.startCalPoint = point;
     if (this.calLable == null)
	  {
         this.calLable =this.CreateLable(content,point.lat(),point.lng(), "calTipStyle",new GSize(-20, 0),90);
         this.calLable.show();
		 calLables.push(this.calLable);
     }
     else 
	 {   
	     prevTotalDisance = parseFloat(totalDistance.toString());
		 var cloneLable = this.calLable.copy();
		 this.AddOverLayer(cloneLable);
		 cloneLable.show();
		 calLables.push(cloneLable);
     }
	 if(typeof point=="undefined" || point==null)
	   return;
	 //add a dot marker.
	 //alert(currentCalLine);
	 //var pvCount = currentCalLine.getVertexCount();
     var marker = new ExpatMarker();
	 marker.lat=point.lat();
     marker.lng=point.lng();
	 marker.iconWidth = 11;
     marker.iconHeight = 11;
     marker.iconArchorX = 5;
     marker.iconArchorY = 5;
	 marker.iconUrl="/images/xdot.png";
     expatMap.AddMarker(marker);
	 calMarkers.push(marker);
 };
 
ExpatMap.prototype.CalDistance = function(pointOne, pointTwo) { 
     if (!pointOne || !pointTwo)
         return 0;
     var distance = pointOne.distanceFrom(pointTwo) / 1000;
     return distance.toFixed(2);
 };
///////////////////////////////////////////////////
ExpatMap.prototype.ToStaticMap = function() 
{
    
};

////////////////////////////////Add Marker////////////////////////////////////////////
ExpatMap.prototype.CleanMap = function() {
    this.markMgr.ClearMarkers();
    this.map.closeInfoWindow();

    this.ShowError("");
    this.sharpArray = [];
    this.buspathArray = [];
	this.buspathIDArray = [];
	
    this.polyLineArray = [];
    this.stopLocalArray = [];
    this.suggestAddrArray = [];
    this.map.clearOverlays();
};

ExpatMap.prototype.OpenMark = function(expatMarkerId) 
{
    var expartMarker =this.markMgr.GetMarker(expatMarkerId);  
	if(expartMarker ==null)
	  return;
	var marker =expartMarker.innerMark;
	this.HideTip(expatMarkerId);
    if(marker)
    { 
		 if (expartMarker.ajaxUrl != null && expartMarker.ajaxUrl != '') 
		 {
		 	marker.openInfoWindowHtml("<div>Loading...</div>");
			$.get(expartMarker.ajaxUrl, function(data){
				 expatMap.map.closeInfoWindow();
			     marker.openInfoWindowHtml(data);
			}); 
         }
         else if(expartMarker.infoHtml && expartMarker.infoHtml !='')
		 {
			marker.openInfoWindowHtml(expartMarker.infoHtml);
         }
    }
};

ExpatMap.prototype.OpenSharpMark = function(expatSharpId) 
{
    var expartSharp =  this.sharpArray[expatSharpId];
	if(expartSharp ==null)
	  return;
	var innerObj =expartSharp.innerObj;
	this.HideTip(expatSharpId,true);
    if(innerObj)
    { 
	     if(expartSharp.clat==null || expartSharp.clat ==0 || expartSharp.clng ==null || expartSharp.clng ==0)
		    return;
		 var cpoint = new GLatLng(expartSharp.clat,expartSharp.clng);
		 if (expartSharp.ajaxUrl != null && expartSharp.ajaxUrl != '') 
		 {
		 	expatMap.map.openInfoWindowHtml(cpoint,"<div>Loading...</div>");
			$.get(expartSharp.ajaxUrl, function(data){
				 expatMap.map.closeInfoWindow();
			     expatMap.map.openInfoWindowHtml(cpoint,data);
			}); 
         }
         else if(expartSharp.infoHtml && expartSharp.infoHtml !='')
		 {
			expatMap.map.openInfoWindowHtml(cpoint,expartSharp.infoHtml);
         }
	     else if(expartSharp.enterFn !=null )
		 {
		 	if (typeof expartSharp.enterFn == 'function') {
				expartSharp.enterFn();
			}
			else{
				eval(expartSharp.enterFn);
			}
		 }
    }
};

ExpatMap.prototype.ShowTip = function(expatMarkerId,isSharp) 
{
	if (isSharp == true) {
		var expatSharp = this.sharpArray[expatMarkerId];
		if (expatSharp == null) 
			return;
		var tipsLable = expatSharp.tipsLable;
		if (tipsLable) {
			if (tipsLable.isHidden() == true) {
				tipsLable.show();
			}
		}
	}
	else{
		var expartMarker = this.markMgr.GetMarker(expatMarkerId);
		if (expartMarker == null) 
			return;
		var tipsLable = expartMarker.tipsLable;
		if (tipsLable) {
			if (tipsLable.isHidden() == true) {
				tipsLable.show();
			}
		}
	}
};

ExpatMap.prototype.HideTip = function(expatMarkerId,isSharp) 
{
	if (isSharp == true) {
		var expatSharp = this.sharpArray[expatMarkerId];
		if (expatSharp == null) 
			return;
		var tipsLable = expatSharp.tipsLable;
		if (tipsLable) {
			if (tipsLable.isHidden() == false) {
				tipsLable.hide();
			}
		}
	}
	else{
		var expartMarker = this.markMgr.GetMarker(expatMarkerId);
		if (expartMarker == null) 
			return;
		var tipsLable = expartMarker.tipsLable;
		if (tipsLable) {
			if (tipsLable.isHidden() == false) {
				tipsLable.hide();
			}
		}
	}
};

ExpatMap.prototype.CreateLable=function(lableContent,lat,lng,className,gsize,opac)
{
	 if(className==null || className=='')
	    className="lableClass";
     var content = '<table width="100%"><tr><td align="left">'+
	                lableContent+
					'</td></tr></table>'; 
     var point = new GLatLng(lat,lng);
	 
	 var offset = gsize;
	 if(!offset)
	 {
	 	offset=new GSize(-5,18);
	 }
	 if(!opac)
	    opac= 100;
		
     var lable = new ELabel(point, content, className, offset, opac, 1);
	 this.AddOverLayer(lable);
	 lable.hide();
	 return lable;
} ;

ExpatMap.prototype.AddSharp=function(expartSharp,canEdit,isLine,strokeColor,strokeWeight,strokeOpacity,fillColor,fillOpacity,lableOffSet)
{
	if($.inArray(expartSharp.id,this.sharpArray)>=0)
     {
      	return;
     }
     var points = expartSharp.points;
	 if(points==null || points.length==0)
	    return;
	 var latlngPoints =[];
     for(var i=0;i<points.length;i++)
	 {
	 	if(points[i].lat <0.001 || points[i].lat < 0.00001)
		  continue;
	 	var latlng = new GLatLng(points[i].lat,points[i].lng);
		latlngPoints.push(latlng);
	 }
	 strokeColor = strokeColor==null? COLORS.blue:strokeColor;
	 fillColor= fillColor==null? COLORS.red:fillColor;
	 strokeWeight = strokeWeight==null? 0.6:strokeWeight;
	 strokeOpacity = strokeOpacity==null? 0.8:strokeOpacity;
	 fillOpacity =fillOpacity==null? 0.2:fillOpacity;
	 if(isLine !=true)
	 {	
        expartSharp.innerObj = new GPolygon(latlngPoints, strokeColor, strokeWeight, strokeOpacity, fillColor, fillOpacity);
	 }
	 else
	 {
        expartSharp.innerObj = new GPolyline(latlngPoints, strokeColor,strokeWeight, strokeOpacity);
	 }
     this.AddOverLayer(expartSharp.innerObj);

	 if (canEdit == true) 
	  {
        expartSharp.innerObj.enableDrawing(null); 
        expartSharp.innerObj.enableEditing({onEvent: "mouseover" });
        expartSharp.innerObj.disableEditing({onEvent: "mouseout" });
		
		GEvent.addListener(expartSharp.innerObj, "endline", function(){
	           expatMap.EnableDragging();
			   if (expatMap.lineTipLabel) 
			   { 
				  expatMap.RemoveOverLayer(expatMap.lineTipLabel);
				  expatMap.lineTipLabel =null;
			   }
			   expatMap.toolBar.drawline=false;
			   expatMap.toolBar.drawSharp=false;
			   expatMap.toolBar.cal = false;
          }
		);
	  }
	  GEvent.addListener(expartSharp.innerObj, "endline", function()
	  {
	        expatMap.EnableDragging();
		    if (expatMap.lineTipLabel) 
			{ 
			  expatMap.RemoveOverLayer(expatMap.lineTipLabel);
			  expatMap.lineTipLabel =null;
		   }
		    expatMap.toolBar.drawline=false;
		    expatMap.toolBar.drawSharp=false;
		    expatMap.toolBar.cal = false;
       });  
		
      GEvent.addListener(expartSharp.innerObj, "click", function(){expatMap.OpenSharpMark(expartSharp.id);});
	  
	  GEvent.addListener(expartSharp.innerObj, "mouseout", function(){expatMap.HideTip(expartSharp.id,true);});
	  
	  GEvent.addListener(expartSharp.innerObj, "mouseover", function(){expatMap.ShowTip(expartSharp.id,true);});
	   
	  if(expartSharp.tipInfo !=null && expartSharp.tipInfo !='')
	  { 
	  	 expartSharp.tipsLable=this.CreateLable(expartSharp.tipInfo,expartSharp.clat,expartSharp.clng,"",new GSize(20,0),100);
	  }
	   if(expartSharp.lableHtml !=null && expartSharp.lableHtml !='')
	  { 
	      if(typeof lableOffSet == "undefined") lableOffSet=new GSize(-5,20);
	  	  expartSharp.lableObj=this.CreateLable(expartSharp.lableHtml,expartSharp.clat,expartSharp.clng,"sharpLable",lableOffSet,100);
		  expartSharp.lableObj.show();
	  }
	 
      this.sharpArray[expartSharp.id]= expartSharp;  
};

ExpatMap.prototype.CreateMarkerIcon=function(iconUrl,width,height,iconCenter,iconArchorX,iconArchorY)
{
	 var markIcon =new GIcon();
	 if (width !=null && height != null) 
	 {
	 	markIcon.iconSize = new GSize(width, height);
	 }
	 else 
	 {
	 	markIcon.iconSize = new GSize(24, 24);
	 }//
	 if(iconArchorX !=null && iconArchorX !=-1 && iconArchorY != null && iconArchorY != -1)
	 {
	 	markIcon.iconAnchor = new GPoint(iconArchorX, iconArchorY);
		markIcon.infoWindowAnchor=new GPoint(iconArchorX, iconArchorY);
	 }
	 else if (iconCenter == true) 
	 {
	 	markIcon.iconAnchor = new GPoint(15, 14);
		markIcon.infoWindowAnchor=new GPoint(15, 14);
	 }
	 else{
	 	markIcon.iconAnchor = new GPoint(16,32);
		markIcon.infoWindowAnchor=new GPoint(16,32);
	 }
	 
    
     markIcon.image=iconUrl;
     markIcon.shadow =null;
	 return markIcon;
};

ExpatMap.prototype.AddPopMarker = function(expartMarker,draggable,dragstart,dragend){
	 if(expartMarker.lat<0.01 || expartMarker.lng<0.01) return;
	 if(expartMarker.popInfo=='')
	    expartMarker.popInfo="none";
     var point = new GLatLng(expartMarker.lat,expartMarker.lng);
     var markerIcon = this.CreateMarkerIcon(expartMarker.iconUrl,
	                                        expartMarker.iconWidth,
											expartMarker.iconHeight,
											expartMarker.iconAnchorCenter,
											expartMarker.iconArchorX,
											expartMarker.iconArchorY);
	 markerIcon.infoWindowAnchor=new GPoint(5,5);
	 var marker = null;
	 if (draggable == true) {
	 	if (expartMarker.popInfo != null && expartMarker.popInfo != "") {
		   marker = new GMarkerEx(point, {
		   	    title:expartMarker.popInfo,
				icon: markerIcon,
				draggable: true
			});
		}
 	   GEvent.addListener(marker, "mouseover", function(){
		  if (expartMarker.alwaysShowPopInfo == false) {marker.showPopup(marker.getLatLng());}
 		      expatMap.map.closeInfoWindow();
	 	});
	 }
	 else {
	 	   marker = new GMarkerEx(point, {
				title:expartMarker.popInfo, 
				icon: markerIcon,
				dragCrossMove: true
			});
	 }
	 GEvent.addListener(marker,"dragstart", function(){marker.hidePopup();});       
	 GEvent.addListener(marker,"dragend", function(){marker.showPopup(marker.getLatLng());});     
    
	 GEvent.addListener(marker, "click", function(){if (expartMarker.alwaysShowPopInfo != true) {marker.hidePopup();} expatMap.OpenMark(expartMarker.id); });
	 GEvent.addListener(marker, "mouseout", function(){if (expartMarker.alwaysShowPopInfo != true) {marker.hidePopup();} expatMap.HideTip(expartMarker.id);});
	 GEvent.addListener(marker, "mouseover", function(){if (expartMarker.alwaysShowPopInfo != true) {marker.showPopup();} expatMap.ShowTip(expartMarker.id);});
	 
	 if(typeof expartMarker.tipInfo !='undefined' && expartMarker.tipInfo !=null && expartMarker.tipInfo !='')
	 { 
	     var sizeLable = new GSize(0,60);
		 if(expartMarker.iconAnchorCenter !=true)
		     sizeLable = new GSize(0,40);
	    expartMarker.tipsLable=this.CreateLable(expartMarker.tipInfo,expartMarker.lat,expartMarker.lng,"lableClass",sizeLable,100)
	 }
	 expartMarker.innerMark= marker;
	 this.markMgr.AddMarker(expartMarker,8,17); 
	 if (expartMarker.alwaysShowPopInfo==true){ marker.showPopup(); }
};

ExpatMap.prototype.FocusMarker = function(markerId){
	var expartMarker =this.markMgr.GetMarker(markerId); 
	expartMarker.iconUrl=expartMarker.iconUrlFocus;
	this.markMgr.RemoveMarker(markerId);
	this.AddMarker(expartMarker,false,false,false);
};
ExpatMap.prototype.LeaveMarker = function(markerId){
	var expartMarker =this.markMgr.GetMarker(markerId); 
	expartMarker.iconUrl=expartMarker.iconUrlNormarl;
	this.markMgr.RemoveMarker(markerId);
	this.AddMarker(expartMarker,false,false,false);
};
ExpatMap.prototype.AddMarker=function(expartMarker,draggable,dragstart,dragend)
{
	 if(expartMarker.lat<0.01 || expartMarker.lng<0.01) return;
     var point = new GLatLng(expartMarker.lat,expartMarker.lng);
     var markerIcon = this.CreateMarkerIcon(expartMarker.iconUrl,
	                                        expartMarker.iconWidth,
											expartMarker.iconHeight,
											expartMarker.iconAnchorCenter,
											expartMarker.iconArchorX,
											expartMarker.iconArchorY);
	 var marker = null;
	 if (draggable == true) {
	 	marker = new GMarker(point, {icon: markerIcon,draggable: true});
	 	if (dragstart != null) {
	 		GEvent.addListener(marker, "dragstart", dragstart);
	 	}
	 	if (dragend != null) {
	 		GEvent.addListener(marker, "dragend", dragend);
	 	}
	 	GEvent.addListener(marker, "mouseover", function(){
	 		expatMap.map.closeInfoWindow();
	 	});
	 }
	 else {
	 	 marker = new GMarker(point, {icon: markerIcon,	dragCrossMove: true});
	 }
	 
	 if (typeof expartMarker.clickMethod !='undefined' && 
	     expartMarker.clickMethod != null &&
		 expartMarker.clickMethod != "") {
	 	GEvent.addListener(marker, "click", function(){
	 		 expartMarker.clickMethod();
	 	});
	 }
	 else {
	 	GEvent.addListener(marker, "click", function(){
	 		expatMap.OpenMark(expartMarker.id);
	 	});
	 }

	 GEvent.addListener(marker, "mouseout", function(){ expatMap.HideTip(expartMarker.id);  });
	 GEvent.addListener(marker, "mouseover", function(){expatMap.ShowTip(expartMarker.id);  });
	 
	 if(typeof expartMarker.tipInfo !='undefined' && expartMarker.tipInfo !=null && expartMarker.tipInfo !='')
	 { 
	     var sizeLable = new GSize(0,58);
		 if(expartMarker.iconAnchorCenter !=true)
		     sizeLable = new GSize(0,38);
	    expartMarker.tipsLable=this.CreateLable(expartMarker.tipInfo,expartMarker.lat,expartMarker.lng,"lableClass",sizeLable,100)
	 }
	  expartMarker.innerMark= marker;
	  this.markMgr.AddMarker(expartMarker,expartMarker.minZoom,expartMarker.maxZoom); 
};

ExpatMap.prototype.AddCenterMarker = function(expartMarker, radDistance){
	if (!expartMarker) 
		return;
	if (this.centerSearchMarker) {
		this.markMgr.RemoveMarker(this.centerSearchMarker.id)
	}
	expartMarker.iconUrl = "/images/center.gif";
	expartMarker.ajaxUrl = "/CenterWin.aspx?lat=" + expartMarker.lat +
	"&lng=" +
	expartMarker.lng +
	"&addr=" +
	encodeURIComponent(expartMarker.disp);
	expartMarker.ajaxUrl = "";
	expartMarker.iconWidth = 18;
	expartMarker.iconHeight = 24;
	expartMarker.iconArchorX = 6;
	expartMarker.iconArchorY = 22;
	expartMarker.tipInfo = "Drag to change center.";
	
	c_lat = expartMarker.lat;
	c_lng = expartMarker.lng;
	
	var draggable = expartMarker.draggable;
	if (draggable != false) {
	   draggable = true;
    }
	if(draggable==false)
	{
		expartMarker.tipInfo="";
	}
   
   this.AddMarker(expartMarker,draggable,null,function(){
   	  if(expartMarker==null)
	      return;
   	   var latlng =expartMarker.innerMark.getLatLng();
   	   expatMap.MoveCenterCircle(latlng.lat(),latlng.lng());
   });
   
    var radValue = GetDistanceValue(radDistance);
 
   expartMarker.tagObj =GPolygon.Circle(new GLatLng(expartMarker.lat,expartMarker.lng),radValue,'#3267b9',1,1,'#5e89b8',0.17);
   GEvent.addListener(expartMarker.tagObj, "click", function(){
   	   expatMap.map.closeInfoWindow();
   	});
 
   this.AddOverLayer(expartMarker.tagObj);
   this.centerSearchMarker = expartMarker;
   this.SetCenter(expartMarker.lat,expartMarker.lng);
   
   this.DrawCirleDistanceLine(radDistance);
   
   if (radValue == 500){this.map.setZoom(16);}
   else if (radValue == 1000) {this.map.setZoom(15);}
   else if (radValue == 2000) {this.map.setZoom(14);}
   else if (radValue == 5000) {this.map.setZoom(13);}
};

function GetDistanceValue(radDistance)
{
	var radValue = 2000;
    if(typeof radDistance != "undefined" )
    {
		if(radDistance<500)  radValue = 2000;
	 	else if (radDistance == 500){radValue = 500;}
		else if (radDistance == 1000) {radValue = 1000;}
		else if (radDistance == 2000) {radValue = 2000;}
		else if (radDistance == 5000) {	radValue = 5000;}
		else {	
		  radValue = 2000; } 
     } 
	else{
		radValue = 2000; 
	}
	return radValue;
};

ExpatMap.prototype.ChangeCenterCirleRadiu = function(radDistance)
{
	if(this.centerSearchMarker ==null)
	   return;
	var radValue =GetDistanceValue(radDistance); 
	this.RemoveOverLayer(this.centerSearchMarker.tagObj);
	
	this.centerSearchMarker.tagObj =GPolygon.Circle(new GLatLng(this.centerSearchMarker.lat,this.centerSearchMarker.lng),radValue,'#3267b9',1,1,'#5e89b8',0.17);
    this.AddOverLayer(this.centerSearchMarker.tagObj);
 
	if ($("#categoryFlag").val() == "1")
	{
		RefreshCategoryCount();
		this.DrawCirleDistanceLine(radDistance);
	
		if (radValue == 500){this.map.setZoom(16);}
		else if (radValue == 1000) {this.map.setZoom(15);}
		else if (radValue == 2000) {this.map.setZoom(14);}
		else if (radValue == 5000) {this.map.setZoom(13);}
	}
	else 
	{
		this.LoadCenterSearchPanel(c_caddr, c_lat, c_lng, c_mid, 1, c_categoryName, c_categoryId, radValue, c_searchKey,c_district,c_orderby);
	}
};

var distanceLine =null;
ExpatMap.prototype.DrawCirleDistanceLine = function(radDistance){
	if(this.centerSearchMarker ==null)
	   return;
	var radValue =GetDistanceValue(radDistance); 
	var offSet = radValue / 95190.34686;
	if (distanceLine != null) {
		this.RemoveOverLayer(distanceLine.innerObj);
		this.RemoveOverLayer(distanceLine.lableObj);
	}
	var distLine = new ExpatSharp();
	var rowMarker = 0.0004;
	if(radValue<=2000)
	    rowMarker = 0.0002;
	distLine.points =[{'lat':this.centerSearchMarker.lat,'lng':this.centerSearchMarker.lng},
	                  {'lat':this.centerSearchMarker.lat,'lng':this.centerSearchMarker.lng+offSet},
					  {'lat':this.centerSearchMarker.lat+(rowMarker/2),'lng':this.centerSearchMarker.lng+offSet-rowMarker},
					  {'lat':this.centerSearchMarker.lat,'lng':this.centerSearchMarker.lng+offSet-rowMarker/2},
					  {'lat':this.centerSearchMarker.lat-(rowMarker/2),'lng':this.centerSearchMarker.lng+offSet-rowMarker},
					  {'lat':this.centerSearchMarker.lat,'lng':this.centerSearchMarker.lng+offSet}];
	distLine.id="distanceLine";
	distLine.lableHtml="<strong>" + radValue +"m" +"</strong>";
	distLine.clat =this.centerSearchMarker.lat;
	distLine.clng =this.centerSearchMarker.lng +1/2 *offSet;
	this.AddSharp(distLine,false,true,null,1,null,null,null,new GSize(0,2));
	distanceLine =distLine;
} ;
 
ExpatMap.prototype.AddLableMarker=function(expartMarker,className,lbOffset)
{
	if(expartMarker.lat<0.01 || expartMarker.lng<0.01) return;
	 className = className==null?"markerLabler":className;
	 lbOffset = lbOffset==null?new GSize(-15,-25):lbOffset;
     var point = new GLatLng(expartMarker.lat,expartMarker.lng);
     var markerIcon = this.CreateMarkerIcon(expartMarker.iconUrl,expartMarker.iconWidth,expartMarker.iconHeight,expartMarker.iconAnchorCenter);
     var marker = new LabeledMarker(point, {
			icon: markerIcon,
			labelText:expartMarker.disp,
			labelClass:className,
			labelOffset:lbOffset 
		});
      GEvent.addListener(marker, "click", function(){expatMap.OpenMark(expartMarker.id);});
	  GEvent.addListener(marker, "mouseout", function(){expatMap.HideTip(expartMarker.id);});
	  GEvent.addListener(marker, "mouseover", function(){expatMap.ShowTip(expartMarker.id);});
	
	  if(typeof expartMarker.tipInfo !='undefined' && expartMarker.tipInfo !=null && expartMarker.tipInfo !='')
	  { 
	     var sizeLable = new GSize(0,58);
		 if(expartMarker.iconAnchorCenter !=true)
		     sizeLable = new GSize(0,38);
	  	 expartMarker.tipsLable=this.CreateLable(expartMarker.tipInfo,expartMarker.lat,expartMarker.lng,"lableClass",sizeLable,100)
	  }
      expartMarker.innerMark= marker;
	  this.markMgr.AddMarker(expartMarker,expartMarker.minZoom,expartMarker.maxZoom); 
};

ExpatMap.prototype.AddTransStartEndMarker = function(markerEntity,isStart){
	 markerEntity.tipInfo="Drag to change route";
	 markerEntity.iconWidth=19;
	 markerEntity.iconHeight=25;
	 markerEntity.iconArchorX=9;
     markerEntity.iconArchorY=30;
	if(isStart==true)
    {		
		if(this.startMarkerId)
		{
			var pstartMarker = this.markMgr.GetMarker(this.startMarkerId);
			if (pstartMarker) {
				this.markMgr.RemoveMarker(this.startMarkerId);
			}
		}
       this.AddMarker(markerEntity,true,function(){expatMap.HideTip(markerEntity.id);},
	     function(){
	   	    var latLng=expatMap.startMarker.getLatLng();
		    expatMap.FromHere(latLng.lat(),latLng.lng(),'');
	      });
	   	 this.startMarker =markerEntity.innerMark; 
		 this.startMarkerId =markerEntity.id;
    }
    else  
    {
		if(this.endMarkerId)
		{
			var pendMarker = this.markMgr.GetMarker(this.endMarkerId);
			if (pendMarker) {
				this.markMgr.RemoveMarker(this.endMarkerId);
			}
		}
        this.AddMarker(markerEntity,true,function(){expatMap.HideTip(markerEntity.id);},
		 function(){
	  	  var elatlng = expatMap.endMarker.getLatLng();
		  expatMap.ToHere(elatlng.lat(),elatlng.lng(),'');
	  });
	   this.endMarker =markerEntity.innerMark; 
	   this.endMarkerId =markerEntity.id;
    }
    this.markMgr.Refresh();
};

ExpatMap.prototype.Refresh = function() {
    this.markMgr.Refresh();
};

////////////////////////////////Tab Panel//////////////////////////
ExpatMap.prototype.MemuSearchSurMap = function() {	
	TabPanelSelect("searchSurround");
	$('#txtCenterAddr').val('');
	$('#txtCenterAddr').focus();
	
	this.currentPanel = 'search';
	AcceptEnterEvent(function(){expatMap.SurroundSearch();});
	if (loadDefault ==null || loadDefault==true) {
		this.SetDefaultPanel();
	}
};
/////////////////////////////////Load Panel///////////////////////// 
ExpatMap.prototype.SetSearchCenter = function(lat,lng){
	 //this.Reset();
	 if(this.lableSearch !=null)
	 {
	 	this.RemoveOverLayer(this.lableSearch);
	 	this.lableSearch=null;
	 }
	 this.toolBar.searchFlag = false;
	 this.LoadCenterSearchPanel("",lat,lng,"",1,"","-1",2000,"","",0);
     //this.LoadCategoryTreePanel(lat,lng);
	/*
 var queryString="action=getCenterName&lat="+lat +
	                 "&lng=" + lng;
	 this.SearchActionForPage(queryString,1);
	 this.SetCursor("default");
*/
};

ExpatMap.prototype.SetSearchCenterFlag = function(){
	 this.Reset();
     var latlng = this.map.getCenter();
	 var lat = latlng.lat();
	 var lng = latlng.lng();
	 var queryString="action=getCenterName&lat="+lat +
	                 "&lng=" + lng;
	 this.SearchActionForPage(queryString,1);
	 this.SetCursor("default");
};

ExpatMap.prototype.MoveCenterCircle = function(lat,lng){
     if ($("#categoryFlag").val() == "1"){ this.SetSearchCenter(lat,lng);return; }
	 c_mid="";
	 c_caddr="";
	 this.LoadCenterSearchPanel(c_caddr,lat,lng,c_mid,1,c_categoryName,c_categoryId,c_distanc,c_searchKey,c_district,c_orderby);
};

function GetDistance(){
  var dist = $('#dlgPDistance').val();
  if(typeof dist == undefined || dist==null || dist=="")
     return "2000";
  return dist;
};
ExpatMap.prototype.SelectCenterAddr = function(localId)
{
	var addr =this.suggestAddrArray[localId];
	if(!addr) return; 
	var dist = GetDistance();
	this.AddCenterMarker(addr,dist);
	$('#txtPCenterAddr').val(addr.disp);
	$('#pclat').val(addr.lat);
	$('#pclng').val(addr.lng);
	$('#pcmid').val(localId);	
};

ExpatMap.prototype.LoadCategoryTreePanel = function(lat,lng) {
    if (this.currentPanel == 'categoryPanel')
        return;
    if (this.loadLable != null) {
        this.loadLable.show();
    }
	var key =$('#txtGCSearchKey').val();
	if(key == 'undefined'|| key=='Address,location,or landmark')
	   key ="";
	
    $('#mapResult').load("/Panel/CategorTreePanel.aspx",
	   {'clat':lat,'clng':lng,'dist':GetDistance(),'key':key},
		function(){
		    expatMap.loadLable.hide();
		    expatMap.Resize();
		});
    this.currentPanel = 'categoryPanel';
};
ExpatMap.prototype.LoadExpatDefaultPanel = function() 
{ 
    if(this.currentPanel == 'default')
	   return;
	$("#mapResult").load("/Panel/DefaultPanel.aspx"); 
	this.currentPanel = "default";
	this.Resize();
};

ExpatMap.prototype.LoadDirectionPanel = function()
{
	 if(this.currentPanel == 'direction')
	   return;
	if(this.currentPanel == 'direction')
	   return;
	$("#mapResult").load("/Panel/DirectionPanel.aspx"); 
	this.currentPanel = "direction";
	this.Resize();
};
ExpatMap.prototype.LoadMarkerDetailsPanel = function(markerId) {
    if (this.currentPanel == 'markerPanel')
        return;
    if (this.loadLable != null) {
        this.loadLable.show();
    }
    $('#mapResult').load("/Panel/MarkerPanel.aspx", { 'mid': markerId },
		function() {
		    expatMap.loadLable.hide();
		    expatMap.Resize();
		});
    this.currentPanel = 'markerPanel';
};
ExpatMap.prototype.SearchMarkerById = function(markerId){
	this.LoadMarkerDetailsPanel(markerId);
};
ExpatMap.prototype.LoadChannelDefaulPanel = function() {
    if (this.currentPanel == 'channelDefaultPanel')
        return;
    if (this.loadLable != null) {
        this.loadLable.show();
    }
    $('#mapResult').load("/Panel/ChannelPanel.aspx", { 'mid': '' },
		function() {
		    expatMap.loadLable.hide();
		    expatMap.Resize();
		});
    this.currentPanel = 'channelDefaultPanel';
};

ExpatMap.prototype.LoadSearchPanel = function(key, categoryid, categoryName, page,district,orderby) {
    if (this.loadLable != null) {
        this.loadLable.show();
    }
	if(typeof orderby == 'undefined') orderby =0;
	if(typeof district == 'undefined') district ="";
	
    $('#mapResult').load("/Panel/SearchPanel.aspx", { 'key': key, 'page': page, 
	                       'cgyId': categoryid, 'cgyName': categoryName,'district':district,'sort': orderby},
		function() {
		    expatMap.loadLable.hide();
		    expatMap.Resize();
		});
    this.currentPanel = 'searchPanel';
};
 
var c_categoryName="";
var c_categoryId="";
var c_distanc =1;
var c_searchKey ="";
var c_lat ="";
var c_lng="";
var c_caddr="";
var c_mid="";
var c_district ="";
var c_orderby ="";
ExpatMap.prototype.LoadCenterSearchPanel = function(caddr, clat, clng, mId, page, cgyName, cgyId,dist,key,district,orderby) {
    if (this.loadLable != null) {
        this.loadLable.show();
    }
	c_categoryName=cgyName;
	c_categoryId=cgyId;
	c_distanc =dist;
    c_searchKey =key;
	c_lat =clat;
	c_lng =clng;
	c_caddr =caddr;
	c_mid = mId;
	if(typeof orderby == 'undefined') orderby =0;
	if(typeof district == 'undefined') district ="";
	c_orderby= orderby;
	c_district= district;
	
    $('#mapResult').load("/Panel/SearchPanel.aspx", { 'action': 'centerSearch', 'caddr': caddr,
        'clat': clat, 'clng': clng, 'mId': mId, 'cgyId': cgyId, 'cgyName': cgyName, 'page': page,
		'dist':dist,'key':key,'district':district,'sort':orderby},
	    function() {
	        expatMap.loadLable.hide();
	        expatMap.Resize();
	    });
    this.currentPanel = 'searchPanel';
};

ExpatMap.prototype.FromToPanel = function(from, slat, slng, to, elat, elng, method,smid,emid) {
    if (this.loadLable != null) {
        this.loadLable.show();
    }
	expatMap.map.closeInfoWindow();
	
    from = from == null ? "" : from;
    to = to == null ? "" : to;
	if(typeof(smid)=="undefined" || smid ==null)
	{
		smid ="";
	}
	if(typeof(emid)=="undefined" || emid ==null)
	{
		emid ="";
	}
	if(typeof(method)== "undefined" || method=="" || method==null)
	{
		method =$('#selectTransType').val();
		if(method==""){	 method="0";}
	}
    $('#mapResult').load("/Panel/TransPanel.aspx", { 'from': from, 'to': to,
        'slat': slat, 'slng': slng, 'elat': elat, 'elng': elng, 'method': method,'smid':smid,'emid':emid
    },
	    function() {
	        expatMap.loadLable.hide();
	        expatMap.Resize();
	    });
    this.currentPanel = 'transPanel';
};

ExpatMap.prototype.LoadTransPanel = function(from, slat, slng, to, elat, elng, method,smid,emid) {

    $('#mapResult').load("/Panel/TransPanel.aspx", { 'slat': slat, 'slng': slng,
        'from': from, 'elat': elat, 'elng': elng, 'to': to, 'method': method,'smid':smid,'emid':emid
    },
	    function() {
	        expatMap.loadLable.hide();
	        expatMap.Resize();
	    });
    this.currentPanel = 'tanspanel';
};

ExpatMap.prototype.SelectChannel = function(channelType, page, startChar, key, categoryId,hidBox) {
    if (expatMap.loadLable != null) {
       expatMap.loadLable.show();
    }
	//TabPanelSelect("singSearch");
	
    key = (typeof key == "undefined" ? "" : key);
    categoryId = (typeof categoryId == "undefined" ? "" : categoryId);
    startChar = (typeof startChar == "undefined" ? "" : startChar);
	hidBox= (typeof hidBox == "undefined" ? "false" : hidBox);

    $('#mapResult').load("/Panel/ChannelResultPanel.aspx", { 'channel': channelType, 'page': page, 'start': startChar, 'key': key, 'category': categoryId,'hidBox':hidBox },
	  function(result) {
	      expatMap.loadLable.hide();
	      expatMap.Resize();
	  });
    this.currentPanel = 'channelResult';
};
///////////////////////////////////////////////////////////////////////////////////////////////////////
var preStreetLine=null;
ExpatMap.prototype.SelectStreet = function(streetId){
 	this.loadLable.show();
 	$.getJSON("/Handler/Street.ashx",{'streetId':streetId},function(result){
		expatMap.loadLable.hide();
		if(result==null) return;
		if(preStreetLine !=null)
		{
			if (preStreetLine.innerObj != null) {
				expatMap.RemoveOverLayer(preStreetLine.innerObj);  
			}
			if(preStreetLine.tipsLable!=null)expatMap.RemoveOverLayer(preStreetLine.tipsLable);
			if(preStreetLine.lableObj!=null)expatMap.RemoveOverLayer(preStreetLine.lableObj);
		}
	    expatMap.sharpArray=[];
		
		if(result.status!=0){this.ShowError(result.error);return;}
        var expartSharp={points:result.points,id:streetId,tipInfo:result.name,'ajaxUrl':'/StreetMarker.aspx?sid='+streetId};
		expartSharp.clat =result.cmarker.lat;
		expartSharp.clng =result.cmarker.lng
		expatMap.AddSharp(expartSharp,false,true,null,3,0.6,null,null);
		//expatMap.AddMarker(result.cmarker);
		expatMap.SetCenter(result.cmarker.lat,result.cmarker.lng);
		expatMap.GetBestView(result.points);
		preStreetLine =expartSharp;
	});
	this.currentPanel = 'streetResult';
 };

ExpatMap.prototype.SelectTransLine = function(transId,simple) {
     if (this.loadLable != null) {
         this.loadLable.show();
     }
	 if(typeof simple=="undefined" || simple=="" || simple==null)
	    simple = false;
	
     $.getJSON("/Handler/BusMetro.ashx", { 'transid': transId,'simple':simple }, function(result) {
         expatMap.loadLable.hide();
         if (result == null) return;
         expatMap.CleanMap();
         if (result.status != 0) { expatMap.ShowError(result.error); return; }
         var expartSharp = { points: result.points, id: transId, tipInfo: '', ajaxUrl: '/TransMarker.aspx?transId=' + transId };
         expatMap.AddSharp(expartSharp, false, true, null, 3, 0.6, null, null);
         //expatMap.AddMarker(result.transMarker);
         for (var i = 0; i < result.stops.length; i++) {
             expatMap.AddMarker(result.stops[i]);
         }
         expatMap.SetCenter(result.transMarker.lat, result.transMarker.lng);
         expatMap.GetBestView(result.stops);
     });
     this.currentPanel = 'transResult';
 };

ExpatMap.prototype.FromHere = function(lat,lng,address,mid) {
    this.GetStopLocationName(lat, lng, 1,address,mid);
    this.toolBar.fromHere = false;
	if (this.lableStart) {
	 	this.RemoveOverLayer(this.lableStart);
	 	this.lableStart = null;
	}
    this.EnableDragging();
};

ExpatMap.prototype.ToHere = function(lat,lng,address,mid) 
{
     this.GetStopLocationName(lat, lng, 0,address,mid);
     this.toolBar.toHere = false;	
	 if (this.lableEnd) 
	 {
	 	this.RemoveOverLayer(this.lableEnd);
	 	this.lableEnd = null;
	 }
     this.EnableDragging();
 };
 
ExpatMap.prototype.GetStopLocationName = function(lat,lng,isStart,address,mid)
{
	var slat = "";
	var slng = "";
	var saddr = "";
	var elat = "";
	var elng ="";
	var eaddr ="";
	var smid = "";
	var emid = "";
	if (typeof transObj !="undefined" && transObj != null) {
		 slat = transObj.slat;
		 slng = transObj.slng;
		 saddr = transObj.saddr;
		 elat = transObj.elat;
		 elng = transObj.elng;
		 eaddr = transObj.eaddr;
		 smid = transObj.smid;
		 emid = transObj.emid;
	}
	if(isStart==1)
	{
		slat=lat;
		slng =lng;
		saddr=address;
		smid = mid;
	}
	else
	{
		elat=lat;
		elng =lng;
		eaddr=address;
		emid = mid;
	}
	this.FromToPanel(saddr,slat,slng,eaddr,elat,elng,null,smid,emid);
};

ExpatMap.prototype.ChangeDistrict = function(selectObj){
	 var centObj =$('#selectDistrict').val();
	 var latlngParts = centObj.split('_');
	 if(latlngParts.length==2)
	 {
	 	this.SetCenter(parseFloat(latlngParts[0]), parseFloat(latlngParts[1]));
	 } 
};

////////////////////////////Ajax Core////////////////////////
ExpatMap.prototype.SearchActionForPage = function(queryString,pageNumber)
{
    var url = "/Handler/ExpatMap.ashx?" + trimEndChar(queryString, '&') + "&page=" + pageNumber;
   this.ExecuteAjaxProxy(url);
};

ExpatMap.prototype.ExecuteAjaxProxy = function(url, dataMap) {
    if (this.loadLable != null) {
        this.loadLable.show();
    }
    try {
        $.getJSON(url, dataMap, function(data) {
            expatMap.ProcessResult(data);
        });
    }
    catch (e) {
        $("#divInfo").text("Failed to connect server,message:" + e);
    }
};

ExpatMap.prototype.ProcessResult = function(data) {
    if (this.loadLable != null) {
        this.loadLable.hide();
    }
    if (!data) {
        this.ShowError("Error.");
        return;
    }
    $("#divInfo").text("");
    if (data.status == -1) {
        this.ShowError("Failed:" + data.error);
        return;
    }
    this.ShowError("");
    this.map.closeInfoWindow();
    this.map.clearOverlays();

    this.buspathArray = [];
    this.polyLineArray = [];
    this.stopLocalArray = [];
    this.suggestAddrArray = [];
    this.markMgr.ClearMarkers();

    var methodId = data.methodId;
     if (methodId == 3) {
        //最近站点查询
        this.ProcessStopResult(data.result);
    }
    else if (methodId == 4) {
        //中心点信息
        this.AddCenterMarker(data.result);
		if(!data.result)
          return;
		SetSearchPanel(data.result.lat,data.result.lng,data.result.disp);
		$("#clat_g").val(data.result.lat);
		$("#clng_g").val(data.result.lng);
		
		$("#pclat").val(data.result.lat);
		$("#pclng").val(data.result.lng);
		$("#pcmid").val(data.result.id);
		$('#txtPCenterAddr').val(data.result.disp);
		try 
		{
			if ($("#categoryFlag").val() == "1") {
				RefreshCategoryCount();
			}
		}catch(err){}
    }
    else if (methodId == 5) {
        //相似位置信息
        this.ProcessStopName(data.result);
    }
    this.Resize();
};

ExpatMap.prototype.ProcessSearch = function(searchResult,distance) 
{
	if(searchResult==null)
	   return;
	this.ShowError(searchResult.errorInfo);
    /////////////////////////////////////////
    var markerJasonData = searchResult.results;
	var markerCount = markerJasonData.length;
	var markArray=[];
    for (var i = 0; i < markerCount; i++) 
	{
        var pmarker = markerJasonData[i];
		this.AddMarker(pmarker);
		markArray.push(pmarker);
    }
	var center = searchResult.center;
	if(center)
	{
		this.AddCenterMarker(center,distance);
	}	
	var suggestionAddr = searchResult.suggest;
	if (suggestionAddr) 
	{
		for (var i = 0; i < suggestionAddr.length; i++) 
		{
			var addr = suggestionAddr[i];
			addr.iconUrl='/images/center.gif';
			addr.infoHtml=addr.disp;
			this.suggestAddrArray[addr.id] = addr;
		}
	}
    markerJasonData = [];
    searchResult = null;
	if (center==null) 
	{
		if(markArray.length>0)
		{
			this.SetCenter(markArray[0].lat,markArray[0].lng);
		}
		this.GetBestView(markArray);
	}
	this.markMgr.Refresh();
};
//////////////////////公交查询处理//////////// 
ExpatMap.prototype.ProcessSuggestionStop = function(stopData)
{
   if (stopData.startdata != null) {
   	for (var i = 0; i < stopData.startdata.length; i++) {
   		var local = stopData.startdata[i];
   		this.stopLocalArray[local.id] = local;
   	}
   }
   if (stopData.enddata != null) {
   	for (var i = 0; i < stopData.enddata.length; i++) {
   		var local = stopData.enddata[i];
   		this.stopLocalArray[local.id] = local;
   	}
   }
};

ExpatMap.prototype.ProcessTransFromToStop =function(stopResult)
{
   if(stopResult.startdata != null)
    {
	   stopResult.startdata.iconUrl= "/img/icon_a.gif";
       this.AddTransStartEndMarker(stopResult.startdata,true);
       
    }
    else if(stopResult.enddata != null)
    {
       stopResult.enddata.iconUrl= "/img/icon_b.gif";
	   this.AddTransStartEndMarker(stopResult.enddata,false); 
    }
};

ExpatMap.prototype.SelectEndStop = function(localid){
	var local = this.stopLocalArray[localid];
	local.infoHtml = local.disp;
	local.iconUrl = "/img/icon_b.gif";
     
	transObj.eaddr =local.disp;
    transObj.preeaddr=local.disp;
    transObj.elat =local.lat;
    transObj.elng =local.lng;
    transObj.emid =localid;
	transObj.hasEnd = true;
	
	$("#txtEndStop").val(local.disp);
	
	this.AddTransStartEndMarker(local,false);
	this.SetCenter(local.lat,local.lng);
    this.OpenMark(localid);
	if(transObj.hasStart==true)
	{
		this.FromToPanel( transObj.saddr, transObj.slat, transObj.slng, 
		                  transObj.eaddr, transObj.elat, transObj.elng, "",transObj.smid,transObj.emid);
	}
};
 
ExpatMap.prototype.SelectStartStop = function(localid)
{   
   var local = this.stopLocalArray[localid];
   local.infoHtml=local.disp;
   local.iconUrl= "/img/icon_a.gif";
     
    transObj.saddr =local.disp;
    transObj.presaddr=local.disp;
    transObj.slat =local.lat;
    transObj.slng =local.lng;
    transObj.smid =localid;
	transObj.hasStart =true;
	
    $("#txtStartStop").val(local.disp);
   this.AddTransStartEndMarker(local,true);
   this.SetCenter(local.lat,local.lng);
   this.OpenMark(localid);
   if(transObj.hasEnd==true)
	{
		this.FromToPanel( transObj.saddr, transObj.slat, transObj.slng, 
		                  transObj.eaddr, transObj.elat, transObj.elng, "",transObj.smid,transObj.emid);
	}
};
 
ExpatMap.prototype.SearchTrans=function(flag)
{
	var startAddr=""
	var endAddr ="";
	if (flag == 1) 
	{
	    startAddr=$('#txtStart').val();
		endAddr= $('#txtEnd').val();
		if(startAddr==''||startAddr=='Address,location,or landmark')
		{
			alert("Please input start address.");
			$('#txtStart').focus();
			return;
		}
		if(endAddr==''||endAddr=='Address,location,or landmark')
		{
			alert("Please input target address.");
			$('#txtEnd').focus();
			return;
		}
		$('#startlat').val('');
		$('#startlng').val('');
		$('#endlat').val('');
		$('#endlng').val('');
		
		$('#txtStartStop').val(startAddr);
		$('#txtEndStop').val(endAddr);
	}
	else
	{
		startAddr=$('#txtStartStop').val();
		endAddr= $('#txtEndStop').val();
		if(startAddr=='')
		{
			alert("Please input start address.");
			$('#txtStartStop').focus();
			return;
		}
		if(endAddr=='')
		{
			alert("Please input target address.");
			$('#txtEndStop').focus();
			return;
		}
		$('#txtStart').val(startAddr);
		$('#txtEnd').val(endAddr);
	}
	var strategy =$("#selectTransType").val();
	this.FindBusTrans(startAddr,$('#startlat').val(),$('#startlng').val(),endAddr,$('#endlat').val(),$('#endlng').val(),strategy);
};

ExpatMap.prototype.FindBusTransThread = function(startAddr,slat,slng,endAddr,elat,elng,strategy,smid,emid)
{ 
    slat = slat==null?"":slat;
	slng = slng==null?"":slng;
	elat = elat==null?"":elat;
	elng = elng==null?"":elng;
	smid = (typeof smid=='undefined'|| smid==null)?"":smid;
	emid = (typeof emid=='undefined'|| emid==null)?"":emid;
	
	endAddr = endAddr==null?"":endAddr;
	startAddr = startAddr==null?"":startAddr;
	if(endAddr==startAddr)
	{
		//alert("Please input different locations.");
		//return;
	}
    expatMap.LoadTransPanel(startAddr,slat,slng,endAddr,elat,elng,strategy,smid,emid);
};
ExpatMap.prototype.FindBusTrans = function(startAddr,slat,slng,endAddr,elat,elng,strategy,smid,emid)
{
	if (this.loadLable != null) {
        this.loadLable.show();
    }
	Concurrent.Thread.create(expatMap.FindBusTransThread,startAddr,slat,slng,endAddr,elat,elng,strategy,smid,emid);
};
 
ExpatMap.prototype.ProcessTrans = function(transData) 
{    
    if(transData==null)
	   return;
	this.buspathIDArray=[];
	this.buspathArray=[];
	
	var strategry = transData.strategy;
	document.getElementById("selectTransType").options[strategry].selected= true;
	
    for (var i = 0; i < transData.transPath.length; i++) 
	{
        var busPath = transData.transPath[i];
		
        this.buspathArray[busPath.pathId] = busPath;
		this.buspathIDArray.push(busPath.pathId);
    }
    if (transData.transPath.length > 0) 
	{
        this.SelectPath(transData.transPath[0].pathId);
    }
    TabMenumSelect(2)
};

ExpatMap.prototype.SelectPathThread = function(busPathId)
{
	var busPath = expatMap.buspathArray[busPathId];
    if (!busPath) {
		expatMap.loadLable.hide();
        return;
    }
	///////////////////////////////////////////////////////
	for(var i=0;i<expatMap.buspathIDArray.length;i++)
	{
		document.getElementById("S"+expatMap.buspathIDArray[i]).style.background="#FFFFFF";
	}
    document.getElementById("S"+busPathId).style.background="#e4edf3";
	
    expatMap.markMgr.ClearMarkers();
	expatMap.map.clearOverlays();
	
	$('#divRouteTitle').html("Details of Route <strong>" +busPath.index +"</strong>");
	//$('#tripResultList').html(busPath.content);
	replaceHtml("tripResultList", busPath.content); 
    //////////////////////////////////////
	var stepCount =busPath.steps.length;
	var color = '#424200';
	var startMarker = busPath.startMarker;
	var endMarker = busPath.endMarker;
	
	expatMap.AddTransStartEndMarker(startMarker,true);
	expatMap.AddTransStartEndMarker(endMarker,false);
	
	var markArray=[];
    for (var i = 0; i < stepCount; i++) 
	{
		var step = busPath.steps[i];
		markArray.push(step.marker);
		if (stepCount == 2 && i > 0) {
			break;
		}
        ///////////////////////////////
		var marker =step.marker;
		var index =step.index;
        if (index != -1) {
            marker.iconWidth = 11;
            marker.iconHeight = 11;
            marker.iconArchorX = 5;
            marker.iconArchorY = 5;
            expatMap.AddPopMarker(marker);
            if (step.stepType == 0 && i<stepCount-1 && step.distance<0.5) {
                marker.innerMark.hidePopup();
            }
        }
    }
	expatMap.DrawlTransLine(busPath.line);
	
	expatMap.GetBestView(markArray);
	expatMap.loadLable.hide();
};
ExpatMap.prototype.SelectPath = function(busPathId) 
{
    this.loadLable.show();
	Concurrent.Thread.create(expatMap.SelectPathThread,busPathId);
};

ExpatMap.prototype.SelectStep = function(stepId) 
{
   this.OpenMark(stepId);
};

var startLine =null;
var endLine = null;
ExpatMap.prototype.DrawlTransLine = function(lineEncodeStr) 
{
	if(lineEncodeStr==null)
	  return;
	for (var i = 0; i < lineEncodeStr.length; i++) 
	{
		var stepObj =lineEncodeStr[i];
		var stepType =stepObj.type;
		var color = COLORS.purple;
		if (stepType == 0||stepType==20) {color = COLORS.red;	}
		else if (stepType == 1) {color = COLORS.blue;}
		else if (stepType == 2) {color = "#FF00FF";	}
	    else {color = COLORS.purple;	}
		var linePoint = [];
		
		var distance =0.0;
		var prePoint = null;
		for(var j=0;j<stepObj.data.length;j++)
		{
		    var point = stepObj.data[j];
			var gPoint = new GLatLng(point.lat,point.lng);
			linePoint.push(gPoint);	
			if (prePoint != null) {
				distance += prePoint.distanceFrom(gPoint) / 1000;
			}
			prePoint = gPoint;
		}
		distance =distance.toFixed(1);
		//alert(distance);
		if (stepType != 20 && (stepType != 0 || distance<0.12)) {
			var line = new GPolyline(linePoint, color, 6, 0.6);
			expatMap.AddOverLayer(line);
			continue;
		}	
		if(stepType == 0 && distance>0.12)
		{  	
		    eval(
			 'var divObj = document.createElement("div");'+
			 'var dirOptions ={getPolyline:true,getSteps:false,preserveViewport:false,travelMode: G_TRAVEL_MODE_WALKING};'+
			 'var dirGObj_'+i+ ' = new GDirections(null,divObj);'+
			 'GEvent.addListener(dirGObj_'+i+', "load", function(){'+
					'var path = dirGObj_'+i+'.getPolyline();'+
					'if(path==null)'+
					   'return;'+
					'path.color = COLORS.red;'+
					'expatMap.AddOverLayer(path);	'+			 
				'});'+
			   'GEvent.addListener(dirGObj_'+i+', "error", function(){'+
					'var errline = new GPolyline(linePoint, color, 6, 0.6);'+
			        'expatMap.AddOverLayer(errline);'+
				 '});'+
				'var routArray = [];'+
				'routArray.push(stepObj.data[0].lat + "," + stepObj.data[0].lng);'+
				'routArray.push(stepObj.data[stepObj.data.length - 1].lat + "," + stepObj.data[stepObj.data.length - 1].lng);'+
				'dirGObj_'+i+'.loadFromWaypoints(routArray, dirOptions);'
			   );
		}
		////////////////////////////////////////////////////////////////////////
		if((stepType==20 && (i==0||i==lineEncodeStr.length-1)))
		{
			var dirOptions ={getPolyline:true,getSteps:false,preserveViewport:false};
			if (i == 0) {
				startLine = line;
				var gdirStart = new GDirections(null);
				GEvent.addListener(gdirStart, "load", function(){
					var path = gdirStart.getPolyline();
					if(path==null)
					   return;
					path.color = COLORS.red;
					expatMap.AddOverLayer(path);
					var distance = path.Distance()/ 1000;
					$('#Tx_StartStop').text(distance.toFixed(2));
					$('#Dx_Taxi').text(distance.toFixed(2));
					if(lineEncodeStr.length==1)
					{
						expatMap.CalTaxiPrice(distance.toFixed(2));
					}
					
					var startMark =expatMap.markMgr.GetMarker("StartStop");  
					if(startMark !=null)
					{
						var infoHtml = startMark.infoHtml;
						var content ="<span name='taxiDist'>"+distance.toFixed(2)+"</span>";
						infoHtml =infoHtml.replace(/\<span\sname="taxiDist"\>.+\<\/span\>/g,content);
						startMark.infoHtml = infoHtml;
					}
				});
				GEvent.addListener(gdirStart, "error", function(){
					var errline = new GPolyline(linePoint, color, 6, 0.6);
			        expatMap.AddOverLayer(errline);
				 });
				var routArray = [];
				routArray.push(stepObj.data[0].lat + "," + stepObj.data[0].lng);
				routArray.push(stepObj.data[stepObj.data.length - 1].lat + "," + stepObj.data[stepObj.data.length - 1].lng);
				gdirStart.loadFromWaypoints(routArray, dirOptions);
			}
			else 
			{
				var gdir = new GDirections(null);
				endLine = line;
				GEvent.addListener(gdir, "load", function(){
					var path = gdir.getPolyline();
					if(path==null)
					   return;
					path.color = COLORS.red;
					expatMap.AddOverLayer(path);
					var distance = path.Distance()/ 1000;
					$('#Tx_EndStop').text(distance.toFixed(2));
					$('#Dx_Taxi').text(distance.toFixed(2));

					var endMark =expatMap.markMgr.GetMarker("EndStop");  
					if(endMark !=null)
					{
						var infoHtml = endMark.infoHtml;
						var content ="<span name='taxiDist'>"+distance.toFixed(2)+"</span>";
						infoHtml =infoHtml.replace(/\<span\sname="taxiDist"\>.+\<\/span\>/g,content);
						endMark.infoHtml = infoHtml;
					}
				});
				GEvent.addListener(gdir, "error", function(){
					var errline = new GPolyline(linePoint, color, 6, 0.6);
			        expatMap.AddOverLayer(errline);
 
				 });
				var routArray = [];
				routArray.push(stepObj.data[0].lat + "," + stepObj.data[0].lng);
				routArray.push(stepObj.data[stepObj.data.length - 1].lat + "," + stepObj.data[stepObj.data.length - 1].lng);
				gdir.loadFromWaypoints(routArray, dirOptions);
			}
		} 
	}
};
 ExpatMap.prototype.CalTaxiPrice=function(distance)
 {
 	var taxiPriceDay = 12;
	var taxiPriceNight = 16;
	var taxiPriceBus = 17+(2.4*distance);
	var taxiPriceOuter = 10;
	var left =(distance-3);
	var leftIn10 = left<=7?left:7;
	var leftOut10 = distance-10;
	if(left >0)
	{
		if(leftIn10>0)
		{
			taxiPriceDay +=leftIn10*2.4;
			taxiPriceNight +=leftIn10*3.1;
			taxiPriceOuter +=leftIn10*2.4;
		}
		if (leftOut10 > 0) {
		    taxiPriceDay   +=leftOut10*3.6;
			taxiPriceNight +=leftOut10*4.7;
			taxiPriceOuter +=leftOut10*2.4;
		}
	}
	$('#taxiPriceDay').text(taxiPriceDay.toFixed(1));
	$('#taxiPriceNight').text(taxiPriceNight.toFixed(1));
	$('#taxiPriceBus').text(taxiPriceBus.toFixed(1));
	$('#taxiPriceOuter').text(taxiPriceOuter.toFixed(1));
 };
////////////////////////////////////////////////////////////////////
ExpatMap.prototype.CommiteInfo = function(lat,lng,markerId) 
{
    var url ="/CommitForm.aspx";
    $.get(url,{ 'lat':lat,'lng': lng, 'id': markerId},
       function(html)
       {
         var latlngObj = new GLatLng(lat,lng);
		 var marker = new GMarker(latlngObj);
		 marker.openExtInfoWindow(expatMap.map,'marke_info_window',html);
		 expatMap.EnableDragging();
      }
    ); 
};

ExpatMap.prototype.CorrectInfo = function(lat,lng,markerId) 
{
	var url = "/LocalPoint.aspx?id=" +markerId; 
	window.open(url);
};

ExpatMap.prototype.SaveCommitInfo = function(flag) {
    if (flag == 0) {
        expatMap.map.closeInfoWindow();
        return;
    }
    if ($("#poiname").val() == '') {
        alert("Please input name.");
        $("#poiname").focus();
        return;
    }
    if ($("#poiaddress").val() == '') {
        alert("Please input address.");
        $("#poiaddress").focus();
        return;
    }    
	var dataMap = 
	{
        action: 'saveCommit',
        lat: $("#commitLat").val(),
        lng: $("#commitLng").val(),
        id: $('#localId').val(),
        name: $('#poiname').val(),
        addr: $('#poiaddress').val(),
        tel: $('#poitela').val(),
        desc: $('#errcontent').val() 
    };

    this.ExecuteAjaxProxy("/Handler/ExpatMap.ashx", dataMap);
};

ExpatMap.prototype.SaveCorrectInfo = function(flag) 
{
    
    if ($('#txtCnName').val() == '')
	 {
        alert("Please input Chinese name.");
        $("#txtCnName").focus();
        return;
    }   
	 if ($('#txtLat').val() == '')
	 {
        alert("Please input Lat value.");
        $("#txtLat").focus();
        return;
    } 
	 if ($('#txtLng').val() == '')
	 {
        alert("Please input Lng value.");
        $("#txtLng").focus();
        return;
    }        
    var dataMap = 
	{
        action: 'saveLocal',
        id: $('#LocalId').val(),
        cnName: $('#txtCnName').val(),
        enName: $('#txtEnName').val(),
        lat: $('#txtLat').val(),
        lng: $('#txtLng').val(),
        cnAddr: $('#txtCnAddr').val(),
        enAddr: $('#txtEnAddrss').val(),
        tel: $('#txtTel').val(),
        dist: $('#cmbDistrict').val(),
        ltype: $('#cmbLocalType').val(),
        engServ: $('#cmbEnglisServ').val()
    };
    this.ExecuteAjaxProxy("/Handler/ExpatMap.ashx", dataMap);
};

ExpatMap.prototype.MoreInfo = function(id,cnName,enName,cnAddr,enAddr,tel){
	if((cnName ==null || cnName =='') && (enName ==null || enName ==''))
	   return;
	 $.get("/MoreInfo.aspx",{'mid':id,'cnName':cnName,'enName':enName,'cnAddr':cnAddr,'enAddr':enAddr,'tel':tel});
};

ExpatMap.prototype.LogFile = function(content,fileName) 
{   
    if(!fileName)
	 {
	 	fileName="c:\\maplog.txt";
	 }
	var  fso,f,r   
	var ForReading=1;  
	var ForWriting=2;   
	fso = new ActiveXObject("Scripting.FileSystemObject")   
	f = fso.OpenTextFile(fileName,   ForWriting,   true)   
	f.Write(content);   
	f.Close();   
	fso=null;      
 } ;
/////////////////////////////////BlueWalk/////////////////////////////////////////////////
var bluewalkMarkerArray =[];
var bluewalkPolyonArray =[];
var bluewalkPolylineArray =[];
ExpatMap.prototype.SetBlueWalk = function(blueWalkObj){
	
	markArray =[];
	if(typeof blueWalkObj=="undefined" || blueWalkObj==null)
	   return;
	if (typeof blueWalkObj.markers !="undefined" && blueWalkObj.markers != null && blueWalkObj.markers.length > 0) {
		for (var i = 0; i < blueWalkObj.markers.length; i++) {
		   var marker = blueWalkObj.markers[i];
		   var blueMarker = new BlueWalkerMarker();
		   blueMarker.id = marker.id;
		   blueMarker.lat = marker.lat;
		   blueMarker.lng = marker.lng;
		   blueMarker.title = marker.title;
		   blueMarker.desc = marker.desc;
		   blueMarker.readonly = marker.readonly;
		   blueMarker.icon = marker.icon;
		   this.AddBlueMarker(blueMarker);
		   markArray.push({lat:marker.lat,lng:marker.lng});
		}
	}
	if (typeof blueWalkObj.polyons !="undefined" && blueWalkObj.polyons != null && blueWalkObj.polyons.length > 0) {
		for (var i = 0; i < blueWalkObj.polyons.length; i++) {
		   var polyonObj = blueWalkObj.polyons[i];
		   var bluePolyon = new BlueWalkerPolyon();
		   bluePolyon.id = polyonObj.id;
		   bluePolyon.clat = polyonObj.clat;
		   bluePolyon.clng = polyonObj.clng;
		   bluePolyon.title = polyonObj.title;
		   bluePolyon.desc = polyonObj.desc;
		   bluePolyon.readonly = polyonObj.readonly;
		   bluePolyon.color = polyonObj.color;
		   bluePolyon.opacity = polyonObj.opacity;
		   
		   var pArray=[];
		   for(var j=0;j<polyonObj.points.length;j++)
		   {
		   	  pArray.push(new GLatLng(polyonObj.points[j].lat,polyonObj.points[j].lng));
			  markArray.push(polyonObj.points[j]);
		   }
		    var polygon = new GPolygon(pArray, bluePolyon.color, 3, bluePolyon.opacity, COLORS.red, 0.2);
			bluePolyon.innerPolyon = polygon;
			bluewalkPolyonArray.push(bluePolyon);
			this.SaveBlueDrawObj(bluePolyon,true,false);
		}
	}
	if (typeof blueWalkObj.polylines !="undefined" && blueWalkObj.polylines != null && blueWalkObj.polylines.length > 0) {
		for (var i = 0; i < blueWalkObj.polylines.length; i++) {
		   var polyonObj = blueWalkObj.polylines[i];
		   var bluePolyline = new BlueWalkerPolyline();
		   bluePolyline.id = polyonObj.id;
		   bluePolyline.clat = polyonObj.clat;
		   bluePolyline.clng = polyonObj.clng;
		   bluePolyline.title = polyonObj.title;
		   bluePolyline.desc = polyonObj.desc;
		   bluePolyline.readonly = polyonObj.readonly;
		   bluePolyline.color = polyonObj.color;
		   bluePolyline.opacity = polyonObj.opacity;
		   
		   var pArray=[];
		   for(var j=0;j<polyonObj.points.length;j++)
		   {
		   	  pArray.push(new GLatLng(polyonObj.points[j].lat,polyonObj.points[j].lng));
			   markArray.push(polyonObj.points[j]);
		   }
		   var line = new GPolyline(pArray, bluePolyline.color,4, bluePolyline.opacity);
	       bluePolyline.innerPolyline = line;
	       bluewalkPolylineArray.push(bluePolyline);
           this.SaveBlueDrawObj(bluePolyline,false,false);
		}
	}
	 expatMap.EnableDragging();
	 this.GetBestView(markArray);
};

ExpatMap.prototype.GetBlueWalkInfo = function()
{
	var xml ='<?xml version="1.0" encoding="utf-8" ?>';
	xml +='<bluewalk>';
	xml +='  <markers>';
	for(var i=0;i<bluewalkMarkerArray.length;i++)
	{
		var marker = bluewalkMarkerArray[i];
		if(marker==null || marker.innerMark==null)
		    continue;
		xml +='<marker id="'+marker.id+
		      '" lat="'+marker.innerMark.getLatLng().lat()+ 
			  '" lng="'+marker.innerMark.getLatLng().lng()+
			  '" icon="'+marker.icon +
			  '" title="'+xmlencode(marker.title) +
			  '"><![CDATA[' +
			  marker.desc +
			  ']]></marker>';
        
	}
	xml +='  </markers>';
	xml +='  <polyons>';
	for(var i=0;i<bluewalkPolyonArray.length;i++)
	{
		var polyon = bluewalkPolyonArray[i];
		if(polyon==null || polyon.innerPolyon==null)
		    continue;
		 var pointstr ="";
		for(var j=0;j<polyon.innerPolyon.getVertexCount();j++)
		{
			var vpoint =polyon.innerPolyon.getVertex(j);
			if(vpoint==null) continue;
			pointstr +=vpoint.lat()+","+vpoint.lng()+";";
		}
		xml +='<polyon id="'+polyon.id+
		      '" clat="'+polyon.innerPolyon.getVertex(0).lat()+ 
			  '" clng="'+polyon.innerPolyon.getVertex(0).lng()+
			  '" color="'+polyon.color +
			  '" opacity="'+polyon.opacity +
			  '" points="'+pointstr +
			  '" title="'+xmlencode(polyon.title) +
			  '"><![CDATA[' +
			    polyon.desc +
			  ']]></polyon>';
        
	}
	xml +='  </polyons>';
	xml +='  <polylines>';
	for(var i=0;i<bluewalkPolylineArray.length;i++)
	{
		var polyline = bluewalkPolylineArray[i];
		if(polyline==null || polyline.innerPolyline==null)
		    continue;
		 var pointstr ="";
		for(var j=0;j<polyline.innerPolyline.getVertexCount();j++)
		{
			var vpoint =polyline.innerPolyline.getVertex(j);
			pointstr +=vpoint.lat()+","+vpoint.lng()+";";
		}
		xml +='<polyline id="'+polyline.id+
		      '" clat="'+polyline.innerPolyline.getVertex(0).lat()+ 
			  '" clng="'+polyline.innerPolyline.getVertex(0).lng()+
			  '" color="'+polyline.color +
			  '" opacity="'+polyline.opacity +
			  '" points="'+pointstr +
			  '" title="'+xmlencode(polyline.title) +
			  '"><![CDATA[' +
			    polyline.desc +
			  ']]></polyline>';
        
	}
	xml +='  </polylines>';
	xml +='  </bluewalk>';
	return xml;
};
ExpatMap.prototype.AddBlueMarker=function(blueMarker)
{
	 if(blueMarker.lat<0.01 || blueMarker.lng<0.01) return;
     var point = new GLatLng(blueMarker.lat,blueMarker.lng);
     var markerIcon = this.CreateMarkerIcon(blueMarker.icon,null,null,true,null,null);
	 var marker = new GMarker(point, {icon: markerIcon,draggable: !blueMarker.readonly});

	 GEvent.addListener(marker, "click", function(){
	 	var html="";
		if (blueMarker.readonly == false) {
			html =blueMarker.getInfoHtml();
			marker.openInfoWindowHtml(html);
			//$("#txtBlueTitle").val(blueMarker.title);
	        //$("#txtBlueDesc").val(blueMarker.desc);
		}else
		{
			html =blueMarker.getViewInfoHtml();
			marker.openInfoWindowHtml(html);
		}
	 });
	  blueMarker.innerMark= marker;
	  bluewalkMarkerArray.push(blueMarker);
	  this.AddOverLayer(marker);
};
 
ExpatMap.prototype.AddPolyone=function(bluePolyon)
{
	 bluewalkPolyonArray.push(bluePolyon);
};
ExpatMap.prototype.AddPolyline=function(bluePolyline)
{
	 bluewalkPolylineArray.push(bluePolyline);
};

ExpatMap.prototype.FindBlueMarker=function(id)
{
	for(var i=0;i<bluewalkMarkerArray.length;i++)
	{
		var marker = bluewalkMarkerArray[i];
		if(marker!=null && marker.id==id)
		   return marker;
	}
	return null;
};
ExpatMap.prototype.FindBluePolyon=function(id)
{
	for(var i=0;i<bluewalkPolyonArray.length;i++)
	{
		var polyon = bluewalkPolyonArray[i];
		if(polyon!=null && polyon.id==id)
		   return polyon;
	}
	return null;
};
ExpatMap.prototype.FindPolyline=function(id)
{
	for(var i=0;i<bluewalkPolylineArray.length;i++)
	{
		var polyline = bluewalkPolylineArray[i];
		if(polyline!=null && polyline.id==id)
		   return polyline;
	}
	return null;
};

ExpatMap.prototype.RemoveBlueMarker=function(id)
{
	for(var i=0;i<bluewalkMarkerArray.length;i++)
	{
		var marker = bluewalkMarkerArray[i];
		if(marker!=null && marker.id==id)
		 {
		 	this.RemoveOverLayer(marker.innerMark);
		  	bluewalkMarkerArray[i]=null;
			break;
		 }
	}
	expatMap.map.closeInfoWindow();
};
ExpatMap.prototype.RemoveBluePolyon=function(id)
{
	for(var i=0;i<bluewalkPolyonArray.length;i++)
	{
		var polyon = bluewalkPolyonArray[i];
		if(polyon!=null && polyon.id==id)
		 {
		 	this.RemoveOverLayer(polyon.innerPolyon);
		 	bluewalkPolyonArray[i]=null;
		 	break;
		 }
	}
	expatMap.map.closeInfoWindow();
};
ExpatMap.prototype.RemoveBluePolyline=function(id)
{
	for(var i=0;i<bluewalkPolylineArray.length;i++)
	{
		var polyline = bluewalkPolylineArray[i];
		if(polyline!=null && polyline.id==id)
		 {
		 	this.RemoveOverLayer(polyline.innerPolyline);
		 	bluewalkPolylineArray[i]=null;
		 	break;
		 }
	}
	expatMap.map.closeInfoWindow();
};

ExpatMap.prototype.SaveBlueMarker=function(id)
{
	 var marker = this.FindBlueMarker(id);
	 if(marker ==null)
	   return;
	 marker.title=$("#txtBlueTitle").val();
	 marker.desc=$("#txtBlueDesc").val();
	 expatMap.map.closeInfoWindow();
};
ExpatMap.prototype.SaveBluePolyon=function(id)
{
	 var polyon = this.FindBluePolyon(id);
	 if(polyon ==null)
	   return;
	 polyon.title=$("#txtBluePolyTitle").val();
	 polyon.desc=$("#txtBluePolyDesc").val();
	 expatMap.map.closeInfoWindow();
};
ExpatMap.prototype.SaveBluePolyline=function(id)
{
	 var polyline = this.FindPolyline(id);
	 if(polyline ==null)
	   return;
	 polyline.title=$("#txtBluePolyTitle").val();
	 polyline.desc=$("#txtBluePolyDesc").val();
	 expatMap.map.closeInfoWindow();
};

ExpatMap.prototype.CreateBlueMarker=function(latlng)
{
	var marker = new BlueWalkerMarker();
	marker.lat = latlng.lat();
	marker.lng = latlng.lng();
	this.AddBlueMarker(marker);
};
ExpatMap.prototype.DrawBlueLine = function(){
    var polyLine = new BlueWalkerPolyline();
    var line = new GPolyline([], polyLine.color,4, polyLine.opacity);
	polyLine.innerPolyline = line;
	bluewalkPolylineArray.push(polyLine);

    this.SaveBlueDrawObj(polyLine,false,true);
};
ExpatMap.prototype.DrawBlueSharp = function(){
	var polyonObj = new BlueWalkerPolyon();
    var polygon = new GPolygon([], polyonObj.color, 3, polyonObj.opacity, COLORS.red, 0.2);
	polyonObj.innerPolyon = polygon;
	bluewalkPolyonArray.push(polyonObj);
    
	this.SaveBlueDrawObj(polyonObj,true,true);
};

ExpatMap.prototype.SaveBlueDrawObj = function(polyObj,isPolyon,edit)
{
	if(typeof polyObj =="undefined" || polyObj==null)
	  return;
	var poly =null;
	if(isPolyon==true)
	{
		poly=polyObj.innerPolyon;
	}
	else{
		poly=polyObj.innerPolyline;
	}
    this.AddOverLayer(poly);
	if (edit == true) {
		poly.enableDrawing(null);
	}
	if (polyObj.readonly == false) {
		poly.enableEditing({
			onEvent: "mouseover"
		});
		poly.disableEditing({
			onEvent: "mouseout"
		});
	}
	
    GEvent.addListener(poly, "endline", function(){
       expatMap.EnableDragging();
	   if (expatMap.lineTipLabel) 
		{ 
		  expatMap.RemoveOverLayer(expatMap.lineTipLabel);
		  expatMap.lineTipLabel =null;
	   }
	   expatMap.toolBar.drawBlueLine=false;
	   expatMap.toolBar.drawBlueSharp=false;
	  
	   expatMap.toolBar.drawline=false;
	   expatMap.toolBar.drawSharp=false;
	   expatMap.toolBar.cal = false;
    });
	
    GEvent.addListener(poly, "click", function()
	{
		var html = "";
		if (polyObj.readonly == false)
		{
			html = polyObj.getInfoHtml();
			expatMap.map.openInfoWindowHtml(poly.getVertex(0),html);
		    //$("#txtBluePolyTitle").val(polyObj.title);
	        //$("#txtBluePolyDesc").val(polyObj.desc);
		}
		else{
			html = polyObj.getViewInfoHtml();
			expatMap.map.openInfoWindowHtml(poly.getVertex(0),html);
		}
    });
};
/////////////////////////////////MapEvent/////////////////////////////////////////////////
var MapEvent = Object;
MapEvent.MapClickEvent = function(overlayObj, latlngObj) 
{
    if (expatMap.toolBar.searchFlag == true) 
	{
        expatMap.SetSearchCenter(latlngObj.lat(),latlngObj.lng());
        expatMap.EnableDragging();
    }
    else if (expatMap.toolBar.fromHere == true) 
	{
        expatMap.FromHere(latlngObj.lat(), latlngObj.lng(),'');
    }
    else if (expatMap.toolBar.toHere == true) {
        expatMap.ToHere(latlngObj.lat(), latlngObj.lng(),'');
    }
    else if (expatMap.toolBar.addMarker == true) {
        //expatMap.CommiteInfo(latlngObj.lat(), latlngObj.lng());
       // expatMap.toolBar.addMarker = false;
	    expatMap.CreateBlueMarker(latlngObj);
		expatMap.toolBar.addMarker = false;
		expatMap.EnableDragging();
    }
    else if (expatMap.toolBar.cal == true) 
	{
        expatMap.CalDist(latlngObj);
    }
	else if (expatMap.toolBar.searchFlag2 == true) 
	{
		expatMap.RemoveOverLayer(expatMap.lableSearch);
		expatMap.EnableDragging();
		expatMap.toolBar.Init();
		var newUrl ="/EMap.aspx?action=centerSearch&caddr=&cgyId=-1&cgyName=&clat="+latlngObj.lat()+"&clng="+latlngObj.lng();
        window.open(newUrl);
    }
    else if (expatMap.toolBar.fromHere2 == true) 
	{
		expatMap.RemoveOverLayer(expatMap.lableStart);
		expatMap.toolBar.Init();
        expatMap.EnableDragging();

		var newUrl ="/EMap.aspx?action=trans&from=&slat="+latlngObj.lat()+"&slng="+latlngObj.lng()+"&to=&elat=0&elng=0&emid=&strategy=0";
        window.open(newUrl);
    }
    else if (expatMap.toolBar.toHere2 == true) {
		expatMap.RemoveOverLayer(expatMap.lableEnd);
		expatMap.toolBar.Init();
        expatMap.EnableDragging();

		var newUrl ="/EMap.aspx?action=trans&from=&elat="+latlngObj.lat()+"&elng="+latlngObj.lng()+"&to=&slat=0&slng=0&emid=&strategy=0";
        window.open(newUrl);
    }
	expatMap.toolBar.HideToolBar('#archBar','#hideToolbar');  
};

MapEvent.MapRClickEvent = function(overlayObj, latlngObj) 
{
    if (latlngObj) {
         expatMap.map.closeInfoWindow();
    } 
	expatMap.RemoveOverLayer(expatMap.lableStart);
	expatMap.RemoveOverLayer(expatMap.lableEnd);
	expatMap.lableStart = null;
	expatMap.lableEnd = null;
	expatMap.EnableDragging();
};

MapEvent.MoveOnMapEvent = function(latlngObj) 
{
   expatMap.Drawing(latlngObj);	 
};

MapEvent.MapDoubleClick = function(overlayObj, latlngObj) 
{
    expatMap.toolBar.Init();
    expatMap.SetCursor("default");
    expatMap.EnableDragging();
	if (latlngObj) {
       expatMap.map.closeInfoWindow();
    }
};

MapEvent.MapZoomEvent=function ()
{
	var zoom = expatMap.map.getZoom();
	var mapTypes = expatMap.map.getMapTypes();
    var mapMaxZoom = mapTypes[0].getMaximumResolution();
	if(zoom >mapMaxZoom)
	{
	    expatMap.map.setZoom(mapMaxZoom);
	}
};

MapEvent.MapMoveendEvent=function ()
{
};

MapEvent.MapDragendEvent=function ()
{
   /*
 var zoomValue = expatMap.map.getZoom();
    if (!expatMap.allowedBounds.contains(expatMap.map.getCenter())&&zoomValue>10) 
    {
        var C = expatMap.map.getCenter();
        var X = C.lng();
        var Y = C.lat();
 
        var AmaxX = expatMap.allowedBounds.getNorthEast().lng();
        var AmaxY = expatMap.allowedBounds.getNorthEast().lat();
        var AminX = expatMap.allowedBounds.getSouthWest().lng();
        var AminY = expatMap.allowedBounds.getSouthWest().lat();
 
        if (X < AminX) {X = AminX;}
        if (X > AmaxX) {X = AmaxX;}
        if (Y < AminY) {Y = AminY;}
        if (Y > AmaxY) {Y = AmaxY;}
        //expatMap.SetCenter(Y,X);
    }
*/
};
  
/////////////////////////////////ToolBar/////////////////////////////////////////////////
function ExpatMapToolbar() {
    this.searchFlag = false;
    this.removeFlag = false;
    this.fromHere = false;
    this.toHere = false;
    this.clickPoint = null;
    this.drawline = false;
	this.drawSharp =false;
    this.addMarker = false;
    this.cal = false;
	this.drawBlueLine = false;
	this.drawBlueSharp = false;
	this.searchFlag2 = false;
	this.fromHere2 = false;
    this.toHere2 = false;
};

ExpatMapToolbar.prototype.Init = function() {
    this.searchFlag = false;
    this.drawline = false;
	this.drawSharp = false;
    this.removeFlag = false;
    this.fromHere = false;
    this.toHere = false;
	this.fromHere2 = false;
    this.toHere2 = false;
	this.searchFlag2 = false;
    this.addMarker = false;
    this.cal = false;
	this.drawBlueLine = false;
	this.drawBlueSharp = false;
	 
	$('#hideToolbar').css('display','none');
    $('#archBar').html("Tools");
    expatMap.DisableDragging();
};

ExpatMapToolbar.prototype.HideToolBar= function(archId,hideDivId) {
    var ob = $(hideDivId);
	var arch=$(archId);
    ob.css('display','none');
    arch.html("Tools");
};

ExpatMapToolbar.prototype.ShowHideToolbar = function(archId,hideDivId) {
    var ob = $(hideDivId);
	var arch=$(archId);
    if (ob.css('display') == "block") 
	{
        ob.css('display','none');
        arch.html("Tools");
    }
    else 
	{
		ob.css('display','block')
        arch.html("Tools");
    }
};
 
ExpatMapToolbar.prototype.Reset = function() {
    this.Init();
	window.location.reload();
    expatMap.Reset();
}

ExpatMapToolbar.prototype.Search = function() {
    this.Init();
	this.searchFlag = true;
	expatMap.SetCursor("crosshair"); 
};

ExpatMapToolbar.prototype.Search2 = function() {
   this.Init();
   this.searchFlag2 = true;
   expatMap.SetCursor("crosshair"); 
};
ExpatMapToolbar.prototype.FromHere2 = function() {
    this.Init();
    this.fromHere2 = true;
    expatMap.SetCursor("crosshair");
};
ExpatMapToolbar.prototype.ToHere2 = function() {
    this.Init();
    this.toHere2 = true;
    expatMap.SetCursor("crosshair");
};

ExpatMapToolbar.prototype.DrawLine = function() {
    this.Init();
    this.drawline = true;
	expatMap.PrepareDrawline();
    expatMap.SetCursor("crosshair");
	expatMap.DrawLine();
};
ExpatMapToolbar.prototype.DrawBlueLine = function() {
    this.Init();
    this.drawBlueLine = true;
    expatMap.SetCursor("crosshair");
	expatMap.DrawBlueLine();
};
ExpatMapToolbar.prototype.DrawBlueSharp = function() {
    this.Init();
    this.drawBlueSharp = true;
    expatMap.SetCursor("crosshair");
	expatMap.DrawBlueSharp();
};

ExpatMapToolbar.prototype.DrawSharp = function() {
    this.Init();
    this.drawSharp = true;
	expatMap.PrepareDrawline();
    expatMap.SetCursor("crosshair");
	expatMap.DrawSharp();
};

ExpatMapToolbar.prototype.StaticMap = function() {
    this.Init();
    expatMap.ToStaticMap();
    expatMap.EnableDragging();
};

ExpatMapToolbar.prototype.FromHere = function() {
    this.Init();
    this.fromHere = true;
    expatMap.SetCursor("crosshair");
};

ExpatMapToolbar.prototype.ToHere = function() {
    this.Init();
    this.toHere = true;
    expatMap.SetCursor("crosshair");
};

ExpatMapToolbar.prototype.AddMyMark = function() {
    this.Init();
    this.addMarker = true;
};

ExpatMapToolbar.prototype.Clean = function() {
    this.Init();
    expatMap.Clean();
};

ExpatMapToolbar.prototype.Cal = function() 
{
    this.Init();
    expatMap.PrepareDrawline();
    expatMap.calLable = null;
    expatMap.startCalPoint = null;
    this.cal = true;
    totalDistance =0.0;
	prevTotalDisance =0.0;
    expatMap.SetCursor("crosshair");
	expatMap.DrawDistance();
};

ExpatMapToolbar.prototype.EarseLine = function() {
    this.Init();
    this.removeFlag = true;
};
////////////////////////////////其他页面函数/////////////////////////////////
ExpatMarkerMgr = function(vmap){
	this.markMgrOpt = { borderPadding: 10, trackMarkers: true };
	this.map = vmap;
    this.markerMgr = new MarkerManager(this.map,this.markMgrOpt);
	this.expatMarkerArray=new ExpatMapHashtable();
	this.AutoRefresh = true;
};
ExpatMarkerMgr.prototype.Reset = function () {
   this.expatMarkerArray.Clear(); 
   //this.markerMgr.clearMarkers();
};

ExpatMarkerMgr.prototype.ClearMarkers = function () {

   var markerArray = this.expatMarkerArray.Values();
   for(var i=0;i<markerArray.length;i++)
   {
   	  var expatMarker = markerArray[i];
	  if(expatMarker==null){continue;}
	  if(expatMarker.innerMark)
	  {
	  	// this.markerMgr.removeMarker(expatMarker.innerMark);
		 this.map.removeOverlay(expatMarker.innerMark);
	  }
	  if(expatMarker.innerLable)
	  {
	  	 //this.markerMgr.removeMarker(expatMarker.innerLable);
		 this.map.removeOverlay(expatMarker.innerLable);
	  }
	  if(expatMarker.tipsLable)
	  {
	  	// this.markerMgr.removeMarker(expatMarker.tipsLable);
		 this.map.removeOverlay(expatMarker.tipsLable);
	  }
	  if(expatMarker.tagObj)
	  {
	  	// this.markerMgr.removeMarker(expatMarker.tagObj);
		this.map.removeOverlay(expatMarker.tagObj);
	  }
   }
   this.Reset();
};

ExpatMarkerMgr.prototype.AddMarker = function (marker, minZoom, maxZoom) {
   var existMarker = this.expatMarkerArray.GetValue(marker.id);
   if(existMarker != null)
   {
   	  if(ExpatMarker.Equal(existMarker,marker)==true)
	     return;
	  this.RemoveMarker(marker.id);
   }
   existMarker = marker;
   if (existMarker.innerMark!=null) {
		// this.markerMgr.addMarker(existMarker.innerMark,existMarker.minZoom,existMarker.maxZoom);
		 this.map.addOverlay(existMarker.innerMark);
   }
   if (existMarker.innerLable !=null) {
       // this.markerMgr.addMarker(existMarker.innerLable,existMarker.minZoom,existMarker.maxZoom);
	   this.map.addOverlay(existMarker.innerLable);
   }
    if (existMarker.tagObj !=null) {
       //this.markerMgr.addMarker(existMarker.tagObj,existMarker.minZoom,existMarker.maxZoom);
	   this.map.addOverlay(existMarker.tagObj);
    }
   this.expatMarkerArray.Add(marker.id,marker);
   if (this.AutoRefresh == true) {
    	this.Refresh();
   }
};

ExpatMarkerMgr.prototype.OnMapMoveEnd = function(marker, oldPoint, newPoint){
};

ExpatMarkerMgr.prototype.RemoveMarker = function(markerId){
   var existMarker = this.expatMarkerArray.GetValue(markerId);
   if(existMarker != null)
   {
   	 if (existMarker.innerMark != null) {
	 	// this.markerMgr.removeMarker(existMarker.innerMark);
		 this.map.removeOverlay(existMarker.innerMark);
		 existMarker.innerMark = null;
	 }
	 if (existMarker.innerLable != null) {
	 	//this.markerMgr.removeMarker(existMarker.innerLable);
		  this.map.removeOverlay(existMarker.innerLable);
		existMarker.innerLable = null;
	 }
	 if(existMarker.tipsLable)
	{
		// this.markerMgr.removeMarker(existMarker.tipsLable);
		  this.map.removeOverlay(existMarker.tipsLable);
		existMarker.tipsLable = null;
	}
	if(existMarker.tagObj)
	{
		//this.markerMgr.removeMarker(existMarker.tagObj);
	     this.map.removeOverlay(existMarker.tagObj);
		existMarker.tagObj = null;
	}
	this.expatMarkerArray.Remove(markerId);
   }
   if (this.AutoRefresh == true) {
   	this.Refresh();
   }
};

ExpatMarkerMgr.prototype.GetMarker = function(markerId)
{
    var existMarker = this.expatMarkerArray.GetValue(markerId);
    if (existMarker != null) 
        return existMarker;
    return null;
};

ExpatMarkerMgr.prototype.MarkerArray = function()
{
    var markerArray = this.expatMarkerArray.Values();
	return markerArray;
};

ExpatMarkerMgr.prototype.Refresh = function(){
	 
};


/////////////////////////////////////////////////////////
function ExpatMapHashtable(){
      this.items = {};
}
ExpatMapHashtable.prototype.Add = function(key,value) {
      if (typeof(key) == "undefined")
            return;
      if (this.Contains(key)==true)
            return;
      if (typeof(value)=="undefined")
            return
      this.items[key] = value;
};

ExpatMapHashtable.prototype.Contains = function (key) {
        return typeof(this.items[key])!="undefined";
};

ExpatMapHashtable.prototype.Remove = function(key){
       delete this.items[key];
};

ExpatMapHashtable.prototype.Count = function (){
    var i=0;
    for (var k in this.items) i++;
    return i;
};

ExpatMapHashtable.prototype.GetValue = function (key) {
       return this.items[key];
};

ExpatMapHashtable.prototype.Clear = function() {
      for (var k in this.items)
            delete this.items[k];
};

ExpatMapHashtable.prototype.Values = function(){
    var dataArray = [];
    for (var k in this.items) {
      dataArray.push(this.items[k]);
    }
    return dataArray;
};

ExpatMapHashtable.prototype.PrintContent = function(){
	var content ="";
    for (var k in this.items) {
	   content +=k+":" +this.items[k] +"\n\r";
    }
	alert(content);
};








function ExtLargeMapControl(opts) {
    this.sliderStep = 9;
    this.imgSrc = "/images/mapcontrols3d.png";
    this.imgSmallSrc = "/images/szc3d.png";

    this.divTbl = {};
    this.divTbl.container = { "left": 0, "top": 0, "width": 59 };
    this.divTbl.topArrowBtn = { "left": 20, "top": 0, "width": 18, "height": 18 };
    this.divTbl.leftArrowBtn = { "left": 0, "top": 20 };
    this.divTbl.rightArrowBtn = { "left": 40, "top": 20 };
    this.divTbl.bottomArrowBtn = { "left": 20, "top": 40 };
    this.divTbl.centerBtn = { "left": 20, "top": 20 };
    this.divTbl.zoomSlideBarContainer = { "left": 19, "top": 86, "width": 22 };
    this.divTbl.zoomSliderContainer = { "left": 0, "top": 0, "width": 22, "height": 14 };
    this.divTbl.zoomSliderContainerImg = { "left": 0, "top": -384, "width": 22, "height": 14 };
    this.divTbl.zoomOutBtnContainer = { "left": 0, "top": 0, "width": 59, "height": 23 };
    this.divTbl.zoomOutBtnContainerImg = { "left": 0, "top": -360, "width": 59, "height": 23 };

    opts = opts || {};
    this.zoomInBtnTitle = opts.zoomInBtnTitle || "zoom in";
    this.zoomOutBtnTitle = opts.zoomOutBtnTitle || "zoom out";
    this.moveNorthBtnTitle = opts.moveNorthBtnTitle || "north";
    this.moveSouthBtnTitle = opts.moveSouthBtnTitle || "south";
    this.moveEastBtnTitle = opts.moveEastBtnTitle || "east";
    this.moveWestBtnTitle = opts.moveWestBtnTitle || "west";
    this.homeBtnTitle = opts.homeBtnTitle || "home position";
    this.opts = opts;

    this.divSmallTbl = {};
    this.divSmallTbl.container = { "left": 0, "top": 0, "width": 19, "height": 42 };
    this.divSmallTbl.zoomInBtn = { "left": 0, "top": 0, "width": 19, "height": 21 };
    this.divSmallTbl.zoomOutBtnImg = { "left": 0, "top": -21, "width": 19, "height": 21 };
    this.divSmallTbl.zoomOutBtn = { "left": 0, "top": 21, "width": 19, "height": 21 };

};
ExtLargeMapControl.prototype = new GControl();
ExtLargeMapControl.prototype.initialize = function(map) {

    this._map = map;

    GEvent.addListener(map, 'maptypechanged', GEvent.callback(this, this._updateZoomSliderRange));

    var _handleList = {};

    this._keyboardhandler = new GKeyboardHandler(map);
    var agt = navigator.userAgent.toLowerCase();

    this._is_ie = ((agt.indexOf("msie") !== -1) && (agt.indexOf("opera") === -1));
    this._is_gecko = (agt.indexOf('gecko') !== -1);
    this._is_opera = (agt.indexOf("opera") !== -1);

    //common image
    var commonImg = new Image();
    commonImg.src = this.imgSrc;

    var container;
    var zoomOutBtn;
    var zoomInBtn;
    if (this.opts.type === "small") {
        // create container
        container = document.createElement("div");
        container.style.left = this.divSmallTbl.container.left + "px";
        container.style.top = this.divSmallTbl.container.top + "px";
        container.style.width = this.divSmallTbl.container.width + "px";
        container.style.height = this.divSmallTbl.container.height + "px";
        container.style.position = "absolute";
        container.style.overflow = "hidden";
		container.style.zIndex ="500";
        this._container = container;

        //zoom up button
        zoomInBtn = this.makeImgDiv_(this.imgSmallSrc, this.divSmallTbl.zoomInBtn);
        zoomInBtn.style.cursor = "pointer";
        zoomInBtn.title = this.zoomInBtnTitle;
        container.appendChild(zoomInBtn);

        //zoom down button
        zoomOutBtn = this.makeImgDiv_(this.imgSmallSrc, this.divSmallTbl.zoomOutBtnImg);
        zoomOutBtn.style.cursor = "pointer";
        zoomOutBtn.style.overflow = "hidden";
        zoomOutBtn.style.position = "absolute";
        zoomOutBtn.style.left = this.divSmallTbl.zoomOutBtn.left + "px";
        zoomOutBtn.style.top = this.divSmallTbl.zoomOutBtn.top + "px";
        zoomOutBtn.style.width = this.divSmallTbl.zoomOutBtn.width + "px";
        zoomOutBtn.style.height = this.divSmallTbl.zoomOutBtn.height + "px";
        zoomOutBtn.title = this.zoomOutBtnTitle;
        container.appendChild(zoomOutBtn);

        // events
        GEvent.bindDom(zoomOutBtn, "click", this, this._eventZoomOut);
        GEvent.bindDom(zoomInBtn, "click", this, this._eventZoomIn);
    } else {
        // calculation of controller size
        var currentMapType = map.getCurrentMapType();
        var minZoom = parseInt(currentMapType.getMinimumResolution(), 10);
        var maxZoom = parseInt(map.getCurrentMapType().getMaximumResolution(), 10);
        this._maxZoom = maxZoom;
        this._step = this.sliderStep;
        var ctrlHeight = (86 + 5) + (maxZoom - minZoom + 1) * this.sliderStep + 5;

        // create container
        container = this.makeImgDiv_(this.imgSrc, this.divTbl.container);
        container.style.height = (ctrlHeight + this.sliderStep + 2) + "px";
		container.style.zIndex ="800";
        _handleList.container = container;
        this._container = container;

        //top arrow button
        var topBtn = this.makeImgDiv_(this.imgSrc, this.divTbl.topArrowBtn);
        topBtn.style.cursor = "pointer";
        topBtn.style.left = "20px";
        topBtn.style.top = "0px";
		topBtn.style.zIndex ="800";
        topBtn.title = this.moveNorthBtnTitle;
        container.appendChild(topBtn);

        //left arrow button
        var leftBtn = topBtn.cloneNode(true);
        leftBtn.style.left = this.divTbl.leftArrowBtn.left + "px";
        leftBtn.style.top = this.divTbl.leftArrowBtn.top + "px";
        leftBtn.title = this.moveWestBtnTitle;
		leftBtn.style.zIndex ="800";
        container.appendChild(leftBtn);

        //right arrow button
        var rightBtn = topBtn.cloneNode(true);
        rightBtn.style.left = this.divTbl.rightArrowBtn.left + "px";
        rightBtn.style.top = this.divTbl.rightArrowBtn.top + "px";
        rightBtn.title = this.moveEastBtnTitle;
		rightBtn.style.zIndex ="800";
        container.appendChild(rightBtn);

        //bottom arrow button
        var bottomBtn = topBtn.cloneNode(true);
        bottomBtn.style.left = this.divTbl.bottomArrowBtn.left + "px";
        bottomBtn.style.top = this.divTbl.bottomArrowBtn.top + "px";
        bottomBtn.title = this.moveSouthBtnTitle;
		bottomBtn.style.zIndex ="800";
        container.appendChild(bottomBtn);

        //center button
        var homeBtn = topBtn.cloneNode(true);
        homeBtn.style.left = this.divTbl.centerBtn.left + "px";
        homeBtn.style.top = this.divTbl.centerBtn.top + "px";
        homeBtn.title = this.homeBtnTitle;
		homeBtn.style.zIndex ="800";
        container.appendChild(homeBtn);

        _handleList.topBtn = topBtn;
        _handleList.leftBtn = leftBtn;
        _handleList.rightBtn = rightBtn;
        _handleList.bottomBtn = bottomBtn;
        _handleList.homeBtn = homeBtn;


        // zoom slider container
        var zoomSlideBarContainer = document.createElement("div");
        zoomSlideBarContainer.style.position = "absolute";
        zoomSlideBarContainer.style.left = this.divTbl.zoomSlideBarContainer.left + "px";
        zoomSlideBarContainer.style.top = this.divTbl.zoomSlideBarContainer.top + "px";
        zoomSlideBarContainer.style.width = this.divTbl.zoomSlideBarContainer.width + "px";
        zoomSlideBarContainer.style.height = ((maxZoom - minZoom + 1) * this.sliderStep) + "px";
        zoomSlideBarContainer.style.overflow = "hidden";
        zoomSlideBarContainer.style.cursor = "pointer";
		zoomSlideBarContainer.style.zIndex="800";
        container.appendChild(zoomSlideBarContainer);
        _handleList.slideBar = zoomSlideBarContainer;

        // zoom slider Button
        var zoomLevel = map.getZoom();
        var zoomSliderContainer = this.makeImgDiv_(this.imgSrc, this.divTbl.zoomSliderContainerImg);

        zoomSliderContainer.style.top = ((maxZoom - zoomLevel) * this.sliderStep + 1) + "px";
        zoomSliderContainer.style.left = this.divTbl.zoomSliderContainer.left + "px";
        zoomSliderContainer.style.width = this.divTbl.zoomSliderContainer.width + "px";
        zoomSliderContainer.style.height = this.divTbl.zoomSliderContainer.height + "px";

        zoomSlideBarContainer.cursor = "url(http://maps.google.com/mapfiles/openhand.cur), default";
        zoomSlideBarContainer.appendChild(zoomSliderContainer);
        _handleList.slideBarContainer = zoomSliderContainer;



        //zoomOut Btn container
        var zoomOutBtnContainer = this.makeImgDiv_(this.imgSrc, this.divTbl.zoomOutBtnContainerImg);
        zoomOutBtnContainer.style.top = (86 + (maxZoom - minZoom + 1) * this.sliderStep) + "px";
        zoomOutBtnContainer.style.left = this.divTbl.zoomOutBtnContainer.left + "px";
        zoomOutBtnContainer.style.width = this.divTbl.zoomOutBtnContainer.width + "px";
        zoomOutBtnContainer.style.height = this.divTbl.zoomOutBtnContainer.height + "px";
		zoomOutBtnContainer.style.zIndex="500";

        zoomOutBtnContainer.cursor = "url(http://maps.google.com/mapfiles/openhand.cur), default";
        container.appendChild(zoomOutBtnContainer);
        _handleList.zoomOutBtnContainer = zoomOutBtnContainer;


        //zoomOut button
        zoomOutBtn = document.createElement("div");
        zoomOutBtn.style.position = "absolute";
        zoomOutBtn.style.left = "20px";
        zoomOutBtn.style.top = (91 + (maxZoom - minZoom + 1) * this.sliderStep) + "px";
        zoomOutBtn.style.width = "18px";
        zoomOutBtn.style.height = "23px";
        zoomOutBtn.style.cursor = "pointer";
        zoomOutBtn.style.overflow = "hidden";
		zoomOutBtn.style.zIndex="500";
        zoomOutBtn.title = this.zoomOutBtnTitle;
        container.appendChild(zoomOutBtn);
        _handleList.zoomOutBtn = zoomOutBtn;

        //zoomIn button
        zoomInBtn = document.createElement("div");
        zoomInBtn.style.position = "absolute";
        zoomInBtn.style.left = "20px";
        zoomInBtn.style.top = "65px";
        zoomInBtn.style.width = "18px";
        zoomInBtn.style.height = "23px";
        zoomInBtn.style.cursor = "pointer";
        zoomInBtn.style.overflow = "hidden";
        zoomInBtn.title = this.zoomInBtnTitle;
		zoomInBtn.style.zIndex="500";
        container.appendChild(zoomInBtn);
        _handleList.zoomInBtn = zoomInBtn;

        // events
        GEvent.bindDom(_handleList.topBtn, "click", this, this._eventTop);
        GEvent.bindDom(_handleList.leftBtn, "click", this, this._eventLeft);
        GEvent.bindDom(_handleList.rightBtn, "click", this, this._eventRight);
        GEvent.bindDom(_handleList.bottomBtn, "click", this, this._eventBottom);
        GEvent.bindDom(_handleList.homeBtn, "click", this, this._eventHome);
        GEvent.bindDom(_handleList.zoomOutBtn, "click", this, this._eventZoomOut);
        GEvent.bindDom(_handleList.zoomInBtn, "click", this, this._eventZoomIn);
        GEvent.bindDom(_handleList.slideBar, "click", this, this._eventSlideBar);
        GEvent.bind(map, "zoomend", this, this._eventZoomEnd);

        var drgOpt = {
            container: _handleList.slideBar
        };
        var drgCtrl = new GDraggableObject(_handleList.slideBarContainer, drgOpt);
        GEvent.bindDom(drgCtrl, "dragend", this, this._eventSlideDragEnd);
        this._slider = drgCtrl;

        //set current slider position
        this._eventZoomEnd(map.getZoom(), map.getZoom());
    }
    this._handleList = _handleList;
    map.getContainer().appendChild(container);
	//expatMap.LogFile(container.outerHTML );
	//$('#testDiv').html(container.outerHTML);
    return container;
};

ExtLargeMapControl.prototype._updateZoomSliderRange = function(setMaxZoom) 
{
    var minZoom = parseInt(this._map.getCurrentMapType().getMinimumResolution(), 10);
    var maxZoom = parseInt(this._map.getCurrentMapType().getMaximumResolution(), 10);
    if (this.isNull(setMaxZoom) === false) {
        maxZoom = setMaxZoom;
    } else {
        this._maxZoom = maxZoom;
    }
    var ctrlHeight = (86 + 5) + (maxZoom - minZoom + 1) * this.sliderStep + 5;

    if (this.isNull(this._handleList) === true) {
        return;
    }

    // Update DOM elements to ajust to current Resolution range.
    this._handleList.container.style.height = (ctrlHeight + this.sliderStep + 2) + "px";
    this._handleList.slideBar.style.height = ((maxZoom - minZoom + 1) * this.sliderStep) + "px";
    this._handleList.zoomOutBtnContainer.style.top = (86 + (maxZoom - minZoom + 1) * this.sliderStep) + "px";
    this._handleList.zoomOutBtn.style.top = (91 + (maxZoom - minZoom + 1) * this.sliderStep) + "px";
    this._handleList.slideBarContainer.style.top = ((maxZoom - this._map.getZoom()) * this.sliderStep + 1) + "px";

};

ExtLargeMapControl.prototype._eventTop = function() {
    this._map.panDirection(0, 1);
};

ExtLargeMapControl.prototype._eventLeft = function() {
    this._map.panDirection(1, 0);
};

ExtLargeMapControl.prototype._eventRight = function() {
    this._map.panDirection(-1, 0);
};

ExtLargeMapControl.prototype._eventBottom = function() {
    this._map.panDirection(0, -1);
};

ExtLargeMapControl.prototype._eventZoomOut = function() {
    this._map.zoomOut();
};

ExtLargeMapControl.prototype._eventZoomIn = function() {
    this._map.zoomIn();
};

ExtLargeMapControl.prototype._eventSlideBar = function(e) {
    var map = this._map;
    //calculate zoomlevel
    var mouseY = e.clientY;
    var slideStep = this._step;
    var maxZoom = this._maxZoom;
    var container = this._container;

    //set new zoomLevel
    var ctrlPos = this._getDomPosition(container);
    mouseY -= (ctrlPos.y + 91);
    var zoomLevel = Math.floor(maxZoom - (mouseY / slideStep));
    zoomLevel = zoomLevel < 0 ? 0 : zoomLevel;
    map.setZoom(zoomLevel);
};

ExtLargeMapControl.prototype._getDomPosition = function(that) {
    var targetEle = that;
    var pos = { x: 0, y: 0 };

    while (targetEle) {
        pos.x += targetEle.offsetLeft;
        pos.y += targetEle.offsetTop;
        targetEle = targetEle.offsetParent;

        if (targetEle && this._is_ie) {
            pos.x += (parseInt(ExtLargeMapControl.getElementStyle(targetEle,
          "borderLeftWidth", "border-left-width"), 10) || 0);
            pos.y += (parseInt(ExtLargeMapControl.getElementStyle(targetEle,
          "borderTopWidth", "border-top-width"), 10) || 0);
        }
    }

    if (this._is_gecko) {
        var bd = document.getElementsByTagName("BODY")[0];
        pos.x += 2 * (parseInt(ExtLargeMapControl.getElementStyle(bd,
        "borderLeftWidth", "border-left-width"), 10) || 0);
        pos.y += 2 * (parseInt(ExtLargeMapControl.getElementStyle(bd,
        "borderTopWidth", "border-top-width"), 10) || 0);
    }
    return pos;
};

ExtLargeMapControl.getElementStyle = function(targetElm, IEStyleProp, CSSStyleProp) {
    var elem = targetElm;
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
};

ExtLargeMapControl.prototype._eventSlideDragEnd = function(e) {
    //calculate zoomlevel
    var maxZoom = this._maxZoom;
    var mouseY = this._slider.top;
    var step = this._step;

    //set new zoomLevel
    var zoomLevel = Math.floor(maxZoom - (mouseY / step));
    zoomLevel = zoomLevel < 0 ? 0 : zoomLevel;
    this._map.setZoom(zoomLevel);
};

ExtLargeMapControl.prototype._eventHome = function() {
    this._map.returnToSavedPosition();
};

ExtLargeMapControl.prototype._eventZoomEnd = function(oldZoom, newZoom) {
    var maxZoom = this._maxZoom;
    if (newZoom < maxZoom) {
        this._updateZoomSliderRange();
    } else {
        this._updateZoomSliderRange(newZoom);
        maxZoom = newZoom;
    }
    var step = this._step;
    this._slider.moveTo(new GPoint(0, (maxZoom - newZoom) * step));
};

ExtLargeMapControl.prototype.copy = function() {
    return new ExtLargeMapControl(this.latlng_, this.opts);
};

ExtLargeMapControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 10));
};

ExtLargeMapControl.prototype.selectable = function() {
    return false;
};

ExtLargeMapControl.prototype.printable = function() {
    return true;
};

ExtLargeMapControl.prototype.isNull = function(value) {
    if (!value && value !== 0 ||
     value === undefined ||
     value === "" ||
     value === null ||
     typeof value === "undefined") {
        return true;
    }
    return false;
};
ExtLargeMapControl.prototype.makeImgDiv_ = function(imgSrc, params) {
    var imgDiv = document.createElement("div");
    imgDiv.style.position = "absolute";
    imgDiv.style.overflow = "hidden";

    if (params.width) {
        imgDiv.style.width = params.width + "px";
    }
    if (params.height) {
        imgDiv.style.height = params.height + "px";
    }


    var img = null;
    if (!this._is_ie) {
        img = new Image();
        img.src = imgSrc;
    } else {
        img = document.createElement("div");
        if (params.width) {
            img.style.width = params.width + "px";
        }
        if (params.height) {
            img.style.height = params.height + "px";
        }
    }
    img.style.position = "relative";
    img.style.left = params.left + "px";
    img.style.top = params.top + "px";
    img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgSrc + "')";
    imgDiv.appendChild(img);

    return imgDiv;
};
var TransSearchObj = function(){
   this.saddr ="";
   this.slat ="";
   this.slng ="";
   this.smid ="";
   
   this.eaddr="";
   this.elat="";
   this.elng="";
   this.emid ="";
   
   this.strategy =0;  
   
   this.presaddr =""; 
   this.preeaddr ="";
   
   this.hasStart = false;
   this.hasEnd = false;
};
TransSearchObj.prototype.CleanValue= function(flag) 
{
	if(flag==0)
	{
	   //this.saddr ="";
	   this.slat ="";
	   this.slng ="";
	   this.smid ="";
	}
	else{
	   //this.eaddr="";
       this.elat="";
       this.elng="";
       this.emid ="";
	}
};
 TransSearchObj.prototype.Search= function() 
{
	  if(this.presaddr !="" && this.presaddr != this.saddr)
	   {
	   	  this.CleanValue(0);
	   }
	   if(this.preeaddr !="" && this.preeaddr != this.eaddr)
	   {
	   	  this.CleanValue(1);
	   }
	  window.location.href = "/EMap.aspx?action=trans&from=" + encodeURIComponent(this.saddr) +
	                                 "&slat=" + this.slat +
	                                 "&slng=" + this.slng +
									 "&smid=" + this.smid +
	                                 "&to=" + encodeURIComponent(this.eaddr) +
	                                 "&elat=" + this.elat +
	                                 "&elng=" + this.elng +
									 "&emid=" + this.emid +
	                                 "&strategy=" + this.strategy;
};

var ExpatMarker = function()
{
   this.iconWidth=24;
   this.iconHeight=24;
   
   this.title ="";
   this.disp ="";
   
   this.lat=0;
   this.lng=0;
   this.infoHtml="";
   this.tipInfo ="";
   this.ajaxUrl="";
   this.minZoom=8;
   this.maxZoom=17;
   this.id =new Date().getTime()+"";
   
   this.index =-1;
   this.innerMark=null;
   this.innerLable =null;
   this.tipsLable = null;
   
   this.currentDistrictMarker=null;
   this.hasData=false;
   
   this.tagObj =null;
   this.popInfo ="";
   this.alwaysShowPopInfo=false;
   this.iconAnchorCenter = false;
   this.iconArchorX=-1;
   this.iconArchorY=-1;
   this.iconUrl="";
   this.iconUrlFocus="";
   this.iconUrlNormarl="";
   this.clickMethod ="";
};
ExpatMarker.Equal = function(markerOne,markerTwo)
{  
      if(markerTwo==null && markerOne==null)
	     return true;
   	  if((markerTwo==null && markerOne != null)||
	    (markerOne==null && markerTwo != null))
	      return false;
   	  return (markerOne.iconWidth=markerTwo.iconWidth)&&
	  (markerOne.iconHeight=markerTwo.iconHeight)&&
	  (markerOne.title=markerTwo.title)&&
	  (markerOne.disp=markerTwo.disp)&&
	  (markerOne.iconUrl=markerTwo.iconUrl)&&
	  (markerOne.lat=markerTwo.lat)&&
	  (markerOne.lng=markerTwo.lng)&&
	  (markerOne.infoHtml=markerTwo.infoHtml)&&
	  (markerOne.tipInfo=markerTwo.tipInfo)&&
	  (markerOne.ajaxUrl=markerTwo.ajaxUrl)&&
	  (markerOne.minZoom=markerTwo.minZoom)&&
	  (markerOne.maxZoom=markerTwo.maxZoom)&&
	  (markerOne.id=markerTwo.id)&&
	  (markerOne.popInfo=markerTwo.popInfo)&&
	  (markerOne.alwaysShowPopInfo=markerTwo.alwaysShowPopInfo)&&
	  (markerOne.iconAnchorCenter=markerTwo.iconAnchorCenter);
};

var ExpatSharp = function()
{
	this.title="";
	this.points =[];
	this.ajaxUrl="";
	this.infHtml="";
	this.id ="";
	this.tipInfo="";
	
	this.clat=0;
    this.clng=0;
	this.lableHtml="";
	
	this.innerObj=null;
    this.tipsLable = null;
	this.lableObj =null;
	
	this.enterFn = null;
	
	this.clat =0;
	this.clng =0;
};

ExpatSharp.Equal = function(sharpOne,sharpTwo){
    if (sharpOne == null && sharpTwo == null) 
        return true;
    if ((sharpOne == null && sharpTwo != null) ||
        (sharpOne == null && sharpTwo != null)) 
        return false;
    return (sharpOne.title = sharpTwo.title) &&
    (sharpOne.id = sharpTwo.id) &&
    (sharpOne.infHtml = sharpTwo.infHtml) &&
    (sharpOne.ajaxUrl = sharpTwo.ajaxUrl) &&
    (sharpOne.clat = sharpTwo.clat) &&
    (sharpOne.clng = sharpTwo.clng) &&
    (sharpOne.lableHtml = sharpTwo.lableHtml);
};




















var GMarkerEx = function(latlng, options){
    this.latlng_ = latlng;
    this.title_ = options.title || "";
    if (options.title) {options.title = undefined;}
    this.opts_ = options;
    this.isIE_ = (navigator.userAgent.toLowerCase().indexOf('msie') != -1 ) ? true : false;
    
    //marker popup's matrix
    var yPos=0;
    this.popupImgSrc_="/images/popmark.png";
    this.popupTbl=new Object();
    
    //left-top
    this.popupTbl["leftTop"]={ "left": 0, "top":yPos, "width":19, "height":7};
    this.popupTbl["leftTopFill"]={ "left": 16, "top":3, "width":4, "height":4};
    
    //right-top
    this.popupTbl["rightTop"]={ "left": 19, "top":yPos, "width":10, "height":7};
    this.popupTbl["rightTopImg"]={ "left": -125, "top":0, "width":10, "height":7};
    
    //center-top
    this.popupTbl["centerTopFill"]={ "left": 19, "top":yPos, "width":0, "height":7};
    
    //left-body
    yPos+=this.popupTbl["leftTop"].height;
    this.popupTbl["leftBody"]={ "left": 11, "top":yPos, "width":8, "height":0};
    
    //center-body
    this.popupTbl["centerBodyFill"]={ "left": 19, "top":yPos, "width": 40, "height":15};
    
    //right-body
    this.popupTbl["rightBody"]={ "left": 19, "top":yPos, "width":9, "height":0};
    
    //left-bottom
    this.popupTbl["leftBottom"]={ "left": 0, "top":yPos, "width":20, "height":21};
    this.popupTbl["leftBottomImg"]={ "left": 0, "top":-13, "width":20, "height":21};
    this.popupTbl["leftBottomFill"]={ "left": 16, "top":0, "width":4, "height":6};
    
    //right-bottom
    this.popupTbl["rightBottom"]={ "left": 19, "top":yPos, "width":10, "height":7};
    this.popupTbl["rightBottomImg"]={ "left": -125, "top":-13, "width":10, "height":7};

    //center-bottom
    this.popupTbl["centerBottomFill"]={ "left": 19, "top":(yPos + (this.isIE_ ? -1 : 0)), "width":0, "height":(6 + (this.isIE_ ? 1 : 0))};
    GMarker.apply(this, arguments);
};

GMarker.prototype.initialize_ = GMarker.prototype.initialize;
GMarker.prototype.redraw_ = GMarker.prototype.redraw;
GMarker.prototype.remove_ = GMarker.prototype.remove;

GMarkerEx.prototype = GMarker.prototype;

GMarkerEx.prototype.initialize = function(map) {

    function makeImgDiv(imgSrc, params){
        var isIE_ = (navigator.userAgent.toLowerCase().indexOf('msie') != -1 ) ? true : false;
        
        var imgDiv = document.createElement("div");
        with(imgDiv.style){
            position = "absolute";
            overflow="hidden";
            if(params.width){width = params.width+"px";};
            if(params.height){height = params.height+"px";};
        };
        
        var img = null;
        if(!isIE_){
            img = new Image();
            img.src = imgSrc;
        }else{
            img = document.createElement("div");
            with(img.style){
                if(params.width){width = params.width+"px";};
                if(params.height){height = params.height+"px";};
            };
        };
        with(img.style){
            position="relative";
            left = params.left+"px";
            top =  params.top+"px";
            filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgSrc+"')";
        };
        imgDiv.appendChild(img);
        return imgDiv;
    };
    function fillDiv(params){
        
        var bgDiv = document.createElement("div");
        with(bgDiv.style){
            position="absolute";
            backgroundColor="#f9f9f9";
            fontSize="1px";
            lineHeight="1px";
            overflow="hidden";
            left = params.left+"px";
            top = params.top+"px";
            width = params.width+"px";
            height = params.height+"px";
        };
        return bgDiv;
    };
    
    GMarker.prototype.initialize_.apply(this, arguments);
    this.map_ = map;
    this.latlng_ = this.getLatLng();
    
    this.popupImg_ = new Image();
    this.popupImg_.src = "/images/popmark.png";
 
    this.container_ = document.createElement("div");
    map.getPane(G_MAP_MARKER_PANE).appendChild(this.container_);
    with(this.container_.style){
        zIndex = GOverlay.getZIndex(this.latlng_.lat());
        position = "absolute";
        visibility = "hidden";
    };
    if(this.popupTbl==null)
	  return;
  
    this.leftTop_ = makeImgDiv(this.popupImgSrc_, this.popupTbl["leftTop"]);
    this.leftTop_.appendChild(fillDiv(this.popupTbl["leftTopFill"]));
    this.container_.appendChild(this.leftTop_);
    
    //====================================//
    //          left-body                 //
    //====================================//
    this.leftBody_ = fillDiv(this.popupTbl["leftBody"]);
    with(this.leftBody_.style){
        borderWidth="0 0 0 1px";
        borderStyle="none none none solid";
        borderColor="#000000";
    };
    this.container_.appendChild(this.leftBody_);
    
    
    //====================================//
    //   make container left-bottom side  //
    //====================================//
    this.leftBottom_ = makeImgDiv(this.popupImgSrc_, this.popupTbl["leftBottomImg"]);
    with(this.leftBottom_.style){
        left=this.popupTbl["leftBottom"].left+"px";
        top=this.popupTbl["leftBottom"].top+"px";
        width=this.popupTbl["leftBottom"].width+"px";
        height=this.popupTbl["leftBottom"].height+"px";
    };
    this.leftBottom_.appendChild(fillDiv(this.popupTbl["leftBottomFill"]));
    this.container_.appendChild(this.leftBottom_);
    
    //====================================//
    //          body container boddom           //
    //====================================//
    //make text container
    this.bodyContainer_  = document.createElement("div");
    with(this.bodyContainer_.style){
        position="absolute";
        backgroundColor="#f9f9f9";
        overflow="hidden";
        left = this.popupTbl["centerBodyFill"].left+"px";
        top = this.popupTbl["centerBodyFill"].top+"px";
        width = this.popupTbl["centerBodyFill"].width+"px";
        height = this.popupTbl["centerBodyFill"].height+"px";
    };
    this.container_.appendChild(this.bodyContainer_);
    
    //====================================//
    //             right-top              //
    //====================================//
    this.rightTop_ = makeImgDiv(this.popupImgSrc_, this.popupTbl["rightTopImg"]);
    with(this.rightTop_.style){
        left=this.popupTbl["rightTop"].left+"px";
        top=this.popupTbl["rightTop"].top+"px";
        width=this.popupTbl["rightTop"].width+"px";
        height=this.popupTbl["rightTop"].height+"px";
    };
    this.container_.appendChild(this.rightTop_);

    //====================================//
    //             right-bottom           //
    //====================================//
    this.rightBottom_ = makeImgDiv(this.popupImgSrc_, this.popupTbl["rightBottomImg"]);
    with(this.rightBottom_.style){
        left=this.popupTbl["rightBottom"].left+"px";
        top=this.popupTbl["rightBottom"].top+"px";
        width=this.popupTbl["rightBottom"].width+"px";
        height=this.popupTbl["rightBottom"].height+"px";
    };
    this.container_.appendChild(this.rightBottom_);

    
    //====================================//
    //          right-body                 //
    //====================================//
    this.rightBody_ = fillDiv(this.popupTbl["rightBody"]);
    with(this.rightBody_.style){
        borderWidth="0 1px 0 0";
        borderStyle="none solid none none";
        borderColor="#000000";
    };
    this.container_.appendChild(this.rightBody_);


    //====================================//
    //          body container bottom     //
    //====================================//
    this.centerBottom_ = fillDiv(this.popupTbl["centerBottomFill"]);
    with(this.centerBottom_.style){
        borderWidth="0 0 1px 0";
        borderStyle="none none solid none";
        borderColor="#000000";
    };
    this.container_.appendChild(this.centerBottom_);
    
    //====================================//
    //          body container top     //
    //====================================//
    this.centerTop_ = fillDiv(this.popupTbl["centerTopFill"]);
    with(this.centerTop_.style){
        borderColor="#000000";
        borderWidth="1px 0 0 0";
        borderStyle="solid none none none";
    };
    this.container_.appendChild(this.centerTop_);
    
    //====================================//
    //              events                //
    //====================================//
    var this_ = this;
    GEvent.addDomListener(this.container_, "mousedown", function(){return GEvent.trigger(this_, "mousedown");});
    GEvent.addDomListener(this.container_, "dragstart", function(){return GEvent.trigger(this_, "dragstart");});
    GEvent.addDomListener(this.container_, "mouseup", function(){return GEvent.trigger(this_, "mouseup");});
    GEvent.addDomListener(this.container_, "mouseover", function(){return GEvent.trigger(this_, "mouseover");});
    GEvent.addDomListener(this.container_, "mouseout", function(){return GEvent.trigger(this_, "mouseout");});
    
};

GMarkerEx.prototype.redraw = function(force){
    GMarker.prototype.redraw_.apply(this, arguments);
    
    if(force){
        this.setTitle(this.title_);
        this.latlng_=this.getLatLng();
        this.container_.style.zIndex = GOverlay.getZIndex(this.latlng_.lat());
    };
};

GMarkerEx.prototype.copy = function() {
    this.opts_.title = this.title_;
    return new GMarkerEx(this.latlng_, this.opts_);
};

GMarkerEx.prototype.showPopup = function(title){
    if(!this.isNull(title)){
        this.setTitle(title);
    };
	if(this.map_ ==null)
	   return;
    var info = this.map_.getInfoWindow();
    if(!info.isHidden() || this.isNull(this.title_)){
        return;
    };
    this.container_.style.visibility="visible";
};
GMarkerEx.prototype.hidePopup = function(){
    this.container_.style.visibility="hidden";
};


GMarkerEx.prototype.remove = function() {
    GEvent.clearInstanceListeners(this.container_);
    while(this.container_.firstChild){
        this.container_.removeChild(this.container_.firstChild);
    };
    this.container_.parentNode.removeChild(this.container_);
    GMarker.prototype.remove_.apply(this, arguments);
    delete arguments.callee;
};

GMarkerEx.prototype.setTitle = function(title) {
    this.title_ = title;
	if(this.bodyContainer_==null)
	  return;
    while(this.bodyContainer_.firstChild){
        this.bodyContainer_.removeChild(this.bodyContainer_.firstChild);
    };
    this.bodyContainer_.innerHTML =title;
    if(!this.isIE_ && this.bodyContainer_.hasChildNodes){
        if(this.bodyContainer_.firstChild.nodeType==1){
            this.bodyContainer_.firstChild.style.margin = 0;
        };
    };
    var offsetBorder = this.isIE_ ? 2 : 0;
    var cSize  = this.getHtmlSize(title);

    var rightX = this.popupTbl["leftTop"].width + cSize.width;
    
    this.leftBottom_.style.top = (cSize.height +  this.popupTbl["leftBody"].top)+"px" ;
    this.leftBody_.style.height=cSize.height+"px";
    this.bodyContainer_.style.width = cSize.width+"px";
    this.bodyContainer_.style.height = cSize.height+"px";
    this.bodyContainer_.style.top = this.popupTbl["leftBody"].top;
    this.rightTop_.style.left=rightX+"px";
    this.rightBottom_.style.left=this.rightTop_.style.left;
    this.rightBottom_.style.top=this.leftBottom_.style.top;
    this.rightBody_.style.left=rightX +"px";
    this.rightBody_.style.height=this.leftBody_.style.height;
    this.centerBottom_.style.top =this.leftBottom_.style.top;
    this.centerBottom_.style.width = cSize.width+"px";
    this.centerTop_.style.width=cSize.width+"px";
    
    this.size_ = {"width":(rightX+ this.popupTbl["rightTop"].width), "height":(cSize.height + this.popupTbl["leftTop"].height + this.popupTbl["leftBottom"].height)};
    this.container_.style.width=this.size_.width+"px";
    this.container_.style.height=this.size_.height+"px";
 
    var pxPos = this.map_.fromLatLngToDivPixel(this.latlng_);
    this.container_.style.left =  pxPos.x+"px";
    this.container_.style.top = ( pxPos.y - this.size_.height) +"px";
};

GMarkerEx.prototype.getTitle = function() {
    return this.title_;
};

GMarkerEx.prototype.isNull = function(value) {
    if(!value && value!=0 ||
       value==undefined ||
       value=="" ||
       typeof value=="undefined"){return true;};
    return false;
};
GMarker.prototype.getHtmlSize = function(html) {
    var dummyTextNode = document.createElement("span");
    dummyTextNode.innerHTML = html;
    dummyTextNode.style.display="inline";
    document.body.appendChild(dummyTextNode);
    
    var elements = dummyTextNode.getElementsByTagName("*");
    var size = new Object();
    if(elements.length){
        var maxX = 0;
		var maxY=0;
        var width = 6;  //margin
        var height = 6;  //margin
        for(var i=0;i<elements.length;i++){
            elements[i].style.display="inline";
            width=elements[i].offsetWidth;
            if(maxX<width){maxX = width;};
			
			height =elements[i].offsetHeight;
			if(maxY<height){maxY = height;};
            //height+=elements[i].offsetHeight;
        };
        size.width = maxX-2;//dummyTextNode.offsetWidth;
        size.height = maxY-2;// height;
    }else{
        size.width = dummyTextNode.offsetWidth;
        size.height = dummyTextNode.offsetHeight;
    };
    document.body.removeChild(dummyTextNode);
    return size;
};
GPolyline.Shape = function(point, r1, r2, r3, r4, rotation, vertexCount, colour, weight, opacity, opts, tilt){
    var rot = -rotation * Math.PI / 180;
    var points = [];
    var latConv = point.distanceFrom(new GLatLng(point.lat() + 0.1, point.lng())) * 10;
    var lngConv = point.distanceFrom(new GLatLng(point.lat(), point.lng() + 0.1)) * 10;
    var step = (360 / vertexCount) || 10;
    
    var flop = -1;
    if (tilt) {
        var I1 = 180 / vertexCount;
    }
    else {
        var I1 = 0;
    }
    for (var i = I1; i <= 360.001 + I1; i += step) {
        var r1a = flop ? r1 : r3;
        var r2a = flop ? r2 : r4;
        flop = -1 - flop;
        var y = r1a * Math.cos(i * Math.PI / 180);
        var x = r2a * Math.sin(i * Math.PI / 180);
        var lng = (x * Math.cos(rot) - y * Math.sin(rot)) / lngConv;
        var lat = (y * Math.cos(rot) + x * Math.sin(rot)) / latConv;
	 
        points.push(new GLatLng(point.lat() + lat, point.lng() + lng));
    }
    return (new GPolyline(points, colour, weight, opacity, opts))
};

GPolyline.Circle = function(point, radius, colour, weight, opacity, opts){
    return GPolyline.Shape(point, radius, radius, radius, radius, 0, 100, colour, weight, opacity, opts)
};

GPolyline.RegularPoly = function(point, radius, vertexCount, rotation, colour, weight, opacity, opts){
    rotation = rotation || 0;
    var tilt = !(vertexCount & 1);
    return GPolyline.Shape(point, radius, radius, radius, radius, rotation, vertexCount, colour, weight, opacity, opts, tilt)
};

GPolyline.Star = function(point, r1, r2, points, rotation, colour, weight, opacity, opts){
    rotation = rotation || 0;
    return GPolyline.Shape(point, r1, r1, r2, r2, rotation, points * 2, colour, weight, opacity, opts)
};

GPolyline.Ellipse = function(point, r1, r2, rotation, colour, weight, opacity, opts){
    rotation = rotation || 0;
    return GPolyline.Shape(point, r1, r2, r1, r2, rotation, 100, colour, weight, opacity, opts)
};
GPolygon.Shape = function(point, r1, r2, r3, r4, rotation, vertexCount, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts, tilt){
    var rot = -rotation * Math.PI / 180;
    var points = [];
    var latConv = point.distanceFrom(new GLatLng(point.lat() + 0.1, point.lng())) * 10;
    var lngConv = point.distanceFrom(new GLatLng(point.lat(), point.lng() + 0.1)) * 10;
    var step = (360 / vertexCount) || 10;
    
    var flop = -1;
    if (tilt) {
        var I1 = 180 / vertexCount;
    }
    else {
        var I1 = 0;
    }
    for (var i = I1; i <= 360.001 + I1; i += step) {
        var r1a = flop ? r1 : r3;
        var r2a = flop ? r2 : r4;
        flop = -1 - flop;
        var y = r1a * Math.cos(i * Math.PI / 180);
        var x = r2a * Math.sin(i * Math.PI / 180);
        var lng = (x * Math.cos(rot) - y * Math.sin(rot)) / lngConv;
        var lat = (y * Math.cos(rot) + x * Math.sin(rot)) / latConv;
        
        points.push(new GLatLng(point.lat() + lat, point.lng() + lng));
    }
    return (new GPolygon(points, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts))
};

GPolygon.Circle = function(point, radius, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts){
    return GPolygon.Shape(point, radius, radius, radius, radius, 0, 100, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts)
};

GPolygon.RegularPoly = function(point, radius, vertexCount, rotation, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts){
    rotation = rotation || 0;
    var tilt = !(vertexCount & 1);
    return GPolygon.Shape(point, radius, radius, radius, radius, rotation, vertexCount, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts, tilt)
};

GPolygon.Star = function(point, r1, r2, points, rotation, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts){
    rotation = rotation || 0;
    return GPolygon.Shape(point, r1, r1, r2, r2, rotation, points * 2, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts)
};

GPolygon.Ellipse = function(point, r1, r2, rotation, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts){
    rotation = rotation || 0;
    return GPolygon.Shape(point, r1, r2, r1, r2, rotation, 100, strokeColour, strokeWeight, Strokepacity, fillColour, fillOpacity, opts)
};
function EOffset(point, easting, northing){
    var latConv = point.distanceFrom(new GLatLng(point.lat() + 0.1, point.lng())) * 10;
    var lngConv = point.distanceFrom(new GLatLng(point.lat(), point.lng() + 0.1)) * 10;
    return new GLatLng(point.lat() + northing / latConv, point.lng() + easting / lngConv)
};
;
function EOffsetBearing(point, dist, bearing){
    var latConv = point.distanceFrom(new GLatLng(point.lat() + 0.1, point.lng())) * 10;
    var lngConv = point.distanceFrom(new GLatLng(point.lat(), point.lng() + 0.1)) * 10;
    var lat = dist * Math.cos(bearing * Math.PI / 180) / latConv;
    var lng = dist * Math.sin(bearing * Math.PI / 180) / lngConv;
    return new GLatLng(point.lat() + lat, point.lng() + lng)
};


var COLORS = {red: "#ff0000", orange: "#ff8800",green: "#008000",blue:"#000080",purple:"#800080"};
var Colors = ["#FF4500", "#FF1493", "#EE1289", "#EE00EE", "#EE2C2C", "#FF00FF", "#8B008B", "#4B0082","#0A0A0A","#1F1F1F","#2E2E2E","#00008B","#292929"];

function MapLogControl(){
};
MapLogControl.prototype = new GControl();
MapLogControl.prototype.initialize = function(map){
    var container = document.createElement("div");
    var logDiv = document.createElement("div");
    this.setButtonStyle_(logDiv);
    container.appendChild(logDiv);
	this.contentDiv =document.createElement("div");
    logDiv.appendChild(this.contentDiv);
	
    GEvent.addDomListener(logDiv, "click", function(){
    });
    map.getContainer().appendChild(container);
    return container;
};

MapLogControl.prototype.getDefaultPosition = function(){
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(8, 8));
};
 
MapLogControl.prototype.setButtonStyle_ = function(button){
    button.style.textDecoration = "none";
    button.style.color = "#555555";
    button.style.backgroundColor = "#ffffff";
    button.style.font = "small Arial";
    button.style.fontWeight = "bold";
    button.style.border = "1px solid #aaccff";
    button.style.padding = "5px";
    button.style.marginBottom = "1px";
    button.style.textAlign = "left";
    button.style.width = "250px";
    button.style.cursor = "pointer";
};
	
MapLogControl.prototype.setContent = function(content){
   this.contentDiv.innerHTML = content; 
};
////////////////////////////////////////////////////////////////////////////
function MapLogControl(){
};
MapLogControl.prototype = new GControl();
MapLogControl.prototype.initialize = function(map){
    var container = document.createElement("div");
    var logDiv = document.createElement("div");
    this.setButtonStyle_(logDiv);
    container.appendChild(logDiv);
	this.contentDiv =document.createElement("div");
    logDiv.appendChild(this.contentDiv);
	
    GEvent.addDomListener(logDiv, "click", function(){
    });
    map.getContainer().appendChild(container);
    return container;
};

MapLogControl.prototype.getDefaultPosition = function(){
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(8, 8));
};
 
MapLogControl.prototype.setButtonStyle_ = function(button){
    button.style.textDecoration = "none";
    button.style.color = "#555555";
    button.style.backgroundColor = "#ffffff";
    button.style.font = "small Arial";
    button.style.fontWeight = "bold";
    button.style.border = "1px solid #aaccff";
    button.style.padding = "5px";
    button.style.marginBottom = "1px";
    button.style.textAlign = "left";
    button.style.width = "320px";
    button.style.cursor = "pointer";
};
	
MapLogControl.prototype.setContent = function(content){
   this.contentDiv.innerHTML = content; 
};

////////////////////////////////////////////////////////////////
function MapToolBarControl()
{
};
MapToolBarControl.prototype = new GControl();

MapToolBarControl.prototype.initialize = function(map){
    var container = document.createElement("div");
    this.toolBarDiv = document.createElement("div");
    this.setButtonStyle_( this.toolBarDiv);
    container.appendChild( this.toolBarDiv);
	this.contentDiv =document.createElement("div");
	this.contentDiv.id ="toobarDiv";
    this.toolBarDiv.appendChild(this.contentDiv);
	
    GEvent.addDomListener( this.toolBarDiv, "click", function(){
    });
    map.getContainer().appendChild(container);
    return container;
};

MapToolBarControl.prototype.getDefaultPosition = function(){
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
};
 
MapToolBarControl.prototype.setButtonStyle_ = function(button){
    button.style.textDecoration = "none";
    button.style.color = "#555555";
    button.style.padding = "0";
    button.style.textAlign = "left";
    button.style.width = "100%";
	button.style.height = "26px";
    button.style.cursor = "default";
};
	
MapToolBarControl.prototype.setContentAjax = function(url,dataMap,callback){
	$.get(url,dataMap,function(result){$('#toobarDiv').append(result);});
};
 
MapToolBarControl.prototype.setWidth = function(width){
   this.toolBarDiv.style.width = (width+12) +"px";
};
////////////////////////////////////////////////////////////////
function MapIcLogoControl()
{
	this.isShow = false;
};
MapIcLogoControl.prototype = new GControl();
MapIcLogoControl.prototype.initialize = function(map){
    var container = document.createElement("div");
    this.logoDiv = document.createElement("div");
    this.setButtonStyle_( this.logoDiv);
    container.appendChild( this.logoDiv);
	this.contentDiv =document.createElement("div");
	this.contentDiv.id ="logoDiv";
    this.logoDiv.appendChild(this.contentDiv);
	
    GEvent.addDomListener( this.logoDiv, "click", function(){
    });
    map.getContainer().appendChild(container);
    return container;
};

MapIcLogoControl.prototype.getDefaultPosition = function(){
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
};
MapIcLogoControl.prototype.setButtonStyle_ = function(button){
    button.style.textDecoration = "none";
    button.style.color = "#555555";
    button.style.padding = "0";
    button.style.textAlign = "left";
    button.style.width = "62px";
	button.style.height = "28px";
    button.style.cursor = "default";
};
	
MapIcLogoControl.prototype.setContent  = function(content){
	$('#logoDiv').append(content);
};
MapIcLogoControl.prototype.setWidth = function(width){
   this.logoDiv.style.width = (width) +"px";
};


////////////////////////////////////////////////////////////////
 function MapLoadControl()
{
};
MapLoadControl.prototype = new GControl();

MapLoadControl.prototype.initialize = function(map){
    var container = document.createElement("div");
    
	this.loadDiv = document.createElement("div");
	this.loadDiv.style.textDecoration = "none";
    this.loadDiv.style.color = "#555555";
    this.loadDiv.style.padding = "0";
    this.loadDiv.style.textAlign = "left";
    this.loadDiv.style.width = "100%";
	this.loadDiv.style.height = "100%";
    this.loadDiv.style.cursor = "default";
	this.loadDiv.style.backgroundImage='url("/img/loading.gif")';
	this.loadDiv.style.backgroundRepeat="no-repeat";
	this.loadDiv.style.backgroundPosition="center";
	this.loadDiv.style.overflow ="hidden";
	this.loadDiv.style.zIndex ="60";
	this.loadDiv.style.position="absolute";
	this.loadDiv.style.filter="alpha(opacity=50)";
	this.loadDiv.style.mozOpacity =".5";
	this.loadDiv.style.opacity="0.5";
 
    container.appendChild( this.loadDiv);
	this.contentDiv =document.createElement("div");
	this.contentDiv.id ="loadDiv";
    this.loadDiv.appendChild(this.contentDiv);
	
    GEvent.addDomListener(this.loadDiv, "click", function(){
    });
    map.getContainer().appendChild(container);
	this.pmap = map;
    return container;
};

MapLoadControl.prototype.getDefaultPosition = function(){
    return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0, 0));
};


MapLoadControl.prototype.setWidth = function(width){
   if( this.loadDiv==null)
	 return;
   if (this.isShow == true|| width==0) {
	this.loadDiv.style.width = width + "px";
   }
   if (width > 0) {this.width = width;  }
};

MapLoadControl.prototype.setHeight = function(height){
   if( this.loadDiv==null)
	  return;
   if(this.isShow==true || height==0){
   	this.loadDiv.style.height = height + "px";
   }
   if (height > 0) {this.height = height; }
};
MapLoadControl.prototype.hide = function(){
   this.isShow =false;
   this.setHeight(0);
   this.setWidth(0);
};

MapLoadControl.prototype.show  = function(){
   this.isShow = true;
   this.setHeight(this.height);
   this.setWidth(this.width);
};
 
 
 
 
 
 
 
 
 
 
 