";
}
newdiv.appendChild(incomingMessagesDiv);
var inputDiv = document.createElement('DIV');
inputDiv.className = "inputMessage";
var n = "inputMessage"+userId;
var nn = 'limitText(this,null,120,event,"'+userId+'");';
inputDiv.innerHTML = "";
newdiv.appendChild(inputDiv);
var sendDiv = document.createElement('DIV');
sendDiv.className = "sendMessage";
sendDiv.innerHTML = "send";
sendDiv.id = "sendMessage";
sendDiv.onclick = function(){sendMessage(userId)};
newdiv.appendChild(sendDiv);
$("#frame").prepend(newdiv);
Drag.init(userInfo.descriptionDiv, newdiv);
userInfo.incomingMessagesDiv = incomingMessagesDiv;
userInfo.messengerWindow = newdiv;
populateDivWithDescription(userInfo);
newdiv.appendChild(userInfo.descriptionDiv);
// if(!userInfo.isProfile()){
// //Get the users full profile from the server
// TurboMingleBean.getUserProfile(userId, {callback:function(usrDataDTO){
// userData[usrDataDTO.usrDTO.id].usrDataDTO = usrDataDTO;
// var descriptionDiv = $("#userMessengerDescription"+usrDataDTO.usrDTO.id);
// populateDivWithDescription(descriptionDiv,userData[usrDataDTO.usrDTO.id]);
// }});
// }
}
/** Close the message bar and the corresponding messenger panel, if any */
function closeMessenger(usrId){
minimiseMessenger(usrId);
var v = userData[usrId].messageBarDiv;
if(v!=null){
//$("#messageBarPanel").remove(v);
v.parentNode.removeChild(v);
myResize();
userData[usrId].messageBarDiv = null;
}
userData[usrId].incomingMessagesDiv = null;
}
/** We're actually deleting the div here, but we keep the information */
function minimiseMessenger(usrId){
var div = userData[usrId].messengerWindow;
if(div!=null){
div.parentNode.removeChild(div);
userData[usrId].messengerWindow = null;
userData[usrId].incomingMessagesDiv = null;
}
}
function sendMessage(toUsrId){
if(isLoggedIn){
var dto = userData[toUsrId];
var field = $("#inputMessage"+toUsrId);
if(field!=null){
var msg = field.val();
if(msg!=null && msg != ""){
TurboMingleBean.sendMessage(toUsrId, msg, messageSentCallback);
field.val("");
dto.addChatMessage( me+":"+msg);
}
}
}else{
showSignUpPanel(true);
}
}
function chatCallback(chatMessageDTO){
showMessageBarItemFetch(chatMessageDTO.fromUserId, chatMessageDTO, false); //Open a panel on the bar for this user
}
//The method to be called to display a messenger window, it will fetch the users profile if needed
function showMessageBarItemFetch(usrId, chatMessageDTO, openWindow){
var userInfo = userData[usrId];
if(userInfo!=null && userInfo.isProfile()) {
showMessageBarItem(userInfo);
if(openWindow==true){
openMessengerWindow(usrId);
}
if(chatMessageDTO!=null){
userInfo.addChatMessage(userInfo.username()+":"+chatMessageDTO.message);
}
}else{
if(userInfo==null){
userInfo = new UserInfo(null); //TODO CHECK THIS! Create a dummy holder so we don't request a users profile data twice
userInfo.setId(usrId);
userData[usrId] = userInfo;
}
//FIXME - userInfo.username() will be unknown
if(chatMessageDTO!=null){
userInfo.addChatMessage(userInfo.username()+":"+chatMessageDTO.message);
}
if(userInfo.profileRequested == false){
userInfo.profileRequested = true; //note that we have requested the profile so we don't ask for this twice
TurboMingleBean.getUserProfile(usrId, {callback:function(usrDataDTO){
if(userData[userInfo.id()]==null){ //just incase
userInfo = new UserInfo(usrDataDTO);
}else{
userInfo.usrDataDTO = usrDataDTO;
}
userData[userInfo.id()] = userInfo;
showMessageBarItem(userInfo); //Open a panel on the bar for this user
if(openWindow==true){
openMessengerWindow(usrId);
populateDivWithDescription(userInfo)
}
}
});
}
}
}
function showMessageBarItem(userInfo){
if(userData[userInfo.id()].messageBarDiv!=null){
return;
}
var newdiv = document.createElement('DIV');
newdiv.className = "messageBarItem";
var avatarDiv = document.createElement('DIV');
avatarDiv.innerHTML = "
";
avatarDiv.className = "messageBarAvatar";
newdiv.appendChild(avatarDiv);
var usernameDiv = document.createElement('DIV');
usernameDiv.onmousedown = function(){ openMessengerWindow(userInfo.id()); }
usernameDiv.className = "minimisedItemUsername";
usernameDiv.innerHTML = userInfo.username();
newdiv.appendChild(usernameDiv);
var closeDiv = document.createElement('DIV');
closeDiv.className = "closeMinimiseBarItem";
closeDiv.innerHTML = "
";
newdiv.appendChild(closeDiv);
userData[userInfo.id()].messageBarDiv = newdiv;
$("#messageBarPanel").prepend(newdiv);
myResize();
}
function showInfoMessage(str){
if(str=="" || str==null){
$("#infoPanel").html("");
$("#infoPanel").hide();
}else{
if(infoMessageTimeout){
clearTimeout(infoMessageTimeout);
infoMessageTimeout = null;
}
$("#infoPanel").html(str);
$("#infoPanel").show();
infoMessageTimeout = setTimeout("$('#infoPanel').hide();",1200);
}
}
/* Called when a third party used logs in */
function userLoggedOnCallback(usrDataDTO){
var info = createUserPanel(usrDataDTO);
//Create the notification in the bottom corner
//var newdiv = $("");//document.createElement('DIV');
var newdiv = $("");
var tId = "newsnotification" + newsItemId++;
newdiv.attr('id', tId);
newdiv.addClass("popUpNotification");
newdiv.css("bottom",100 + ($(".popUpNotification").length*64) + "px");
newdiv.onmousedown=function(){
showMessageBarItemFetch(usrDataDTO.usrDTO.id, null, true);
};
newdiv.html('' +
''+ info.username() +' has logged in
');
$("body").append(newdiv);
//$("#usersContainer").prepend(newdiv);
newdiv.attr("timeDisplayed",8);
//newsDivs.push(newdiv);
}
function userLoggedOutCallback(usrDTO){
var userInfo = userData[usrDTO.id];
if(userInfo!=null){
//TODO IMPLEMENT ME
}
}
function scheduledTask(){
//Update the news/user logged in notices
var newsDivs = $(".popUpNotification");
//alert(divs);
for(i=0; i < newsDivs.length; i){
var d = $(newsDivs[i]);
var a = parseInt(d.attr("timeDisplayed"));
if(--a <= 0){
d.remove();
newsDivs.splice(i,1);
}else{
i++;
d.attr("timeDisplayed",a);
}
}
for(i in userData){
if(userData[i].unreadMsg==true){
if(scheduledTaskRuns%2==0){
userData[i].messageBarDiv.style.background = "#f79d39";
}else{
userData[i].messageBarDiv.style.background = "#E9E9E9";
}
}
}
//var notificationDiv = $("#newsnotification");
//notificationDiv.style.visibility = "visible";
//notificationDiv.style.bottom = notificationDivBottom +"px";
//notificationDivBottom--;
scheduledTaskRuns++;
setTimeout("scheduledTask()",1000);
}
function messageRead(usrId){
var d = userData[usrId];
if(d!=null){
d.unreadMsg = false;
d.messageBarDiv.style.background = "#E9E9E9";
}
}
/* limit the input of a text field */
function limitText(limitField, limitCount, limitNum,event, usrId) {
if(event.keyCode==13){
//alert(event.keyCode);
sendMessage(usrId);
}
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
if(limitCount!=null){
limitCount.value = limitNum - limitField.value.length;
}
}
}
function showSignUpPanel(b, heading){
if(b){
if(heading){
$('#signUpHeading').html(heading);
}
$('#signUpPanel').css("display", "inline");
}else{
$('#signUpPanel').css("display", "none");
}
}
function getRoomNameFromParam(){
// name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
// var regexS = "[\\?&]"+name+"=([^]*)";
// var regex = new RegExp( regexS );
// var results = regex.exec( window.location.href );
var pathElement = "chat-rooms/";
var idx = window.location.href.indexOf(pathElement);
if(idx > 0){
var roomName = window.location.href.substring(idx+pathElement.length)
return roomName;
}else{
}
}
/** Return param values from the URL */
function gup( name ){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
var showOfflineMessages = function(data){
if(data != null){
_showOfflineMessages(data);
}
}
function _showOfflineMessages(data){
var i=0;
for(i=0;i'+dateFormat+"
"+oneInfo.message+"
");
showMessageBarItemFetch(oneInfo.fromUsrID, msg, true);
}
}
}
function msgDTO(msg){
this.message = msg;
}
function resetImages(){
for(i in userData){
userData[i].createUserDiv();
}
}
//if ($("#showAdult").attr("checked"){
//TODO if we use this remove the from ads.jsp
// function refreshAds(){
// //adsiframe
// setTimeout("refreshAds()",60000);
//}
//refreshAds();