function nearbyUpdate(Status)
	{
	var text='';
	lrow=Status.getElementsByTagName('geoname');
	var cnt=lrow.length;
	for(var i=0;i<cnt;i++)
		{
		lname=lrow[i].getElementsByTagName("name");				
		lat=lrow[i].getElementsByTagName("lat");
		lng=lrow[i].getElementsByTagName("lng");
		cc=lrow[i].getElementsByTagName("countryCode");
		text+='<h2>Nearest location is  ';
		text+=lname[0].firstChild.data;
		text+='</h2><br />(Latitude : '+decimal2Degrees('lat',lat[0].firstChild.data);
		text+=', longitude : '+decimal2Degrees('lng',lng[0].firstChild.data);
		text+=')<br /><br /><strong>Permanent link to ';
		text+=lname[0].firstChild.data;
		text+='</strong><br /><a href="http://www.geography.info/maps/coordinates_';
		text+=lng[0].firstChild.data+'_'+lat[0].firstChild.data+'.html">';
		text+='http://www.geography.info/maps/coordinates_';
		text+=lng[0].firstChild.data+'_'+lat[0].firstChild.data+'.html</a><br /><br /><br />';
		}
	document.getElementById("nearby").innerHTML=text;
	newLat=lat[0].firstChild.data;
	newLng=lng[0].firstChild.data;
	newName=lname[0].firstChild.data;
	}

function similarUpdate(Status)
	{
	var text='<table class="forumline" border="0" cellpadding="3" cellspacing="1" width="100%">';
	text+='<tbody><tr><th class="thCornerL" height="25" nowrap="nowrap">#</th>';
	text+='<th class="thTop" nowrap="nowrap">Name</th>';
	text+='<th class="thTop" nowrap="nowrap">Country</th>';
	text+='<th class="thTop" nowrap="nowrap">Feature class</th>';
	text+='<th class="thTop">Latitude</th>';
	text+='<th class="thCornerR" nowrap="nowrap">Longitude</th>';
	text+='</tr>'	;
	lres=Status.getElementsByTagName('totalResultsCount');
	totalRes=lres[0].firstChild.data;
	if(totalRes>0)
		{
		lrow=Status.getElementsByTagName('geoname');
		var cnt=lrow.length;
		for(var i=0;i<cnt;i++)
			{
			j=i+1;
			lname=lrow[i].getElementsByTagName("name");				
			lat=lrow[i].getElementsByTagName("lat");
			lng=lrow[i].getElementsByTagName("lng");
			cc=lrow[i].getElementsByTagName("countryCode");
			fcl=lrow[i].getElementsByTagName("fcl");
			fcode=lrow[i].getElementsByTagName("fcode");
			tcode=fcl[0].firstChild.data+'.'+fcode[0].firstChild.data;
			text+='<tr>';
			if(i % 2 == 0){row='row2';}else{row='row1';}
			text+='<td class="'+row+'">'+j+'</td><td class="'+row+'"><a href="http://www.geography.info/maps/coordinates_';
			text+=lng[0].firstChild.data+'_'+lat[0].firstChild.data+'.html">';
			text+=lname[0].firstChild.data+'</a></td>';	
			text+='<td class="'+row+'"><img src="http://www.geography.info/images/flags/';
			text+=cc[0].firstChild.data.toLowerCase()+'.png" border="0" /></td>';
			text+='<td class="'+row+'">'+codes[tcode]+'</td>';
			text+='<td class="'+row+'">'+decimal2Degrees('lat',lat[0].firstChild.data)+'</td>';
			text+='<td class="'+row+'">'+decimal2Degrees('lng',lng[0].firstChild.data)+'</td>';
			text+='</tr>';
			}
		text+='</tbody></table><br /><h1>Total results containing your search string : '+totalRes+'</h1>';
		}
	else
		{
		text='<h1><div style="color:red" align="center">No Results found!</div></h1><br /><br />';
		}		
	document.getElementById("nearby").innerHTML=text;
	
	}

function newMarker(point, html) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, 'click', function() {
	marker.openInfoWindowHtml(html);
  });

  return marker;
}

function decimal2Degrees(type,dec)
	{	
	if(type=="lat")
		{
		//latitude
		 if (dec<0) { degrees='S ';} else {degrees="N ";}
		 }
	else if(type=="lng")
		{
		if (dec<0) { degrees='W ';} else {degrees="E ";}
		}		 
	dec = Math.abs(dec);
	deg = Math.floor(dec);
	min = Math.floor((dec-deg)*60);
	sec =  (Math.round((((dec - deg) - (min/60)) * 60 * 60) * 100) / 100 ) ;
	degrees+=deg+'&deg;'+min+"'"+sec+'"';	  
	return degrees;
	}
function distance(lat1, lon1, lat2, lon2, unit) {
//borrowed from http://www.zipcodeworld.com  

	var radlat1 = Math.PI * lat1/180
	var radlat2 = Math.PI * lat2/180
	var radlon1 = Math.PI * lon1/180
	var radlon2 = Math.PI * lon2/180
	var theta = lon1-lon2
	var radtheta = Math.PI * theta/180
	var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
	dist = Math.acos(dist)
	dist = dist * 180/Math.PI
	dist = dist * 60 * 1.1515
	if (unit=="K") { dist = dist * 1.609344 }
	if (unit=="N") { dist = dist * 0.8684 }
	return dist.toFixed(3)
} 