<?php
include(__DIR__.'/../includes/sysinit.php');
function calculateDistance($lat, $lng)
{
	$dist = SableGeneralFunctions::getDistanceBetweenLocations(floatval($_POST['lat']), floatval($_POST['lng']), floatval($lat), floatval($lng));
	return $dist;
}
SableSystem::deleteCookie('locationCompanyId');
$sql = 'select company_name, company_id, address_lng, address_lat 
		from company 
		inner join address on address.address_id = company.address_id 
		where (company.company_type_id = 3) and (company.deleted = 0)';
$rows = $sableDB->getRows($sql);
$coyid = 0;
foreach($rows as $row)
{
	$distance = calculateDistance($row['address_lng'], $row['address_lat']);
	if ($distance <= 7)
	{
		$coyid = $row['company_id'];
		SableSystem::setCookie('locationCompanyId', $coyid);	
		break;
	}
}
SableSystem::ajaxFillTag($coyid, 'selCompanyId');