var windowFocus=true;var username;var chatHeartbeatCount=0;var minChatHeartbeat=1000;var maxChatHeartbeat=33000;var chatHeartbeatTime=minChatHeartbeat;var originalTitle;var blinkOrder=0;var serverChat="/member/chat.aspx";var chatboxFocus=new Array();var newMessages=new Array();var newMessagesWin=new Array();var chatBoxes=new Array();var isSubscribed;$.expr[":"].asp=function(B,C,A){return(B.id&&B.id.match(A[3]+"$"))};$(document).ready(function(){if($("a:asp(LoginStatus1)").hasClass("subscribed")){isSubscribed=true}else{isSubscribed=false}originalTitle=document.title;startChatSession();$([window,document]).blur(function(){windowFocus=false}).focus(function(){windowFocus=true;document.title=originalTitle});$(".startChat").click(function(){var A=this;jConfirm("Are you sure ?","Jujeh",function(B){if(B==true){var C=$(A)[0].id;chatWith(C.substring(C.indexOf("ChatWith")+8))}});return false})});function restructureChatBoxes(){align=0;for(x in chatBoxes){chatboxtitle=chatBoxes[x];if($("#chatbox_"+chatboxtitle).css("display")!="none"){if(align==0){$("#chatbox_"+chatboxtitle).css("right","20px")}else{width=(align)*(225+7)+20;$("#chatbox_"+chatboxtitle).css("right",width+"px")}align++}}}function chatWith(A){createChatBox(A);$("#chatbox_"+A+" .chatboxtextarea").focus()}function createChatBox(A,B){if($("#chatbox_"+A).length>0){if($("#chatbox_"+A).css("display")=="none"){$("#chatbox_"+A).css("display","block");restructureChatBoxes()}$("#chatbox_"+A+" .chatboxtextarea").focus();return}if(!(isSubscribed)){$("<div />").attr("id","chatbox_"+A).addClass("chatbox").html('<div class="chatboxhead"><div class="chatboxtitle">'+A+'</div><div class="chatboxoptions"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+A+'\')">-</a> <a href="javascript:void(0)" onclick="javascript:closeChatBox(\''+A+'\')">X</a></div><br clear="all"/></div><div class="chatboxcontent"></div><div class="chatboxinput"><input type="radio" name="and" value="I think we should both get subscriptions so we can message each other." onclick="javascript:return selectChatInput(event,this,\''+A+'\');"/>I think we should both get subscriptions so we can message each other.<br /><input type="radio" name="and" value="One of us has to be a paying member to send a message and I think the gentlemen should take initiative." onclick="javascript:return selectChatInput(event,this,\''+A+'\');"/>One of us has to be a paying member to send a message and I think the gentlemen should take initiative.<br /><input type="radio" name="and" value="Im broke and can not afford the $10 Subscription fee." onclick="javascript:return selectChatInput(event,this,\''+A+'\');"/>Im broke and can not afford the $10 Subscription fee.<br /><input type="radio" name="and" value="Im in the process of subscribing and will be writing you soon." onclick="javascript:return selectChatInput(event,this,\''+A+'\');"/>Im in the process of subscribing and will be writing you soon.<br /><input type="radio" name="and" value="I find this fun!" onclick="javascript:return selectChatInput(event,this,\''+A+'\');"/>I find this fun!<br /><input type="radio" name="and" value="I do not have a subscription and was hoping that you message me." onclick="javascript:return selectChatInput(event,this,\''+A+"');\"/>I do not have a subscription and was hoping that you message me.</div>").appendTo($("body"))}else{$("<div />").attr("id","chatbox_"+A).addClass("chatbox").html('<div class="chatboxhead"><div class="chatboxtitle">'+A+'</div><div class="chatboxoptions"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+A+'\')">-</a> <a href="javascript:void(0)" onclick="javascript:closeChatBox(\''+A+'\')">X</a></div><br clear="all"/></div><div class="chatboxcontent"></div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+A+"');\"></textarea></div>").appendTo($("body"))}$("#chatbox_"+A).css("bottom","0px");chatBoxeslength=0;for(x in chatBoxes){if($("#chatbox_"+chatBoxes[x]).css("display")!="none"){chatBoxeslength++}}if(chatBoxeslength==0){$("#chatbox_"+A).css("right","20px")}else{width=(chatBoxeslength)*(225+7)+20;$("#chatbox_"+A).css("right",width+"px")}chatBoxes.push(A);if(B==1){minimizedChatBoxes=new Array();if($.cookie("chatbox_minimized")){minimizedChatBoxes=$.cookie("chatbox_minimized").split(/\|/)}minimize=0;for(j=0;j<minimizedChatBoxes.length;j++){if(minimizedChatBoxes[j]==A){minimize=1}}if(minimize==1){$("#chatbox_"+A+" .chatboxcontent").css("display","none");$("#chatbox_"+A+" .chatboxinput").css("display","none")}}chatboxFocus[A]=false;$("#chatbox_"+A+" .chatboxtextarea").blur(function(){chatboxFocus[A]=false;$("#chatbox_"+A+" .chatboxtextarea").removeClass("chatboxtextareaselected")}).focus(function(){chatboxFocus[A]=true;newMessages[A]=false;$("#chatbox_"+A+" .chatboxhead").removeClass("chatboxblink");$("#chatbox_"+A+" .chatboxtextarea").addClass("chatboxtextareaselected")});$("#chatbox_"+A).click(function(){if($("#chatbox_"+A+" .chatboxcontent").css("display")!="none"){$("#chatbox_"+A+" .chatboxtextarea").focus()}});$("#chatbox_"+A).show()}function chatHeartbeat(){var C=0;if(windowFocus==false){var B=0;var A=0;for(x in newMessagesWin){if(newMessagesWin[x]==true){++B;if(B>=blinkOrder){document.title=x+" says...";A=1;break}}}if(A==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){$("#chatbox_"+x+" .chatboxhead").toggleClass("chatboxblink")}}}$.ajax({url:serverChat+"?action=chatheartbeat",cache:false,dataType:"json",success:function(D){$.each(D.items,function(E,F){if(F){chatboxtitle=F.f;if($("#chatbox_"+chatboxtitle).length<=0){createChatBox(chatboxtitle)}if($("#chatbox_"+chatboxtitle).css("display")=="none"){$("#chatbox_"+chatboxtitle).css("display","block");restructureChatBoxes()}if(F.s==1){F.f=username}if(F.s==2){$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+F.m+"</span></div>")}else{newMessages[chatboxtitle]=true;newMessagesWin[chatboxtitle]=true;$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+F.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+F.m+"</span></div>");if(!(isSubscribed)){$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<span class="chatboxNotSubscribed">You need to be a paid subscriber to respond, please click <a href="/member/subscribe.aspx">here</a> to subscriber to Jujeh.com</span>')}}$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);C+=1}});chatHeartbeatCount++;if(C>0){chatHeartbeatTime=minChatHeartbeat;chatHeartbeatCount=1}else{if(chatHeartbeatCount>=10){chatHeartbeatTime*=2;chatHeartbeatCount=1;if(chatHeartbeatTime>maxChatHeartbeat){chatHeartbeatTime=maxChatHeartbeat}}}setTimeout("chatHeartbeat();",chatHeartbeatTime)}})}function closeChatBox(A){$("#chatbox_"+A).css("display","none");restructureChatBoxes();$.post(serverChat+"?action=closechat",{chatbox:A},function(B){})}function toggleChatBoxGrowth(A){if($("#chatbox_"+A+" .chatboxcontent").css("display")=="none"){var B=new Array();if($.cookie("chatbox_minimized")){B=$.cookie("chatbox_minimized").split(/\|/)}var C="";for(i=0;i<B.length;i++){if(B[i]!=A){C+=A+"|"}}C=C.slice(0,-1);$.cookie("chatbox_minimized",C);$("#chatbox_"+A+" .chatboxcontent").css("display","block");$("#chatbox_"+A+" .chatboxinput").css("display","block");$("#chatbox_"+A+" .chatboxcontent").scrollTop($("#chatbox_"+A+" .chatboxcontent")[0].scrollHeight)}else{var C=A;if($.cookie("chatbox_minimized")){C+="|"+$.cookie("chatbox_minimized")}$.cookie("chatbox_minimized",C);$("#chatbox_"+A+" .chatboxcontent").css("display","none");$("#chatbox_"+A+" .chatboxinput").css("display","none")}}function selectChatInput(B,A,C){checkChatBoxInputKey(B,A,C)}function checkChatBoxInputKey(C,A,D){if((C.keyCode==13&&C.shiftKey==0)||!(isSubscribed)){message="";message=$(A).val();message=message.replace(/^\s+|\s+$/g,"");$(A).val("");$(A).focus();if(isSubscribed){$(A).css("height","44px")}if(message!=""){$.post(serverChat+"?action=sendchat",{to:D,message:message},function(F){message=message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");$("#chatbox_"+D+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+username+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+message+"</span></div>");$("#chatbox_"+D+" .chatboxcontent").scrollTop($("#chatbox_"+D+" .chatboxcontent")[0].scrollHeight)})}chatHeartbeatTime=minChatHeartbeat;chatHeartbeatCount=1;return false}var E=A.clientHeight;var B=94;if(B>E){E=Math.max(A.scrollHeight,E);if(B){E=Math.min(B,E)}if(E>A.clientHeight){$(A).css("height",E+8+"px")}}else{$(A).css("overflow","auto")}}function startChatSession(){$.ajax({url:serverChat+"?action=startchatsession",cache:false,dataType:"json",success:function(A){username=A.username;$.each(A.items,function(B,C){if(C){chatboxtitle=C.f;if($("#chatbox_"+chatboxtitle).length<=0){createChatBox(chatboxtitle,1)}if(C.s==1){C.f=username}if(C.s==2){$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+C.m+"</span></div>")}else{$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+C.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+C.m+"</span></div>")}}});for(i=0;i<chatBoxes.length;i++){chatboxtitle=chatBoxes[i];$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);setTimeout('$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);',100)}setTimeout("chatHeartbeat();",chatHeartbeatTime)}})}(function(A){A.cookie=function(I,E,B){if(typeof E!="undefined"){B=B||{};if(E===null){E="";B.expires=-1}var H="";if(B.expires&&(typeof B.expires=="number"||B.expires.toUTCString)){var C;if(typeof B.expires=="number"){C=new Date();C.setTime(C.getTime()+(B.expires*24*60*60*1000))}else{C=B.expires}H="; expires="+C.toUTCString()}var L=B.path?"; path="+(B.path):"";var D=B.domain?"; domain="+(B.domain):"";var J=B.secure?"; secure":"";document.cookie=[I,"=",encodeURIComponent(E),H,L,D,J].join("")}else{var G=null;if(document.cookie&&document.cookie!=""){var M=document.cookie.split(";");for(var K=0;K<M.length;K++){var F=jQuery.trim(M[K]);if(F.substring(0,I.length+1)==(I+"=")){G=decodeURIComponent(F.substring(I.length+1));break}}}return G}}})(jQuery);