/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is WCPierce Web Controls.
 *
 * The Initial Developer of the Original Code is William C. Pierce.
 * Portions created by the Initial Developer are Copyright (C) 2005
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   René Strauss
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */


var _ef = function(){};
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 __DoCallBack(eventTarget, eventArgument)
{
  __theFormPostData = '';
  WebForm_InitCallback();
  window.GMap_SaveState(eventTarget);
  WebForm_DoCallback(eventTarget.id, eventArgument, function(){Callback_Complete.apply(eventTarget, arguments)}, '', Callback_Error, true);
}

function GMap_ServerClick(overlay, point)
{
  var arg = 'GMap_Click|'+point.lat()+','+point.lng();
  __DoCallBack(this, arg);
}

function GMap_ServerMoveStart()
{
  var center = this.getCenter();
  var arg = 'GMap_MoveStart|'+center.lat()+','+center.lng();
  __DoCallBack(this, arg);
}
      
function GMap_ServerMoveEnd()
{
  var center = this.getCenter();
  var arg = 'GMap_MoveEnd|'+center.lat()+','+center.lng();
  __DoCallBack(this, arg);
}

function GMarker_ServerClick()
{
  var arg = 'GMarker_Click|'+this.point.lat()+','+this.point.lng()+','+this.id;
  __DoCallBack(this.map, arg);
}

function GMap_ServerZoom(oldZoomLevel, newZoomLevel)
{
  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;
  var evtId = evt.id.replace(_gMapRegX,'_');
  document.getElementById(evtId + '_CenterLatLng').value = evt.getCenter();
  //document.getElementById(evtId + '_SpanLatLng').value   = evt.getBounds();
  document.getElementById(evtId + '_BoundsLatLng').value = evt.getBounds();
  document.getElementById(evtId + '_ZoomLevel').value = evt.getZoom();
  
  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;
    case G_PHYSICAL_MAP:
      mapType = 'G_PHYSICAL_MAP';
      break;
    case G_MOON_ELEVATION_MAP:
      mapType = 'G_MOON_ELEVATION_MAP';
      break;
    case G_MOON_VISIBLE_MAP:
      mapType = 'G_MOON_VISIBLE_MAP';
      break;
    case G_MARS_ELEVATION_MAP:
      mapType = 'G_MARS_ELEVATION_MAP';
      break;
    case G_MARS_VISIBLE_MAP:
      mapType = 'G_MARS_VISIBLE_MAP';
      break;
    case G_MARS_INFRARED_MAP:
      mapType = 'G_MARS_INFRARED_MAP';
      break;
    case G_SKY_VISIBLE_MAP:
      mapType = 'G_SKY_VISIBLE_MAP';
      break;
    default:
      mapType = 'G_NORMAL_MAP';
      break;
  }
  document.getElementById(evtId + '_MapType').value = mapType;
} 

function Callback_Complete(result, context)
{
  try
  {
    eval(result);
  }
  catch(e)
  {
    Callback_Error(result);
  }
}

function Callback_Error(result, context)
{
  alert('--ERROR--\n\n' + result);
}