var map = null;
var geocoder = null;
var latsgn = 1;
var lgsgn = 1;
var zm = 13; 
var marker = null;
var posset = 0;

function BornMap() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(20.0, -10.0), 13);
map.setMapType(G_NORMAL_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new MapTypeControl());
map.addControl(new GScaleControl());
map.disableScrollWheelZoom();
map.disableDoubleClickZoom();
geocoder = new GClientGeocoder();
marker = new GMarker(new GLatLng(20.0, -10.0), {draggable: false});
map.addOverlay(marker);
GEvent.addListener(map, 'click', function(overlay,point) 
{
if (overlay) 
{
} 
else 
{
posset = 1;

fc( point) ;
//marker.setPoint(point);
if (zm == 0)
{map.setCenter(point,13); zm = 13;}
else
{map.setCenter(point,13);}
computepos(point);
}
});

GEvent.addListener(map, 'singlerightclick', function(point,src,overlay) 
{
if (overlay) 
{
if (overlay != marker)
{
map.removeOverlay(overlay)
document.getElementById("latbox").value='';
document.getElementById("latboxm").value='';
document.getElementById("latboxmd").value='';
document.getElementById("latboxms").value='';
document.getElementById("lonbox").value='';
document.getElementById("lonboxm").value='';
document.getElementById("lonboxmd").value='';
document.getElementById("lonboxms").value='';
} 
}
else 
{}
});

/*GEvent.addListener(marker, "dragend", function() {
var point = marker.getLatLng();
posset = 1;
if (zm == 0)
{map.setCenter(point,7); zm = 1;}
else
{map.setCenter(point);}
computepos(point);
});*/


GEvent.addListener(marker, "click", function() {
var point = marker.getLatLng();
//marker.openInfoWindowHtml(marker.getLatLng().toUrlValue(6));
marker.openInfoWindowHtml(address);
computepos (point);
});
}}



function MapTo2(address) {
 if (geocoder) {
 geocoder.getLatLng(
 address,
 function(point) {
 /*
 if (!point) {
 alert(address + " not found");
 } else {
 */
 posset = 1;

 map.setMapType(G_NORMAL_MAP);
 map.setCenter(point,13);
 zm = 13;
 marker.setPoint(point);
 GEvent.trigger(marker, "click");
 //}
 }
 );
 }
}

function createMarker(point, html) 
{
 var marker = new GMarker(point);
 GEvent.addListener(marker, "click", function()
 {
 marker.openInfoWindowHtml(html);
 });
 return marker;
}


function MapTypeControl(opt_opts) {
  this.options = opt_opts || {};
}

MapTypeControl.prototype = new GControl();

MapTypeControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var me = this;
  var mapDiv = me.createButton_("Map");
  var satDiv = me.createButton_("Satellite");
  var hybDiv = me.createButton_("Hybrid");
  var phyDiv = me.createButton_("Terrain");
  
 
  me.assignButtonEvent_(mapDiv, map, G_NORMAL_MAP, [phyDiv, satDiv, hybDiv]);
  me.assignButtonEvent_(phyDiv, map, G_PHYSICAL_MAP, [mapDiv, satDiv, hybDiv]);
  me.assignButtonEvent_(satDiv, map, G_SATELLITE_MAP, [phyDiv, mapDiv, hybDiv]);
  me.assignButtonEvent_(hybDiv, map, G_HYBRID_MAP, [phyDiv, satDiv, mapDiv]);
  GEvent.addListener(map, "maptypechanged", function() {
    if (map.getCurrentMapType() == G_NORMAL_MAP) {
      GEvent.trigger(mapDiv, "click"); 
    } else if (map.getCurrentMapType() == G_PHYSICAL_MAP) {
      GEvent.trigger(phyDiv, "click");
    } else if (map.getCurrentMapType() == G_SATELLITE_MAP) {
      GEvent.trigger(satDiv, "click");
    } else if (map.getCurrentMapType() == G_HYBRID_MAP) {
      GEvent.trigger(hybDiv, "click");
    }
  });

  container.appendChild(mapDiv);
  container.appendChild(satDiv);
  container.appendChild(hybDiv);
  container.appendChild(phyDiv);

  map.getContainer().appendChild(container);

  GEvent.trigger(map, "maptypechanged");
  return container;
}

MapTypeControl.prototype.createButton_ = function(text) {
  var buttonDiv = document.createElement("div");
  this.setButtonStyle_(buttonDiv);
  buttonDiv.style.cssFloat = "left";
  buttonDiv.style.styleFloat = "left";
  var textDiv = document.createElement("div");
  textDiv.appendChild(document.createTextNode(text));
  textDiv.style.width = "6em";
  buttonDiv.appendChild(textDiv);
  return buttonDiv;
}

MapTypeControl.prototype.assignButtonEvent_ = function(div, map, mapType, otherDivs) {
  var me = this;

  GEvent.addDomListener(div, "click", function() {
    for (var i = 0; i < otherDivs.length; i++) {
      me.toggleButton_(otherDivs[i].firstChild, false);
    }
    me.toggleButton_(div.firstChild, true);
    map.setMapType(mapType);
  });
}

MapTypeControl.prototype.toggleButton_ = function(div, boolCheck) {
   div.style.fontWeight = boolCheck ? "bold" : "";
   div.style.border = "1px solid white";
   var shadows = boolCheck ? ["Top", "Left"] : ["Bottom", "Right"];
   for (var j = 0; j < shadows.length; j++) {
     div.style["border" + shadows[j]] = "1px solid #b0b0b0";
  } 
}

MapTypeControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
}

MapTypeControl.prototype.setButtonStyle_ = function(button) {
  button.style.color = "#000000";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "0px";
  button.style.margin= "0px";
  button.style.textAlign = "center";
  button.style.fontSize = "10px"; 
  button.style.cursor = "pointer";
}


