/* SEND MESSAGE { */
function sendMessage(creator_id, button_el) 
{
    var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    var subject = document.getElementById('subject').value;
    var body = document.getElementById('send_message').value;
    if (subject.length == 0)
    {
        showAlert(i18n['m1382'] ? i18n['m1382'] : 'Please indicate message subject.');
        return false;
    }
    if (body.length == 0)
    {
        showAlert(i18n['m1383'] ? i18n['m1383'] : 'Please enter your message.');
        return false;
    }
    buttonPlain(button_el);
    button_el.disabled = true;
    req.onreadystatechange = function() 
    {
        if (req.readyState == 4) 
        {
            if (req.status == 200) 
            {
                button_el.disabled = false;
                showAlert(i18n['m1384'] ? i18n['m1384'] : 'Your message has been sent!');
                toggleEll('send_mes');
            }
        }
    } 
    req.open('post', 'ajax/send_message/', true); 
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    req.send('creator_id=' + creator_id + '&body=' + body + '&subject=' + subject);
  

}

function clearInput(targetel)
{
    targetel.value='';
}
/* } SEND MESSAGE */

/* FRIEND { */
function sendFriendInvist(creator_id, target_el)
{
    $.get('ajax/xml_check_blocked/?userid=' + creator_id,
        function(data)
        {
            isBlocked = data.getElementsByTagName('is-blocked').item(0).firstChild.nodeValue;
        
    if (isBlocked == 1 )
    {
        showAlert('You cannot send a friend invitation to this user.');
    }
    else
    {
        sendHTTPRequest('ajax/send_friend_invist/?&creator_id=' + creator_id, stub);
        target_el.className = 'invited';
        target_el.firstChild.nodeValue = i18n['m0120'] ? i18n['m0120'] : 'Invited';
        if (is_ie)
        {
            target_el.setAttribute("onclick", new Function ("javascript:void(0);"));
        }
        else
        {
            target_el.setAttribute('onclick', 'javascript:void(0);');
        }
        showAlert(i18n['m1379'] ? i18n['m1379'] : 'Your invitation has been sent!');
    }
    });
}

function removeFriend(creator_id, target_el)
{
    sendHTTPRequest('ajax/remove_friend/?&creator_id=' + creator_id, stub);
    target_el.className = 'friend';
    target_el.firstChild.nodeValue = i18n['m0119'] ? i18n['m0119'] : 'Add as friend';
    if (is_ie)
    {
        target_el.setAttribute("onclick", new Function ("sendFriendInvist(" + creator_id + ", this)"));    
    }
    else
    {
        target_el.setAttribute('onclick', 'sendFriendInvist(' + creator_id + ', this);');
    }
    showAlert(i18n['m1380'] ? i18n['m1380'] : 'This user has been removed from your friends.');
}

function acceptInvite(creator_id, target_el)
{
    sendHTTPRequest('ajax/accept_invite/?&creator_id=' + creator_id, stub);
    target_el.className = 'friend_remove';
    target_el.firstChild.nodeValue = i18n['m0121'] ? i18n['m0121'] : 'Remove friend';
    if (is_ie)
    {
        target_el.setAttribute("onclick", new Function ("removeFriend(" + creator_id + ", this)"));    
    }
    else
    {
        target_el.setAttribute('onclick', 'removeFriend(' + creator_id + ', this);');
    } 
    showAlert(i18n['m1381'] ? i18n['m1381'] : 'This user has been added to your friends.');
}
/* } FRIEND */

/* BLOCK USER { */
function sendBlockUser(blockEl, creatorId, type)
{
    blockEl.old = blockEl.onclick;
    blockEl.onclick = '';
    var params = new Array(blockEl);
    sendHTTPRequest('ajax/manage_blocked_users/?creator_id=' + creatorId, setBlockUser, params); 
}

function setBlockUser(xml_http, params)
{
    var isBlocked = xml_http.responseXML.getElementsByTagName('is-blocked').item(0).firstChild.nodeValue;
    if (isBlocked == 0)
    {
        showAlert(i18n['m1560'] ? i18n['m1560'] : 'This user have been unblocked');
        params[0].className = 'block_user';
        params[0].firstChild.nodeValue = i18n['m1547'] ? i18n['m1547'] : 'Block User';
    }
    else
    {
        showAlert(i18n['m1559'] ? i18n['m1559'] : 'This user have been blocked'); 
        params[0].className = 'unblock_user';
        params[0].firstChild.nodeValue = i18n['m1548'] ? i18n['m1548'] : 'Unblock User';
    }
    params[0].onclick = params[0].old;
}
/* } BLOCK USER */

/* MORE CHANNEL { */
function sendCreatorItemList(listStr, pageNo, perPage, sortId, creatorId)
{
    listEl = document.getElementById(listStr);
    if (listEl.pageNo && listEl.pageNo != 0 && pageNo == 0)
    {
        if (listEl.perPage && listEl.perPage == perPage) 
        {
            pageNo = listEl.pageNo;
            sortId = listEl.sortId;
        }
    }
    listEl.pageNo = pageNo;
    listEl.perPage = perPage;
    listEl.sortId = sortId;
    
	fixItem(listEl, 'hidden');

	els = listEl.childNodes;
	existEl = null;
    for (i = 0; i < els.length; i++)
    {
        if (els[i].id == pageNo + '_' + perPage + '_' + sortId)
        {
            els[i].className = '';
            existEl = els[i];
        }
        else
        {
            els[i].className = 'hidden';
        }
    }
    if (!existEl)
    {
        divEl = listEl.appendChild(document.createElement('div'));
        divEl.setAttribute('id', pageNo + '_' + perPage + '_' + sortId);
        loadingMessage(divEl);
        var params = new Array(divEl, 0);
        sendHTTPRequest('ajax/xml_creatorlist/?&creator_id=' + creatorId + '&sort=' + sortId + '&list_id=' + listStr + '&pn=' + pageNo + '&pp=' + perPage, setItemList, params); 
    }
}
/* } MORE CHANNEL */