echo '</div>
		</div>';
        } else {
            echo '<div class="home_wrap">
			<div class="home_img">
				<a href="' . $playlink . '">';
            if ($in['type'] == 1) {
                echo '<img src="' . $domain . '/' . $thumbsfolder . '/' . $in['thumb'] . '" alt="' . $gamename . '" class="home_img" />';
            } else {
                echo '<img src="' . $in['thumburl'] . '" alt="' . $gamename . '" class="home_img" />';
            }
            echo '</a>
			</div>
			<div class="home_info">
				<div class="home_title"><a href="' . $playlink . '">' . titlelimit($in['name']) . '</a></div>
				<div class="home_desc">' . desclimit($in['description']) . '</div>';
            if ($usrdata['user_level'] == 2) {
                echo '<div style="float: right; vertical-align: top; padding-right: 20px;">
						<a href=\'' . $domain . '/index.php?action=admin&amp;case=managegames&amp;cmd=edit&amp;ID=' . $in['ID'] . '&amp;type=' . $in['type'] . '\' onclick="return confirm(\'Are you sure you want to edit the game ' . $in['name'] . '?\')"><img src=\'' . $domain . '/templates/' . $template . '/style/images/edit.png\' title=\'edit game\' alt=\'edit game\' border=\'0\' /></a>
						<a href=\'' . $domain . '/index.php?action=admin&amp;case=managegames&amp;cmd=delete&amp;ID=' . $in['ID'] . '\' onclick="return confirm(\'Are you sure you want to delete the game ' . $in['name'] . '?\')"><img src=\'' . $domain . '/templates/' . $template . '/style/images/delete.png\' title=\'delete game\' alt=\'delete game\' border=\'0\' /></a>
					</div>';
            }
            echo '</div>
		</div>';
        }
        $count++;
    }
    echo '</div>
<div class="page-box">
' . $totalres . ' game(s) - Page ' . $show . ' of ' . $totalpages;
    $pre = $show - '1';
function writebody()
{
    global $db, $domain, $sitename, $cachelife, $template, $gamesfolder, $thumbsfolder, $limitboxgames, $seo_on, $blogentriesshown, $enabledcode_on, $comments_on, $directorypath, $autoapprovecomments, $gamesonpage, $abovegames, $belowgames, $showwebsitelimit, $supportemail, $showblog, $blogentriesshown, $blogcharactersshown, $blogcommentpermissions, $blogcommentsshown, $blogfollowtags, $blogcharactersrss, $usrdata, $userid, $r;
    $ID = clean($_GET['ID']);
    $ID = abs((int) $ID);
    $max = $gamesonpage;
    $show = clean($_GET['page']);
    if (empty($show)) {
        $show = 1;
    }
    $limits = ($show - 1) * $max;
    $r2 = "SELECT * FROM fas_games WHERE category='{$ID}' && active='1' ORDER BY ID DESC LIMIT " . $limits . "," . $max;
    $sqltitle = "browse-cat" . $ID . "page" . $show;
    $r1 = sqlcache($sqltitle, $cachelife, $r2);
    $totalres = mysql_result($db->query('SELECT COUNT(ID) AS total FROM fas_games WHERE active=\'1\' and category=\'' . $ID . '\''), 0);
    $totalpages = ceil($totalres / $max);
    echo '<table width=\'100%\' border=\'0\' align=\'center\'>
	<tr>
		<td colspan=\'2\' class=\'header\'>' . clean($_GET['name']) . ' Games</td>
	</tr>';
    $count = 0;
    if (!isset($r1)) {
        echo '	<tr>
		<td colspan=\'2\' class=\'content\'><div align="center"><b>There currently are no games in this category.</b></div></td>
	</tr>';
    } else {
        foreach ($r1 as $in) {
            $gamename = preg_replace('#\\W#', '-', $in['name']);
            if ($seo_on == 1) {
                $playlink = '' . $domain . '/play/' . $in['ID'] . '-' . $gamename . '.html';
            } else {
                $playlink = '' . $domain . '/index.php?action=play&amp;ID=' . $in['ID'] . '';
            }
            if ($count % 2 == 0) {
                echo '<tr>
	      	<td width=\'50%\' valign=\'top\'>

	      		<table width=\'100%\' border=\'0\'>
	      			<tr>
	      				<td valign=\'top\' colspan=\'2\' class=\'header\'><b>' . titlelimit($in['name']) . '</b></td>
	      			</tr>
	      			<tr>
	      				<td width=\'55\' height=\'55\' valign=\'top\' class=\'content\'>
	      				<a href=\'' . $playlink . '\'>
	      				';
                if ($in['type'] == 1) {
                    echo '	<img src=\'' . $domain . '/' . $thumbsfolder . '/' . $in['thumb'] . '\' width=\'55\' height=\'55\' border=\'0\'>';
                } else {
                    echo '	<img src=\'' . $in['thumburl'] . '\' width=\'55\' height=\'55\' border=\'0\'>';
                }
                echo '	</a>
	      				</td>
	      				<td valign=\'top\' class=\'content\'>' . desclimit($in['description']) . '
	      				<a href=\'' . $playlink . '\' class=\'playlink\'><b>Play</b></a></td>
	      			</tr>
	      		</table>

	      	</td>
	';
            } else {
                echo '
	      	<td width=\'50%\' valign=\'top\'>

	      		<table width=\'100%\' border=\'0\'>
	      			<tr>
	      				<td valign=\'top\' colspan=\'2\' class=\'header\'><b>' . titlelimit($in['name']) . '</b></td>
	      			</tr>
	      			<tr>
	      				<td width=\'55\' height=\'55\' valign=\'top\' class=\'content\'>
	      				<a href=\'' . $playlink . '\'>
	      				';
                if ($in['type'] == 1) {
                    echo '	<img src=\'' . $domain . '/' . $thumbsfolder . '/' . $in['thumb'] . '\' width=\'55\' height=\'55\' border=\'0\'>';
                } else {
                    echo '	<img src=\'' . $in['thumburl'] . '\' width=\'55\' height=\'55\' border=\'0\'>';
                }
                echo '	</a>
	      				</td>
	      				<td valign=\'top\' class=\'content\'>' . desclimit($in['description']) . '
	      				<a href=\'' . $playlink . '\' class=\'playlink\'><b>Play</b></a></td>
	      			</tr>
	      		</table>

	      	</td>
	</tr>';
            }
            $count++;
        }
    }
    echo "</table>";
    echo 'Pages: ';
    for ($i = 1; $i <= $totalpages; $i++) {
        if ($seo_on == 1) {
            $urk = '' . $domain . '/browse/' . $ID . '-' . clean($_GET['name']) . '/page' . $i . '.html';
        } else {
            $urk = '' . $domain . '/index.php?action=browse&ID=' . $ID . '&page=' . $i . '';
        }
        echo '<a href=\'' . $urk . '\' class=\'pagenat\'>' . $i . '</a>&nbsp; ';
    }
    echo '<br /><br />';
    $pgname = clean($_GET['name']);
}
                } else {
                    $playlink = '' . $domain . '/index.php?action=play&amp;ID=' . $row['ID'] . '';
                }
                echo '<div class="home_wrap">
	      					<div class="home_img">
				      			<a href=\'' . $playlink . '\'>';
                if ($row['type'] == 1) {
                    echo '	<img src=\'' . $domain . '/' . $thumbsfolder . '/' . $row['thumb'] . '\' class="home_img" alt=\'' . $gamename . '\' title= \'' . $gamename . '\' />';
                } else {
                    echo '	<img src=\'' . $row['thumburl'] . '\' class="home_img" alt= \'' . $gamename . '\' title= \'' . $gamename . '\' />';
                }
                echo '</a>
				      		</div>
							<div class="home_info">
				      			<div class=\'home_title\'><a href=\'' . $playlink . '\'>' . titlelimit($row['name']) . '</a></div>
				      			<div class=\'home_desc\'>' . desclimit($row['description']) . '</div>
				      		</div>
						</div>';
            }
        } else {
            echo '<div>
							No games have been added to this category yet.
						</div>';
        }
        echo '</div>
		</div>
	</div>';
    }
    $count++;
}
//end foreach baser1
function writebody()
{
    global $db, $domain, $sitename, $cachelife, $template, $gamesfolder, $thumbsfolder, $limitboxgames, $seo_on, $blogentriesshown, $enabledcode_on, $comments_on, $directorypath, $autoapprovecomments, $gamesonpage, $abovegames, $belowgames, $showwebsitelimit, $supportemail, $showblog, $blogentriesshown, $blogcharactersshown, $blogcommentpermissions, $blogcommentsshown, $blogfollowtags, $blogcharactersrss, $usrdata, $userid;
    $count = 0;
    $baser2 = "SELECT * FROM fas_categories where active='1'";
    $baser1 = sqlcache('mainpagecats', $cachelife, $baser2);
    if ($baser1 == false) {
        //If no games are added to the category yet, display error.
        echo '<div class="msg">No categories added yet</div>';
        return;
    }
    //end if $baser1
    echo '<table width=\'99%\' border=\'0\' cellpadding=\'0\' cellspacing=\'0\'  align=\'center\'>';
    foreach ($baser1 as $row) {
        $categorynamev = $row['name'];
        $categorynameu = preg_replace('#\\W#', '-', $categorynamev);
        if ($seo_on == 1) {
            $categoryurl = '' . $domain . '/browse/' . $row['ID'] . '-' . $categorynameu . '.html';
        } else {
            $categoryurl = '' . $domain . '/index.php?action=browse&amp;ID=' . $row['ID'] . '';
        }
        if ($count % 2 == 0) {
            echo '<tr>
	      	<td width=\'50%\' valign=\'top\'>
	      	<table width=\'97%\' border=\'0\'>
	      		<tr>
	      			<td class=\'header\'>' . $row['name'] . '</td>
	      		</tr>
	      		<tr>
	      			<td>';
            echo '<table>';
            $catid1 = $row['ID'];
            $sqltitle = 'mainpagecat' . $catid1;
            $baseir2 = "SELECT * FROM fas_games WHERE category='{$catid1}' and active='1' ORDER BY rand() LIMIT 0," . $limitboxgames;
            $baseir1 = sqlcache($sqltitle, $cachelife, $baseir2);
            if (isset($baseir1)) {
                foreach ($baseir1 as $row) {
                    $gamename = preg_replace('#\\W#', '-', $row['name']);
                    if ($seo_on == 1) {
                        $playlink = '' . $domain . '/play/' . $row['ID'] . '-' . $gamename . '.html';
                    } else {
                        $playlink = '' . $domain . '/index.php?action=play&amp;ID=' . $row['ID'] . '';
                    }
                    echo '	<tr>
	      			<td width=\'45\' height=\'45\' valign=\'top\' class=\'content\'>
	      			<a href=\'' . $playlink . '\'>
	      			';
                    if ($row['type'] == 1) {
                        echo '	<img src=\'' . $domain . '/' . $thumbsfolder . '/' . $row['thumb'] . '\' width=\'45\' height=\'45\' border=\'0\'>';
                    } else {
                        echo '	<img src=\'' . $row['thumburl'] . '\' width=\'45\' height=\'45\' border=\'0\'>';
                    }
                    echo '
	      			</a>
	      			</td>
	      			<td valign=\'top\' class=\'content\'><div class=\'gamehometitle\'>' . $row['name'] . '</div>
	      						<div class=\'gamehomedesc\'>' . desclimit($row['description']) . '
	      						<a href=\'' . $playlink . '\'>Play</a></div></td>
	      		</tr>';
                }
            } else {
                echo '<div>
						No games in this category yet.
					</div>';
            }
            echo '<tr><td colspan=\'2\' class=\'content\'>';
            echo '<a href=\'' . $categoryurl . '\'>Play more ' . $categorynamev . ' games</a>';
            echo '</td></tr>';
            echo '  </table>';
            echo '	</td>
	      		</tr>
	      	</table>
	      		</td>';
        } else {
            echo '
	      	<td width=\'50%\' valign=\'top\'>
	      	<table width=\'97%\' border=\'0\'>
	      		<tr>
	      			<td class=\'header\'>' . $row['name'] . '</td>
	      		</tr>
	      		<tr>
	      			<td>';
            echo '<table>';
            $catid1 = $row['ID'];
            $sqltitle = 'mainpagecat' . $catid1;
            $baseir2 = "SELECT * FROM fas_games WHERE category='{$catid1}' and active='1' ORDER BY rand() LIMIT 0," . $limitboxgames;
            $baseir1 = sqlcache($sqltitle, $cachelife, $baseir2);
            if (isset($baseir1)) {
                foreach ($baseir1 as $row) {
                    $gamename = preg_replace('#\\W#', '-', $row['name']);
                    if ($seo_on == 1) {
                        $playlink = '' . $domain . '/play/' . $row['ID'] . '-' . $gamename . '.html';
                    } else {
                        $playlink = '' . $domain . '/index.php?action=play&amp;ID=' . $row['ID'] . '';
                    }
                    echo '	<tr>
				      			<td width=\'45\' height=\'45\' valign=\'top\' class=\'content\'>
				      			<a href=\'' . $playlink . '\'>';
                    if ($row['type'] == 1) {
                        echo '	<img src=\'' . $domain . '/' . $thumbsfolder . '/' . $row['thumb'] . '\' width=\'45\' height=\'45\' border=\'0\'>';
                    } else {
                        echo '	<img src=\'' . $row['thumburl'] . '\' width=\'45\' height=\'45\' border=\'0\'>';
                    }
                    echo '	</a>
				      			</td>
				      			<td valign=\'top\' class=\'content\'><div class=\'gamehometitle\'>' . $row['name'] . '</div>
				      						<div class=\'gamehomedesc\'>' . desclimit($row['description']) . '
				      						<a href=\'' . $playlink . '\'>Play</a></div></td>
				      		</tr>';
                }
            } else {
                echo '<div>
						No games in this category yet.
					</div>';
            }
            echo '<tr><td colspan=\'2\' class=\'content\'>';
            echo '<a href=\'' . $categoryurl . '\'>Play more ' . $categorynamev . ' games</a>';
            echo '</td></tr>';
            echo '  </table>';
            echo '	</td>
	      		</tr>
	      	</table>
	      		</td>
	      	</tr>';
        }
        $count++;
    }
    echo "</table>";
    $pgname = 'Your resource for fantastic games!';
}
function writebody()
{
    global $db, $domain, $sitename, $cachelife, $template, $gamesfolder, $thumbsfolder, $limitboxgames, $seo_on, $blogentriesshown, $enabledcode_on, $comments_on, $directorypath, $autoapprovecomments, $gamesonpage, $abovegames, $belowgames, $showwebsitelimit, $supportemail, $showblog, $blogentriesshown, $blogcharactersshown, $blogcommentpermissions, $blogcommentsshown, $blogfollowtags, $blogcharactersrss, $usrdata, $userid;
    $max = $gamesonpage;
    if (!isset($_GET['page'])) {
        $show = '1';
    } else {
        $show = clean($_GET['page']);
    }
    $limits = ($show - 1) * $max;
    $r = $db->query(sprintf('SELECT * FROM fas_games ORDER BY views DESC LIMIT ' . $limits . ',' . $max . ' '));
    $totalres = mysql_result($db->query('SELECT COUNT(ID) AS total FROM fas_games'), 0);
    $totalpages = ceil($totalres / $max);
    echo '<table width=\'100%\' border=\'0\' align=\'center\'>
	<tr>
		<td colspan=\'2\' class=\'header\'>Most Played Games</td>
	</tr>';
    $count = 0;
    while ($in = $db->fetch_row($r)) {
        $gamename = preg_replace('#\\W#', '-', $in['name']);
        if ($seo_on == 1) {
            $playlink = '' . $domain . '/play/' . $in['ID'] . '-' . $gamename . '.html';
        } else {
            $playlink = '' . $domain . '/index.php?action=play&amp;ID=' . $in['ID'] . '';
        }
        if ($count % 2 == 0) {
            echo '<tr>
	      	<td width=\'50%\' valign=\'top\'>

	      		<table width=\'100%\' border=\'0\'>
	      			<tr>
	      				<td valign=\'top\' colspan=\'2\' class=\'header\'><b>' . titlelimit($in['name']) . '</b></td>
	      			</tr>
	      			<tr>
	      				<td width=\'55\' height=\'55\' valign=\'top\' class=\'content\'>
	      				<a href=\'' . $playlink . '\'>
	      				';
            if ($in['type'] == 1) {
                echo '	<img src=\'' . $domain . '/' . $thumbsfolder . '/' . $in['thumb'] . '\' width=\'55\' height=\'55\' border=\'0\'>';
            } else {
                echo '	<img src=\'' . $in['thumburl'] . '\' width=\'55\' height=\'55\' border=\'0\'>';
            }
            echo '	</a>
	      				</td>
	      				<td valign=\'top\' class=\'content\'>' . desclimit($in['description']) . '
	      				<a href=\'' . $playlink . '\' class=\'playlink\'><b>Play</b></a></td>
	      			</tr>
	      		</table>

	      	</td>
	';
        } else {
            echo '
	      	<td width=\'50%\' valign=\'top\'>

	      		<table width=\'100%\' border=\'0\'>
	      			<tr>
	      				<td valign=\'top\' colspan=\'2\' class=\'header\'><b>' . titlelimit($in['name']) . '</b></td>
	      			</tr>
	      			<tr>
	      				<td width=\'55\' height=\'55\' valign=\'top\' class=\'content\'>
	      				<a href=\'' . $playlink . '\'>
	      				';
            if ($in['type'] == 1) {
                echo '	<img src=\'' . $domain . '/' . $thumbsfolder . '/' . $in['thumb'] . '\' width=\'55\' width=\'55\' border=\'0\'>';
            } else {
                echo '	<img src=\'' . $in['thumburl'] . '\' width=\'55\' width=\'55\' border=\'0\'>';
            }
            echo '	</a>
	      				</td>
	      				<td valign=\'top\' class=\'content\'>' . desclimit($in['description']) . '
	      				<a href=\'' . $playlink . '\' class=\'playlink\'><b>Play</b></a></td>
	      			</tr>
	      		</table>

	      	</td>
	</tr>';
        }
        $count++;
    }
    echo "</table>";
    echo '<div class="page-box">
' . $totalres . ' game(s) - Page ' . $show . ' of ' . $totalpages;
    $pre = $show - '1';
    $ne = $show + '1';
    if ($seo_on == 1) {
        $previous = '' . $domain . '/mostplayed/page' . $pre . '.html';
        $next = '' . $domain . '/mostplayed/page' . $ne . '.html';
    } else {
        $previous = '' . $domain . '/index.php?action=mostplayed&page=' . $pre . '';
        $next = '' . $domain . '/index.php?action=mostplayed&page=' . $ne . '';
    }
    if ($totalpages != '1') {
        echo ' - ';
        if ($show > '1') {
            echo '<a href="' . $previous . '" class="page">Previous</a>';
        }
        for ($i = 1; $i <= $totalpages; $i++) {
            if ($show - $i < '4' || $totalpages - $i < '7') {
                if ($i - $show < '4' || $i < '8') {
                    if ($seo_on == 1) {
                        $urk = '' . $domain . '/mostplayed/page' . $i . '.html';
                    } else {
                        $urk = '' . $domain . '/index.php?action=mostplayed&page=' . $i . '';
                    }
                    if ($show == $i) {
                        echo '<a href="' . $urk . '" class="page-select">' . $i . '</a>';
                    } else {
                        echo '<a href="' . $urk . '" class="page">' . $i . '</a>';
                    }
                }
            }
        }
        if ($show < $totalpages) {
            echo '<a href="' . $next . '" class="page">Next</a>';
        }
    }
    echo '</div>';
}