/**Ajax Request (Submits the form below through AJAX
 *               and then calls the ajax_response function)
 */
function ajax_request() {
  var place = document.getElementById('placename');	
  var submitTo = 'Places.php?place='+ place.value;
  place.value = '';
  //location.href = submitTo; //uncomment if you need for debugging
  http('GET', submitTo, ajax_response);
}

/**Ajax Response (Called when ajax data has been retrieved)
 *
 * @param   object  data   Javascript (JSON) data object received
 *                         through ajax call
 */
function ajax_response(data) {
  var a = new Array();
  var i;
  eval("a = data;");
	var thePlaceName = document.getElementById('placename');
	thePlaceName.value = a[0];

	if (a.length > 1)
	{
		if (a.length > 2)
		{
			var content =	'<form name="xtraCountiesList">' 
			+'<fieldset>'
			+'<select class="formSelect" onchange="getHTML('
			+'\'findCounties\')'
			+'"size="1" name="listofCounties">'
			+'<option selected="yes"value="no">';
			
			var counties = a.length -1;
			for (i = 1; i < counties ;i = i + 2 )
			{
				var n = counties / 2;
				if (n > 1)
				{
					content += a[0];
					content += ' lies in ' +n +' counties</option>';
				}
				content += '<option value="' +a[i] +'">' + a[i+1] + '</option><br>';
			}
			content += '</select></fieldset> </form>';
			document.getElementById('xtraCounties').innerHTML = content;
			toggleBox('xtraCounties',1); //turn on
		}
		getHTML(a[1]);
	}

	// window.alert( 'The value of the text node is:\n' + thePlace.childNodes[0].nodeValue );

  }

