﻿function updateLink(linkId, postCount)
{
    var l = document.getElementById(linkId);
    if(l != null)
    {
        var url = l.href;
        url += ((url.indexOf("?") > -1) ? "&" : "?") + "pcount=" + postCount.toString();
        l.href = url;
    }
}
function gotoElement(focusElementId)
{
    var url = document.location.toString();
    if (url.indexOf("#") > 0) // remove anchor
        url = url.substring(0, url.lastIndexOf("#"));
    url += "#" + focusElementId;
    document.location = url;
}
function renderMessage(containerId)
{
    var container = $("#" + containerId);
    if (container)
    {
        var html = container.html();
        if (window.SmileManager && SmileManager.showSmileImages)
        {
            html = SmileManager.showSmileImages(html);    
        }
        container.html(html);
        $(document).ready(function()
        {
            container.find("img").resizeToMax(750, 0, true);
        });
    }
}
function quote(author)
{
    if (author && $ && bbcode)
    {
        var text = bbcode.documentSelection();
        text = ($.trim(text) != "") ? 
            "[quote][b]" + author + " scrive:[/b]\r" + text + "[/quote]\r" : 
            "[b]@ " + author + "[/b]: ";
        bbcode.val(text);
        bbcode.focus();
    }
    else
        gotoElement("#newMessage");
}