<?

function get_related($iblock_id, $id)
{
	$res = CIBlockElement::GetList(Array("NAME" => "ASC"), Array("IBLOCK_ID" => $iblock_id, "ID" => $id, "ACTIVE" => "Y"), false, Array("nPageSize" => 1000));

	$ar_res = Array();
	while ($obElement = $res->GetNextElement())
	{
		$ar_res = $obElement->GetFields();
		$ar_res['PROPERTIES'] = $obElement->GetProperties();
	}

	return $ar_res;
}

function get_related_array($iblock_id, $ids)
{
	$ar_res = Array();

	foreach($ids AS $id)
	{
		$res = CIBlockElement::GetList(Array("NAME" => "ASC"), Array("IBLOCK_ID" => $iblock_id, "ID" => $id, "ACTIVE" => "Y"), false, Array("nPageSize" => 1000));

		while ($obElement = $res->GetNextElement())
		{
			$ar_res_element = $obElement->GetFields();
			$ar_res_element['PROPERTIES'] = $obElement->GetProperties();
			$ar_res[] = $ar_res_element;
		}
	}

	return $ar_res;
}

AddEventHandler("main", "OnEpilog", "OnEpilogHandler", 1);
function OnEpilogHandler()
{
	if (defined('ERROR_404') && ERROR_404 == 'Y')
	{
		global $APPLICATION;
		$APPLICATION->RestartBuffer();
		include $_SERVER['DOCUMENT_ROOT'].'/local/templates/404/header.php';
		include $_SERVER['DOCUMENT_ROOT'].'/404.php';
		include $_SERVER['DOCUMENT_ROOT'].'/local/templates/404/footer.php';
	}
}

?>