/* refresh the current view of the admin console */
function refresh(type)
{
    xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function()
    {
        /* make sure request has finished succesfully */
        if (this.readyState == 4 && this.status == 200)
        {
            /* fill the content container */
            document.getElementById("contentContainer").innerHTML = this.responseText;
            /* update the header message bubble */
            pollModeratorMessage();
        }
    }
    xmlhttp.open("GET","verifyRequest.php?value=" + type,true);
    xmlhttp.send();
}

/* verify the selected thread */
function verifyThread(id)
{
    xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function()
    {
        /* make sure request has finished succesfully */
        if (this.readyState == 4 && this.status == 200)
        {
            /* refresh for type thread */
            refresh(1);
        }
    }
    xmlhttp.open("GET","verify.php?type=1&id=" + id,true);
    xmlhttp.send();
}

/* remove the selected thread from DB */
function removeThread(id)
{
    xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function()
    {
        /* make sure request has finished succesfully */
        if (this.readyState == 4 && this.status == 200)
        {
            /* refresh for type thread */
            refresh(1);
        }
    }
    xmlhttp.open("GET","removethread.php?id=" + id,true);
    xmlhttp.send();
}

/* verify the selected comment */
function verifyComment(id)
{
    xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function()
    {
        /* make sure request has finished succesfully */
        if (this.readyState == 4 && this.status == 200)
        {
            /* refresh for type thread */
            refresh(2);
        }
    }
    xmlhttp.open("GET","verify.php?type=2&id=" + id,true);
    xmlhttp.send();
}

/* remove selected comment from DB */
function removeComment(id)
{
    xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function()
    {
        /* make sure request has finished succesfully */
        if (this.readyState == 4 && this.status == 200)
        {
            /* refresh for type thread */
            refresh(2);
        }
    }
    xmlhttp.open("GET","removecomment.php?id=" + id,true);
    xmlhttp.send();
}
