var contextPath = ""; var turboMingleState; /** An array of UserInfo object that stores data about users locally */ var userData = new Array(); var isLoggedIn = false; var newWindowStartPositionX = 20; var newWindowStartPositionY = 20; var messageSentCallback = function(){} var minimisedPanelId = 0; var notificationDivBottom = 100; //var newsDivs = new Array(); var newsDisplayTimer; //The timer for the scheduledTask timeout var newsItemId = 0; var infoMessageTimeout; var scheduledTaskRuns = 0; var errorMessageTimeout; //timer to show the error message for a certain amount of time var todoAfterLogin; //destination to go to after login var currentRoomData; //TODO var me = "Me:" var queryPageNum = 1; /* onbeforeunload = function() { //alert('Closing'); TurboMingleBean.logoutFromChatRoom(); }; */ //-------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- function showDatingTab(){ $("#clubLite").css("display","none"); $("#turboMingle").css("display","inline"); } function showMyInformationPanelIfNeeded(){ if(turboMingleState.hasSetDofB==true){ $("#profile_dofb_p").hide(); }else{ var str=""; for(x=1992;x > 1900;x--){ str += ""; } $("#profile_dofb_year").html(str); $("#userInformationPanel").show(); } if(turboMingleState.countrySet==true){ $("#profile_country_p").hide(); //$("#profile_country_p").css("display","none"); }else{ $("#userInformationPanel").show(); } if(turboMingleState.locationSet==true){ $("#profile_city_p").hide(); //$("#profile_city_p").css("display","none"); }else{ $("#userInformationPanel").show(); } } /** Updates a users information */ function updateInformation(){ var notSet = false; $("#profile_country_warning").html(""); $("#profile_city_warning").html(""); $("#profile_dofb_warning").html(""); if($("#profile_country_p").is(':visible') && $("#profile_country").val()==""){ $("#profile_country_warning").html("Please fill in this field"); notSet=true;} if($("#profile_city_p").is(':visible') && $("#profile_city").val()==""){ $("#profile_city_warning").html("Please fill in this field"); notSet=true;} if($("#profile_dofb_p").is(':visible') && $("#profile_dofb_year").val()==""){ $("#profile_dofb_warning").html("Please fill in this field"); notSet=true;} if(notSet==true){ return; } var dofb; var country; var city; if($("#profile_country_p").is(':visible')){ country = $("#profile_country").val(); } if($("#profile_city_p").is(':visible')){ city = $("#profile_city").val(); } if($("#profile_dofb_p").is(':visible')){ dofb = "1/1/" + $("#profile_dofb_year").val(); } $("#userInformationPanel").hide(); TurboMingleBean.updateMyInformation(country, city, dofb, { callback: function(){ showInfoMessage("Great, enjoy!");}, errorHandler:function(errorString, exception){ $("#loggingIn").css("display","none"); $("#topLogInDetailsPanel").css("display","inline"); showErrorMessage("Error updating profile info"); } }); } function JadeQuery(){ this.pageNo=1; this.pageSize=64; this.keyword; this.country; this.city; this.expression; this.minAge; this.maxAge; this.gameName; this.gender; this.sexuality; this.website = "turbomingle"; this.avatarClassification; } /* * A wrapper object to provide convieniant functions for data access. * Note usrDataDTO can be null while we fetch extra data from the server */ function UserInfo(usrDataDTO){ this.usrDataDTO = usrDataDTO; this.incomingMessageList = new Array(); this.userDiv; //The div that contains the avatar in the main view this.incomingMessagesDiv; //The div that contains the incoming messages this.descriptionDiv; this.messageBarDiv; this.messengerWindow; this.unreadMsg; //There is an unread message from this user this.imgFramediv; this.usrId; this.profileRequested = false; if(usrDataDTO!=null){ this.usrId = usrDataDTO.usrDTO.id; } //----------------- this.id = function(){ return this.usrId; } this.username = function(){ if(usrDataDTO!=null){ return this.usrDataDTO.usrDTO.fullUsername.substr(0,this.usrDataDTO.usrDTO.fullUsername.indexOf("@")); }else{ return "loading"; } } this.website = function(){ if(usrDataDTO!=null){ return this.usrDataDTO.usrDTO.fullUsername.substr(this.usrDataDTO.usrDTO.fullUsername.indexOf("@")+1); }else{ return "loading"; } } this.avatar = function(){ if(usrDataDTO!=null){ if ($("#showAdult").attr("checked") || usrDataDTO.classification=="NORMAL") { if(this.usrDataDTO.usrDTO.avatarUrl.substring(0,4)=="http"){ return this.usrDataDTO.usrDTO.avatarUrl; }else{ return contextPath + "/" + this.usrDataDTO.usrDTO.avatarUrl.substring(1); } }else{ return contextPath + "/usergfx/turbomingle/adult.gif"; } }else{ return contextPath + "/usergfx/turbomingle/default.gif"; } } this.bigAvatar = function(){ if(usrDataDTO!=null){ var _path = TurboMingleBean.getBigAvatar(""+usrDataDTO.usrDTO.id); if(_path){ return contextPath+"/"+_path; } var u = this.usrDataDTO.usrDTO.avatarUrl; if(u.indexOf("small/")>0){ var a = u.substring(1,u.indexOf("small/")); var b = u.substring(u.indexOf("small/")+6); return contextPath + "/" + a + b ; }else{ return contextPath + u; } }else{ return contextPath + "/usergfx/turbomingle/default.gif"; } } this.status = function() { if(usrDataDTO==null){ return "unknown"; }else if(this.usrDataDTO.onlineGames!=null && this.usrDataDTO.onlineGames.indexOf("fortunecity")>=0){ return "fortunecity"; }else if(this.usrDataDTO.onlineGames!=null && this.usrDataDTO.onlineGames.indexOf("TurboMingle")>=0){ return "TurboMingle"; }else{ return "offline"; } } this.gender = function() { return getProfileData("gender"); } this.country = function(){ return getProfileData("country"); } this.city = function(){ return getProfileData("city"); } this.age = function(){ return getProfileData("age"); } this.description = function() { return getProfileData("description"); } this.isProfile = function() { return (usrDataDTO.profileData!=null) ? true : false; } this.setId = function(tId){ //Can be used to set the id when the usrDataDTO is null this.usrId = tId; } this.addChatMessage = function(msg){ this.incomingMessageList.push( msg); if(this.incomingMessagesDiv!=null){ this.incomingMessagesDiv.innerHTML += msg+"
"; }else{ if(this.messengerWindow==null){ soundManager.play('notification'); }; } this.unreadMsg = true; } this.createUserDiv = function(){ try { var tId = "user" + this.id(); if (this.userDiv == null) { this.userDiv = document.createElement('DIV'); this.userDiv.setAttribute('id', tId); this.userDiv.className = "user"; this.userDiv.setAttribute("onmousedown", "showMessageBarItemFetch(" + this.id() + ",null,true);"); this.userDiv.setAttribute("onmouseover", "mouseoverUser(" + this.id() + ");"); this.userDiv.setAttribute("onmouseout", "mouseoutUser(" + this.id() + ");"); } else { $("#" + tId).html(""); } this.imgFramediv = document.createElement('DIV'); this.imgFramediv.innerHTML = ''; this.imgFramediv.setAttribute('id', "imgFrame" + tId); mouseoutUser(this.id()); //To set the correct colour this.imgFramediv.style.width = "100px"; this.imgFramediv.style.height = "100px"; this.userDiv.appendChild(this.imgFramediv); var statusdiv = document.createElement('DIV'); statusdiv.style.fontSize = "10px"; //statusdiv.style.background = "#dddddd"; statusdiv.style.background = "transparent url(" + contextPath + "/games_gfx/turbomingle/transparent_bg.png) repeat-y scroll 0 0"; statusdiv.style.bottom = "14px"; statusdiv.style.left = "2px"; statusdiv.style.height = "12px"; statusdiv.style.width = "100px"; statusdiv.style.position = "relative"; statusdiv.style.zIndex = "1"; if (this.status() == "TurboMingle") { statusdiv.innerHTML = this.username(); this.userDiv.appendChild(statusdiv); } else if (this.status() == "fortunecity") { statusdiv.innerHTML = this.username(); this.userDiv.appendChild(statusdiv); } else { //we don't add the status bar if the user is offline } }catch(ex){ showErrorMessage(ex); } //$("#usersPanel").prepend(newdiv); } function getProfileData(prop){ if(usrDataDTO!=null && usrDataDTO.profileData!=null){ var d; for(d in usrDataDTO.profileData){ if(prop == "age" && usrDataDTO.profileData[d].property == "dateofbirth"){ //d.val() return "TODO - calculate age"; }else if(usrDataDTO.profileData[d].property == prop){ var t = usrDataDTO.profileData[d]; return t.value; }else{ //ignore } } } return null; } } var myErrorHandler = function(errorString, exception){ //alert("MyErrorHandler "+errorString + " " + exception); showErrorMessage("Error "+errorString + " " + exception.javaClassName); }; var getUsersCallback = function(retVal) { if(retVal==null){ $("#usersPanel").html("???en.turbomingle.filter.errorUpdating???"); }else if(retVal.length==0){ $("#usersPanel").html("No users found = please adjust filter parameters"); }else{ $("#usersPanel").html(""); //for (var i = 0; i < retVal.length; i++) { for (var i = retVal.length - 1; i >= 0; i--) { var usrDataDTO = retVal[i]; createUserPanel(usrDataDTO); } } } /* called when the local user logs in */ var loggedOnCallback = function(tTurboMingleState) { isLoggedIn = true; turboMingleState = tTurboMingleState; showErrorMessage(""); showInfoMessage("You are now logged in"); showMyInformationPanelIfNeeded(); $("#loggedInMenuOptions").css("display","inline"); $("#topLogInPanel").css("display","none"); $("#joinNowTab").css("display","none"); $("#loggingIn").css("display","none"); $("#logout").css("display","inline"); $("#messagesButton").css("display","inline"); reopenAllChatRooms(); TurboMingleBean.getOfflineMessages({callback: showOfflineMessages}); //if(todoAfterLogin!=null){ //TODO - support club rooms also // joinPlainChatRoom(todoAfterLogin); //} } /** * The user has pressed the logon button * NOTE - Overrides the logon() in top.jsp */ function logon(){ if(isLoggedIn==false){ var username = $("#username").val(); var password = $("#password").val(); $("#topLogInDetailsPanel").css("display","none"); $("#loggingIn").css("display","inline"); TurboMingleBean.login(username, password, { callback: loggedOnCallback, errorHandler:function(errorString, exception){ $("#loggingIn").css("display","none"); $("#topLogInDetailsPanel").css("display","inline"); showErrorMessage("Incorrect username/password"); //showTickerMessage("LoginErrorHandler "+errorString + " " + exception.javaClassName); } }); }else{ alert("You appear to be already logged in, refresh the page then try again"); } } function showErrorMessage(msg){ if(errorMessageTimeout){ clearTimeout(errorMessageTimeout); } $("#error").html(msg); if(msg==null || msg==""){ $("#error").css("height", "0px"); $("#error").css("display", "none"); }else{ $("#error").css("height", "20px"); $("#error").css("display", "inline"); } myResize(); errorMessageTimeout = setTimeout("showErrorMessage('');",5000); } //////////////////////////////////// function myResize(){ var viewportwidth; var viewportheight; // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight if (typeof window.innerWidth != 'undefined'){ viewportwidth = window.innerWidth, viewportheight = window.innerHeight } // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) { viewportwidth = document.documentElement.clientWidth, viewportheight = document.documentElement.clientHeight } // older versions of IE else { viewportwidth = document.getElementsByTagName('body')[0].clientWidth, viewportheight = document.getElementsByTagName('body')[0].clientHeight } var searchPanelHeight = 30; var topAndBottomAreaHeight = 148 + $("#error").height(); //Turbomingle var h = (viewportheight-(topAndBottomAreaHeight+$("#messageBarPanel").height())); //or try .attr('offsetHeight') $("#usersContainer").css("height", (h-searchPanelHeight)+"px"); //ClubLite //$("#clubLite").style.height = (h-30)+"px"; } /* Create a user panel and add it to the beginging of the panels */ function createUserPanel(usrDataDTO){ var userInfo = userData[usrDataDTO.usrDTO.id]; if(userInfo==null){ userInfo = new UserInfo(usrDataDTO); userData[userInfo.id()] = userInfo; }else{ userInfo.usrDataDTO = usrDataDTO; //update our data } var tId = "user" + userInfo.id(); if(userInfo.userDiv==null || $(tId)==null){ userInfo.createUserDiv(); } $("#usersPanel").prepend(userInfo.userDiv); return userInfo; } function mouseoverUser(id){ try{ if(userData[id]!=null){ userData[id].imgFramediv.style.border = "2px solid yellow"; userData[id].imgFramediv.style.padding = "0px"; } }catch(ex){ //alert("error "+ex+" "+id); } } function mouseoutUser(tId){ try{ var info = userData[tId]; if(info!=null){ if(info.status()=="TurboMingle"){ if(info.gender() == "female"){ info.imgFramediv.style.border = "2px solid #ed6401"; }else{ info.imgFramediv.style.border = "2px solid #5164ed"; } info.imgFramediv.style.padding = "0px"; }else if(info.status()=="fortunecity"){ info.imgFramediv.style.border = "2px solid #e4247e"; info.imgFramediv.style.padding = "0px"; }else{ info.imgFramediv.style.border = "0px solid #ffffff"; info.imgFramediv.style.padding = "2px"; } } }catch(ex){ showErrorMessage("error in mouseoutUser "+ex); } } /** Called from the form filter button */ function filterUsers(){ queryPageNum = 1; $("#usersPanel").html("Loading users..."); TurboMingleBean.getUsers(getFilterUsersQuery(),{callback: getUsersCallback}); } function moreUsers(){ queryPageNum++; $("#usersPanel").html("Loading users..."); TurboMingleBean.getUsers(getFilterUsersQuery(),{callback: getUsersCallback}); } function getFilterUsersQuery(){ //var q = {$dwrClassName:'JadeQuery',pageNo:1,city:$("#filterCity").val()}; //example code for special dwr syntax var filterUsersQuery = new JadeQuery(); filterUsersQuery.pageNo=queryPageNum; //filterUsersQuery.pageSize=100; filterUsersQuery.gender = $("#filterGender").val(); filterUsersQuery.country = $("#filterCountry").val(); filterUsersQuery.city = $("#filterCity").val(); filterUsersQuery.minAge = $("#filterFromAge").val(); filterUsersQuery.maxAge = $("#filterToAge").val(); filterUsersQuery.keyword = $("#filterKeywords").val(); //Instead we return the users but filter t /* if($("#showAdult").checked==true){ filterUsersQuery.avatarClassification = "ADULT"; }else{ filterUsersQuery.avatarClassification = "NORMAL"; } */ return filterUsersQuery; } function populateDivWithDescription(userInfo){ userInfo.descriptionDiv.innerHTML = userInfo.username()+"
"; if(userInfo.gender()!=null) { userInfo.descriptionDiv.innerHTML += userInfo.gender()+"
"; } if(userInfo.age()!=null) { userInfo.descriptionDiv.innerHTML += userInfo.age()+"
"; } if(userInfo.city()!=null) {userInfo.descriptionDiv.innerHTML += userInfo.city()+"
"; } if(userInfo.country()!=null) {userInfo.descriptionDiv.innerHTML += userInfo.country()+"
"}; if(userInfo.description()!=null) {userInfo.descriptionDiv.innerHTML += userInfo.description()+"
";} //alert(userInfo.country()); //alert(userInfo.descriptionDiv.innerHTML); //We create all the components of the user panel but just adjust the style depending on the status of that user if(userInfo.status()=="TurboMingle") { userInfo.descriptionDiv.innerHTML += "User online"; //TODO //var ignoreDiv = document.createElement('DIV'); //ignoreDiv.className = "userMessengerIgnore"; //ignoreDiv.innerHTML = "ignore user add checkbox here"; //newdiv.appendChild(ignoreDiv); }else if(userInfo.status()=="fortunecity"){ userInfo.descriptionDiv.innerHTML += "User online"; //userInfo.descriptionDiv.innerHTML += "User is in the chat rooms. Go to user"; userInfo.incomingMessagesDiv.style.position = "hidden"; userInfo.incomingMessagesDiv.style.background = "#f0f0f0"; //TODO add link to go to user }else{ userInfo.descriptionDiv.innerHTML += "User is currently offline"; userInfo.incomingMessagesDiv.style.background = "#e0e0e0"; userInfo.incomingMessagesDiv.innerHTML = "User currently offline.
You can send them an offline message."; //$(n).disabled = true; //incomingMessagesDiv.style.display = "none"; //incomingMessagesDiv.style.visibility = "hidden"; } userInfo.descriptionDiv.innerHTML += "
Full profile"; } function openPicWindow(url){ w=window.open(url,'pic', 'width=600,height=600,left=25,top=20,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1'); w.focus(); } function markAsAdult(userId, tSpan){ TurboMingleBean.markAvatarAsAdult(userId); tSpan.onclick = null; tSpan.style.textDecoration = ""; tSpan.style.cursor = ""; tSpan.innerHTML="Thanks"; } var zIndex = 3; /** Open a messenger window. Should not be called directly, instead call showMessageBarItemFetch */ function openMessengerWindow(userId){ messageRead(userId); if(userData[userId].messengerWindow!=null){ return; } var userInfo = userData[userId]; //TODO check if this is null var newdiv = document.createElement('DIV'); //newdiv.className = "userMessengerPanel"; newdiv.className = "userMessengerPanel"; if(newWindowStartPositionX > 250) { newWindowStartPositionX = 20; } if(newWindowStartPositionY > 250) { newWindowStartPositionY = 20; } newdiv.style.left = newWindowStartPositionX.toString()+"px"; newdiv.style.top = newWindowStartPositionY.toString()+"px"; newdiv.style.zIndex = ++zIndex; newWindowStartPositionX+=5; newWindowStartPositionY+=5; //newdiv.onfocus = function(){alert(userId)}; newdiv.onmouseover = function(){messageRead(userId)}; var closeMinimiseDiv = document.createElement('DIV'); closeMinimiseDiv.className = "closeMinimiseDiv"; closeMinimiseDiv.innerHTML = ""; newdiv.appendChild(closeMinimiseDiv); var userMessengerAvatar = document.createElement('DIV'); userMessengerAvatar.className = "userMessengerAvatar"; var js = "javascript:openPicWindow('"+userInfo.bigAvatar()+"');"; userMessengerAvatar.innerHTML = ''; userMessengerAvatar.innerHTML += "Mark pic adult?"; newdiv.appendChild(userMessengerAvatar); userInfo.descriptionDiv = document.createElement('DIV'); userInfo.descriptionDiv.className = "userMessengerDescription"; userInfo.descriptionDiv.id = "userMessengerDescription"+userId; var incomingMessagesDiv = document.createElement('DIV'); incomingMessagesDiv.setAttribute("id","incomingMessages"); incomingMessagesDiv.className = "incomingMessages"; var msgList = userInfo.incomingMessageList; var x=0; for(x; x"; } 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 = "