CS.PAGES.AUTH={};CS.PAGES.AUTH.REGISTER=Class.create();CS.PAGES.AUTH.REGISTER={init:function(){var C=$("form-register");var B='<a href="/legal/terms" title="Click this link to view the Terms of Service" target="_blank">Terms of Service</a>';var A="I agree to the "+B;this.formObj=CS.UI.FORMS.build({buttons:{save:{label:"Register"},cancel:{label:"Cancel"}},settings:{startineditmode:true,nofocusonload:false},form:{register:{fields:{username:{label:"Username",value:"",info:"5-20 characters; letters and numbers only, no spaces.",type:"text",required:true},email:{label:"Email",value:"",example:"foobear@clearspring.com",type:"text",required:true},confirm_email:{label:"Re-type Email",value:"",type:"text",required:true},password:{label:"Password",value:"",type:"password",required:true},confirm_password:{label:"Re-type Password",value:"",type:"password",required:true},tos:{label:"",value:0,checkboxLabel:A,type:"checkbox",required:true}}}},saveFunction:this.save.bind(this),cancelFunction:this.cancel.bind(this),validateFunction:this.validate.bind(this)});if(C){C.appendChild(this.formObj.div);this.formObj.init()}},cancel:function(){window.location="/";return false},save:function(A){data={name:this.formObj.getValue("register","username").toLowerCase().strip(),email:this.formObj.getValue("register","email").strip(),password:this.formObj.getValue("register","password",true),acceptedAgreement:this.formObj.getValue("register","tos"),campaignCode:CS.UTIL.COOKIES.getCookie("cmpid")||""};CS.DATA.call("user.registration.request",data,this._post.bind(this,A))},_post:function(C,A){if(A.success){C({message:"Thank you for registering.",success:A.success});this.UserEmail=this.formObj.getValue("register","email");this.showSuccess()}else{var B=(A.message&&A.message.indexOf("Not enough non-alpha")>-1)?"Your password should contain at least 1 non-alphabetical character.":"There was an error processing your registration.";B=(A.message&&A.message.indexOf("Username already in use")>-1)?"That username is already in use.  Please try again.":B;C({setfocus:{groupname:"register",fieldname:"username"},message:B,success:A.success})}},validate:function(B,A,F,D){switch(A){case"username":response=CS.UTIL.VALIDATOR.username(F,{name:D});if(response.feedbackType===0){return response}response=CS.UTIL.VALIDATOR.strLength(F,{minLength:5,name:D});if(response.feedbackType===0){return response}response=CS.UTIL.VALIDATOR.maxStrLength(F,{maxLength:20,name:D});if(response.feedbackType===0){return response}break;case"email":response=CS.UTIL.VALIDATOR.email(F,{minLength:5,name:D});if(response.feedbackType===0){return response}break;case"confirm_email":if(this.formObj.getValue("register","email")!=this.formObj.getValue("register","confirm_email")){response={feedbackType:FDBK_BAD,feedbackText:"Your email addresses do not match."};return response}break;case"password":var E=this.formObj.getValue("register","password");var C=this.formObj.getValue("register","confirm_password");response=CS.UTIL.VALIDATOR.passwordPair(E,C);if(response.feedbackType===0){return response}break;case"tos":if(!this.formObj.getValue("register","tos")){response={feedbackType:FDBK_BAD,feedbackText:"You must agree to the Terms of Service."};return response}default:break}return CS.UTIL.VALIDATOR.goodFeedback},showSuccess:function(){var A="Thank you for registering with the Clearspring Community Platform.\r\n<br /><br />An email has been sent to <strong>"+this.UserEmail+"</strong>.\r\n<br /><br />\r\nPlease click the <strong>validation link</strong> in the email to confirm your email address.\r\n<br /> <br />\r\n";var B='<h2 title="Register with Clearspring">Your Registration was Successful!</h2>\r\n<div id="fdbk" style="width:50%;text-align:left;"></div>\r\n<div class="pad10">\r\n    <div id="thankyou">'+A+"</div>\r\n    <br /><br />\r\n</div>";setTimeout(this.redirectToConsole,1000)},redirectToConsole:function(){window.location="/csmanager"},_eof:{}};Event.observe(window,"load",CS.PAGES.AUTH.REGISTER.init.bindAsEventListener(CS.PAGES.AUTH.REGISTER));
