var checkIndividualChatId;
function checkIndividualChat(){
    /*
    clearInterval(checkIndividualChatId);
    checkIndividualChatId = setInterval("checkIndividualChat()",3000);  
    ajax = new Ajax();
    ajax.post(SYSTEM_URL + "/individual_chat/check_individual_chat.html", checkIndividualChatCallback, false);
    */
}

function checkIndividualChatCallback(msg){
/*
    if(msg){
        if(msg.indexOf('Rejected from') == 0){
            alert(msg);
            checkIndividualChatId = setTimeout("showTopMessageBox()",3000);
        }else if(msg.indexOf('http://') == 0){
            window.open(msg);
        }else{
            putTopMessageBox(msg);
            showTopMessageBox();
            clearInterval(checkIndividualChatId);
        }
    }
*/
}

function requestIndividualChat(toMemberId,toMemberName){
    if(confirm("Do you want to chat with "+toMemberName+"?")){
        ajax = new Ajax();
        ajax.post( 
            SYSTEM_URL + "/individual_chat/request_individual_chat.html", requestIndividualChatCallback, [
                [ "toMemberId", encodeURI( toMemberId )],
                [ "toMemberName", encodeURI( toMemberName )]
            ]
        );
    }
}

function requestIndividualChatCallback(msg){
    if(msg) alert(msg);
}

function rejectIndividualChat(fromMemberId,fromMemberName){
    if(confirm("Do you want to decline to chat with "+fromMemberName+"?")){
        ajax = new Ajax();
        ajax.post( 
            SYSTEM_URL + "/individual_chat/reject_individual_chat.html", rejectIndividualChatCallback, [
                [ "fromMemberId", encodeURI( fromMemberId )],
                [ "fromMemberName", encodeURI( fromMemberName )]
            ]
        );
    }
}

function rejectIndividualChatCallback(msg){
    if(msg) alert(msg);
    clearTimeout(timerID);
    hideTopMessageBox();
}

function acceptIndividualChat(fromMemberId,fromMemberName){
    if(confirm("Do you want to accept the chat invitation from "+fromMemberName+"?")){
        ajax = new Ajax();
        ajax.post( 
            SYSTEM_URL + "/individual_chat/accept_individual_chat.html", acceptIndividualChatCallback, [
                [ "fromMemberId", encodeURI( fromMemberId )],
                [ "fromMemberName", encodeURI( fromMemberName )]
            ]
        );
    }
}

function acceptIndividualChatCallback(msg){
    window.open(msg);
}

function changeStatus(status){
    ajax = new Ajax();
    ajax.post( 
        SYSTEM_URL + "/individual_chat/change_status.html", changeStatusCallback, [
            [ "status", encodeURI( status )]
        ]
    );
}

function changeStatusCallback(msg){
    if(msg) alert(msg);
}