function TPCComment(a){this.objectId=a.objectId;this.objectType=a.objectType;this.objectSource=a.objectSource;this.thread=undefined;this.sort="";this.sliceSize=0;this.sliceFloor=0;this.commentTotal=0;this.commentPosition=0;this.user=(a.user!==undefined)?a.user:undefined;this.initialized=false;this.loading=false;this.reset=false;this.ajaxUrl="/components/content/comment/list";this.canComment=false;this.isUserLoggedIn=function(){try{return(this.user.id>0)}catch(b){alert(b);return false}};this.init=function(){var d=this,g=$("<option/>").attr("id","c-sort-desc").attr("selected","selected").attr("value","comment_create_date desc").html("Newest First"),f=$("<option/>").attr("id","c-sort-asc").attr("value","comment_create_date asc").html("Oldest First"),e=$("<option/>").attr("id","c-sort-score").attr("value","score_up desc, score_down asc").html("Top Rated"),c=$("<select/>").attr("id","c-sort").append(g).append(f).append(e).hide(),b=$("<span/>").attr("id","c-live").html("");c.change(function(){d.sort=$(this).val();d.resetWidgets();d.loadThread()});$("#c-info-panel").append(b).append(c).append($("<br />").attr("clear","all"));this.user=tpc.getUser();this.examinePrivileges();d.loadThread()};this.examinePrivileges=function(){if(this.user.privileges){for(var b=0;b<this.user.privileges.length;b++){if(this.user.privileges[b]=="comment"){this.canComment=true;return}}}this.canComment=false};this.loadThread=function(){var b=this;$.getJSON(this.buildCommentRequestUrl(),function(d){b.thread=d;if(!b.initialized){if(b.thread.threadState=="hidden"){return false}$("#c-container").show();if(b.thread.threadState=="open"){b.initCommentForm()}var c=tpc.param("postCode"),f;if(c){f=$("<div/>").addClass("c-post-message").attr("id","c-post-message-id");var e=/\d+/;if(c.length<=3){$.ajax({async:true,url:"/components/content/code?code="+c+"&response=json",dataType:"json",success:function(g){f.html(g.message);if(f.html()!=""){$("#c-create").after(f);setTimeout(function(){$("#c-post-message-id").hide("blind",{},1000)},20000)}}})}else{f.html(c);if(f.html()!=""){$("#c-create").after(f);setTimeout(function(){$("#c-post-message-id").hide("blind",{},1000)},20000)}}}b.reset=true;b.initialized=true}b.loadComments()})};this.initCommentForm=function(){var b=this;if(b.user.id>0){if(!b.user.accountVerified){$("#c-create-text").html("You must ").append($("<a/>").attr("href","/components/account/forgotverificationcode/"+b.user.loginName).html("validate your email address")).append(" before you can publish a comment.");$("#c-create-form-container").remove()}else{$("#c-create-form").append($('<input type="hidden"/>').attr("name","objectId").attr("value",b.objectId)).append($('<input type="hidden"/>').attr("name","objectType").attr("value",b.objectType)).append($('<input type="hidden"/>').attr("name","source").attr("value",b.objectSource));$("#c-chars").html('You have <span id="c-char-count" style="color: #0000cc">1000 characters</span> remaining.');$("#c-text").keyup(function(d){var f=$("#c-text").val(),c=f.length,e,g="#00c";if(c>=1000){$("#c-text").val(f.substring(0,1000));$("#c-char-count").html("no more characters").css("color","#c00")}else{e=1000-c;if(e<200){g="#c00"}else{if(e<400){g="#903"}else{if(e<600){g="#606"}else{if(e<800){g="#309"}}}}$("#c-char-count").html(e+" character"+((e!=1)?"s":"")).css("color",g)}});if(b.thread.moderated){$("#c-text-container").append($('<div style="text-align: center; font-size: 0.9em; padding: 3px; margin: 5px 0; background-color: #ffc; border: 2px solid #fc3; color: #666; font-weight: bold;">This thread is moderated. Your comment will be reviewed before appearing online.</div>'))}}}else{$("#c-create-text").html("You must ").append($("<a/>").attr("href","/components/account/login").html("Login")).append(" or ").append($("<a/>").attr("href","/components/account/registration").html("Register")).append(" to publish a comment.");$("#c-create-form-container").remove()}$("#c-create").show()};this.loadComments=function(){$("#c-load-more-comments").html('<img src="/universal/images/bc-loading-video.gif" alt="Loading..." border="0" />');var c=this,b,d;c.commentTotal=c.thread.totalComments;c.sliceSize=c.thread.comments.length;c.sliceFloor=c.thread.start;$("#c-live").html((c.thread.totalComments==1)?"There is 1 comment":"There are "+c.thread.totalComments+" comments");if(c.reset){$("#c-view").html($("<div/>").attr("id","c-list"));$("#c-info-panel").show();c.reset=false}if(c.thread.comments.length>=1){b=c.thread.comments,d=new TPCDateFormat();$.each(b,function(e,f){d.setTime(f.postDate);_icon=c.createCommentIcon(f);_body=c.createCommentBody(f);$("#c-list").append($("<div/>").attr("id","c-"+f.id).addClass("tb-comment").append($("<a/>").attr("name","c-"+f.id)).append(_icon).append(_body));c.commentPosition++});if((c.sliceSize+c.sliceFloor)<c.commentTotal){$("#c-list").append(c.createLoadMoreCommentsAnchor())}$("#c-sort").show()}};this.resetWidgets=function(){this.reset=true;this.commentPosition=0;$("#c-view").html($("<div/>").attr("id","c-list").html($("<div />").addClass("comments-loading").attr("align","center").append($("<strong/>").html("Loading comments...")).append($("<br />")).append($("<img />").attr("src","/universal/images/bc-loading-video.gif").attr("alt","Loading...").attr("border","0"))))};this.buildCommentRequestUrl=function(){var b=this.ajaxUrl+"?objectId="+this.objectId+"&type="+this.objectType+"&key="+this.objectSource+"&start="+this.commentPosition+"&sort="+escape(this.sort);if(this.sliceSize>0){b+="&slice="+this.sliceSize}return b};this.createLoadMoreCommentsAnchor=function(){var e=this,b,d,c;b=this.sliceFloor+this.sliceSize+1;d=(b+this.sliceSize)-1;if(d>this.commentTotal){d=this.commentTotal}c="Click here to load comments "+b+"-"+d+" of "+this.commentTotal;return $("<a/>").attr("id","c-load-more-comments").attr("href","javascript:void(0);").bind("click",function(){e.loadThread();$(this).fadeOut("slow")}).html(c)};this.createCommentIcon=function(){var b=$("<div />").addClass("comment-icon").append($("<img/>").attr("src","/universal/images/woo/comment_user_32-rev.png").attr("alt","").attr("border","0"));return b};this.createCommentBody=function(i){var j=this,f,c,h,e,g,b,d;f=$("<div/>").addClass("site-comment");c=$("<div />").addClass("comment-name");c.append($("<span/>").addClass((!i.user)?"comment-anonymous":"comment-user").html((i.user)?i.user.loginName:(i.legacyName)?i.legacyName:"Anonymous")).append(" wrote:");h=$("<div/>").addClass("comment-body").html(i.body);e=$("<div/>").addClass("comment-footer");g=new TPCDateFormat();g.setTime(i.postDate);b=$("<div/>").addClass("comment-date").html(g.format("MMM dx, yyyy h:ii a"));d=$("<div/>").addClass("comment-abuse");if(j.thread.voteState=="open"){if(j.isUserLoggedIn()){d.append($('<a class="c-thumb-vote c-thumb-up-1" />').attr("id","c-thumb-up-"+i.id).attr("href","javascript:void(0);").html(i.scoreUp+"").bind("click",function(){var k=$(this).html();$(this).html('<img src="/universal/images/loading-12.gif" alt="Loading" border="0" />');j.vote(i.id,1,k)}));d.append($('<a class="c-thumb-vote c-thumb-down-1" />').attr("id","c-thumb-down-"+i.id).attr("href","javascript:void(0);").html(i.scoreDown+"").bind("click",function(){var k=$(this).html();$(this).html('<img src="/universal/images/loading-12.gif" alt="Loading" border="0" />');j.vote(i.id,-1,k)}))}else{d.append($('<span class="c-thumb-vote c-thumb-up-0" />').html(i.scoreUp+"").hover(function(){$(this).html('<a href="/components/account/login">Log in to vote</a>')},function(){$(this).html(i.scoreUp+"")}));d.append($('<span class="c-thumb-vote c-thumb-down-0" />').html(i.scoreDown+"").hover(function(){$(this).html('<a href="/components/account/login">Log in to vote</a>')},function(){$(this).html(i.scoreDown+"")}))}}if(j.thread.reportState=="open"||(j.thread.reportState=="user"&&j.isUserLoggedIn())){d.append($("<a/>").addClass("comment-report-abuse").html("Report Abuse").attr("href","javascript:void(0)").attr("id","c-abuse-"+i.id).bind("click",function(){$(this).html("Sending report...");j.reportAbuse(i.id)}))}if(j.user&&j.user.admin==1){d.append($("<a/>").addClass("comment-admin").html("Delete").attr("href","javascript:void(0);").attr("id","c-abuse-"+i.id).bind("click",function(){j.admrm(i.id)}))}e.append(b);e.append(d);e.append($("<br />").attr("clear","all"));f.append(c);f.append(h);f.append(e);return f};this.admrm=function(b){$.getJSON("/components/content/comment/admrm?cid="+b,function(c){var d=(c.message)?c.message:"No response from server. Please try again";$("#c-"+b).after($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+b).html(d));if(c.message){$("#c-"+b).hide("slow")}setTimeout("tpcc_hideReportedMessage("+b+")",5000)})};this.reportAbuse=function(b){$.getJSON("/components/content/comment/report?cid="+b,function(c){if(!c.data){var d=c.message;$("#c-"+b).after($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+b).html(d));$("#c-"+b).hide("slow");setTimeout("tpcc_hideReportedMessage("+b+")",5000)}else{$("#c-"+b).after($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+b).html("Thank you for reporting this comment."));$("#c-"+b).hide("slow");setTimeout("tpcc_hideReportedMessage("+b+")",5000)}$("#c-abuse-"+b).html("Report Abuse")})};this.vote=function(d,c,b){$.getJSON("/components/content/comment/vote?cid="+d+"&score="+c,function(f){var e=(c>0)?"#c-thumb-up-"+d:"#c-thumb-down-"+d;$(e).html((f.data)?++b:b);$("#c-report-msg-"+d).hide();$("#c-"+d).after($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+d).html(f.message));setTimeout("tpcc_hideReportedMessage("+d+")",5000)})}}function tpcc_hideReportedMessage(a){$("#c-report-msg-"+a).fadeOut("slow")}function tpcc_vote(c,b,a){$.getJSON("/components/content/comment/vote?cid="+c+"&score="+b,function(e){var d=(b>0)?"#c-thumb-up-"+c:"#c-thumb-down-"+c;$(d).html((e.data)?++a:a);$("#c-report-msg-"+c).hide();$("#c-"+c).after($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+c).html(e.message));setTimeout("tpcc_hideReportedMessage("+c+")",5000)})}var tpccd=null,tpccanchor="#comments";function tpcc_load(a){tpccd=a;if(tpccd.anchorPoint!==undefined){tpccanchor=tpccd.anchorPoint}if(tpccanchor.indexOf("#")!=0){tpccanchor="#"+tpccanchor}if(tpccd.start===undefined){tpccd.start=0}if(tpccd.sort===undefined){tpccd.sort=""}if(tpccd.format===undefined){tpccd.format="html"}$.ajaxSettings.cache=false;if(tpccd.start===undefined||tpccd.start==0){if(!tpccd.resort){$(tpccanchor).after($("<div/>").attr("id","tpcc-comment-form-container").load("/components/content/comment/new?objectId="+escape(tpccd.objectId)+"&objectType="+escape(tpccd.objectType)+"&source="+escape(tpccd.objectSource))).after($("<div/>").attr("id","tpcc-comment-list-container").html('<div class="c-loading-comments"><img src="/universal/images/loading-16.gif" style="margin-right:5px;vertical-align:middle;" />Loading comments</div>'))}else{$(tpccanchor).after($("<div/>").attr("id","tpcc-comment-list-container").html('<div class="c-loading-comments"><img src="/universal/images/loading-16.gif" style="margin-right:5px;vertical-align:middle;" />Loading comments</div>'))}tpcc_call_list(tpccd,"#tpcc-comment-list-container")}else{$("#c-load-more-comments").remove();if($("#c-user-ajax-comments").length){$("#c-user-ajax-comments").before($("<div/>").attr("id","tpcc-comment-list-container-"+tpccd.start).html('<div class="c-loading-comments"><img src="/universal/images/loading-16.gif" style="margin-right:5px;vertical-align:middle;" />Loading comments</div>'))}else{$("#c-list").append($("<div/>").attr("id","tpcc-comment-list-container-"+tpccd.start).html('<div class="c-loading-comments"><img src="/universal/images/loading-16.gif" style="margin-right:5px;vertical-align:middle;" />Loading comments</div>'))}tpcc_call_list(tpccd,"#tpcc-comment-list-container-"+tpccd.start)}}function tpcc_call_list(b,a){$.ajax({cache:false,url:"/components/content/comment/list",data:{objectId:b.objectId,objectType:b.objectType,source:b.objectSource,sort:b.sort,start:b.start,format:b.format},success:function(c){$(a).html(c)}})}function tpcc_init_form(){$("#c-publish").bind("click",function(){$("#c-publish").hide().after($("<span/>").css("float","right").html('<img src="/universal/images/loading-16.gif" style="margin-right:5px;vertical-align:middle;" />Communicating with server...'));$.post("/components/content/comment/new",{comment:$("#c-text").val(),objectId:tpccd.objectId,objectType:tpccd.objectType,source:tpccd.objectSource,format:tpccd.format,moderated:$("#c-moderated").val()},function(a){$("#tpcc-comment-form-container").html(a)},"html")});$("#c-chars").html('You have <span id="c-char-count" style="color: #0000cc">1000 characters</span> remaining!');$("#c-text").keyup(function(b){var d=$("#c-text").val(),a=d.length,c,e="#00c";if(a>=1000){$("#c-text").val(d.substring(0,1000));$("#c-char-count").html("no more characters").css("color","#c00")}else{c=1000-a;if(c<200){e="#c00"}else{if(c<400){e="#903"}else{if(c<600){e="#606"}else{if(c<800){e="#309"}}}}$("#c-char-count").html(c+" character"+((c!=1)?"s":"")).css("color",e)}})}function tpcc_init(){$(".c-thumb-up-1, .c-thumb-down-1").bind("click",function(){var d=$(this).html(),a="c-thumb-up-".length,c=1;if($(this).hasClass("c-thumb-down-1")){a="c-thumb-down-".length;c=-1}var b=$(this).attr("id").substring(a,$(this).attr("id").length);$(this).html('<img src="/universal/images/loading-12.gif" alt="Loading" border="0" />');tpcc_vote(b,c,d)});$(".c-thumb-up-0, .c-thumb-down-0").mouseover(function(){$(this).find("span").toggle()}).mouseout(function(){$(this).find("span").toggle()});$(".comment-report-abuse").bind("click",function(){var a=$(this).attr("id");a=a.substr("c-abuse-".length,a.length);tpcc_report(a)});$("#c-sort").change(function(){$("#tpcc-comment-list-container").remove();tpcc_load({sort:$(this).val(),start:0,objectId:tpccd.objectId,objectType:tpccd.objectType,objectSource:tpccd.objectSource,format:tpccd.format,anchorPoint:tpccd.anchorPoint,resort:true})})}function tpcc_report(a){$.getJSON("/components/content/comment/report?cid="+a,function(b){if(!b.data){var c=b.message;$("#c-"+a).after($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+a).html(c));$("#c-"+a).hide("slow");setTimeout("tpcc_hideReportedMessage("+a+")",5000)}else{$("#c-"+a).after($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+a).html("Thank you for reporting this comment."));$("#c-"+a).hide("slow");setTimeout("tpcc_hideReportedMessage("+a+")",5000)}$("#c-abuse-"+a).html("Report Abuse")})}function tpcc_post_comment(f,e){$("#c-list").append($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+f).html('<img src="/universal/images/loading-16.gif" style="margin-right:5px;vertical-align:middle;" />Formatting your comment...'));if(!$("#c-user-ajax-comments").length){$("#c-list").append($("<a/>").attr("id","c-user-ajax-comments").attr("name","ugc"))}if(!e){$.get("/components/content/comment/fetch",{cid:f},function(g){$("#c-list").append(g);$("#c-report-msg-"+f).fadeOut("slow");$("#c-text").val("")},"html");var c=$("#c-live").html();var d=/(\d+)/i;if(c.search(d)){var a=d.exec(c);var b=a[1];b++;$("#c-live").html("There "+((b==1)?"is ":"are ")+b+" comment"+((b==1)?"":"s"))}}}function tpcc_admrm(a){$.getJSON("/components/content/comment/admrm?cid="+a,function(b){var c=(b.message)?b.message:"No response from server. Please try again";$("#c-"+a).after($("<div/>").addClass("c-reported-message").attr("id","c-report-msg-"+a).html(c));if(b.message){$("#c-"+a).hide("slow")}setTimeout("tpcc_hideReportedMessage("+a+")",5000)})}function tpcc_clear_dupes(){$(".tb-ugc").each(function(){var a=$(this).attr("id");a=a.substring(4);if($("#c-"+a).length){if(tpccd.format=="html"){$(this).effect("transfer",{to:"#c-"+a,className:"c-effects-transfer"},500);$("#c-"+a).effect("highlight",{},500)}$(this).fadeOut().remove()}})};
