// JavaScript Document
//Browser Support Code

    
   function GM_initializeAdd(address,mapZoom,divId,locId,tableId,secMd5,secAddress) {
      if (GBrowserIsCompatible()) {

        geocoder = new GClientGeocoder();
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
            
            
              geocoder2 = new GClientGeocoder();
              geocoder2.getLatLng(
                secAddress,
                function(point2) {
                  if(!point2) {
                    adminLocation(locId,tableId);
                  } else{
                    showFoundMap(point2,mapZoom, divId, locId, tableId, secMd5);
                  }
                }
              );
				
              //alert(address + " not found");
            } else {
              showFoundMap(point,mapZoom, divId, locId, tableId, secMd5);
// 				document.getElementById(divId).style.width = '100%';
// 				document.getElementById(divId).style.height = '250px';
// 		        map = new GMap2(document.getElementById(divId));
//         		map.setCenter(new GLatLng(53.346258,-6.265604), 14);
// 		        map.addControl(new GSmallMapControl());
//         		map.addControl(new GOverviewMapControl());
// 				map.enableScrollWheelZoom();
// 				map.setCenter(point, mapZoom);
// 				var marker = new GMarker(point);
// 				map.addOverlay(marker);
// //              marker.openInfoWindowHtml(address);
// 				saveGmapPos(""+point.lat() + ',' + point.lng() + ',' + map.getZoom(), locId, tableId, secMd5 );
            }
          }
        );
        //return map;
	  }
      else {
        return false;
      }
    }
function showFoundMap(point,mapZoom, divId, locId, tableId, secMd5)
{
				document.getElementById(divId).style.width = '100%';
				document.getElementById(divId).style.height = '250px';
		        map = new GMap2(document.getElementById(divId));
        		map.setCenter(new GLatLng(53.346258,-6.265604), 14);
		        map.addControl(new GSmallMapControl());
        		map.addControl(new GOverviewMapControl());
				map.enableScrollWheelZoom();
				map.setCenter(point, mapZoom);
				var marker = new GMarker(point);
				map.addOverlay(marker);
//              marker.openInfoWindowHtml(address);
				saveGmapPos(""+point.lat() + ',' + point.lng() + ',' + map.getZoom(), locId, tableId, secMd5 );
}

function saveGmapPos(newPos,ID,tableId,fieldMd5)
{
	var ajaxUpdBoxUrl = "/includes/gmapupdate.php"; // The server-side script
	var ajaxRequest = getAjaxObject();
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4  && ajaxRequest.status == 200)
		{
			//document.getElementById('quicksearch2').innerHTML = ajaxRequest.responseText;
			//document.getElementById("gmapresults").innerHTML= "Saved "+ajaxRequest.responseText;
			//updateFeatured();
		}
		
		if(ajaxRequest.readyState!=4)
		{
			//document.getElementById("quicksearch").innerHTML= "One moment please ...";
			//document.getElementById("gmapresults").innerHTML= "One moment please ...";
		}
	}
	
	var queryString = "?lid=" + ID + "&sid=" + fieldMd5 + "&tid=" + tableId + "&value=" + newPos + "&rannum="+Math.random();
	ajaxRequest.open("GET", ajaxUpdBoxUrl + queryString, true);
	ajaxRequest.send(null);
}

    function adminLocation(locId,tableId){
      document.getElementById('map_canvas').innerHTML = '<a href="/includes/gmapadmin.php?lid=' + locId + '&tid=' + tableId +'" target="_blank"><img src="http://www.dublinevents.com/images/bars/gmapadmin.gif" title="gmap" border="0" /></a>';
      document.getElementById('map_canvas').style.width = '10px';
      document.getElementById('map_canvas').style.height = '5px';
	  map = false;
    }
















