// JavaScript Document/*	The function initialize gets the latitude and longitude values for the given office from	hidden fields in the form. It then creates a map with marker and navigator from these	hidden values. It then creates a geocoder object for later use. Finally, it creates a	string that will be used to create the URL that will pass the variables to the page	used for printing a map and directions.*/function initialize() {		var destlat = document.directions.destlat.value;		var destlng = document.directions.destlng.value;		map = new GMap2(document.getElementById("map_canvas"));		map.setCenter(new GLatLng(destlat, destlng), 15);		map.addControl(new GSmallMapControl());		map.addOverlay(new GMarker (new GLatLng(destlat,destlng)));}/*	The function makedesturl will create the destpassurl fragment for the overall string	to be passed as the URL containing the starting and ending latitudes and longitudes.	The values will be contained in hidden fields in the form on the corresponding office page.*/function makedesturl() {	var destlat = document.directions.destlat.value;	var destlng = document.directions.destlng.value;	var destpassurl = "&destlat=" + destlat + "&destlng=" + destlng;	return destpassurl;}/*	The function valstrgeo does the following:		1)	clear the "error" div		2)	confirm that something has been entered into both the address and zip fields.		3)	if no entry in one or the other, it places the error message into the "error" div.		4)	if both entered, it gets the values from the address and zip fields.		5)	the values are concatenated to a string that will be used by the geocoder object.		6)	HTML is stripped from the concatenated string.*/function valstrgeo() {	document.getElementById("error").innerHTML = "";	if (document.directions.add.value == ""|| document.directions.zip.value == "") {		document.getElementById("error").innerHTML = "Address and ZIP are both required.";	} else {		var rawaddress = String(document.directions.add.value);		var rawzip = String(document.directions.zip.value);		var rawgeocodestring = rawaddress + ", " + rawzip;		var geocodestring = rawgeocodestring.replace(/(<([^>]+)>)/ig,"");		return geocodestring;	}}/*	The function urlvarpass creates the entire URL to be passed to the page for printing	directions and a map. It serves as the callback function for the geocoder's getLatLng method.*/function getstartpoint() {	var geocoder = new GClientGeocoder();	startaddress = valstrgeo();	geocoder.getLatLng(startaddress, function (point) {										var startlat = point.lat();										var startlng = point.lng();										var start = "startlat=" + startlat + "&startlng=" + startlng;										var end = makedesturl();										var host = "http://www.gpoa.com/ofc/printdrxn.htm?";										var passurl = host + start + end										window.location.href = passurl;									});}/*	The following functions are for creating the printable page of directions with map. *//*	The function layoutPage creates the page map and directions panel, converts the URL containing the 	variables for starting and ending latitudes and longitudes for use by the GDirections object, and stores	these variables in hidden fields on the page.*/function layoutPage() {	rawpoints = new Array();	points = new Array();	map = new GMap2(document.getElementById("dirmap"));	directionsPanel = document.getElementById("dirtext");	directions = new GDirections(map, directionsPanel);	GEvent.addListener(directions, "error", handleErrors);	passedvar = window.location;	document.converter.convert.value = passedvar;	stringtobreak = document.converter.convert.value;	trimmedstring = stringtobreak.substring(stringtobreak.indexOf("?") +1);	rawpoints = trimmedstring.split("&");	startlat = rawpoints[0].substring(rawpoints[0].indexOf("=") + 1);	startlng = rawpoints[1].substring(rawpoints[1].indexOf("=") + 1);	destlat = rawpoints[2].substring(rawpoints[2].indexOf("=") + 1);	destlng = rawpoints[3].substring(rawpoints[3].indexOf("=") + 1);	document.converter.startlat.value = startlat;	document.converter.startlng.value = startlng;	document.converter.destlat.value = destlat;	document.converter.destlng.value = destlng;	searchstrg = "from: " + startlat + "," + startlng + " to: " + destlat + "," + destlng;	directions.load(searchstrg);}function printPage() {	window.print();}	function handleErrors() {	if (directions.getStatus().code == 602) {		document.write("<p>No corresponding geographic location could be found for the address. Please close this window, return to the previous page, and re-enter your address.</p>");		}	else if (directions.getStatus().code == 603) {			document.write("<p>We're sorry, but the directions and/or route cannot be provided due to legal or contractual reasons.</p>");			}	else if (directions.getStatus().code == 604) {				document.write("<p>We're sorry, but Google does not have data available for providing a route and directions.</p>"); 				}	else if (directions.getStatus().code == 400) {					document.write("<p>There was a problem encoding the address you entered. Please return to the previous page, and re-enter your address.</p>");					}	else if (directions.getStatus().code == 500) {						document.write("<p>We're sorry, but the Google Maps server is unavailable or cannot process the request. Please try again later.</p>");						}}