function newShape(shape) {
	if (!polyAddListener && !circleAddListener && !rectangleAddListener) // Prevent multiple shapes from being created at once
	{
		if (shape == 'polygon')
			polyAddListener = addPolygonListener();
		else if (shape == 'circle')
			circleAddListener = addCircleListener();
		else if (shape == 'rectangle')
			rectangleAddListener = addRectangleListener();
	}
}

function populateShapeInputs() {
	var shapes = 0;
	var strRectangleLLs = "";
	var strPolygonLLs = "";
	var strCircleLLs = "";
	
	for (var r=0; r<rectangles.length; r++) {
		if (rectangles[r].active) {
			strRectangleLLs += (rectangles[r].startPoint.getLatLng().lat() + ",");
			strRectangleLLs += (rectangles[r].startPoint.getLatLng().lng() + ";");
			strRectangleLLs += (rectangles[r].midPointLL.lat() + ",");
			strRectangleLLs += (rectangles[r].midPointLL.lng() + "|");
			shapes++;
		}
	}
	$("#rectangles").val(strRectangleLLs);
	
	for (var p=0; p<polygons.length; p++) {
		if (polygons[p].active) {
			for (var point=0; point<polygons[p].points.length;point++) {
				strPolygonLLs += (polygons[p].points[point].lat() + ",");
				strPolygonLLs += (polygons[p].points[point].lng() + ";");
			}
			strPolygonLLs += ("|");
			shapes++;
		}
	}
	$("#polygons").val(strPolygonLLs);
	
	for (var c=0; c<circles.length; c++) {
		if (circles[c].active) {
			strCircleLLs += (circles[c].startPoint.getLatLng().lat() + ",");
			strCircleLLs += (circles[c].startPoint.getLatLng().lng() + ";");
			strCircleLLs += (circles[c].radiusPoint.lat() + ",");
			strCircleLLs += (circles[c].radiusPoint.lng() + "|");
			shapes++;
		}
	}
	$("#circles").val(strCircleLLs);
	
	return (shapes > 0);
}

$(document).ready(function(){
	$("a.addshape").bind("click", function(e) {
		e.preventDefault();
		newShape($(this).attr("title"));
	});
	loadMap();
	document.onunload = GUnload;
});