/* refresh the inbox view */
function refresh()
{
    /* get variables from dropdown for sorting, types to show and filtering */
    var sort = document.getElementById('sort').value;
    var show = document.getElementById('show').value;
    var filter = document.getElementById('filter').value;

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function()
    {
        if (this.readyState == 4 && this.status == 200)
        {
            document.getElementById('contentContainer').innerHTML = this.responseText;
        }
    };
    xmlhttp.open("GET", "getinbox.php?show=" + show + "&sort=" + sort + "&filter=" + filter, true);
    xmlhttp.send();
}

/* mark all comments on a thread as read */
function mark_read_comment()
{

    var xmlhttp = new XMLHttpRequest();
    var id = getQueryVariable('id');
    xmlhttp.onreadystatechange = function()
    {
        if (this.readyState == 4 && this.status == 200)
        {
            pollModeratorMessage();
        }
    };
    xmlhttp.open("GET", "markread.php?id="+id+"&type=1", true);
    xmlhttp.send();
}

/* expand message in message view in the inbox */
function expand_message(id)
{
    /* get the message div */
    var message = document.getElementById('message'+id)

    /* get the read bubble */
    var bubble = document.getElementById('readbubble'+id);
    message.style.display = message.style.display === 'inline' ? 'none' : 'inline';

    if(bubble)
    {
        bubble.style.display = 'none';
    }

    mark_read_message(id);
}

/* mark a message as read */
function mark_read_message(id)
{

    var xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function()
    {
        if (this.readyState == 4 && this.status == 200)
        {
            pollModeratorMessage();
        }
    };
    xmlhttp.open("GET", "markread.php?id="+id+"&type=2", true);
    xmlhttp.send();
    // document.getElementById('bubble'+id).style.height = '300px';
}
