<?php
function fn_properties_c($aql)
{
	$data = $aql->Consume(1);
	
	$propshortlist = array();	
	$bing = array();
	
	$allprops = Properties::GetAllProperties();
	
	if ($data[0]->islist == true)
		$propset = $data[0]->value;
	else
		$propset = array($data[0]->value);
	
	$targetscore = 1;//count($propset);
	
	$any = false;
	foreach($allprops as $pr)
	{
		$bing[$pr->id] = 0;
		foreach($propset as $psx)
		{						
			if (strpos(strtolower($pr->name),strtolower($psx)) !== FALSE)
			{				
				$bing[$pr->id]++;
				$any = true;
			}
		}
	}
	
	if ($any == false)
	{
		foreach($allprops as $pr)
		{
			$bits = explode(' - ',$pr->name);
			if (count($bits) > 1)
			{
				$mod = strtolower($bits[1].' '.$bits[0]);
				$bing[$pr->id] = 0;
				//echo 'Checking For '.$mod;
				foreach($propset as $psx)
				{					
					//echo 'Comparing '.$pr->name.' to '.$mod;
					if (strpos($mod,strtolower($psx)) !== FALSE)
					{										
						$bing[$pr->id]++;						
					}
				}
			}			
		}
	}
	
	foreach($bing as $k => $v)
	{
		if ($v >= $targetscore)
		{
			$propid = $k;			
			$propshortlist[] = $k;
		}
	}
	
	$a = new AQLStackElement();
	$a->typename = "proplist";
	$a->islist = true;
	$a->value = $propshortlist;
	array_push($aql->stack,$a);
	
	//echo "Found ...";
	//print_r($propshortlist);
	return;
}
