var map = null;
var geocoder = null;

function GetMap()
{
/*	map = new VEMap('myMap');
	map.LoadMap();*/
	geocoder = new GClientGeocoder();
}

function FindMe()
{
	if ( null == geocoder )
	{
		alert( 'Please wait for the page to finish loading...' );
		return false;
	}

/*	map.FindLocations( document.getElementById('loc_loc').value + ', UK', CB_FindLocations);
	setTimeout("getLong()", 3000);*/
	
	geocoder.getLocations( document.getElementById('loc_loc').value + ', UK', CB_FindLocations );
	
	stopInput();
	return false;
}

function CB_FindLocations( locs )
{
	if ( !locs || locs.Status.code != 200)
	{
		document.getElementById('find').value = 'Unable to find postcode.';
		return;
	}
	
	var place = locs.Placemark[0];

	document.getElementById('co_long').value = place.Point.coordinates[0];
	document.getElementById('co_lat').value =  place.Point.coordinates[1];
	document.getElementById('co_form').submit();
	
}

function stopInput()
{
/*	document.getElementById('co_rad').readOnly = true;
	document.getElementById('loc_loc').readOnly = true;*/
	document.getElementById('find').value = 'Seaching ... Please wait.';
	document.getElementById('find').disabled = true;
}

function FindThis(location, dist)
{
	GetMap();
	map.FindLocation ( location + ', UK');
	document.getElementById('co_postcode').value = location;
	document.getElementById('co_dist').value = dist;
	setTimeout("getLong()", 3000);
}

function catchReturn(e)
{
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}

	if (13 == keynum)
	{
		return FindMe();
	}
}

function getLong()
{
	if ( null == map)
		return;

	var loc = map.GetCenter();
	document.getElementById('co_long').value = loc.Longitude;
	document.getElementById('co_lat').value =  loc.Latitude;
	document.getElementById('co_form').submit();
}

