var windowFocus = true; var username; var chatHeartbeatCount = 0; var minChatHeartbeat = 5000; var maxChatHeartbeat = 33000; var chatHeartbeatTime = minChatHeartbeat; var originalTitle; var blinkOrder = 0; var emails=''; var chatboxFocus = new Array(); var newMessages = new Array(); var newMessagesWin = new Array(); var chatBoxes = new Array(); var chId=0; $j=jQuery.noConflict(); $j(document).ready(function(){ originalTitle = document.title; startChatSession(); $j([window, document]).blur(function(){ windowFocus = false; }).focus(function(){ windowFocus = true; document.title = originalTitle; }); }); function restructureChatBoxes() { align = 0; for (x in chatBoxes) { chatboxtitle = chatBoxes[x]; if ($j("#chatbox_"+chatboxtitle).css('display') != 'none') { if (align == 0) { $j("#chatbox_"+chatboxtitle).css('right', '20px'); } else { width = (align)*(225+7)+20; $j("#chatbox_"+chatboxtitle).css('right', width+'px'); } align++; } } } function chatWith(chatuser) { var chatuser1=chatuser.split(/-(.+)?/)[0]; chId=chatuser.split(/-(.+)?/)[1]; createChatBox(chatuser1); $j("#chatbox_"+chatuser1+" .chatboxtextarea").focus(); } function createChatBox(chatboxtitle,minimizeChatBox) { if ($j("#chatbox_"+chatboxtitle).length > 0) { if ($j("#chatbox_"+chatboxtitle).css('display') == 'none') { $j("#chatbox_"+chatboxtitle).css('display','block'); restructureChatBoxes(); } $j("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus(); return; } if(emails.length==0){ // emails = 'Email: '; //alert('Please give your email'); emails = prompt("May I know your name please?",""); if(emails.length<3){ alert("Not a valid name"); } } $j("
" ).attr("id","chatbox_"+chatboxtitle) .addClass("chatbox") .html('
'+chatboxtitle+'

') .appendTo($j( "body" )); $j("#chatbox_"+chatboxtitle).css('bottom', '0px'); chatBoxeslength = 0; for (x in chatBoxes) { if ($j("#chatbox_"+chatBoxes[x]).css('display') != 'none') { chatBoxeslength++; } } if (chatBoxeslength == 0) { $j("#chatbox_"+chatboxtitle).css('right', '20px'); } else { width = (chatBoxeslength)*(225+7)+20; $j("#chatbox_"+chatboxtitle).css('right', width+'px'); } chatBoxes.push(chatboxtitle); if (minimizeChatBox == 1) { minimizedChatBoxes = new Array(); if ($j.cookie('chatbox_minimized')) { minimizedChatBoxes = $j.cookie('chatbox_minimized').split(/\|/); } minimize = 0; for (j=0;j= blinkOrder) { document.title = x+' replied...'; titleChanged = 1; break; } } } if (titleChanged == 0) { document.title = originalTitle; blinkOrder = 0; } else { ++blinkOrder; } } else { for (x in newMessagesWin) { newMessagesWin[x] = false; } } for (x in newMessages) { if (newMessages[x] == true) { if (chatboxFocus[x] == false) { $j('#chatbox_'+x+' .chatboxhead').toggleClass('chatboxblink'); } } } $j.ajax({ url: "http://anytimereply.com/chat.php?action=chatheartbeat", cache: false, dataType: "json", success: function(data) { $j.each(data.items, function(i,item){ if (item) { chatboxtitle = item.f; if ($j("#chatbox_"+chatboxtitle).length <= 0) { createChatBox(chatboxtitle); } if ($j("#chatbox_"+chatboxtitle).css('display') == 'none') { $j("#chatbox_"+chatboxtitle).css('display','block'); restructureChatBoxes(); } if (item.s == 1) { item.f = username; } if (item.s == 2) { $j("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+item.m+'
'); } else { newMessages[chatboxtitle] = true; newMessagesWin[chatboxtitle] = true; $j("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+item.f+':  '+item.m+'
'); $j(".thinking").empty(); } $j("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($j("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight); itemsfound += 1; } }); chatHeartbeatCount++; if (itemsfound > 0) { chatHeartbeatTime = minChatHeartbeat; chatHeartbeatCount = 1; } else if (chatHeartbeatCount >= 10) { chatHeartbeatTime *= 2; chatHeartbeatCount = 1; if (chatHeartbeatTime > maxChatHeartbeat) { chatHeartbeatTime = maxChatHeartbeat; } } setTimeout('chatHeartbeat();',chatHeartbeatTime); }}); } function closeChatBox(chatboxtitle) { $j('#chatbox_'+chatboxtitle).css('display','none'); restructureChatBoxes(); $j.post("http://anytimereply.com/chat.php?action=closechat", { chatbox: chatboxtitle} , function(data){ }); } function toggleChatBoxGrowth(chatboxtitle) { if ($j('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display') == 'none') { var minimizedChatBoxes = new Array(); if ($j.cookie('chatbox_minimized')) { minimizedChatBoxes = $j.cookie('chatbox_minimized').split(/\|/); } var newCookie = ''; for (i=0;i/g,">").replace(/\"/g,"""); $j("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+username+':  '+message+'
'); $j(".thinking").append("Replying.."); $j("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($j("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight); }); } chatHeartbeatTime = minChatHeartbeat; chatHeartbeatCount = 1; return false; } var adjustedHeight = chatboxtextarea.clientHeight; var maxHeight = 94; if (maxHeight > adjustedHeight) { adjustedHeight = Math.max(chatboxtextarea.scrollHeight, adjustedHeight); if (maxHeight) adjustedHeight = Math.min(maxHeight, adjustedHeight); if (adjustedHeight > chatboxtextarea.clientHeight) $j(chatboxtextarea).css('height',adjustedHeight+8 +'px'); } else { $j(chatboxtextarea).css('overflow','auto'); } } function startChatSession(){ $j.ajax({ url: "http://anytimereply.com/chat.php?action=startchatsession", cache: false, dataType: "json", success: function(data) { username = data.username; $j.each(data.items, function(i,item){ if (item) { chatboxtitle = item.f; if ($j("#chatbox_"+chatboxtitle).length <= 0) { createChatBox(chatboxtitle,1); } if (item.s == 1) { item.f = username; } if (item.s == 2) { $j("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+item.m+'
'); } else { $j("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+item.f+':  '+item.m+'
'); } } }); for (i=0;i