
if (!document.getElementById && document.all)
	document.getElementById = function(id)
	{
		return document.all[id];
	}

var coords;

function convertText(textCoords, quiet, showMap)
{
  if (showMap == null)
	showMap = true;

  if (textCoords == "" || textCoords == null || textCoords == "undefined")
  {
    if (!quiet)
      alert("Please enter some GPS coordinates");

      return false;
  }

  var mantissa = 1000000;

	// Checking if we got one google maps "link this"
	if ( matches = textCoords.match(/.*ll=(-?[0-9]+\.[0-9]+),(-?[0-9]+\.[0-9]+).*/i) ) {
		document.getElementById('c').value = matches[1] + " " + matches[2];
		textCoords = matches[1] + " " + matches[2];
	}

//  alert(textCoords);

  coords = new GPSCoordinateSet(textCoords);

  if (coords.isValid())
  {
    setValue("lat_dec", Math.round(coords.getLat().toDec() * mantissa) / mantissa);
    setValue("long_dec", Math.round(coords.getLong().toDec() * mantissa) / mantissa);

    setValue("lat_dms", coords.getLat().toDMSString());
    setValue("long_dms", coords.getLong().toDMSString());

    setValue("zone_utm", coords.getHemi() + coords.getZone());
    setValue("x_utm", Math.round(coords.getUTMx()));
    setValue("y_utm", Math.round(coords.getUTMy()));

    setValue("lat_gps", coords.getLat().toGPSString());
    setValue("long_gps", coords.getLong().toGPSString());

    if (showMap)
      mapURL();

    return true;
  }
  else 
  {
    if (!quiet)
      alert("Sorry, your coordinates could not be understood.");
    return false;
  }
}

function var_dump(arr) {
	var txt;
	alert( arr[1] + ' ' + arr[2] );
}

function theholygoogleURL(lat, lon)
{
   return 'http://maps.google.com/maps?q=' + lat + ',' + lon;
}

function getValue(node)
{
  alert(node);
 return document.getElementById(node).childNodes[0].nodeValue;
}

function setValue(node, val)
{
 document.getElementById(node).childNodes[0].nodeValue = val;
}

function bodyOnLoad()
{
	window.onresize = resizeMap;
	resizeMap();

	initialize_GMap();

	str = document.getElementById('c').value;

	if ( str == '' ) {
	 convertText("39.469645 -0.376539", true, true);
	 getElevation(39.469645,-0.376539);
	} else {
	 convertText(str, true, true);
	 var coords = str.split(" ", 2);
	 getElevation(coords[0], coords[1]);
	}
	showCenter();
}
