<?php

function fn_or_ll($aql)
{
	$data = $aql->Consume(2);
	$framea = $data[0]->value;
	$frameb = $data[1]->value;
	
	$final = $framea;
	foreach($frameb as $fb)
	{
		$final[] = $fb;
	}
		
	$changes = true;
	//while($changes == true)
	//{
		$changes = false;
		for ($x=0;$x<count($final);$x++)
		{
			for($y=0;$y<count($final);$y++)
			{
				if ($x == $y) continue;
				$a = $final[$x];
				$b = $final[$y];
				if (($a['from'] <= $b['to']) && ($b['from'] < $a['to']))
				{
					$st = $a['from'];
					$en = $b['to'];
					if ($a['to'] > $en)
						$en = $a['to'];
					if ($b['from'] < $st)
						$st = $b['from'];
					$final[$x]['from'] = $st;
					$final[$x]['to'] = $en;
					unset($final[$y]);
					if ($y < $x) $x--;
					$y--;
					$changes = true;
				}				
			}
		}
	//}
	
	$a = new AQLStackElement();
	$a->typename = "timelist";
	$a->islist = true;
	$a->value = $final;
	array_push($aql->stack,$a);
}
?>