
function C_ChangeTeamsDialog()
{this.window=null;var helpmsg="<div class=help-title>Share Your Profile with Two Teams</div> \
                   <div class=help-body> \
                   If you belong to a racing team and a workplace commuter team, you can share your \
                   profile between both teams by checking \"share my profile between two teams\" \
                   <ul class=help>\
                   <li class=help>Your profile will appear in both team rosters.\
                   <li class=help>Your race results will appear on your racing team\'s page.\
                   <li class=help>Your commute and errand rides will count towards your commuting team\'s stats.\
                   </ul></div>";g_helpDialog=new C_HelpDialog(helpmsg);this.show=function(params)
{this.redirectToHome=params.redirectToHome;this.newTeamDomain=""
if(!this.window)
{this.dsTeamLookup=new Ext.data.JsonStore({root:'results',totalProperty:'rowcount',idProperty:'TeamID',fields:[{name:'TeamID',type:'int'},{name:'TeamName'},{name:'TeamType'},{name:'Domain'}],proxy:new Ext.data.HttpProxy({url:'/data/lookup-team.php'})});this.form=new Ext.form.FormPanel({baseCls:'x-plain',url:'/data/change-teams.php',labelAlign:'right',labelWidth:110,bodyStyle:'padding:0px',buttonAlign:'center',baseParams:{},items:[{xtype:'container',cls:'form-spacer',height:10},{xtype:'remotecombobox',fieldLabel:'Racing Team',displayField:'TeamName',valueField:'TeamID',hiddenName:'RacingTeamID',forceSelection:true,maxHeight:450,width:300,listWidth:350,pageSize:100,triggerClass:'x-form-search-trigger',emptyText:'Type the first few letters of the team name...',allowBlank:false,blankText:'You must select a team',store:this.dsTeamLookup,listeners:{scope:this,select:function(c,r,i){if(!Ext.getCmp('two-teams-cb').getValue())
{this.form.getForm().findField('CommutingTeamID').setValue(r.data.TeamID);this.form.getForm().findField('CommutingTeamID').setRawValue(r.data.TeamName);}
this.newTeamDomain=r.data.Domain;}},tpl:'<tpl for="."><div class="x-combo-list-item" style="border-bottom:1px solid #ccc"><table cellpadding=0 cellspacing=0><tr>\
                           <td><div class="ellipses" style="padding-left:5px;width:210px">\
                             <div class="find-name">{TeamName}</div>\
                             <div class="find-info">{TeamType}</div>\
                           </div></td>\
                           <td style="height:32px;width:120px;text-align:center"><img src="'+getFullDomainRoot()+'/imgstore/team-logo/fit/{TeamID}.png"></td>\
                         </tr></table>\
                         </div></tpl>'},{xtype:'panel',id:'team2',layout:'form',baseCls:'x-plain',collapsed:true,items:[{xtype:'remotecombobox',fieldLabel:'Commuting Team',displayField:'TeamName',valueField:'TeamID',hiddenName:'CommutingTeamID',forceSelection:true,maxHeight:450,width:300,listWidth:350,pageSize:100,triggerClass:'x-form-search-trigger',emptyText:'Type the first few letters of the team name...',allowBlank:false,blankText:'You must select a team',store:this.dsTeamLookup,tpl:'<tpl for="."><div class="x-combo-list-item" style="border-bottom:1px solid #ccc"><table cellpadding=0 cellspacing=0><tr>\
                               <td><div class="ellipses" style="padding-left:5px;width:210px">\
                                 <div class="find-name">{TeamName}</div>\
                                 <div class="find-info">{TeamType}</div>\
                               </div></td>\
                               <td style="height:32px;width:120px;text-align:center"><img src="'+getFullDomainRoot()+'/imgstore/team-logo/fit/{TeamID}.png"></td>\
                             </tr></table>\
                             </div></tpl>'}]},{xtype:'container',cls:'form-spacer',height:5},{xtype:'container',layout:'column',items:[{xtype:'container',html:'&nbsp;',width:15},{xtype:'checkbox',id:'two-teams-cb',hideLabel:true,boxLabel:'Share my profile between two teams',width:200,listeners:{scope:this,check:this.checkMultipleTeams}},{xtype:'container',style:'padding-top:3px',html:'<span id="help-btn" onclick="g_helpDialog.show({ ypos:100, width:530, animateTarget: \'help-btn\' });">info</span>'}]},{xtype:'container',cls:'form-spacer',height:15},{xtype:'fieldset',title:'Create New Team',style:'margin-bottom:5px',items:[{xtype:'displayfield',hideLabel:true,style:'font: 12px arial, \'helvetica neue\', sans-serif;color:#666',html:'If your team is not on RideNet yet, send as an email <a href="mailto:info@ridenet.net" style="color:blue"> \
                               info@ridenet.net</a> and we\'ll create a team for you.'}]},{xtype:'container',id:'status-msg2',style:'display:none',cls:'form-status'}],buttons:[{text:'Change Teams',width:100,handler:this.saveButtonClick,scope:this},{text:'Cancel',handler:this.cancelButtonClick,scope:this}],listeners:{scope:this,actioncomplete:function(form,action){if(action.type=="load"){this.window.getEl().unmask();}},actionfailed:function(form,action){if(action.type=="load"){window.location.href='/login?expired=1'}}}});this.window=new Ext.Window({title:'Change Teams',width:460,y:params.ypos,autoHeight:true,forceLayout:true,resizable:false,closeAction:'hide',modal:true,bodyStyle:'padding:5px;',items:this.form});this.window.on('show',function(){this.form.getForm().reset();this.checkMultipleTeams();this.setMessage('','black');},this);}
this.window.show(params.animateTarget);}
this.checkMultipleTeams=function()
{if(Ext.getCmp('two-teams-cb').getValue())
{Ext.getCmp('team2').expand(true);this.form.getForm().findField('RacingTeamID').label.update('Racing Team:');}
else
{Ext.getCmp('team2').collapse(true);this.form.getForm().findField('RacingTeamID').label.update('Choose New Team:');if(this.form.getForm().findField('RacingTeamID').getValue())
{this.form.getForm().findField('CommutingTeamID').setValue(this.form.getForm().findField('RacingTeamID').getValue());this.form.getForm().findField('CommutingTeamID').setRawValue(this.form.getForm().findField('RacingTeamID').getRawValue());}
else
{this.form.getForm().findField('CommutingTeamID').reset();}}}
this.cancelButtonClick=function()
{this.window.hide();}
this.saveButtonClick=function()
{this.setMessage("Changing Teams...","black",true);this.window.getEl().mask();this.form.getForm().submit({reset:false,success:this.onPostSuccess,failure:this.onPostFailure,scope:this});}
this.onPostSuccess=function(form,action)
{if(this.redirectToHome&&this.newTeamDomain)
{window.location.href=buildTeamBaseURL(this.newTeamDomain);}
else
{window.location.reload();}}
this.onPostFailure=function(form,action)
{this.window.getEl().unmask();switch(action.failureType){case Ext.form.Action.CLIENT_INVALID:this.setMessage("Team information is not complete. Fix fields marked in red.","red");break;case Ext.form.Action.SERVER_INVALID:this.setMessage("Error changing teams: "+action.result.message,"red");break;case Ext.form.Action.CONNECT_FAILURE:this.setMessage("Error changing teams: Server did not respond","red");break;}}
this.setMessage=function(message,color,loading)
{setFormMessage(message,color,loading,'status-msg2');this.window.syncSize();}}
