function getMap(lon, lat) {
   var baseIcon = new GIcon();
   baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
   baseIcon.iconSize = new GSize(20, 34);
   baseIcon.shadowSize = new GSize(37, 34);
   baseIcon.iconAnchor = new GPoint(9, 34);
   baseIcon.infoWindowAnchor = new GPoint(9, 2);
   baseIcon.infoShadowAnchor = new GPoint(18, 25);
   map = new GMap(document.getElementById("map"));
   map.addControl(new GLargeMapControl());
   map.addControl(new GMapTypeControl());
   map.centerAndZoom(new GPoint(lon,lat), 8);
   function createMarker(point, index, img, l) {
     //var letter = String.fromCharCode("A".charCodeAt(0) + index);
     var icon = new GIcon(baseIcon);
    // icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	 icon.image = "/images/icons/iconr" + img + ".gif";
	 var marker = new GMarker(point, icon);
	 var docMarker = l + img;
	 var elem = document.getElementById(docMarker);
	 var html = '<table><tr valign="top"><td>';
	 if(ls[index].photo != "") html = html + '<IMG SRC="/images/doctor/thumbs/' + ls[index].photo + '" STYLE="border:none;padding:5px;">';
	 html = html + '</td><td>' + '<b><a href="/folio.cfm' + ls[index].link + '">' + ls[index].name + '</a></b><br>' + ls[index].address + '<br>' + ls[index].city + ', ' + ls[index].state + ' ' + ls[index].zip + '<br><A HREF="https://www.locateadoc.com/folio.cfm/Action/Contact' + ls[index].link + '">Contact Me</A></td></tr></table>';
	 htmlForm = html + "<p><p>Directions: <strong>To here</strong><p><form id=\"gForm\" onsubmit=\"return openGWindow(this);\" target=\"_blank\"><input type=\"hidden\" name=\"daddr\" value=\"" + ls[index].address.replace(/ /g,"+") + ",+" + ls[index].city.replace(/ /g,"+") + "+" + ls[index].state.replace(/ /g,"+") + "\">Start address<br><input type=\"text\" size=\"32\" value=\"\" name=\"saddr\" maxlength=\"255\"><br><input type=\"submit\" value=\"Get Directions\"></form></p></p>";
	 html = html + '<p>Directions: <a href="##map" id="i' + docMarker + '" onclick="openGForm(this.id)">To here</a></p>';
	 aList[img] = htmlForm;
	 
	 if(typeof(a) == "undefined")
	 {
	 	var a;
	 }
	 if(elem != null)
	 {
	 elem.onclick = function(a) {
	 	var thisHTML = html;
		if(a >= 0){thisHTML = aList[a]};
	 	document.getElementById('map').style.display = 'block';
		document.getElementById('message').style.display = 'block';
		document.getElementById('map_image').src = "/images/button_hide_map.gif";
	 	marker.openInfoWindowHtml(thisHTML);
	}
	}
	 GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
	 return marker;
   }
   var bounds = map.getBoundsLatLng();
   var width = bounds.maxX - bounds.minX;
   var height = bounds.maxY - bounds.minY;
   for (var i = 0; i < ls.length; i++) {
   	 var lat = ls[i].lat;
	 var lon = ls[i].lon;
	 if (lat != "" && lon !=""){
     var point = new GPoint(lon, lat);
     var marker = createMarker(point, i, ls[i].img, ls[i].l);
     map.addOverlay(marker);
	 }
   }
   document.getElementById('map_image').src = "/images/button_hide_map.gif";
}
function writeMap(){
	document.write('<div id="map" style="width: 100%; height: 400px; display: none; border:solid; border-color:9391D9;"></div>');
	document.write('<div id="message" style="display: none;">How to Use the Map<UL><LI>Moving Around: to move the map use the arrow buttons, or click on the map and drag it.</LI><LI>Zooming: to zoom in our out of that map click the plus or minus signs.</LI><LI>Red Pins: to read a doctor\'s information click on a red pin.</LI></UL></div>');
}
function openGForm(a){
	var thisID = a.replace("i","");
	thisID = thisID.replace("e","");
	if(thisID.search("f")){thisID = "f" + thisID;}
	document.getElementById(thisID).onclick(thisID.replace("f",""));
	}
function checkMap(a) {
 	document.getElementById('map').style.display = 'block';
	document.getElementById('message').style.display = 'block';
 	if(!isObject(map)) {
		loadMap();
		if(a != null) document.getElementById(a).onclick();
	}
	return false;
}
function isObject(a) {
	return (a && typeof a == 'object');
}
function toggleMap(){
	if(document.getElementById('map').style.display == 'block'){
		document.getElementById('map').style.display = 'none';
		document.getElementById('message').style.display = 'none';
		document.getElementById('map_image').src = "/images/button_map.gif";
	}
	else{
		document.getElementById('map').style.display = 'block';
		document.getElementById('message').style.display = 'block';
		document.getElementById('map_image').src = "/images/button_hide_map.gif";
		loadMap();
	}
}

function openGWindow(gform){
	var thislink="http://maps.google.com/maps?f=d&hl=en&saddr=" + gform.saddr.value.replace(/ /g,"+") + "&daddr=" + gform.daddr.value.replace(/ /g,"+");
	window.open(thislink,"gwindow", "", false);
	return false;
}