
var _ef = function(){};
//var _defaultMarker = new GMarker();
var _gMapRegX = new RegExp(":", "gi");
_gMapRegX.compile(":", "gi");
GMap.prototype.getOverlayById=function(a){for(var b=0;b<this.overlays.length;b++){if(this.overlays[b].id==a)return this.overlays[b];}return null;};
function addListener(a,b,c,d){if(a.addEventListener){a.addEventListener(b,c,d);return true;}else if(a.attachEvent){var e=a.attachEvent("on"+b,c);return e;}else{alert("Handler could not be attached");}}
function bind(a,b,c,d){return window.addListener(a,b,function(){d.apply(c,arguments)});}

function cbo_Complete(responseText, responseXML)
{
  //eval(responseText);
}

function cbo_Error(status, statusText, responseText)
{
  alert('Error: ' + status + '\n' + statusText + '\n' + responseText);
}

function __DoCallBack(eventTarget, eventArgument)
{
  var cbo = new CallBackObject();
  cbo.OnComplete = function(){cbo_Complete.apply(eventTarget, arguments)};
  cbo.OnError = cbo_Error;
  window.GMap_SaveState(eventTarget);
  
  var idExist=true;
  if(eventTarget==undefined) idExist=false;
  var eventID="";
  if(idExist) eventID=eventTarget.id;
  cbo.DoCallBack(eventID, eventArgument);
}

function GMap_ServerClick(overlay, point)
{
	if(point!=undefined)
	{
		var arg = 'GMap_Click|' + point.lat() + ',' + point.lng() ;
		__DoCallBack(this, arg);
  }
}

function GMap_ServerMoveStart()
{
  var center = this.getCenter();
  var arg = 'GMap_MoveStart|'+center.x+','+center.y;
  __DoCallBack(this, arg);
}
      
function GMap_ServerMoveEnd()
{
	if(this.getCenter()!=undefined)
	{
		var center = this.getCenter();
		var arg = 'GMap_MoveEnd|'+center.x+','+center.y;
		__DoCallBack(this, arg);
  }
}

function GMarker_ServerClick()
{
	if(this.getPoint()!=undefined)
	{
		var arg = 'GMarker_Click|' + this.getPoint().lat() + ',' + this.getPoint().lng() + ','+ this.id;
		__DoCallBack(this.map, arg);
  }
}

function GMap_ServerZoom(oldZoomLevel, newZoomLevel)
{
  if(oldZoomLevel==undefined)oldZoomLevel=0;
  if(newZoomLevel==undefined)newZoomLevel=0;
  var arg = 'GMap_Zoom|' + oldZoomLevel + ',' + newZoomLevel;
  __DoCallBack(this, arg);
}

function GMap_ServerClientLoad(map)
{
  var arg = 'GMap_ClientLoad|';
  __DoCallBack(map, arg);
}

function GMap_ServerMapTypeChanged()
{
  var arg = 'GMap_MapTypeChanged|';
  __DoCallBack(this, arg);
}  

function GMap_SaveState(eventTarget)
{
  var evt = eventTarget;//eventTarget.pan?eventTarget:this;
  if(evt==undefined)evt=this;
  if(evt.id==null)evt=this;
  
  var idExist=true;
  if(evt.id==null) idExist=false;
  if(evt.id==undefined) idExist=false;
  
  if(evt!=undefined && idExist)
  {
	var evtId = evt.id.replace(_gMapRegX,'_');
	document.getElementsByName(evtId + '_CenterLatLng').value = evt.getCenter();
	document.getElementsByName(evtId + '_SpanLatLng').value   = evt.getBounds();//evt.getSpanLatLng();
	document.getElementsByName(evtId + '_BoundsLatLng').value = evt.getBounds();//evt.getBoundsLatLng();
	document.getElementsByName(evtId + '_ZoomLevel').value = evt.getZoom();//evt.getZoomLevel();
	  
	var mapType = 'G_NORMAL_MAP';
	switch( evt.getCurrentMapType() )
	{
		case G_HYBRID_MAP:
		mapType = 'G_HYBRID_MAP';
		break;
		case G_SATELLITE_MAP:
		mapType = 'G_SATELLITE_MAP';
		break;
		default:
		mapType = 'G_NORMAL_MAP';
		break;
	}
	document.getElementsByName(evtId + '_MapType').value = mapType;
  }
}  
