function getLocationArray() {
	var locations = new Array();
	var currentLoc;
<?php
	include_once "../siteFunctions.php";
	init();
	$radius = $_GET['radius'];
	$zipCode = $_GET['zipCode'];
	$count = 0;
	$result = mysql_query("SELECT * FROM locations") or die(mysql_error());
	while($row = mysql_fetch_array($result))
	{
		echo "currentLoc = new Array();\n";
		echo "currentLoc[0] = new GLatLng(".$row['latitude'].",".$row['longitude'].");\n";
		echo "currentLoc[1] = \"".$row["name"]."\";\n";
		echo "currentLoc[2] = ".$row["locationID"].";\n";
		echo "currentLoc[3] = decodeURIComponent(\"".rawurlencode(nl2br($row["address"]))."\");\n";
		echo "currentLoc[4] = decodeURIComponent(\"".rawurlencode(nl2br($row["comments"]))."\");\n";
		echo "currentLoc[5] = \"".formatPhoneNumber($row["phone"])."\";\n";
		echo "locations[".$count."] = currentLoc;\n";
		echo "currentLoc = 0;\n";
		$count++;
	}
?>
	return locations;
}
function _GET( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function pointsNear(address, pointsArray, radius) {
	if (radius == 0)
	{
		radius = 24000;
	}
	var geocodedPoint;
	var geocoder = new GClientGeocoder();
  	geocoder.getLatLng(address, function(point) {	
		var count = 0;
		geocodedPoint = point; 
		var validPoints = new Array();
		for(var i=0;i<pointsArray.length;i++)
		{
			var currentGLatLng = pointsArray[i][0];
			var distance = 0.000621371192*(point.distanceFrom(currentGLatLng));
			if (distance<=radius)
			{
				pointsArray[i][6] = distance;
				validPoints[count] = pointsArray[i];
				count++;
			}
		}
		returnedPoints(sort2DArray(validPoints,6), geocodedPoint);
      }
  );
}
function sort2DArray(array, index)
{
	var workingArray = array;
	var newArray = new Array();
	var ha = 0;
	for(var i=0;i<workingArray.length;i++)
	{
		if (workingArray[i][index] > ha)
		{
			ha = workingArray[i][index];
		}
	}
	while (workingArray.length != newArray.length)
	{
		var hb = ha;
		var hc;
		var hd;
		for(var i=0;i<workingArray.length;i++)
		{
			if (workingArray[i][index] <= hb)
			{
				hb = workingArray[i][index];
				hc = workingArray[i];
				hd = i;
				
			}			
		}
		newArray[newArray.length] = hc;
		workingArray[hd] = 0;
	}
	return newArray;
}
