// JavaScript Document//<![CDATA[
// Latitude and Longitude math routines are from: http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html

var map = null;
var geocoder = null;
var zm = 0; 
var marker = null;
var posset = 0;

function xz() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(61.227957176677876, -149.94140625), 4);
map.setMapType(G_NORMAL_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new MapTypeControl());
map.addControl(new GScaleControl());
map.enableScrollWheelZoom();
map.disableDoubleClickZoom();
geocoder = new GClientGeocoder();

marker = new GMarker(new GLatLng(61.227957176677876, -149.94140625), { draggable: true });
map.addOverlay(marker);


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));
computepos (point);
});

}}

function computepos (point)
{
var latA = Math.abs(Math.round(value=point.y * 1000000.));
var lonA = Math.abs(Math.round(value=point.x * 1000000.));

if(value=point.y < 0)
{
	var ls = '-' + Math.floor((latA / 1000000));
}
else
{
	var ls = Math.floor((latA / 1000000));
}

var lm = Math.floor(((latA/1000000) - Math.floor(latA/1000000)) * 60);
var ld = ( Math.floor(((((latA/1000000) - Math.floor(latA/1000000)) * 60) - Math.floor(((latA/1000000) - Math.floor(latA/1000000)) * 60)) * 100000) *60/100000 );

if(value=point.x < 0)
{
  var lgs = '-' + Math.floor((lonA / 1000000));
}
else
{
	var lgs = Math.floor((lonA / 1000000));
}

var lgm = Math.floor(((lonA/1000000) - Math.floor(lonA/1000000)) * 60);
var lgd = ( Math.floor(((((lonA/1000000) - Math.floor(lonA/1000000)) * 60) - Math.floor(((lonA/1000000) - Math.floor(lonA/1000000)) * 60)) * 100000) *60/100000 );
document.getElementById("FormView1_LatitudeTextBox").value=point.y;
document.getElementById("FormView1_LongitudeTextBox").value=point.x;
}

function showAddress(address) {
 if (geocoder) {
 geocoder.getLatLng(
 address,
 function(point) {
 if (!point) {
 alert(address + " not found");
 } else {
 
 posset = 1;

 map.setMapType(G_HYBRID_MAP);
 map.setCenter(point,16);
 zm = 1;
 marker.setPoint(point);
 GEvent.trigger(marker, "click");
 }
 }
 );
 }
}

//]]>