// $Id: $

// Display locality information

function decimal_to_degrees(decimal)
{
	decimal = Math.abs(decimal);
	degrees = Math.floor(decimal);
	minutes = Math.floor(60 * (decimal - degrees));
	seconds = Math.round(60 * (60 * (decimal - degrees) - minutes));

	html = degrees + '&deg;' + minutes + '&rsquo;' + seconds + '&rdquo;';
	return html;
}

function format_decimal_latlon(latitude, longitude)
{
	html = decimal_to_degrees(latitude);
	html += (latitude < 0.0 ? 'S' : 'N');
	html += '&nbsp;';
	html += decimal_to_degrees(longitude);
	html += (latitude < 0.0 ? 'W' : 'E');
	return html;
}

				
function api_localities(obj) 
{
	d = document.getElementById('localities');
	d.innerHTML= '';

	var html = '';//'<h3>Localities</h3>'; 
	
	html += '<ul>';


	if (obj.results.length > 0)
	{
	 for(i=0;i<obj.results.length;i++)
	 {
		if (obj.results[i].degree_of_separation == 0)
		{
	 	html += '<li>';
	
	    html += '' + obj.results[i].id + ': [' 
			+ '<a href="http://maps.google.com/maps?q='
			+ obj.results[i].pt[1] + ' ' + obj.results[i].pt[0] + '" target="_new">'			 
			+ obj.results[i].pt[1] 
			+ ', ' 
			+ obj.results[i].pt[0]
			+ '</a>';
	
		html += '] ' + format_decimal_latlon(obj.results[i].pt[1], obj.results[i].pt[0]);
	
	 	if (obj.results[i].confidence != -1)
	    {
			html += ' (' + obj.results[i].loc;
			html += ', confidence = ' + obj.results[i].confidence + ')';
		}
	
		html += '</li> ';
	}
	 }
	}
	html += '</ul>';
	d.innerHTML= html;
}
