otherLoginBoxFieldsVisible=false;$(document).ready(function(){otherFunctionsInit();$("textarea.expanding").elastic();});$.extend($.expr[':'],{inView:function(a){var st=(document.documentElement.scrollTop||document.body.scrollTop),ot=$(a).offset().top,wh=(window.innerHeight&&window.innerHeight<$(window).height())?window.innerHeight:$(window).height();return ot>st&&($(a).height()+ot)<(st+wh);}});function loginBoxInit(){refreshLoginBoxCaptcha();$("#loginBoxUsernameField").focus(revealLoginFields);if($("#loginBoxUsernameField").val().length>0)revealLoginFields();$("#loginBoxLogoutLink").click(loginBoxLogout);}function revealLoginFields(){if(!otherLoginBoxFieldsVisible){$("#loginBoxOtherFields").slideDown("slow");$("#loginBoxPasswordField").removeAttr("disabled");$("#loginBoxLoginForm").attr("action","/login/dologin");var options={dataType:'json',beforeSubmit:disableLoginBoxLoginButton,success:processLoginBoxResponse};$("#loginBoxLoginForm").ajaxForm(options);otherLoginBoxFieldsVisible=true;}}function disableLoginBoxLoginButton(){$("#loginBoxLoginButton").attr("disabled","disabled");}function processLoginBoxResponse(response){$("#loginBoxLoginButton").removeAttr("disabled");if(!response.succeeded){refreshLoginBoxCaptcha();alert(response.errorMessage);}else {if(response.doRefresh)window.location.reload();else window.location=response.successURL;}}function refreshLoginBoxCaptcha(){postJSON("/login/captcha",function(json){$("#loginBoxCid").val(json.id);$("#loginBoxCimg").html(json.image);$("#loginBoxCtext").val("");});}function loginBoxLogout(){simplePost("/login/dologout",function(){window.location.reload();});return false;}function registerFormInit(){$("#registerForm").attr("action","/login/doregister");var options={dataType:'json',beforeSubmit:disableRegisterFormRegisterButton,success:processRegisterResponse};$("#registerForm").ajaxForm(options);}function disableRegisterFormRegisterButton(){$("#registerFormRegisterButton").attr("disabled","disabled");}function processRegisterResponse(response){$("#registerFormRegisterButton").removeAttr("disabled");if(!response.succeeded){refreshRegisterFormCaptcha();alert(response.errorMessage);}else {$("#registerDiv").html(response.successHTML);}}function refreshRegisterFormCaptcha(){postJSON("/login/captcha",function(json){$("#registerFormCid").val(json.id);$("#registerFormCimg").html(json.image);$("#registerFormCtext").val("");});}function forgotPasswordFormInit(){$("#forgotPasswordForm").attr("action","/login/doforgot");var options={dataType:'json',beforeSubmit:disableForgotPasswordFormSendPasswordButton,success:processForgotPasswordResponse};$("#forgotPasswordForm").ajaxForm(options);}function disableForgotPasswordFormSendPasswordButton(){$("#forgotPasswordFormSendPasswordButton").attr("disabled","disabled");}function processForgotPasswordResponse(response){$("#forgotPasswordFormSendPasswordButton").removeAttr("disabled");if(!response.succeeded){alert(response.errorMessage);}else {$("#forgotPasswordDiv").html(response.successHTML);}}function addLinkFormInit(){$("#addLinkForm").attr("action","/links/save_link");var options={dataType:'json',beforeSubmit:disableAddLinkFormAddButton,success:processAddLinkResponse};$("#addLinkForm").ajaxForm(options);}function disableAddLinkFormAddButton(){$("#addLinkFormAddButton").attr("disabled","disabled");}function processAddLinkResponse(response){$("#addLinkFormAddButton").removeAttr("disabled");if(!response.succeeded){alert(response.errorMessage);}else {window.location=response.successURL;}}function contactFormInit(){$("#contactForm").attr("action","/contact/dosend");var options={dataType:'json',beforeSubmit:disableContactFormSendMessageButton,success:processContactResponse};$("#contactForm").ajaxForm(options);}function disableContactFormSendMessageButton(){$("#contactFormSendMessageButton").attr("disabled","disabled");}function processContactResponse(response){$("#contactFormSendMessageButton").removeAttr("disabled");if(!response.succeeded){alert(response.errorMessage);}else {$("#contactDiv").html(response.successHTML);}}function settingsFormInit(){$("#settingsForm").attr("action","/login/dosettings");var options={dataType:'json',beforeSubmit:disableSettingsFormSaveButton,success:processSettingsResponse};$("#settingsForm").ajaxForm(options);}function disableSettingsFormSaveButton(){$("#settingsFormSaveButton").attr("disabled","disabled");}function processSettingsResponse(response){$("#settingsFormSaveButton").removeAttr("disabled");if(!response.succeeded){alert(response.errorMessage);}else {$("#settingsDiv").html(response.successHTML);}}function avatarFormInit1(){var randomnumber=Math.floor(Math.random()*11);$("#avatarDiv").load("/avatar/edit_avatar/"+randomnumber);}function avatarFormInit(){otherFunctionsInit();}function submitAvatarForm(){$("#avatarForm").attr("action","/avatar/save_avatar");var options={dataType:'json',beforeSubmit:disableAvatarFormSaveButton,success:processAvatarResponse};$("#avatarForm").ajaxSubmit(options);return false;}function submitAvatarForm2(){$("#avatarForm2").attr("action","/avatar/save_avatar");$("#avatarFormDescField2").val($("#avatarFormDescField").val());var options={dataType:'json',success:processAvatarResponse};$("#avatarForm2").ajaxSubmit(options);return false;}function disableAvatarFormSaveButton(){$("#avatarFormSaveButton").attr("disabled","disabled");if($("#avatarFormPictureField").val().length>0)$("#avatarFormPictureSelectedField").val(1);else $("#avatarFormPictureSelectedField").val(0);}function processAvatarResponse(response){$("#avatarFormSaveButton").removeAttr("disabled");if(!response.succeeded){alert(response.errorMessage);}else {if(response.successHTML.length>0)$("#avatarDiv").html(response.successHTML);else avatarFormInit1();}}function addTopicFormInit(){$("#addTopicForm").attr("action","/forum/save_topic");var options={dataType:'json',beforeSubmit:disableAddTopicFormPostButton,success:processAddTopicResponse};$("#addTopicForm").ajaxForm(options);}function disableAddTopicFormPostButton(){$("#addTopicFormPostButton").attr("disabled","disabled");}function processAddTopicResponse(response){$("#addTopicFormPostButton").removeAttr("disabled");if(!response.succeeded){alert(response.errorMessage);}else {window.location=response.successURL;}}function addPostFormInit(){$("#addPostForm").attr("action","/forum/save_new_post");var options={dataType:'json',beforeSubmit:disableAddPostFormPostButton,success:processAddPostResponse};$("#addPostForm").ajaxForm(options);}function disableAddPostFormPostButton(){$("#addPostFormPostButton").attr("disabled","disabled");}function processAddPostResponse(response){$("#addPostFormPostButton").removeAttr("disabled");if(!response.succeeded){alert(response.errorMessage);}else {window.location=response.successURL;}}function subscribeTopic(topicId,pageNum){postJSON("/forum/subscribe_topic/"+topicId,function(response){if(!response.succeeded){alert(response.errorMessage);}else gotoPostsPageOrRefresh(topicId,pageNum);});return false;}function unsubscribeTopic(topicId,pageNum){postJSON("/forum/unsubscribe_topic/"+topicId,function(response){if(!response.succeeded){alert(response.errorMessage);}else gotoPostsPageOrRefresh(topicId,pageNum);});return false;}currentPostIdBeingEdited=0;function editPost(postId){cancelExistingEditPost();hideAddPostDiv();postJSON("/forum/gen_edit_post_div/"+postId,function(response){if(!response.succeeded){alert(response.errorMessage);}else {currentPostIdBeingEdited=postId;w=$("#postMessageDiv_"+postId).width();$("#postMessageEditDiv_"+postId).html(response.successHTML);editPostFormInit();$("#postTools_"+postId).fadeOut("fast",function(){$("#rulesOfPosting_"+postId).fadeIn("slow");});$("#postMessageDiv_"+postId).fadeOut("slow",function(){$("#postMessageEditDiv_"+postId).fadeIn("slow",function(){$("#editPostFormMessageField").width(w);$("#editPostFormMessageField").elastic();$("#editPostFormMessageField").focus();$("#normalSmileysDiv2 .simpletooltip").tooltip({position:"bottom left",offset:[-50,20],tip:'#simpletooltipDiv',lazy:false});});});}});return false;}function quotePost(postId){postJSON("/forum/gen_quote_text/"+postId,function(response){if(!response.succeeded){alert(response.errorMessage);}else {if(currentPostIdBeingEdited>0)$("#editPostFormMessageField").insertAtCaret(response.successHTML);else {if($("#addPostFormMessageField:visible").size()==0)scrollToAddPostRow();$("#addPostFormMessageField").insertAtCaret(response.successHTML);}}});return false;}function cancelEditPost(postId){$("#rulesOfPosting_"+postId).fadeOut("fast",function(){$("#postTools_"+postId).fadeIn("slow");});$("#postMessageEditDiv_"+postId).fadeOut("slow",function(){$("#postMessageDiv_"+postId).fadeIn("slow");$("#postMessageEditDiv_"+postId).html("");$(".mailDivider").text('@');});currentPostIdBeingEdited=0;return false;}function cancelExistingEditPost(){if(currentPostIdBeingEdited>0)cancelEditPost(currentPostIdBeingEdited);return false;}function editPostFormInit(){$("#editPostForm").attr("action","/forum/save_existing_post");var options={dataType:'json',beforeSubmit:disableEditPostFormUpdateButton,success:processEditPostResponse};$("#editPostForm").ajaxForm(options);}function disableEditPostFormUpdateButton(){$("#editPostFormUpdateButton").attr("disabled","disabled");}function processEditPostResponse(response){$("#editPostFormUpdateButton").removeAttr("disabled");if(!response.succeeded){alert(response.errorMessage);}else {$("#postDateHTMLDiv_"+currentPostIdBeingEdited).html(response.successHTML[0]);$("#postUsernameHTMLDiv_"+currentPostIdBeingEdited).html(response.successHTML[1]);$("#postToolsHTMLDiv_"+currentPostIdBeingEdited).html(response.successHTML[2]);$("#postMessageHTMLDiv_"+currentPostIdBeingEdited).html(response.successHTML[3]);cancelExistingEditPost();}}function deletePost(postId){if(confirm("Are you sure you wish to delete this post?")){cancelExistingEditPost();postJSON("/forum/delete_post/"+postId,function(response){if(!response.succeeded){alert(response.errorMessage);}else {$("#postDateHTMLDiv_"+postId).html(response.successHTML[0]);$("#postUsernameHTMLDiv_"+postId).html(response.successHTML[1]);$("#postToolsHTMLDiv_"+postId).html(response.successHTML[2]);$("#postMessageHTMLDiv_"+postId).html(response.successHTML[3]);}});}return false;}function zoomControlsInit(){$("#zoomInLink").click(function(){postJSON("/zoom/zoom_in",function(json){$("body").css("font-size",json.sz+"%");});return false;});$("#zoomOutLink").click(function(){postJSON("/zoom/zoom_out",function(json){$("body").css("font-size",json.sz+"%");});return false;});}function otherFunctionsInit(){$(".loginFirst").click(loginFirst);$(".refreshWindow").click(refreshWindow);$(".doNothing").click(doNothing);$(".comingSoon").click(comingSoon);$(".scrollToAddPostRow").click(scrollToAddPostRow);$(".countrySelector").val(currentCountryId).change();initTooltips();$(".mailDivider").text('@');$(".newWindow").attr("target","_blank");$('.limit500').keyup(function(){textareaLengthLimit(this,500);});$('.limit150').keyup(function(){textareaLengthLimit(this,150);});}function textareaLengthLimit(t,max){if($(t).val().length>max){$(t).val($(t).val().substr(0,max));}$(t).parent().find('.charsRemaining').html((max-$(t).val().length)+' characters remaining');}function initTooltips(){$(".tooltipBig").tooltip({tip:"#tooltipBigDiv",lazy:false});$(".tooltipMedium").tooltip({tip:"#tooltipMediumDiv",lazy:false});$(".tooltipForm").tooltip({position:"center right",offset:[-2,10],effect:"fade",tip:'#tooltipFormDiv',lazy:false});$(".simpletooltip").tooltip({position:"bottom left",offset:[-50,20],tip:'#simpletooltipDiv',lazy:false});$(".zoomtooltip").tooltip({position:"bottom right",offset:[-50,-1],tip:'#simpletooltipDiv',lazy:false});}function loginFirst(){alert("Please login first.");return false;}function refreshWindow(){window.location.reload();return false;}function doNothing(){return false;}function comingSoon(){alert("This feature is coming soon.");return false;}function scrollToAddPostRow(){cancelExistingEditPost();$("#addPostDiv").fadeIn("slow",function(){jQuery.scrollTo($("#addPostRow"),500);$("#addPostFormMessageField").focus().elastic();});return false;}function scrollToID(id){jQuery.scrollTo($("#"+id),500);return false;}function hideAddPostDiv(){$("#addPostDiv").fadeOut("slow");}function fixAddPostLeftColWidth(){var plc=$("#postsLeftCol");var aplc=$("#addPostLeftCol");if(plc.size()>0&&aplc.size()>0){var plcw=plc.width();aplc.width(plcw);}}function gotoPostsPageOrRefresh(topicId,pageNum){if(gotoPostsPage(topicId,pageNum)==true)window.location.reload();return false;}function gotoPostsPage(topicId,pageNum){if($("#addPostForm:hidden").size()==1||$("#addPostForm").size()==0)return true;postJSON("/forum/posts_ajax/"+topicId+"/"+pageNum,function(response){if(!response.succeeded){alert(response.errorMessage);}else {cancelExistingEditPost();$("#topToolTableDiv").html(response.successHTML[0]);$("#bottomToolTableDiv").html(response.successHTML[2]);$("#barTableDiv").fadeOut("slow",function(){$("#barTableDiv").html(response.successHTML[1]);$("#barTableDiv").fadeIn("slow",function(){otherFunctionsInit();});});}});return false;}function gotoLastPostsPage(postId){if($("#addPostForm:hidden").size()==1)return true;postJSON("/forum/last_post_ajax/"+postId,function(response){if(!response.succeeded){alert(response.errorMessage);}else {cancelExistingEditPost();$("#topToolTableDiv").html(response.successHTML[0]);$("#bottomToolTableDiv").html(response.successHTML[2]);$("#barTableDiv").fadeOut("slow",function(){$("#barTableDiv").html(response.successHTML[1]);$("#barTableDiv").fadeIn("slow",function(){otherFunctionsInit();});});}});return false;}function countrySelected(formName){countryId=$("#"+formName+"CountrySelector").val();if(countryId>0){$("#"+formName+"CitySelectorDiv").load('/forum/city_selector/'+formName+'/'+countryId,function(){$("#"+formName+"CitySelectorDiv:hidden").slideDown("fast");});}else {$("#"+formName+"SuburbSelectorDiv:visible").slideUp("fast");$("#"+formName+"SuburbSelectorDiv").html("");$("#"+formName+"CitySelectorDiv:visible").slideUp("fast");$("#"+formName+"CitySelectorDiv").html("");}}function citySelected(formName){cityId=$("#"+formName+"CitySelector").val();if(cityId>0){$("#"+formName+"SuburbSelectorDiv").load('/forum/suburb_selector/'+cityId,function(){$("#"+formName+"SuburbSelectorDiv:hidden").slideDown("fast");});}else {$("#"+formName+"SuburbSelectorDiv:visible").slideUp("fast");$("#"+formName+"SuburbSelectorDiv").html("");}}function insertSmiley(smiley){if($("#editPostFormMessageField").size()==1)$("#editPostFormMessageField").insertAtCaret(" "+smiley+" ");else if($("#addPostFormMessageField").size()==1)$("#addPostFormMessageField").insertAtCaret(" "+smiley+" ");else if($("#addTopicFormMessageField").size()==1)$("#addTopicFormMessageField").insertAtCaret(" "+smiley+" ");return false;}function insertChatSmiley(smiley){$("#chatInputFormMessageField").insertAtCaret(" "+smiley+" ");return false;}$.fn.insertAtCaret=function(myValue){return this.each(function(){if(document.selection){this.focus();sel=document.selection.createRange();sel.text=myValue;this.focus();}else if(this.selectionStart||this.selectionStart=='0'){var startPos=this.selectionStart;var endPos=this.selectionEnd;var scrollTop=this.scrollTop;this.value=this.value.substring(0,startPos)+myValue+this.value.substring(endPos,this.value.length);this.focus();this.selectionStart=startPos+myValue.length;this.selectionEnd=startPos+myValue.length;this.scrollTop=scrollTop;}else {this.value+=myValue;this.focus();}});};function postJSON(url,callback){var randomnumber=Math.floor(Math.random()*11);jQuery.post(url,{ierand:randomnumber},callback,"json");}function simplePost(url,callback){jQuery.post(url,'',callback);}jQuery.fn.enterKeyUp=function(callback){$(this).keyup(function(event){if(event.keyCode==13){callback();return false;}});};lastMsgId=0;function chattingNowInit(){simplePost("/chat/total_chat_participants",function(data){$("#totalChatParticipants").html(data);});}function chatInit(){postJSON("/chat/render_popup",function(json){if(json.succeeded){$("#chatPopupDiv").html(json.successHTML);lastMsgId=json.msgId;if(chatOpen&&$("#chatPopupDiv").is(":hidden"))showHideChatPopup();else if(chatOpen){setTimeout(function(){$("#chatMessagesDiv").scrollTo($("#endOfChatMessages"),100);},100);}setTimeout(chatLiveUpdate,1);}else {alert(json.errorMessage);}});}setUpdateTimer=false;function chatLiveUpdate(){setUpdateTimer=true;if(currentRoomId!=false){jQuery.ajax({type:"POST",url:("/chat/get_live_update/"+lastMsgId),timeout:35000,dataType:"json",cache:false,success:function(json){if(json.isJoinLeaveMessage)chattingNowInit();if(json.chatroomId==currentRoomId){lastMsgId=json.msgId;if(json.isNewMessage||json.isJoinLeaveMessage){if(json.isJoinLeaveMessage&&json.userId==pppn){setUpdateTimer=false;chatInit();}else {if(!chatOpen&&json.isNewMessage)$("#bottomBarChatIcon").attr("src","/images/chat-red.png");$("#endOfChatMessages").before(json.msgHTML);setTimeout(function(){$("#chatMessagesDiv").scrollTo($("#endOfChatMessages"),100);},100);}}}},complete:function(){window.status="";if(setUpdateTimer)setTimeout(chatLiveUpdate,1);}});}}function showHideChatPopup(){if($("#chatPopupDiv").is(":hidden")){$("#chatPopupDiv").fadeIn(function(){clearFilterForIE(this);if(currentRoomId!=false)$("#bottomBarChatIcon").attr("src","/images/chat.png");else $("#bottomBarChatIcon").attr("src","/images/chat-gray.png");postJSON("/chat/open_chat_popup",null);chatOpen=true;$("#chatInputFormMessageField").focus();setTimeout(function(){$("#chatMessagesDiv").scrollTo($("#endOfChatMessages"),100);},100);});}else {postJSON("/chat/close_chat_popup",null);$("#chatPopupDiv").fadeOut();chatOpen=false;}return false;}function closeChat(){postJSON("/chat/close_chat",function(json){window.location.reload();});return false;}function chatInputFormInit(){$("#chatInputForm").attr("action","/chat/send_message");var options={dataType:'json',success:processSendMessageResponse};$("#chatInputForm").ajaxForm(options);$("#chatInputFormMessageField").enterKeyUp(submitChatInputForm);}function submitChatInputForm(){$("#chatInputFormMessageField").attr("readonly","readonly");$("#chatInputForm").submit();return false;}function processSendMessageResponse(response){$("#chatInputFormMessageField").removeAttr("readonly");if(!response.succeeded){alert(response.errorMessage);}else {$("#chatInputFormMessageField").val("");}}function showAvatarChatTooltip(userId){$("#avatarChatTooltipDiv").html("&nbsp;");var randomnumber=Math.floor(Math.random()*11);$("#avatarChatTooltipDiv").load("/avatar/gen_avatar/"+userId);return true;}function showChatPopdownMenu(){$("#chatPopdownMenuTooltipDiv").html("&nbsp;");postJSON("/chat/render_popdown_menu",function(json){if(json.succeeded){$("#chatPopdownMenuTooltipDiv").html(json.successHTML);}else alert(json.errorMessage);});return true;}function joinChatRoom(chatroomId){postJSON("/chat/join_room/"+chatroomId,function(json){if(json.succeeded){window.location.reload();}else {alert(json.errorMessage);}});return false;}
