function searchGoogle()
{
	var xmlHttp;

	try
	{	xmlHttp=new XMLHttpRequest();								}
	catch (e)
	{
		try
		{	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");			}
		catch (e)
		{
			try
			{	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");		}
			catch (e)
			{	return false;										}
		}
	}

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			// Display the returned text
			document.getElementById("store_results").innerHTML = xmlHttp.responseText;
			//display_results( xmlHttp.responseText, true );
		}
	}


	// Setup and send the request
	search_string 	= document.myForm.your_location.value;	//search_string = document.myForm.search_string.value;
	raw_search 		= document.myForm.search_string.value;
	search_distance	= document.myForm.search_distance.value;
	result_count	= document.myForm.result_count.value;


	// We need the product codes (as populated by php)
	fineline_code	= document.myForm.fineline_code.value;
	air_code		= document.myForm.air_code.value;
	shadow_code		= document.myForm.shadow_code.value;

	// And which dropdown is selected
	product_select = document.getElementById( "product_selector" );
	product_selected = product_select[ product_select.selectedIndex ].value;

	full_search 	= "";
	if( "s_fineline" == product_selected )
		full_search = "|" + fineline_code;

	if( "s_air" == product_selected )
		full_search = "|" + air_code;

	if( "s_shadow" == product_selected )
		full_search = "|" + shadow_code;

	/*search_fineline	= document.myForm.s_fineline.checked;
	search_air		= document.myForm.s_air.checked;
	search_shadow	= document.myForm.s_shadow.checked;


	if( search_fineline )
		full_search = full_search + "|" + fineline_code;

	if( search_air )
		full_search = full_search + "|" + air_code;

	if( search_shadow )
		full_search = full_search + "|" + shadow_code;
	*/

	filename 		= "/_php_common/stockists/process/p-find-store-google.php?method=ajax&raw_search=" + raw_search + "&search=" + search_string + "&distance=" + search_distance + "&products=" + full_search + "&result_count=" + result_count;
	xmlHttp.open( "GET", filename ,true );
	xmlHttp.send( null );
}


// This funtion queries our database for store that exactly match what the customer enters
// If we dont find a store that matches - then pass the call on to google what will attempt to
function initialStoreCheck( sourceElementID )
{
	usePointFromPostcode(document.getElementById('search_string').value, searchGoogle )
/*
	var xmlHttp;
	try
	{	xmlHttp=new XMLHttpRequest();								}
	catch (e)
	{
		try
		{	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");			}
		catch (e)
		{
			try
			{	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");		}
			catch (e)
			{	return false;										}
		}
	}

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			// Check the response - see if we got somthing we can use
			if( "" == xmlHttp.responseText )
				usePointFromPostcode(document.getElementById('search_string').value, searchGoogle )
			else
			{
				// We got a direct match - so go ahead and show the results
				display_results( xmlHttp.responseText, false );
			}
		}
	}

	// Setup and send the request
	search_string 	= document.getElementById( sourceElementID ).value;
	raw_search 		= document.myForm.search_string.value;
	filename 		= "/_php_common/stockists/process/p-find-store.php?method=ajax&raw_search=" + raw_search + "&search=" + search_string;
	xmlHttp.open( "GET", filename ,true );
	xmlHttp.send( null );
*/
}



function display_results( resultsText, showDistance )
{
	// Extract the location of the store
	var store_loc = document.getElementById( "stockist_" + resultsText ).value;
	store_loc = store_loc.substring( 1, store_loc.length-1 );
	commaIndex = store_loc.indexOf( "," );
	x = store_loc.substring( 0, commaIndex );
	y = store_loc.substring( commaIndex+1, 1000 );
	var store_point = new GLatLng( x, y );

	// Extract the location of the person
	var your_loc = document.getElementById("your_location").value;
	your_loc = your_loc.substring( 1, your_loc.length-1 );
	commaIndex = your_loc.indexOf( "," );
	x = your_loc.substring( 0, commaIndex );
	y = your_loc.substring( commaIndex+1, 1000 );
	var your_point = new GLatLng( x, y );

	// Calc Mid Point
	/*
	mid_x	= parseFloat( your_point.lat() ) + parseFloat( store_point.lat() ) / 2;
	myx 	= parseFloat( your_point.lat() ) + parseFloat( store_point.lat() )
	myx 	= myx / 2;

	mid_y 	= parseFloat( your_point.lng() ) + parseFloat( store_point.lng() ) / 2;
	myy 	= parseFloat( your_point.lng() ) + parseFloat( store_point.lng() );
	myy		= myy / 2;
	var mid_point = new GLatLng( myx, myy );

	//alert( "you: "+your_point + "\nStore: " + store_point + "\nMid: " + mid_point )
	//alert( "store: "+store_point )
	//alert( "mid: "+mid_point )
	*/

	// Calc and show Distance
	if( true == showDistance )
	{
		distance = store_point.distanceFrom( your_point );
		placeMarkerAtPoint( your_point );
		distance = distance * 0.000621371192;
		document.getElementById("distance_to_store").innerHTML = distance.toFixed(2);
	}

	// Update the map with markers
	setCenterToPoint( store_point  );
	placeMarkerAtPoint( store_point );
}

//javascript:usePointFromPostcode(document.getElementById('search_string').value, ajaxFunction ); return false;