$r = $dbcSearch->dbResultFetch();
$resultcount = $r['count'];
tpl_set_var('results_count', $resultcount);
if ($resultcount <= 5000 && $NrColSortSearch != -1) {
    $SearchWithSort = true;
    $tplname = 'search.result.caches';
    //prepare the output
    $caches_per_page = 999999;
    $cache_line = tpl_do_translate(read_file($stylepath . '/search.result.caches.row.tpl.php'));
    //build lines
} else {
    $SearchWithSort = false;
    $tplname = 'search.result.caches';
    //without sort
    $caches_per_page = 20;
    $cache_line = tpl_do_translate(read_file($stylepath . '/search.result.caches.row.tpl.php'));
    //build lines
}
if ($resultcount) {
    $caches_output = '';
} else {
    $caches_output = '<div class="errormsg" style="font-size:13px;text-align:center;"><b>' . tr('CachesNotMatchCryteria') . '</b></br></br></br></div>';
}
$CalcDistance = true;
if ($SearchWithSort && fHideColumn(findColumn(tr('Distance')), false) == 1) {
    $CalcDistance = false;
}
$CalcCoordinates = true;
if (fHideColumn(findColumn(tr('Coordinates')), false) == 1) {
    $CalcCoordinates = false;
}
function tpl_BuildTemplate($dbdisconnect = true, $minitpl = false, $noCommonTemplate = false)
{
    //template handling vars
    global $stylepath, $tplname, $vars, $langpath, $lang_array, $lang, $language;
    //language specific expression
    global $error_pagenotexist;
    //only for debbuging
    global $b, $bScriptExecution;
    $bScriptExecution->Stop();
    tpl_set_var('scripttime', sprintf('%1.3f', $bScriptExecution->Diff()));
    tpl_set_var('language_flags', writeLanguageFlags($lang_array));
    $bTemplateBuild = new Cbench();
    $bTemplateBuild->Start();
    //set {functionsbox}
    global $page_functions, $functionsbox_start_tag, $functionsbox_middle_tag, $functionsbox_end_tag;
    if (isset($page_functions)) {
        $functionsbox = $functionsbox_start_tag;
        foreach ($page_functions as $func) {
            if ($functionsbox != $functionsbox_start_tag) {
                $functionsbox .= $functionsbox_middle_tag;
            }
            $functionsbox .= $func;
        }
        $functionsbox .= $functionsbox_end_tag;
        tpl_set_var('functionsbox', $functionsbox);
    }
    //include language specific expressions, so that they are available in the template code
    include $langpath . '/expressions.inc.php';
    //load main template
    if ($minitpl) {
        $sCode = read_file($stylepath . '/mini.tpl.php');
    } else {
        if ($noCommonTemplate) {
            $sCode = '{template}';
        } else {
            if (isset($_REQUEST['print']) && $_REQUEST['print'] == 'y') {
                $sCode = read_file($stylepath . '/main_print.tpl.php');
            } else {
                if (isset($_REQUEST['popup']) && $_REQUEST['popup'] == 'y') {
                    $sCode = read_file($stylepath . '/popup.tpl.php');
                } else {
                    $sCode = read_file($stylepath . '/main.tpl.php');
                }
            }
        }
    }
    $sCode = '?>' . $sCode . '<?';
    //does template exist?
    if (!file_exists($stylepath . '/' . $tplname . '.tpl.php')) {
        //set up the error template
        $error = true;
        tpl_set_var('error_msg', htmlspecialchars($error_pagenotexist, ENT_COMPAT, 'UTF-8'));
        tpl_set_var('tplname', $tplname);
        $tplname = 'error';
    }
    //read the template
    $sTemplate = read_file($stylepath . '/' . $tplname . '.tpl.php');
    $sCode = mb_ereg_replace('{template}', $sTemplate, $sCode);
    //process the template replacements
    $sCode = tpl_do_replace($sCode);
    $sCode = tpl_do_translate($sCode);
    //store the cookie
    write_cookie_settings();
    //send http-no-caching-header
    http_write_no_cache();
    // write UTF8-Header
    header('Content-type: text/html; charset=utf-8');
    //run the template code
    eval($sCode);
    //disconnect the database
    if ($dbdisconnect) {
        db_disconnect();
    }
}
$r = $dbcSearch->dbResultFetch($s);
$resultcount = $r['count'];
tpl_set_var('results_count', $resultcount);
if ($resultcount <= 5000 && $NrColSortSearch != -1) {
    $SearchWithSort = true;
    $tplname = 'search.result.caches';
    // prepare the output
    $caches_per_page = 999999;
    $cache_line = tpl_do_translate(file_get_contents($stylepath . '/search.result.caches.row.tpl.php'));
    // build lines
} else {
    $SearchWithSort = false;
    $tplname = 'search.result.caches';
    // without sort
    $caches_per_page = 20;
    $cache_line = tpl_do_translate(file_get_contents($stylepath . '/search.result.caches.row.tpl.php'));
    // build lines
}
if ($resultcount) {
    $caches_output = '';
} else {
    $caches_output = '<div class="errormsg" style="font-size:13px;text-align:center;"><b>' . tr('CachesNotMatchCryteria') . '</b></br></br></br></div>';
}
$CalcDistance = true;
if ($SearchWithSort && fHideColumn(findColumn(tr('Distance')), false) == 1) {
    $CalcDistance = false;
}
$CalcCoordinates = true;
if (fHideColumn(findColumn(tr('Coordinates')), false) == 1) {
    $CalcCoordinates = false;
}