CS.PAGES.COMMENTS={};CS.PAGES.COMMENTS.POST=Class.create();CS.PAGES.COMMENTS.POST={init:function(){div=$("comments-post");this.formObj=CS.UI.FORMS.build({buttons:{save:{label:"Submit"}},settings:{startineditmode:true,nofocusonload:true},form:{post:{grouplabel:"",fields:{name:{label:"Name",value:"",example:"John, J. Doe, Wally Widget, etc",type:"text",required:true},comment:{label:"Comment",value:"",type:"textarea",required:true}}}},saveFunction:this.save.bind(this),cancelFunction:this.cancel.bind(this),validateFunction:this.validate.bind(this)});if(div){div.appendChild(this.formObj.div);this.formObj.init()}},cancel:function(){window.location=CSD.thispage.referer||"";return false},save:function(A){data={name:this.formObj.getValue("post","name"),comment:this.formObj.getValue("post","comment"),wid:CSD.thiswidget.wid};CS.DATA.call("widget.comments.add",data,this._post.bind(this,A))},_post:function(B,A){if(A.success){B({feedback:{message:"Thank you for posting your comment.",type:"ok"}});this._showSuccess()}else{B({setfocus:{groupname:"post",fieldname:"name"},messages:{post:{message:"Please enter your name and comment.",type:"failure"}}})}},_showSuccess:function(){$("widget-comments").show();if($("noComment")){$($("noComment").parentNode).remove()}var B=this.formObj.getValue("post","name");var C=this.formObj.getValue("post","comment");var A="Thank you for posting your comment!";C=CS.UTIL.breakLines(C,80);new Insertion.Top("commentsBody",'<tr><td class="newPost">'+B+'</td><td class="newPost">'+C+"</td></tr>");$("comments-post").hide();CSD.thiswidget.stats.totalComments++;var E=CSD.thiswidget.stats.totalComments;var D=(E==1)?" Comment":" Comments";$("commentsCountText").innerHTML=E+D;CS.UI.scrollTo("comments");CS.UI.MESSAGES.feedback("fdbk-post",A,true);this.formObj.setValue("post","comment","")},validate:function(B,A,E,C){switch(A){case"name":var D="^[\\w\\.\\-\\,\\ ]*$";response=CS.UTIL.VALIDATOR.isValidHumanName(E,{name:C});if(response.feedbackType===0){return response}response=CS.UTIL.VALIDATOR.strLength(E,{minLength:2,name:C});if(response.feedbackType===0){return response}break;case"comment":response=CS.UTIL.VALIDATOR.strLength(E,{minLength:5,name:C});if(response.feedbackType===0){return response}response=CS.UTIL.VALIDATOR.maxStrLength(E,{minLength:255,name:C});if(response.feedbackType===0){return response}break;default:break}return CS.UTIL.VALIDATOR.goodFeedback},_eof:{}};Event.observe(window,"load",CS.PAGES.COMMENTS.POST.init.bindAsEventListener(CS.PAGES.COMMENTS.POST));