// Namespace
function Chat(){}

Chat.launch=function(userId, userNickname, buddyId, buddyNickname)
{
   window.open("/live_chat/dialogue.php?user_id=" + userId + "&user_nickname=" + userNickname + "&buddy_id=" + buddyId + "&buddy_nickname=" + buddyNickname, "Chat - " + buddyNickname,"location=0, status=0, scrollbars=0, width=214, height=400");
};

// JS wrapper for PHP log in 
// Usage:
//    logIn(id, nickname) inserts user with id and nickname, returns id
//    logIn(nickname)     inserts user with nickname, returns newly added id
Chat.logIn=function()
{
   return Ajax.Request({method:"GET", url:"/live_chat/php/log_in.php?id=" + (arguments.length==2 ? arguments[0] : "") + "&nickname=" + (arguments.length==2 ? arguments[1] : arguments[0]), async:false}).responseText;
};

// JS wrapper for PHP log out
// Takes id of user to be logged out
Chat.logOut=function(id)
{
   Ajax.Request({method:"GET", url:"/live_chat/php/log_out.php?id=" + id, async:false});
};

// JS wrapper for XHR send message
// Takes id of sender, id of recipient and content of message
Chat.sendMessage=function(senderId, recipientId, content)
{
   Ajax.Request({method:"GET", 
                 url:"/live_chat/php/send_message.php?sender=" + senderId + "&recipient=" + recipientId + "&content=" + content, 
                 async:false});
};