
function fixEncoding(x)
{
	var r = x;
	r = r.replace("/&apos;?/g","'");
	return r;
}


var pleaseWait = "<p style='text-align:center;'><img src='../images/gears_animated.gif' alt='Please wait...' /><br />Please wait...</p>";

function getTweets()
{
	document.getElementById("results").innerHTML = pleaseWait;
	var p = "action=getTweets";
	p += "&lat="+document.getElementById("lat").value;
	p += "&lng="+document.getElementById("lng").value;
	var kw = document.getElementById('keywords').value;
//	kw = kw.replace(/ /g,"+");
//	kw = kw.replace(/ /g,"%2B");
	p += "&keywords="+kw;
	p += "&dist="+document.getElementById('dist').value;
	var aj = trim(ajax("post",SiteDomain+"/twitter/ajax.php",p));

//	dBug(aj);

	var t = parseJSON(aj);

	/*	SAMPLE:
			image:'http://a1.twimg.com/profile_images/589876532/show1_normal.jpg'
			, pubdate:'2010-02-19'
			, pubtime:'15:20:13'
			, content:'i&apos;m <b>bored</b>'
			, user:'thevampireaudra'	
	*/

	
	var o = "<hr />";
	if (t.length > 0)
	{
		for (var i=0;i<t.length;i++)
		{
			o += "<div class='tweet'>";
			o += "<div class='title'>" + t[i].user + "</div>";
			o += "<img class='userphoto' src='"+t[i].image+"' alt='' />";
			o += "<p>";
			o += fixEncoding(t[i].content);
			o += "</p>";
			o += "</div>";
		}
	}
	else
	{
		o = "<p>No results found. :(</p>";
	}
	document.getElementById("results").innerHTML = o;
}













function changeLatLng()
{
	lookupLatLng(document.getElementById('address').value);
}

function setLatLng(lat,lng)
{
	document.getElementById("lat").value = lat;
	document.getElementById("lng").value = lng;
}

function lookupLatLng(address) {
  try
  {
	var geocoder = new GClientGeocoder();
	  geocoder.getLatLng(
		address,
		function(point) {
			var lat = 0;
			var lng = 0;
			if (point!=null)
			{
				lat = point.y;
				lng = point.x;
			}
			if (!(isNumeric(""+lat))) { lat = 0; }
			if (!(isNumeric(""+lng))) { lng = 0; }

			setLatLng(lat,lng);

		}
	  );
  }
  catch(err) {  }
}





function dBug(x)
{
	if (x!="")
	{
		document.getElementById('debug').innerHTML = "<textarea id='debug' style='width:90%; height:400px;'>"+x+"</textarea>";
	}
	else
	{
		document.getElementById('debug').innerHTML = "";
	}
}




function processLocation(position)
{
	document.getElementById('results').innerHTML = "";
	document.getElementById("lat").value = position.coords.latitude;
	document.getElementById("lng").value = position.coords.longitude;
}



function geotest()
{
	document.getElementById('pleaseWait').innerHTML = pleaseWait;
	if (navigator.geolocation)
	{
		var pos = navigator.geolocation.getCurrentPosition(processLocation);
	}
	else
	{
		document.getElementById('results').innerHTML = "";
		alert("QUICK NOTE: Geolocation does not appear to be supported by your browser, so before you search, you'll need to manually enter your coordinates or try to search for a location using the form at the top of the page.");
	}
}



