//.
//. 
//. Portions (C) Daxal Communications - July 2006.
//. 
//. 

var map		= null; // Google Map Object
var geocoder	= null; // Geocoder Object (address -> cords)
var msgid	= null; // Debugging aid
var _mapid	= null; // globalish
var lastid	= null; // last mapid

function log(msg) {
	if (!msgid) {msgid=document.getElementById('log');}
	msgid.innerHTML+=msg+'<br />';
}

function hideit(id) {
// The "Hide Map" link depends on us returning false. (onclick)
	var p;
	if (lastid!=id) {
		return(false);
	}
	lastid		= null;
	map		= null;
	geocoder	= null;
	p=document.getElementById(id);
	if (p) { p.innerHTML	= "" }
	return(false);
}

function plot(point) {
	var mapid = _mapid;
	if (point) {
		if (mapid != lastid) {
			hideit(lastid);
			map	= null;
		}
		lastid=_mapid;
		if (!map) {
			var p=document.getElementById(mapid);
			p.style.display="inline";
			p.innerHTML='&nbsp;&nbsp;<a href="#HideMap" onclick="return hideit(\''+mapid+'\');">'
				+'Hide Map</a>'
				+'<div id="map" style="'
				+'width: 100%; height: 350px;'
				+'"></div>';
			map = new GMap2(document.getElementById("map"));
		}
		map.setCenter(point, 13);
	} else {
		hideit(lastid);
		p=document.getElementById(mapid);
		p.innerHTML='<br />So sorry, there was a map Error. '
			+'No geocords for this location.<br /><blockquote>'
			+'This may be a sign of:<br />'
			+'<ul><li>a Google Maps Compatibility problem.</li>'
			+'<li>a slow or unresponsive connection.</li>'
			+'<li>an invalid city, state, or country.</li></ul></blockquote>'
			+'Please try again.<br />'
			+'<br />';
		lastid=mapid;
	}
}

function notify(mapid)
{
	var p;
	if(map){return}
	p=document.getElementById(mapid);
	p.innerHTML='<br /><blockquote>'
		+'One moment... Waiting on Google Maps...'
		+'</blockquote>';
}

function showAddress(atag,mapid) {
// The onclick property of the link depends on us returning false
	var address;
	_mapid = mapid;
	if (!GBrowserIsCompatible()) {
		log('<b>GBrowserIsCompatible = false</b> :(');
		return(false);
	}
	address		= atag.innerHTML+' '+thisState+' '+thisCountry;
	if (!geocoder) {
		geocoder = new GClientGeocoder();
	}
	if (!geocoder) {
		return(false);
	}
	notify(mapid);
	geocoder.getLatLng(address,plot);
	return(false);
}

