Ext.namespace("THSite.traveler");THSite.traveler.TravelerRegistrationPanel=Ext.extend(Ext.Panel,{constructor:function(b){var c,a;this.registrationCompleteUrl=b.registrationCompleteUrl;this.entityForm=new Ext.form.FormPanel({labelSeparator:" ",defaultType:"textfield",defaults:{anchor:"100%"},labelWidth:200,items:[{xtype:"hidden",name:"id",value:0,dataIndex:"id"},{xtype:"hidden",name:"version",value:0,dataIndex:"version"},{xtype:"hidden",name:"type",value:2,dataIndex:"type"},{fieldLabel:"Name*",name:"name",allowBlank:false,dataIndex:"name",minLength:1,maxLength:50},{fieldLabel:"Login*",name:"logon",allowBlank:false,dataIndex:"logon",minLength:4,maxLength:100,validator:THSite.misc.Utils.loginValidator},c=new Ext.form.TextField({fieldLabel:"Password*",inputType:"password",minLength:4,maxLength:20,allowBlank:false,dataIndex:"newPassword1",validator:function(d){return THSite.misc.Utils.passwordFieldsValidator(d,c,a)}}),a=new Ext.form.TextField({fieldLabel:"Confirm Password*",inputType:"password",minLength:4,maxLength:20,allowBlank:false,dataIndex:"initialPassword",validator:function(d){return THSite.misc.Utils.passwordFieldsValidator(d,c,a)}}),{fieldLabel:"Email*",allowBlank:false,name:"email",vtype:"email",dataIndex:"email",minLength:0,maxLength:100},{fieldLabel:"Text from the image below*",name:"captcha",dataIndex:"captcha",minLength:0,maxLength:10}]});THSite.traveler.TravelerRegistrationPanel.superclass.constructor.call(this,{renderTo:b.renderTo,cls:"content-text",bodyStyle:"margin-left: 10px; margin-right: 10px",border:false,defaults:{border:false},items:[{html:'					<div class="content-header-with-border">						<h1>New Member Registration</h1>						<h2>*Required Fields</h2>						<div style="clear:both;"/>					</div>'},this.entityForm,{html:"The letters are not case-sensitive. Do not type spaces between the numbers and letters.",anchor:"100%",cls:"form-field-help",bodyStyle:"padding: 0px 0px 5px 205px"},{layout:"hbox",layoutConfig:{align:"middle",pack:"start"},height:60,items:[{width:180,border:false},{width:130,height:40,border:false,html:'<img id="traveler_registration_captcha" src="kaptcha.jpg"></img>'},{border:false,xtype:"button",text:"Try another image",handler:function(){this.refreshCaptcha()},scope:this}]},this.agreeCb=new Ext.form.Checkbox({boxLabel:'By checking this box I agree to the <a href="/travel-host/termsofuse">TRAVELHOST Terms of Use</a>.'})],buttonAlign:"right",buttons:[{text:"Cancel",handler:function(){history.back()},scope:this},{text:"Sign Up Now",handler:function(){this.onEntitySave()},scope:this}]})},refreshCaptcha:function(){var a=Ext.query("img#traveler_registration_captcha");if(a&&a[0]){a[0].src=String.format("kaptcha.jpg?dc={0}",new Date().getTime())}},onEntitySave:function(){if(!this.agreeCb.getValue()){Ext.MessageBox.alert("Form Validation","Check the box if you are agree with TRAVELHOST Terms of Use");return false}if(!this.entityForm.getForm().isValid(false)){Ext.MessageBox.alert("Form Validation","The form is not valid");return false}var a=false;var b=this.adjustEntityOnSave(Ext.apply(new User,this.getEntity()));b.type="TRAVELER";try{this.saveEntity(b);a=true}catch(c){THSite.remote.Pointcuts.handleDwrError(c,"Server problem while saving "+this.getEntityDisplayName(b),"Unable to create new member "+this.getEntityDisplayName(b))}if(a){this.entity=b;THSite.misc.Utils.goToUrl(String.format("{0}?email={1}&logon={2}",this.registrationCompleteUrl,b.email,b.logon))}return a},saveEntity:function(b){var a=false;var c=Ext.apply(new EntityBatch(),{serviceName:"TravelerPublicService",entity:b});BatchEntityService.execute(b.id,b.version,[c],{async:false,callback:function(d){b.id=d.id;b.version=d.version;a=true},errorHandler:function(e,d){error=d}});if(!a){throw error}},adjustEntityOnSave:function(a){if(typeof a.name=="string"){a.name=a.name.trim()}return a},getEntity:function(){return THSite.misc.Utils.getDataObjectFromForm(this.entityForm)},getEntityDisplayName:function(a){return a&&a.name?a.name:""}});
