function setUpDiscussionPages() {
    try {
        var pageTitle = trim(document.title);

        // Apply to Discussions pages only
        if (pageTitle != "Discussions" && pageTitle != "Discussions - New Item" && pageTitle != "Discussions - test subject") {
            return;
        }

        // attach to the new thread OK button
        if (pageTitle == "Discussions - New Item") {
            $('input[value=OK]').click(function() {
                var project = $("meta[name=WT.cg_s]").attr('content');
                wt_PostDiscussionThread(project);
            });
        }

        // help ie wrap some long words that include a backslash
        $('.ms-disc-bordered-noleft div').each(function() {
            $(this).html($(this).html().replace(/\\/g, "\\&#8203;"));
        });

        // show "Discussions" page headline
        $('#DiscussionsHeadline').show();

        // Create a CSS class for container table
        var DiscussionContainerTable = $('#OLMainContentTD table:first');
        DiscussionContainerTable.addClass('DiscContainerTable');

        // if user is not signed in, provide instruction and link
        makeDiscussionSignInLink();

        // call function to customize "New Subject" button
        SetNewSubjectButton();

        // call function to hide "Actions" menu in toolbar
        HideActionsMenu();

    }
    catch (e) {
        //ignore error
    }
}

function HideActionsMenu() {
    //zz3_ListActionsMenu_t
    var oTemp = document.getElementById("zz3_ListActionsMenu_t");

    if ($('#zz3_ListActionsMenu_t').length > 0) {
        try {
            if ($('#zz3_ListActionsMenu_t').attr('class') == "ms-menubuttoninactivehover") {
                //oTemp.style.display = "none"; 
                $('#zz3_ListActionsMenu_t').hide();
            }
        }
        catch (e) {
            // ignore error
        }
    }
}


function SetNewSubjectButton() {
    // customize "New Subject" button
    for (i = 1; i < 10; i++) {
        var sIDString = "zz" + eval(i) + "_NewMenu";
        var oTemp = document.getElementById(sIDString);
        if (oTemp != null) {
            try {
                var oToolbar = oTemp;
                for (j = 0; j < 9; j++) {
                    oToolbar = oToolbar.parentNode;
                }
                if (oToolbar.className == "ms-menutoolbar") {
                    oToolbar.style.height = "41px";
                }
            }
            catch (e) {
                // ignore error
            }

            oTemp.innerHTML = '<img src="/Style%20Library/Images/OLSite/SmallArrow1.gif"  width="11" height="5" alt="" border="0" style="position: relative; top: -2" />&nbsp;New Subject';
            break;
        }
    }
}

function makeDiscussionSignInLink() {
    if ($('#RpsLoginLink').length > 0) {
        // Set this login link to the same one we normally use.
        $('#DiscSignInLink').attr('href', $('#RpsLoginLink').attr('href'));

        // get the project name from the meta tag name="WT.cg_s"
        var project = $("meta[name=WT.cg_s]").attr('content');
        $('#DiscSignInLink').click(function() {
            wt_SignInProject(project);
        });
        $('#DiscussionSignIn').show();
    }
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}