// -------------------------------------------------------------------------------------------------------------------
function includeGoogleMapsRoutines()
{
	document.write("<script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=");

	var lcURL = window.location.href.toLowerCase();

	var lcCode = "";
	if (lcURL.indexOf("eddie.") != -1)
	{
		lcCode = "ABQIAAAAyylbRUhQBkKIPz9XEhz-qRSy5cbtxVDlsNo27WoH9aw6tb6LhxRNgpqkqBnf8yuBptLz9ONNxjbPXQ";
	}
	else if (lcURL.indexOf("beoearth.com/samples/") != -1)
	{
		lcCode = "ABQIAAAAyylbRUhQBkKIPz9XEhz-qRRBJZ4YiA6wLmvMqm4f7wjGQotGGBQI8NdKq_adPqyjm2GP4abinRoqlg";
	}
	else if (lcURL.indexOf("beoearth.com/mapping/") != -1)
	{
		lcCode = "ABQIAAAAyylbRUhQBkKIPz9XEhz-qRRH_wZzTYEmivvE_bZscqxo2g9GLhTgOthSvgPnp1BwzJOO7mdxvzDY3Q";
	}
	else if (lcURL.indexOf("beosphere") != -1)
	{
		lcCode = "ABQIAAAAyylbRUhQBkKIPz9XEhz-qRQcbRih5y_a2KRfdndMFQISDSpI0xR4Q4pZDahRYCFKMe8ds2tAGoiscQ";
	}

	document.write(lcCode);
	document.write("\"");

	document.write(" type=\"text/javascript\"></script>");
}
// -------------------------------------------------------------------------------------------------------------------
// From
// http://code.google.com/apis/maps/documentation/examples/directions-advanced.html
function LocatingError(tnStatusCode)
{
	if (tnStatusCode == G_GEO_UNKNOWN_ADDRESS)
	{
		alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\n\nError code: "
				+ tnStatusCode);
	}
	else if (tnStatusCode == G_GEO_SERVER_ERROR)
	{
		alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n\nError code: " + tnStatusCode);
	}
	else if (tnStatusCode == G_GEO_MISSING_QUERY)
	{
		alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n\nError code: "
				+ tnStatusCode);
	}
	else if (tnStatusCode == G_GEO_BAD_KEY)
	{
		alert("The given key is either invalid or does not match the domain for which it was given.\n\nError code: " + tnStatusCode);
	}
	else if (tnStatusCode == G_GEO_BAD_REQUEST)
	{
		alert("A directions request could not be successfully parsed.\n\nError code: " + tnStatusCode);
	}
	else
	{
		alert("Unable to geocode and/or find directions with the information given.");
	}
}
// -------------------------------------------------------------------------------------------------------------------
function buildDescription(toPlace)
{
	var lcThoroughfare = getThoroughfare(toPlace);
	var lcCity = getLocality(toPlace);
	var lcCounty = getSubAdministrativeArea(toPlace);
	var lcState = getAdministrativeArea(toPlace);
	var lcCountryName = getCountryName(toPlace);
	var lcCountryCode = getCountryCode(toPlace);
	var lcZipcode = getPostalCode(toPlace);

	var lcDescription = "<p><b>" + toPlace.address + "</b><br><br>";
	var llUSA = (lcCountryCode.toLowerCase() == "us");

	if (lcThoroughfare != "")
	{
		lcDescription += "Thoroughfare: <b>" + lcThoroughfare + "</b><br>";
	}

	if (lcCity != "")
	{
		lcDescription += "City: <b>" + lcCity + "</b><br>";
	}

	if (lcCounty != "")
	{
		lcDescription += ((llUSA) ? "County" : "Sub Admin Area") + ": <b>" + lcCounty + "</b><br>";
	}

	if (lcState != "")
	{
		lcDescription += ((llUSA) ? "State" : "Admin Area") + ": <b>" + lcState + "</b><br>";
	}

	if (lcZipcode != "")
	{
		lcDescription += ((llUSA) ? "Zipcode" : "Postal Code") + ": <b>" + lcZipcode + "</b><br>";
	}

	if (lcCountryName != "")
	{
		lcDescription += "Country Name: <b>" + lcCountryName + "</b><br>";
	}

	if (lcCountryCode != "")
	{
		lcDescription += "Country Code: <b>" + lcCountryCode + "</b><br>";
	}

	var lnLongX = toPlace.Point.coordinates[0];
	var lnLatY = toPlace.Point.coordinates[1];

	lcDescription += "<br>Longitude (X): <b>" + lnLongX + "</b><br>Latitude (Y): <b>" + lnLatY + "</b></p>";

	return (lcDescription);
}
// -------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------
// I got these routines from the following page (the code is Java though).
// http://code.google.com/p/gwt-google-apis/source/browse/releases/maps/1.0/maps/src/com/google/gwt/maps/client/geocode/Placemark.java?spec=svn1010&r=1010#154
function getThoroughfare(toPlace)
{
	var loCountry = toPlace.AddressDetails.Country;
	if (loCountry)
	{
		var loAdministrativeArea = toPlace.AddressDetails.Country.AdministrativeArea;
		if (loAdministrativeArea)
		{
			var loArea = loAdministrativeArea.SubAdministrativeArea || loAdministrativeArea;
			var loLocality = loArea.Locality;
			var loDependentLocality = (loLocality && loLocality.DependentLocality) || null;
			var loThoroughfare = (loDependentLocality && loDependentLocality.Thoroughfare) || (loLocality && loLocality.Thoroughfare) || (loArea.Thoroughfare);
			return (loThoroughfare && loThoroughfare.ThoroughfareName || "");
		}
	}

	return ("");
}
// -------------------------------------------------------------------------------------------------------------------
// In the US, this is the city.
function getLocality(toPlace)
{
	var loCountry = toPlace.AddressDetails.Country;
	if (loCountry)
	{
		var loAdministrativeArea = toPlace.AddressDetails.Country.AdministrativeArea;
		if (loAdministrativeArea)
		{
			var loLocality = (loAdministrativeArea.SubAdministrativeArea || loAdministrativeArea).Locality;
			return (loLocality && loLocality.LocalityName || "");
		}
	}

	return ("");
}
// -------------------------------------------------------------------------------------------------------------------
// In the US, this is the county.
function getSubAdministrativeArea(toPlace)
{
	var loCountry = toPlace.AddressDetails.Country;
	if (loCountry)
	{
		var loAdministrativeArea = toPlace.AddressDetails.Country.AdministrativeArea;
		if (loAdministrativeArea)
		{
			var loSubAdministrativeArea = loAdministrativeArea.SubAdministrativeArea;
			return (loSubAdministrativeArea && loSubAdministrativeArea.SubAdministrativeAreaName || "");
		}
	}

	return ("");
}
// -------------------------------------------------------------------------------------------------------------------
// In the US, this is the zipcode.
function getPostalCode(toPlace)
{
	var loCountry = toPlace.AddressDetails.Country;
	if (loCountry)
	{
		var loAdministrativeArea = toPlace.AddressDetails.Country.AdministrativeArea;
		if (loAdministrativeArea)
		{
			var loArea = loAdministrativeArea.SubAdministrativeArea || loAdministrativeArea;
			var loLocality = loArea.Locality;
			var loDependentLocality = (loLocality && loLocality.DependentLocality) || null;
			var loPostalCode = (loDependentLocality && loDependentLocality.PostalCode) || (loLocality && loLocality.PostalCode) || (loArea.PostalCode);

			return (loPostalCode && loPostalCode.PostalCodeNumber || "");
		}
	}

	return ("");
}
// -------------------------------------------------------------------------------------------------------------------
// In the US, this is the state.
function getAdministrativeArea(toPlace)
{
	var loCountry = toPlace.AddressDetails.Country;
	if (loCountry)
	{
		var loAdministrativeArea = toPlace.AddressDetails.Country.AdministrativeArea;

		return (loAdministrativeArea && loAdministrativeArea.AdministrativeAreaName || "");
	}

	return ("");
}
// -------------------------------------------------------------------------------------------------------------------
function getCountryName(toPlace)
{
	var loCountry = toPlace.AddressDetails.Country;
	if (loCountry)
	{
		return (toPlace.AddressDetails.Country.CountryName);
	}

	return ("");
}
// -------------------------------------------------------------------------------------------------------------------
function getCountryCode(toPlace)
{
	var loCountry = toPlace.AddressDetails.Country;
	if (loCountry)
	{
		return (toPlace.AddressDetails.Country.CountryNameCode);
	}

	return ("");
}
// -------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------

