  
var map;
var gmarkers = [];
var htmls = [];
//var side_bar_html = "";
var i = 0;

//function myzoom(a) {
//  map.setZoom(map.getZoom() + a);
//}

// === Custiom Icons: Create an associative array of GIcons() ===
var gicons = [];
gicons["customicon"] = new GIcon(G_DEFAULT_ICON, "/08/images/pointer.png");
gicons["customicon"].shadow = "/08/images/pointer_shadow.png";
gicons["customicon"].iconSize = new GSize(19, 35);
gicons["customicon"].shadowSize = new GSize(37, 45);

function loadmaps(querystring) {
scroll(0,0);
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map"));
 	map.addControl(new GLargeMapControl());
	//map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
	
    
	// set the starting location and zoom
	//map.setCenter(new GLatLng(37.969144, -122.510502), 13);
	map.setCenter(new GLatLng(31.353636941500987, -41.8359375), 1);
	
	// A function to create the marker and set up the event window
	function createMarker(point,name,html,icontype) {
     
	// === create a marker with the requested icon ===
    var marker = new GMarker(point, gicons[icontype]);
	//var marker = new GMarker(point);
   
    GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml('<span class="text3">' + html + '</span>');
     });

     // save the info we need to use later for the side_bar
     gmarkers[i] = marker;
     htmls[i] = html;
	//thelink[i] = thelink;
	
	// add a line to the side_bar html
	//side_bar_html += '';
	    
  	i++;
    return marker;
  	}
	
	var bounds = new GLatLngBounds();
	var qstr
	if(querystring != ''){
		if( querystring.indexOf('id=')==-1){
		var thevalue = document.getElementById(querystring).value
		qstr = querystring + "=" + thevalue
		}
		else {
		qstr = querystring
		}
	}
	GDownloadUrl("/08/ajax/map_xml.asp?" + qstr, function(data) {
	//GDownloadUrl("/08/ajax/map_xml2.asp?id=" + querystring, function(data) {
    var xml = GXml.parse(data);
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
    	var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                parseFloat(markers[i].getAttribute("lng")));
        
		var html = markers[i].getAttribute("html");
        var label = markers[i].getAttribute("label");
		var icontype = markers[i].getAttribute("icontype");
		var marker = createMarker(point,label,html,icontype);
        map.addOverlay(marker);
		bounds.extend(point);		  
	 	var ii = i + 1
	}

	// put the assembled side_bar_html contents into the side_bar div
	//if (side_bar_html == '') {
	//side_bar_html = 'No records found.'} //DEALS WITH EOF
	
	//var fianl_side_bar_html = '<table cellpadding="2" cellspacing="0">'+side_bar_html+'</table>'
	//document.getElementById("side_bar").innerHTML = fianl_side_bar_html;
	
	// ===== determine the zoom level from the bounds =====
	if (ii > 0) { map.setZoom(map.getBoundsZoomLevel(bounds))};

    // ===== determine the centre from the bounds ======
    var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
    var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
  
	if (clat != 0) { map.setCenter(new GLatLng(clat,clng));
	}
	else //if no records then show specific map (rather than world map)
	{ 
		//map.setCenter(new GLatLng(31.95216223802497, -98.61328125), 3);
		map.setCenter(new GLatLng(31.353636941500987, -41.8359375), 1);
		}
	    });
	  }
}

//This function picks up the click and opens the corresponding info window
function myclick(i) {
	gmarkers[i].openInfoWindowHtml(htmls[i]);
 }