var googleMaps = new Object;
googleMaps.mainFunctions =
{
map: null,
initializeByAddress: function(address, containingDiv)
{
if (GBrowserIsCompatible())
{
googleMaps.mainFunctions.map = new GMap2(document.getElementById(containingDiv));
geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point)
{
if (!point)
{
alert(address + " not found");
}
else
{
googleMaps.mainFunctions.map.setCenter(point, 13);
googleMaps.mainFunctions.map.setUIToDefault();
var marker = new GMarker(point, {draggable: true});
GEvent.addListener(marker, "dragstart", function() {
googleMaps.mainFunctions.map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", function() {
marker.openInfoWindowHtml(address);
});
googleMaps.mainFunctions.map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
},
initializeByCoords: function(latitude, longitude, containingDiv, label)
{
if (GBrowserIsCompatible())
{
googleMaps.mainFunctions.map = new GMap2(document.getElementById(containingDiv));
point = new GLatLng(latitude, longitude);
googleMaps.mainFunctions.map.setCenter(point, 13);
googleMaps.mainFunctions.map.setUIToDefault();
var marker = new GMarker(point, {draggable: true});
GEvent.addListener(marker, "dragstart", function() {
googleMaps.mainFunctions.map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", function(latlng) {
if(label.length > 0) marker.openInfoWindowHtml(label);
googleMaps.mainFunctions.dropMarker(latlng);
});
googleMaps.mainFunctions.map.addOverlay(marker);
if(label.length > 0) marker.openInfoWindowHtml(label);
}
},
initializeByCoordsSearch: function(latitude, longitude, containingDiv, label, hideMarker)
{
if (GBrowserIsCompatible())
{
googleMaps.mainFunctions.map = new GMap2(document.getElementById(containingDiv));
point = new GLatLng(latitude, longitude);
googleMaps.mainFunctions.map.setCenter(point, 13);
googleMaps.mainFunctions.map.setUIToDefault();
if(hideMarker != true)
{
var marker = new GMarker(point);
googleMaps.mainFunctions.map.addOverlay(marker);
if(label) marker.openInfoWindowHtml(label);
}
}
},
addPoint: function(latitude, longitude, label, pointImage)
{
point = new GLatLng(latitude, longitude);
// create our marker icon
var iconObj = new GIcon(G_DEFAULT_ICON);
iconObj.image = "http://www.dinnerin.co.uk/images/google_maps_icons/"+pointImage;
iconObj.iconSize = new GSize(32, 37);
// Set up our GMarkerOptions object
markerOptions = { icon:iconObj };
var marker = new GMarker(point, markerOptions);
GEvent.addListener(marker, "click", function()
{
marker.openInfoWindowHtml(label);
});
googleMaps.mainFunctions.map.addOverlay(marker);
},
dropMarker: function(latlng)
{
if (latlng != null)
{
// update form fields
googleMaps.mainFunctions.setCoordinateFields(latlng.y, latlng.x);
}
},
setCoordinateFields: function(lat, lon)
{
document.getElementById('div_longitude').innerHTML = String(lon).substr(0, 9);
document.getElementById('div_latitude').innerHTML = String(lat).substr(0, 9);
document.getElementById('longitude').value = lon;
document.getElementById('latitude').value = lat;
},
retrievePositions: function(addressArr, callbackFunc)
{
var postData = "";
for(i in addressArr)
{
postData += "a_"+i+"="+addressArr[i]+"&"
}
var handleSuccess = function(o)
{
if(o.responseText !== undefined)
{
lObjResponse = YAHOO.lang.JSON.parse(o.responseText);
callbackFunc(lObjResponse.latitude, lObjResponse.longitude);
}
}
var handleFailure = function(o)
{
alert("fail");
}
var callback =
{
success:handleSuccess,
failure: handleFailure
};
sUrl = "ajax/getAddressPosition.php";
var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
},
getAddressArrayNew: function()
{
if(document.getElementById("branchName").value.length == 0)
{
sendError("Please enter the branch name", "branchName");
return false;
}
if(document.getElementById("streetAddress").value.length == 0)
{
sendError("Please enter the street address", "streetAddress");
return false;
}
if(document.getElementById("postCode").value.length == 0)
{
sendError("Please enter the postcode", "postCode");
return false;
}
var rs = new Object;
rs['street'] = document.getElementById("streetAddress").value;
rs['area'] = document.getElementById("areaAddress").value;
rs['city'] = document.getElementById("cityAddress").value;
rs['state'] = document.getElementById("countyAddress").value;
rs['zip'] = document.getElementById("postCode").value;
return rs;
},
getBubbleTextNew: function()
{
var addressArr = googleMaps.mainFunctions.getAddressArrayNew();
var bubbleText = ""+document.getElementById("branchName").value+"
";
for(i in addressArr)
{
if(addressArr[i].length > 0)
{
bubbleText += addressArr[i]+", ";
}
}
bubbleText = bubbleText.substr(0, bubbleText.length-2);
return bubbleText;
}
}