﻿$j(document).ready(function () {
    // Set charCount plugin variables
    $j('.post-form textarea').charCount({
        allowed: 140,
        limit: 140,
        warning: 15,
        counterText: 'Characters left: '
    });
});


function JoinGroup() {
    var cuid = $('currentuid').value;
    var key = $('key').value;
    Bloc.ObjectModel.Groups.JoinGroup(GroupID, cuid, key, OnPostJoinGroupCallBack)
}

function DeleteGroup() {
    var cuid = $('currentuid').value;
    var key = $('key').value;
    Bloc.ObjectModel.Groups.DeleteGroup(GroupID, cuid, key, OnPostJoinGroupCallBack)
}

function OnPostJoinGroupCallBack(res) {
    if (res.value == 1) {
        window.location.href = '/groups/group.rails?Gid=' + GroupID;
    }
    else {
        fb.close();
    }
}

function LeaveGroup() {
    var cuid = $('currentuid').value;
    var key = $('key').value;
    Bloc.ObjectModel.Groups.LeaveGroup(GroupID, cuid, key, OnPostLeaveCallBack)
}

function OnPostLeaveCallBack(res) {
    if (res.value == 1) {
        window.location.href = '/groups/group.rails?Gid=' + GroupID;
    }
    else {
        fb.close();
    }
}
function CheckTitle() {
    if ($("entry").value.trim() == "") {
        $('pmessage').update("You have to type something in the field below before posting")
        $('diverror').style.display = 'block';
        return false;
    }
    return true;
}

function DeleteGuestbook(id) {
    var gid = document.getElementById('delguest').value;
    var cuid = $('currentuid').value;
    var key = $('key').value;
    var groupid = $('groupid').value;

    Bloc.ObjectModel.Groups.DeleteGrpGuestbook(groupid, gid, cuid, key, OnPostDeleteGrpGuestbookCallBack)
}

function OnPostDeleteGrpGuestbookCallBack(res) {
    var gid = $('groupid').value;
    if (res.value == 1) {
        window.location.href = '/groups/group.rails?Gid=' + GroupID;

    }
}

function ShowDetailForNews(id) {
    var li = "li" + id;
    $(li).removeClassName('minimized');
}
