function viewmybio_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "commentaryoptions":
            require_once "lib/commentary.php";
            $link = "bio.php?char=" . $session['user']['acctid'] . "&ret=" . URLEncode(buildcommentarylink("&frombio=true", $_SERVER['REQUEST_URI']));
            debug($link);
            output("`n`n<a href=\"{$link}\">View my Bio</a>", true);
            addnav("", $link);
            break;
    }
    return $args;
}
function biochat_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "bioend":
            require_once "lib/commentary.php";
            output("`n`n`0%s`0's Natter feed:`n", $args['name']);
            addcommentary();
            $section = "bio-" . $args['acctid'];
            viewcommentary($section, "Natter!", 25);
            if (strpos(httpget('ret'), "bio.php") === false) {
                set_module_pref("lastplace", httpget('ret'));
            }
            $sql = "SELECT COUNT(commentid) AS totalcomments FROM " . db_prefix("commentary") . " WHERE section='{$section}'";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            $all = $row['totalcomments'];
            set_module_pref("total", $all, "biochat", $args['acctid']);
            if ($args['acctid'] == $session['user']['acctid']) {
                //this is the player looking at his or her own bio
                set_module_pref("seen", $all);
            }
            $return = get_module_pref("lastplace");
            if ($return) {
                addnav("Been clicking around Bios and Nattering for a while?");
                addnav("Go `iright`i back to where you came from", $return);
            }
            debug($return);
            break;
        case "commentaryoptions":
            if (!strpos($_SERVER['REQUEST_URI'], "char=" . $session['user']['acctid'] . "&") && !strpos($_SERVER['REQUEST_URI'], "global_banter")) {
                $link = "bio.php?char=" . $session['user']['acctid'] . "&ret=" . URLEncode(buildcommentarylink("&frombio=true"));
                $total = get_module_pref("total");
                $seen = get_module_pref("seen");
                output("<a href=\"{$link}\">View my Bio</a> ", true);
                if ($seen != $total) {
                    $new = $total - $seen;
                    if ($new == 1) {
                        output("(1 unread Natter) ");
                    } else {
                        output("(%s unread Natters) ", $new);
                    }
                }
                addnav("", $link);
            }
            break;
    }
    return $args;
}
function talkform($section, $talkline, $limit = 10, $schema = false)
{
    require_once "lib/forms.php";
    global $REQUEST_URI, $session, $translation_namespace, $chatsonpage;
    if ($schema === false) {
        $schema = $translation_namespace;
    }
    tlschema("commentary");
    $jump = true;
    if (isset($session['user']['prefs']['nojump']) && $session['user']['prefs']['nojump'] == true) {
        $jump = false;
    }
    if ($jump && httpget('comment') && httppost('focus') == $section) {
        $focus = true;
    } else {
        $focus = false;
    }
    if (!isset($session['user']['prefs']['ucol'])) {
        $session['user']['prefs']['ucol'] = false;
    }
    if (translate_inline($talkline, $schema) != "says") {
        $tll = strlen(translate_inline($talkline, $schema)) + 11;
    } else {
        $tll = 0;
    }
    $req = buildcommentarylink("&comment=1");
    if ($jump) {
        $req .= "#commentaryjump_" . $section;
    }
    addnav("", $req);
    // *** AJAX CHAT MOD START ***
    output_notl("<form action=\"{$req}\" method='POST' autocomplete='false'>", true);
    $args1 = array("formline" => "<form action=\"{$req}\" id='commentaryform' method='post' autocomplete='false'", "section" => $section, "talkline" => $talkline, "schema" => $schema);
    // $args1 = modulehook("commentarytalkline",$args1);
    //rawoutput('<div id="commentaryformcontainer">');
    output_notl($args1['formline'] . ">", true);
    // *** AJAX CHAT MOD END ***
    global $fiveminuteload;
    if ($session['user']['prefs']['commentary_auto_update'] && !httpget('comscroll') && $fiveminuteload < 8) {
        $jsec = strtolower($section);
        $jsec = str_replace("_", "", $jsec);
        $jsec = str_replace("-", "", $jsec);
        $jsec = str_replace(",", "0", $jsec);
        //debug($jsec);
        previewfield("insertcommentary", $session['user']['name'], $talkline, true, array("size" => "30", "maxlength" => 255 - $tll), false, $jsec, $session['user']['prefs']['ucol'], $focus);
        rawoutput("<script type=\"text/javascript\">\r\n\t\t\tvar typetimelimit" . $jsec . " = 0;\r\n\t\t\tvar timebetween" . $jsec . " = 1500;\r\n\t\t\tvar oldchars" . $jsec . " = 'xxxxx';\r\n\t\t\tvar newchars" . $jsec . " = 'xxxxx';\r\n\t\t\tvar newchars" . $jsec . " = document.getElementById('input" . $jsec . "').value;\r\n\t\t\tvar oldchars" . $jsec . " = newchars" . $jsec . ";\r\n\t\t\tfunction typedisplay" . $jsec . "() {\r\n\t\t\t\ttypetimelimit" . $jsec . " ++;\r\n\t\t\t\tnewchars" . $jsec . " = document.getElementById('input" . $jsec . "').value;\r\n\t\t\t\t\r\n\t\t\t\tif (window.XMLHttpRequest){\r\n\t\t\t\t\t// code for IE7+, Firefox, Chrome, Opera, Safari\r\n\t\t\t\t\ttxmlhttp" . $jsec . "=new XMLHttpRequest();\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// code for IE6, IE5\r\n\t\t\t\t\ttxmlhttp" . $jsec . "=new ActiveXObject(\"Microsoft.XMLHTTP\");\r\n\t\t\t\t}\r\n\t\t\t\ttxmlhttp" . $jsec . ".onreadystatechange=function(){\r\n\t\t\t\t\tif (txmlhttp" . $jsec . ".readyState==4 && txmlhttp" . $jsec . ".status==200 && typetimelimit" . $jsec . " < 600){\r\n\t\t\t\t\t\tdocument.getElementById(\"typedisplay" . $jsec . "\").innerHTML = txmlhttp" . $jsec . ".responseText;\r\n\t\t\t\t\t\tttimer" . $jsec . "=setTimeout(\"typedisplay" . $jsec . "()\",timebetween" . $jsec . ");\r\n\t\t\t\t\t\tttimeopen" . $jsec . " = typetimelimit" . $jsec . " * 2;\r\n\t\t\t\t\t\tttimeleft" . $jsec . " = 600 - ttimeopen" . $jsec . ";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (oldchars" . $jsec . ".length!=newchars" . $jsec . ".length){\r\n\t\t\t\t\ttxmlhttp" . $jsec . ".open(\"GET\",\"whostyping.php?section=" . $section . "&updateplayer=1\",true);\r\n\t\t\t\t} else {\r\n\t\t\t\t\ttxmlhttp" . $jsec . ".open(\"GET\",\"whostyping.php?section=" . $section . "&updateplayer=0\",true);\r\n\t\t\t\t}\r\n\t\t\t\ttxmlhttp" . $jsec . ".send();\r\n\t\t\t\toldchars" . $jsec . " = newchars" . $jsec . ";\r\n\t\t\t}\r\n\t\t\ttypedisplay" . $jsec . "();\r\n\t\t</script>");
    } else {
        if ($fiveminuteload >= 8) {
            output("Server load is currently too high for auto-update chat.  This will hopefully balance out in a few minutes.`n");
        }
        previewfield("insertcommentary", $session['user']['name'], $talkline, true, array("size" => "30", "maxlength" => 255 - $tll), false, false, $session['user']['prefs']['ucol']);
        //debug("System load too high at ".$fiveminuteload);
    }
    rawoutput("<input type='hidden' name='talkline' value='{$talkline}'>");
    rawoutput("<input type='hidden' name='schema' value='{$schema}'>");
    rawoutput("<input type='hidden' name='focus' value='{$section}'>");
    rawoutput("<input type='hidden' name='counter' value='{$session['counter']}'>");
    $session['commentcounter'] = $session['counter'];
    if ($section == "X") {
        $vname = getsetting("villagename", LOCATION_FIELDS);
        $iname = getsetting("innname", LOCATION_INN);
        $sections = commentarylocs();
        reset($sections);
        output_notl("<select name='section'>", true);
        while (list($key, $val) = each($sections)) {
            output_notl("<option value='{$key}'>{$val}</option>", true);
        }
        output_notl("</select>", true);
    } else {
        output_notl("<input type='hidden' name='section' value='{$section}'>", true);
    }
    $add = htmlentities(translate_inline("Add"), ENT_QUOTES, getsetting("charset", "ISO-8859-1"));
    // *** DRAGONBG.COM CORE PATCH START***
    output_notl("<input type='submit' class='button' value='{$add}'>\t", true);
    // *** DRAGONBG.COM CORE PATCH END***
    rawoutput("</form>");
    tlschema();
}
function talkform($section, $talkline, $limit = 10, $schema = false)
{
    require_once "lib/forms.php";
    global $REQUEST_URI, $session, $translation_namespace, $chatsonpage;
    if ($schema === false) {
        $schema = $translation_namespace;
    }
    tlschema("commentary");
    $jump = false;
    if (isset($session['user']['prefs']['nojump']) && $session['user']['prefs']['nojump'] == true) {
        $jump = true;
    }
    $counttoday = 0;
    // if (substr($section,0,5)!="clan-"){
    // $sql = "SELECT author FROM " . db_prefix("commentary") . " WHERE section='$section' AND postdate>'".date("Y-m-d 00:00:00")."' ORDER BY commentid DESC LIMIT $limit";
    // $result = db_query($sql);
    // while ($row=db_fetch_assoc($result)){
    // if ($row['author']==$session['user']['acctid']) $counttoday++;
    // }
    // if (round($limit/2,0)-$counttoday <= 0 && getsetting('postinglimit',1)){
    // if ($session['user']['superuser']&~SU_DOESNT_GIVE_GROTTO){
    // output("`n`)(You'd be out of posts if you weren't a superuser or moderator.)`n");
    // }else{
    // output("`n`)(You are out of posts for the time being.  Once some of your existing posts have moved out of the comment area, you'll be allowed to post again.)`n");
    // return false;
    // }
    // }
    // }
    if (translate_inline($talkline, $schema) != "says") {
        $tll = strlen(translate_inline($talkline, $schema)) + 11;
    } else {
        $tll = 0;
    }
    $req = buildcommentarylink("&comment=1");
    addnav("", $req);
    // *** AJAX CHAT MOD START ***
    //output_notl("<form action=\"$req\" method='POST' autocomplete='false'>",true);
    $args1 = array("formline" => "<form action=\"{$req}\" id='commentaryform' method='post' autocomplete='false'", "section" => $section, "talkline" => $talkline, "schema" => $schema);
    $args1 = modulehook("commentarytalkline", $args1);
    rawoutput('<div id="commentaryformcontainer">');
    output_notl($args1['formline'] . ">", true);
    // *** AJAX CHAT MOD END ***
    previewfield("insertcommentary", $session['user']['name'], $talkline, true, array("size" => "30", "maxlength" => 255 - $tll));
    rawoutput("<input type='hidden' name='talkline' value='{$talkline}'>");
    rawoutput("<input type='hidden' name='schema' value='{$schema}'>");
    rawoutput("<input type='hidden' name='counter' value='{$session['counter']}'>");
    $session['commentcounter'] = $session['counter'];
    if ($section == "X") {
        $vname = getsetting("villagename", LOCATION_FIELDS);
        $iname = getsetting("innname", LOCATION_INN);
        $sections = commentarylocs();
        reset($sections);
        output_notl("<select name='section'>", true);
        while (list($key, $val) = each($sections)) {
            output_notl("<option value='{$key}'>{$val}</option>", true);
        }
        output_notl("</select>", true);
    } else {
        output_notl("<input type='hidden' name='section' value='{$section}'>", true);
    }
    $add = htmlentities(translate_inline("Add"), ENT_QUOTES, getsetting("charset", "ISO-8859-1"));
    // *** DRAGONBG.COM CORE PATCH START***
    output_notl("<input type='submit' class='button' value='{$add}'>\t", true);
    modulehook("commentarytrail", array());
    // *** DRAGONBG.COM CORE PATCH END***
    // *** AJAX CHAT MOD START ***
    //if (round($limit/2,0)-$counttoday < 3 && getsetting('postinglimit',1)){
    //	output("`)(You have %s posts left today)`n`0",(round($limit/2,0)-$counttoday));
    //}
    rawoutput("<div id='previewtext'></div></form>");
    rawoutput('</div>');
    // *** AJAX CHAT MOD END ***
    tlschema();
}