
function plotOutline(latArray, lngArray, wholeArray)
{
	//alert(latArray);	
	var west = getMax(latArray);
	var north = getMax(lngArray);
	var east = getMin(latArray);
	var south = getMin(lngArray);
	
	var squareOutline;
	
	drawOutline(east, west, north, south);

	var outline_coords = "north=" + north + "&south=" + south + "&west=" + west + "&east=" + east;
	requestListings(outline_coords);

	map.removeOverlay(routePolyline);
	map.removeOverlay(startMarker);

}

function drawOutline(east, west, north, south)
{
	PGpoints = new Array(0);
	PGpoints.push(new GPoint(east, north));
	PGpoints.push(new GPoint(east, south));
	PGpoints.push(new GPoint(west, north));
	PGpoints.push(new GPoint(west, south));
	PGpoints.push(new GPoint(east, north));
	PGpoints.push(new GPoint(west, north));
	PGpoints.push(new GPoint(east, south));
	PGpoints.push(new GPoint(west, south));
	
	outlinePolyline = new GPolyline(PGpoints,"#FFFFFF", 3, 1);
	map.addOverlay(outlinePolyline);
}

function removeOutline()
{
	map.removeOverlay(outlinePolyline);
}
function drawOutline_dep(east, west, north, south)
{
	var polyline = new GPolyline([new GPoint(east, north),
                 new GPoint(east, south)],
                  "#000000", 3);
	map.addOverlay(polyline);
	
	var polyline = new GPolyline([new GPoint(west, north),
                 new GPoint(west, south)],
                  "#000000", 3);
	map.addOverlay(polyline);
	
	var polyline = new GPolyline([new GPoint(east, north),
                 new GPoint(west, north)],
                  "#000000", 3);
	map.addOverlay(polyline);
	
	var polyline = new GPolyline([new GPoint(east, south),
                 new GPoint(west, south)],
                  "#000000", 3);
	map.addOverlay(polyline);

}


function createSquareMarkers(index, points)
{
	var bMarker = new GMarker(points[index]);
	map.addOverlay(bMarker);
	
	GEvent.addListener(bMarker, "click", function() {
		marker.openInfoWindowHtml(points[index]);
	});
}

function showCenterOfLand(latArray, lngArray, wholeArray)
{
	var west = getMax(latArray);
	var north = getMax(lngArray);
	var east = getMin(latArray);
	var south = getMin(lngArray);
	
	var lr = ((east - west)/2);
	var ud = ((north - south)/2);
	
	var centerEW = parseFloat(lr) + parseFloat(west);
	var centerNS = parseFloat(ud) + parseFloat(south);
	
	map.centerAndZoom(new GPoint(centerEW, centerNS), 3);
	var marker = new GMarker(new GPoint(centerEW, centerNS));
	map.addOverlay(marker);
}

function getMax(array)
{
	var max=-99999999;
	var index;
	
	for(var i=0; i<array.length; i++)
	{
		if(array[i]>max)
		{
			max = array[i];	
			index = i;
		}
	}	
	
	return max;
}

function getMin(array)
{
	var min=99999999;
	var index;
	
	for(var i=0; i<array.length; i++)
	{
		if(array[i]<min)
		{
			min = array[i];	
			index = i;
		}
	}	
	
	return min;

}

