}
echo "</ul>";
foreach ($_SESSION['R']['W'] as $ID => $NA) {
    if (!isset($RealmID) || (int) $RealmID === (int) $ID) {
        $_RealmID = isset($RealmID) ? $RealmID : (int) $ID;
        $HCount = null;
        $ACount = null;
        $CCount = 0;
        $MAX_ONLINE = _MaxOnlineForR($_RealmID);
        $CUR_RATE = null;
        $CUR_HORDE = null;
        $CUR_ALLIANCE = null;
        $connection = _MySQLConnect(_HostDBSwitch($_RealmID), $DBUser, $DBPassword, _CharacterDBSwitch($_RealmID));
        $query = mysql_query("SELECT `race`, COUNT(*) FROM `characters` WHERE `online` = 1 GROUP BY `race`;", $connection);
        while ($result = mysql_fetch_array($query)) {
            if (_isHorde((int) $result[0])) {
                $HCount += (int) $result[1];
            } else {
                $ACount += (int) $result[1];
            }
            $CCount += (int) $result[1];
        }
        if ($CCount > 0) {
            $CUR_RATE = $CCount / $MAX_ONLINE * 100;
            $CUR_HORDE = $HCount / $CCount * 100;
            $CUR_ALLIANCE = $ACount / $CCount * 100;
        }
        mysql_close($connection) or die(mysql_error());
        echo "\n            <label for = 'r" . $_RealmID . "'>\n            <legend>\n                <h4>" . $NA['N'] . "\n                <span class = 'pull-right'>" . $CCount . " / " . $MAX_ONLINE . "</span></h4>\n            </legend>\n            </label>\n            <div name = 'r" . $_RealmID . "' class = 'progress progress-success progress-striped active'>\n                <div class = 'bar' style = 'width: " . $CUR_RATE . "%'></div>\n            </div>\n            <label for = 'ah" . $_RealmID . "'>\n                <span class = 'pull-left fIcon'>\n                    <img src = '_template/img/alliance.png'/>\n                </span>\n                <span class = 'pull-right fIcon'>\n                    <img src = '_template/img/horde.png'/>\n                </span>\n            </label>\n            <div class = 'progress' name = 'ah" . $_RealmID . "' >\n                <div class = 'bar' style = 'width: " . $CUR_ALLIANCE . "%;'></div>\n                <div class = 'bar bar-danger' style = 'width: " . $CUR_HORDE . "%;'></div>\n            </div>";
    }
}
function _teleportCharacterUnstruck($DBUser, $DBPassword, $SOAPUser, $SOAPPassword, $RealmID, $GUID, $NAME)
{
    $connection = _MySQLConnect(_HostDBSwitch($RealmID), $DBUser, $DBPassword, _CharacterDBSwitch($RealmID));
    $query = mysql_query("SELECT `race` FROM `characters` WHERE `guid` = " . (int) $GUID . ";", $connection) or die(mysql_error());
    $result = mysql_fetch_array($query);
    if (!_isHorde($result['race'])) {
        /* Stormwind */
        _SOAP_SentRemoteCommand($SOAPUser, $SOAPPassword, $RealmID, trim(".tele name " . $NAME . " stormwind"));
    } else {
        /* Orgrimmar */
        _SOAP_SentRemoteCommand($SOAPUser, $SOAPPassword, $RealmID, trim(".tele name " . $NAME . " orgrimmar"));
    }
    mysql_close($connection) or die(mysql_error());
}