Ext.ns("SP.member");
SP.member.loginJoinPanel=function(props){if(!props)props={};var doVerifyEmail=function(email){Ext.Ajax.request({url:SP.link.pURL("member","action/memberActions"),params:{action:"emailVerify",email:email},failure:function(fp,o){Ext.Msg.alert("Problem","Unable to contact server, please try later.")},success:function(response,opts){var obj=Ext.decode(response.responseText);if(obj.success=="true")Ext.Msg.alert("Success","A verification email has been sent to: "+email+". Please click on the link provided in the email to verify your account");else Ext.Msg.alert("Problem",
"Sorry, there was a problem requesting a new verification email: "+obj.message)}})};var joinForm=new Ext.form.FormPanel({baseCls:"x-plain",labelWidth:85,url:SP.link.pURL("member","action/memberActions?action=join"),defaultType:"textfield",id:"joinForm",items:[{fieldLabel:"Email",name:"email",anchor:"90%",vtype:"email",allowBlank:false,validateOnBlur:false},{fieldLabel:"Password",name:"passWord",anchor:"90%",inputType:"password",allowBlank:false,validateOnBlur:false},{fieldLabel:"Display Name",name:"displayName",
anchor:"90%",allowBlank:false,validateOnBlur:false},{boxLabel:"I agree to "+SP.link.realmLink(null,"Terms of Service","terms")+" and "+SP.link.realmLink(null,"Privacy Policy","privacy"),name:"tosAgree",anchor:"95%",xtype:"checkbox",inputValue:"TRUE",checked:true}],buttons:[{text:"Join",cls:"joinButton",handler:function(but,event){joinForm.getForm().submit({method:"GET",waitMsg:"Submitting...",reset:false,success:function(form,action){if(action.result.success=="false")if(action.result.errorCode==3)Ext.Msg.alert("Problem With Join",
action.result.message,function(){if(forgotPassForm.hidden)forgotPassForm.show();email=forgotPassForm.getForm().findField("email");email.setValue(form.findField("email").getValue());email.focus()});else Ext.Msg.alert("Problem With Join",action.result.message);else{Ext.Msg.alert("Congratulations!",action.result.message);loginWindow.close()}},failure:function(form,action){switch(action.failureType){case Ext.form.Action.CLIENT_INVALID:Ext.Msg.alert("Failure","You must fill in all fields.");break;case Ext.form.Action.CONNECT_FAILURE:Ext.Msg.alert("Failure",
"Server communication failed, please try later.");break;case Ext.form.Action.SERVER_INVALID:Ext.Msg.alert("Failure",action.result.message);break}}})}}]});var loginForm=new Ext.form.FormPanel({baseCls:"x-plain",labelWidth:55,id:"loginForm",url:SP.link.pURL("member","action/memberActions?action=memberLogin"),defaultType:"textfield",items:[{fieldLabel:"Email",name:"userName",anchor:"80%",allowBlank:false,validateOnBlur:false},{fieldLabel:"Password",name:"passWord",anchor:"80%",inputType:"password",allowBlank:false,
validateOnBlur:false,listeners:{specialkey:function(field,e){if(e.getKey()==e.ENTER){var form=field.ownerCt.getForm();Ext.getCmp("lSubmit").fireEvent("click")}}}},{xtype:"displayfield",name:"forgotPass",html:'<a href="#" id="sp_forgotpass" style="display:inline-block; z-index:101; margin-left:-80px; *margin-left:-87px; */IE/*">Forgot password?</a>'}],buttons:[{text:"Login",id:"lSubmit",cls:"signInButton",listeners:{click:function(but,event){loginForm.getForm().submit({method:"GET",waitMsg:"Submitting...",
reset:false,success:function(form,action){if(action.result.success=="false")Ext.Msg.alert("Failure",action.result.message);else{SP.active.memberID=action.result.uID;SP.active.ajaxLoggedIn=true;loginWindow.close();if(typeof props.loginSuccess!="undefined")props.loginSuccess();else window.location.reload()}},failure:function(form,action){switch(action.failureType){case Ext.form.Action.CLIENT_INVALID:Ext.Msg.alert("Failure","You must fill in both fields.");break;case Ext.form.Action.CONNECT_FAILURE:Ext.Msg.alert("Failure",
"Server communication failed, please try later.");break;case Ext.form.Action.SERVER_INVALID:if(action.result.loginStatus==SP.def.EMAIL_UNAUTHED){email=action.result.emailAddress;Ext.Msg.confirm("Account Not Yet Verified","This account has not yet been verified. You must click on the link in the verification email sent to "+email+". Do you want to receive this email again?",function(id){if(id=="yes")doVerifyEmail(email)})}else Ext.Msg.alert("Failure",action.result.message);break}}})}}}]});var forgotPassForm=
new Ext.form.FormPanel({baseCls:"x-plain",labelWidth:55,id:"forgotPassForm",url:SP.link.pURL("member","action/memberActions?action=forgotPass"),defaultType:"textfield",hidden:true,items:[{fieldLabel:"Email",name:"email",anchor:"80%",vtype:"email",allowBlank:false,validateOnBlur:false,listeners:{specialkey:function(field,e){if(e.getKey()==e.ENTER){var form=field.ownerCt.getForm();Ext.getCmp("fgSubmit").fireEvent("click")}}}}],buttons:[{text:"Submit",id:"fgSubmit",cls:"submitButton",listeners:{click:function(){forgotPassForm.getForm().submit({method:"GET",
waitMsg:"Submitting...",reset:false,success:function(form,action){if(action.result.success=="false")Ext.Msg.alert("Failure",action.result.message);else{Ext.Msg.alert("Success",action.result.message);form.reset()}},failure:function(form,action){switch(action.failureType){case Ext.form.Action.CLIENT_INVALID:Ext.Msg.alert("Failure","Please enter your email address correctly.");break;case Ext.form.Action.CONNECT_FAILURE:Ext.Msg.alert("Failure","Server communication failed, please try later.");break;case Ext.form.Action.SERVER_INVALID:Ext.Msg.alert("Failure",
action.result.message);break}}})}}}]});if(props.loginSocial)SP.link.ajaxAction("social","status","loginButtons",{success:function(obj,response,opts){loginButtons=obj.loginButtons;loginForm.add({xtype:"displayfield",name:"social",html:loginButtons});loginForm.doLayout()}});loginForm.getForm().findField("forgotPass").addListener("afterrender",function(){Ext.get("sp_forgotpass").on("click",function(){if(forgotPassForm.hidden)forgotPassForm.show();else forgotPassForm.hide()})});var loginWindow=new Ext.Window({id:"loginBox",
width:750,layout:"column",modal:true,bodyStyle:"padding:10px;",plain:false,shadow:true,maximizable:false,minimizable:false,resizable:false,draggable:false});if(!Ext.isEmpty(props.joinPanel)&&props.joinPanel==false){loginWindow.setWidth(350);loginWindow.add({title:"Sign In",items:[loginForm,forgotPassForm]})}else loginWindow.add({bodyStyle:"margin-right:30px;",title:'Join Today <span class="text">(FREE)</font>',columnWidth:0.5,items:[joinForm]},{title:"<div>",columnWidth:0.05},{title:"Sign In",columnWidth:0.4,
items:[loginForm,forgotPassForm]});loginWindow.addListener("show",function(){if(props.loginFocus==true)loginForm.getForm().findField("userName").focus(false,100);else joinForm.getForm().findField("email").focus(false,100)});return loginWindow};Ext.ns("SP.member");SP.member.logout=function(props){if(!SP.isMember())return true;if(typeof props=="undefined")props={success:function(obj,response,opts){window.location.reload()}};SP.link.ajaxAction("member","memberActions","memberLogout",props);return true};SP.member.login=function(props){if(SP.isMember())return true;if(typeof props=="undefined")props={};props.loginFocus=true;var loginWindow=SP.member.loginJoinPanel(props);loginWindow.show();return true};
SP.member.join=function(props){if(SP.isMember())return true;if(typeof props=="undefined")props={};props.joinFocus=true;var loginWindow=SP.member.loginJoinPanel(props);loginWindow.show();return true};SP.member.doSetInfo=function(props,maction){props.params={itype:props.type,itargets:props.targets};SP.link.ajaxAction("member","infoActions",maction,props)};SP.member.setInfo=function(props){SP.member.doSetInfo(props,"setInfo")};SP.member.addInfo=function(props){SP.member.doSetInfo(props,"addInfo")};

