KUS.LoginForm=Ext.extend(Ext.FormPanel,{id:"login-form",autoHeight:true,bodyStyle:{"padding-left":"10px"},buttonAlign:"center",constructor:function(a){this.addEvents("loginSuccess");this.buttons=[this.getForgotPasswordButton(),this.getLoginButton()];this.items=[this.getEmailField(),this.getPasswordField()];KUS.LoginForm.superclass.constructor.call(this,a);this.on("afterrender",function(){new Ext.KeyMap(this.getEl(),{key:Ext.EventObject.ENTER,handler:this.submitLogin.createDelegate(this)})},this)},defaults:{allowBlank:false,anchor:"-20",msgTarget:"side"},forgotPasswordCallback:function(b,d,a){this.getEl().unmask();if(!d){Ext.Msg.alert("Error","There was a problem communication with the server");return false}var c=Ext.decode(a.responseText);if(!c.success){Ext.Msg.alert("Error",c.err_msg);return false}this.forgotPasswordSuccess()},forgotPasswordSuccess:function(){Ext.Msg.alert("Confirmation","We have sent an email to the address specified. Please follow the instructions in your email to retrieve your password.")},frame:true,getEmailField:function(){if(!this.emailField){this.emailField=new Ext.form.TextField({fieldLabel:"<b>E-Mail Address</b>",name:"email",vtype:"email"})}return this.emailField},getForgotPasswordButton:function(){if(!this.forgotPasswordButton){this.forgotPasswordButton=new Ext.Action({handler:this.submitForgotPassword,iconCls:"icon_help",scope:this,text:"Forgot Password"})}return this.forgotPasswordButton},getLoginButton:function(){if(!this.loginButton){this.loginButton=new Ext.Action({formBind:true,handler:this.submitLogin,iconCls:"icon_accept",scope:this,text:"Login"})}return this.loginButton},getPasswordField:function(){if(!this.passwordField){this.passwordField=new Ext.form.TextField({fieldLabel:"<b>Password</b>",inputType:"password",name:"password"})}return this.passwordField},iconCls:"icon_lock",labelWidth:110,loginCallback:function(b,d,a){this.getEl().unmask();if(!d){Ext.Msg.alert("Error","There was a problem communication with the server");return false}var c=Ext.decode(a.responseText);if(!c.success){Ext.Msg.alert("Error",c.err_msg);return false}this.loginSuccess()},loginSuccess:function(){this.fireEvent("loginSuccess");window.location.href=window.location.href},monitorPoll:300,monitorValid:true,submitForgotPassword:function(){if(!this.emailField.isValid()){return false}this.getEl().mask("Processing...");var a={handler:"Customers",method:"forgotPassword",email:this.emailField.getValue()};var b=this.forgotPasswordCallback.createDelegate(this);Ext.Ajax.request({url:"/ajax",params:a,callback:b})},submitLogin:function(){if(!this.form.isValid()){return false}this.getEl().mask("Logging in...");var a=this.form.getValues();a.handler="Customers";a.method="login";var b=this.loginCallback.createDelegate(this);Ext.Ajax.request({url:"/ajax",params:a,callback:b})},title:"Login Form"});KUS.RegisterForm=Ext.extend(Ext.FormPanel,{id:"register-form",autoHeight:true,bodyStyle:{"padding-left":"10px"},buttonAlign:"center",constructor:function(a){this.addEvents("registerSuccess");this.buttons=[this.getRegisterButton()];this.items=[this.getEmailField(),this.getPasswordField(),this.getConfirmPasswordField(),this.getMailingListField()];KUS.RegisterForm.superclass.constructor.call(this,a);this.on("afterrender",function(){new Ext.KeyMap(this.getEl(),{key:Ext.EventObject.ENTER,handler:this.submitRegister.createDelegate(this)})},this)},defaults:{allowBlank:false,msgTarget:"side"},frame:true,getConfirmPasswordField:function(){if(!this.confirmPasswordField){this.confirmPasswordField=new Ext.form.TextField({anchor:"-20",fieldLabel:"<b>Confirm Password</b>",name:"confirm_password",inputType:"password"})}return this.confirmPasswordField},getEmailField:function(){if(!this.emailField){this.emailField=new Ext.form.TextField({anchor:"-20",fieldLabel:"<b>E-Mail Address</b>",name:"email",vtype:"email"})}return this.emailField},getMailingListField:function(){if(!this.mailingListField){this.mailingListField=new Ext.form.Checkbox({boxLabel:'Receive special offers and updates via email.<br /><a href="javascript: privacy_policy();">Privacy Policy</a>',ctCls:"center",hideLabel:true,inputValue:1,name:"mailing_list"})}return this.mailingListField},getPasswordField:function(){if(!this.passwordField){this.passwordField=new Ext.form.TextField({anchor:"-20",fieldLabel:"<b>Password</b>",inputType:"password",name:"password"})}return this.passwordField},getRegisterButton:function(){if(!this.registerButton){this.registerButton=new Ext.Action({formBind:true,handler:this.submitRegister,iconCls:"icon_accept",scope:this,text:"Register"})}return this.registerButton},iconCls:"icon_application_key",labelWidth:110,monitorPoll:300,monitorValid:true,registerCallback:function(b,d,a){this.getEl().unmask();if(!d){Ext.Msg.alert("Error","There was a problem communication with the server");return false}var c=Ext.decode(a.responseText);if(!c.success){Ext.Msg.alert("Error",c.err_msg);return false}this.registerSuccess()},registerSuccess:function(){this.fireEvent("registerSuccess");window.location.href=window.location.href},submitRegister:function(){if(!this.form.isValid()){return false}this.getEl().mask("Processing...");var a=this.form.getValues();if(a.password!=a.confirm_password){Ext.Msg.alert("Error","Password fields do not match.");this.getEl().unmask();return false}delete (a.confirm_password);a.handler="Customers";a.method="register";var b=this.registerCallback.createDelegate(this);Ext.Ajax.request({url:"/ajax",params:a,callback:b})},title:"Register Form"});KUS.LoginOrRegisterWindow=Ext.extend(Ext.Window,{autoHeight:true,bodyCssClass:"p-5",buttonAlign:"center",closable:true,constructor:function(a){this.buttons=[this.getCancelButton()];this.items=[this.getLoginForm({columnWidth:0.5}),{html:"&nbsp;",style:"background-color: transparent;",bodyStyle:"background-color: transparent;",border:false,bodyBorder:false,shadow:false,width:10},this.getRegisterForm({columnWidth:0.5})];KUS.LoginOrRegisterWindow.superclass.constructor.call(this,a)},frame:true,getCancelButton:function(){if(!this.cancelButton){this.cancelButton=new Ext.Action({handler:this.close,iconCls:"icon_cancel",scope:this,text:"Cancel"})}return this.cancelButton},getLoginForm:function(a){if(!this.loginForm){this.loginForm=new KUS.LoginForm(a)}return this.loginForm},getRegisterForm:function(a){if(!this.registerForm){this.registerForm=new KUS.RegisterForm(a)}return this.registerForm},layout:"column",modal:true,title:"Please Login or Register to Continue...",width:760});KUS.MakeAnOffer.LoginForm=Ext.extend(KUS.LoginForm,{loginSuccess:function(){logged_in=true;this.fireEvent("loginSuccess")}});KUS.MakeAnOffer.RegisterForm=Ext.extend(KUS.RegisterForm,{registerSuccess:function(){logged_in=true;this.fireEvent("registerSuccess")}});KUS.MakeAnOffer.LoginOrRegisterWindow=Ext.extend(KUS.LoginOrRegisterWindow,{constructor:function(a){this.setOfferConfig(a);KUS.MakeAnOffer.LoginOrRegisterWindow.superclass.constructor.call(this)},getLoginForm:function(a){if(!this.loginForm){this.loginForm=new KUS.MakeAnOffer.LoginForm(a);this.loginForm.on("loginSuccess",function(){this.close();var b=new KUS.MakeAnOffer.OfferWindow(this.getOfferConfig());b.show()},this)}return this.loginForm},getOfferConfig:function(){return this.offerConfig},getRegisterForm:function(a){if(!this.registerForm){this.registerForm=new KUS.MakeAnOffer.RegisterForm(a);this.registerForm.on("registerSuccess",function(){this.close();var b=new KUS.MakeAnOffer.OfferWindow(this.getOfferConfig());b.show()},this)}return this.registerForm},setOfferConfig:function(a){this.offerConfig=a}});
