﻿// JQuery.js must be included.
// ajax1.0.js must be included.

function ShowStatusForm()
{
    $('div#current-status').fadeOut(200, function() { $('div#current-status-form').fadeIn(300); });
}

function HideStatusForm()
{
    $('div#current-status-form').fadeOut(200, function() { $('div#current-status').fadeIn(300); });
}

function ChangeStatus(sessionid, ResultFunction, rtype)
{
    var text = '';
    var e = document.getElementById('status-update-text');
    var m = document.getElementById('status-mood-dropdown');

    if ((typeof rtype).toString() == 'undefined') rtype = 'xml';
    
    if(e == null)
    {
        alert('Could not update text!');
        return false;
    }
    
    var vars = new Array();
    vars[0] = 'text=' + e.value;
    if(m != null) vars[1] = 'mood=' + m.options[m.selectedIndex].value.toString();
    
    var a = new AjaxObject('statusupdate.save', vars, 'xml');
    
    a.resulttype = rtype;
    a.sessionid = sessionid;
    
    if(typeof(ResultFunction) == 'undefined') a.Send(StatusUpdateComplete);
    else a.Send(ResultFunction);
}

function StatusUpdateComplete(txt)
{
    var xmldoc = LoadXMLDoc(txt);
    var moodname = GetNodeValue(xmldoc, 'mood', 0);
    var moodid = GetNodeValue(xmldoc, 'id', 0);
    var statustext = GetNodeValue(xmldoc, 'text', 0);
    var e = null;
    
    try
    {
        if(parseInt(moodid) >= 0)
        {
            e = document.getElementById('current-mood');
            
            if(e != null)
            {
                e.innerHTML = moodname;
                e.className = 'mood-' + moodid.toString();
            }

            e = document.getElementById('current-status-text');
            if(e != null) e.innerHTML = statustext;
        }
    }
    catch(ex)
    {
    
    }

    HideStatusForm();
}

