

function Join(groupid, username, joinimageid)
{
    try
    {        
        document.getElementById(joinimageid[0]).style.display = "none";        
        SchoolNet.GlobalNet.BusinessObjects.WebServices.SchoolNetWebService.JoinGroup(groupid, username, joinimageid, SucceededCallbackForRecommendation);
        
    }
    catch(e)
    {        
    }
}

function UnJoin(confirmation, progress, groupid, username, controlIds)
{
    try
    {         
        document.getElementById(confirmation).style.display = "none";
        document.getElementById(progress).style.display = "block";
        
        SchoolNet.GlobalNet.BusinessObjects.WebServices.SchoolNetWebService.UnJoinGroup(groupid, username, controlIds, SucceededCallbackForUnJoin);        
    }
    catch(e)
    {        
    }
}

function SucceededCallbackForUnJoin(info)
{    
    try
    {
        if(info[0] == true)
        {    
            document.getElementById('btnRefresh').click(); 
            var unjoinButton = document.getElementById(info[1]);
            unjoinButton.style.display = 'none';
            
            var joinButtom = document.getElementById(info[2]);
            joinButtom.style.display = 'block';
            
            var i;
            for(i=4; i<info.length-1; i++)
            {
                document.getElementById(info[i]).click();            
            }            
        }
        else
        {        
            try
            {
                document.getElementById(info[3]).innerText = "Cannot unjoin this time. Please try again";
            }
            catch(e)
            {
                alert('Cannot unjoin this time. Please try again');        
            }
        }
        
        $find(info[info.length-1]).hide();
    }
    catch(e)
    {}
      
}

function SucceededCallbackForRecommendation(info)
{    
    if(info[0] == true)
    {
        var btnRefresh = document.getElementById('btnRefresh');
        if(btnRefresh)
        {
            btnRefresh.click();
        }
        var joinButton = document.getElementById(info[1]);
        joinButton.style.display = 'none';
        
        var imageJoined = document.getElementById(info[2]);
        imageJoined.style.display = 'block';
        
        var i;
        for(i=4; i<info.length; i++)
        {            
            document.getElementById(info[i]).click();            
        }
    }
    else
    {
        try
        {
            document.getElementById(info[3]).innerText = "Cannot join this time. Please try again";
            
        }
        catch(e)    
        {
            try
            {
                document.getElementById('lblError').innerText = "Cannot join this time. Please try again";        
            }
            catch(e)
            {
                alert('Cannot join this time. Please try again');
            }
        }
    }
}
