function bodyLoad(townLat,townLong,townLabel,townRange) {
	estLink();
  if (GBrowserIsCompatible()){
    loadMap();
  }
}

function loadMap() {

/* Version 3
var townCentre = new google.maps.LatLng(-30.000, 30.000);// townLat,townLong
var mapOptions = {
  center: townCentre,
  zoom: 14,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  streetViewControl: true
};
var map = new google.maps.Map(document.getElementById("mapdiv"), mapOptions); 
// End of Version 3  
*/

// Version 2
  var map = new GMap2(document.getElementById("mapdiv"));
  map.setCenter(new GLatLng(0,0),0);
  // eventually should add to search_region table so we don't need bounds
  map.addControl(new GSmallMapControl());
  //map.addControl(new streetViewControl());
  //map.addControl(new GMapTypeControl()); // blocks the window
  var bounds = new GLatLngBounds();   
  var keyboard = new GKeyboardHandler(map);
  
      
  //reposition map to previous postion afer closing the InfoWindow
  GEvent.addListener(map.getInfoWindow(), "closeclick", function() {
     map.returnToSavedPosition();
  });

  townCentre = new GLatLng(townLat,townLong);
  map.setCenter(townCentre);
  zoom = 13 - Math.floor(Math.log(townRange));
  map.setZoom(zoom); 

  // add the town marker
  function townzOrder(marker){return 0;}
  
  //markerOptions = {icon:myIcon['home'],title:[townLabel],zIndexProcess:townzOrder};
	//townMarker = new GMarker(townCentre, markerOptions);
	//map.addOverlay(townMarker);
  
  // add attraction markers
  for (var a= 0; a < attArray.length; a++) {
    attractionMarker(map,'region',a,blat,blng);
  }
  
  // Insert new Attractions
  if(document.frmInsert){
    //triggered by clicking on any non-overlay point (icons are overlays)   
    GEvent.addListener(map, "click", function(overlay, point){
      if (overlay == null){
        document.frmInsert.attLat.value = point.y;
        document.frmInsert.attLng.value = point.x;
        document.frmInsert.submit();
      }
    });
  } else { // polygon overlay blocks the above listener
    var dlat = townRange/800;
    var dlon = townRange/500;
    var townPolygon = new GPolygon([
      new GLatLng(townLat + dlat, townLong - dlon),
      new GLatLng(townLat + dlat, townLong + dlon),
      new GLatLng(townLat - dlat, townLong + dlon),
      new GLatLng(townLat - dlat, townLong - dlon),
      new GLatLng(townLat + dlat, townLong - dlon)
            
    ], "#f33f00", 2, .3, "#ff0000", 0.1);
    map.addOverlay(townPolygon);
  }
// End of Version 2
} // end of loadMap()

// we need to get the attLabel from the bId and the attText from the divId
function edit(i){
divId = 'div'+i;
bId = 'b'+i;
document.frm1.attId.value = attArray[i][0];
document.frm1.attType.value = attArray[i][1];
document.frm1.attPic.value = attArray[i][4];
// Create attName from attLabel
strName = document.getElementById(bId).innerHTML;
strName = strName.replace(/ /g, "-");
strName = strName.replace(/'/g, "");
document.frm1.attName.value = strName;
// escape attLabel for MySQL
strLabel = document.getElementById(bId).innerHTML;
strLabel = strLabel.replace(/'/g, "\'");
document.frm1.attLabel.value = strLabel;
var strText = (document.getElementById(divId))? document.getElementById(divId).innerHTML : '';
// convert br back to new lines. - not sure why
strText = strText.replace(/<br \/>/g, "\r\n");
strText = strText.replace(/<br>/g, "\r\n");
// escape attText for MySQL
strText = strText.replace(/'/g, "\'");
document.frm1.attText.value = strText;
document.frm1.submit();
}

function wts(userName){
document.location = "http://www.wheretostay.co.za/" + userName;
}

function estLink() {
  if (!document.getElementsByTagName) return false;
  var spans = document.getElementsByTagName("span");
  for (var i=0; i < spans.length; i++) {
    if (spans[i].className.match("link")) {
      spans[i].onmouseover = function() {
        this.style.backgroundColor = '#ffeeee';
      }
      spans[i].onmouseout = function() {
        this.style.backgroundColor = '#eeffff';
      }
			//spans[i].onclick = function() {
			//	document.location = 'http://www.wheretostay.co.za/'+ this.id;
			//}
    } //end of if
  } //end of loop
} //end of function

function showPic(){
  alert('showPic');
}

function hidePic(){
  alert('hidePic');
}
