
MainToolbar = function() {
	
	this.userButton = new Ext.Button({
		id:'userButtonID',
		iconCls:'user_icon',
		handler:this.usermodify,
		text:NAME+' ('+EMAIL+')'
	});
	
	
	
	this.joinButton = new Ext.Button({
		id:'joinButtonID',
		text:'회원가입',

		handler:this.join,
		scope:this
	});
    
    this.loginButton = new Ext.Button({
		id:'loginButtonID',
		text:'<b>로그인</b>',
		iconCls:'green_button',

		handler:this.login,
		scope:this
	});
	
	
   
	
	this.logoutButton = new Ext.Button({
		id:'logoutButtonID',
		text:'로그아웃',


		handler:this.logout,
		scope:this
	});
	
	this.androidButton = new Ext.Button({
		text:'아이폰, 안드로이드용 APP 출시',
		handler:function(){
			window.open("https://market.android.com/details?id=com.campingjido.android#?t=W251bGwsMSwyLDIxMiwiY29tLmNhbXBpbmdqaWRvLmFuZHJvaWQiXQ..","_blank");
		},
		scope:this
	});
	
		
	this.telButton = new Ext.Button({
		text:'캠핑제휴 0505-355-8000',
		scope:this
	});
	
    
	
	MainToolbar.superclass.constructor.call(this, {
		id: 'mainToolbarID',
		cls:'rightTabPanel',
		items:['-',this.userButton,'-', this.loginButton,this.logoutButton,'-',this.joinButton,'-',this.androidButton,'-',this.telButton,'-']
		
		
	});
	
	this.on('render',this.loginState,this);
	
	

};

Ext.extend(MainToolbar, Ext.Toolbar, {
	
	
	login : function(){
			
		if(!Ext.getCmp('loginWindowID')){
			this.loginWin = new Ext.hansub.user.LoginWindow();
		    this.loginWin.on('login', this.loginState, this);
        }
        Ext.getCmp('loginWindowID').reset();
    	Ext.getCmp('loginWindowID').show();
    	
    	
	},
	
	logout : function(){
			
		Ext.Ajax.request({
			url: './src/api/logout.php',
			waitMsg:'회원 로그아웃 중 입니다.',
			scope:this,
			success:function(response, options){
				
				var json = Ext.decode(response.responseText);
				
				if(json.success){
					
					location.reload();
					
            		
            	}else{
            		Ext.MessageBox.alert('로그아웃 에러', json.msg)
            	}
			},
			failure:function(response, options){
				Ext.MessageBox.alert('로그아웃 에러', '로그아웃 에러가 발생하였습니다.')
			}
			            	
					
		});	
		
	},
	
	
	loginState: function(){
	  
		if(IS_LOGIN){
			
			this.loginButton.setVisible(false);
			this.logoutButton.setVisible(true);
			
			this.userButton.setVisible(true);
			this.userButton.setText(NAME+' ('+EMAIL+')');
			
			this.joinButton.setText('내정보변경(<b>사진,소개</b>)');
			this.joinButton.setHandler(this.usermodify);
			
			//Ext.getCmp('AcountSummaryGridPanelID').reload();
			
		}else{
			
            UID = '';
			ISADMIN = '';
			EMAIL = '';
			NAME = '';
			SEX = '';
            
			this.loginButton.setVisible(true);
			this.logoutButton.setVisible(false);
			
			this.userButton.setVisible(false);
			
			//Ext.getCmp('AcountSummaryGridPanelID').reload();
			
			
		
		}
		//this.closeAllTab();
		
		//this.initPage("458");
		
	},
	
	closeAllTab : function(){
		
		//location.href='./';
		// main
	/**	
		tabs = Ext.getCmp('centerCenterPanel');
		tabs.items.each(function(item){
                       // if(item.closable){
                          tabs.remove(item);
                       // }
                    });
        // main left
       // tabs = Ext.getCmp('centerBottomPanel');
        tabs.items.each(function(item){
                       // if (item.closable) {
							tabs.remove(item);
						//}
					});
		
		**/
		
	},
	
	join : function(){
		
		joinWindow = new JoinWindow();
		joinWindow.show();
	},
	
	usermodify : function(){
		
		userModifyWindow = new UserModifyWindow();
		userModifyWindow.show();
	},
	
	viewtype : function(type){
		
		if(type == 'community'){
			
			//Ext.getCmp('centerBottomPanel').expand(false);
			//Ext.getCmp('centerBottomPanel').setHeight(300);
			
			
			
		}else if(type == 'price'){
			
			//Ext.getCmp('centerBottomPanel').collapse(false);
			
			
			
		}else if(type == 'unit'){
			
			//Ext.getCmp('centerBottomPanel').expand(false);
			//Ext.getCmp('centerBottomPanel').setHeight(500);
			
			
			
		}
		
		Ext.getCmp('layout').doLayout();
		
	},
	
	
	
	initPage : function(uid){
		
		
		// 등록 권한 습득
		Ext.Ajax.request({
			url: './src/api/Interface.php',
			params:{
					'class':'Board',
					'method':'getBoardContent',
					s_board_uid:uid
					},
			scope:this,
			success:function(response, options){
				
				var json = Ext.decode(response.responseText);
				
				record = json;
				
				
				
				if(!Ext.getCmp('commentGridPanelID')){
		    		this.commentGridPanel = new Ext.ux.hansub.board.CommentGridPanel({
						title: "댓글 목록",
						id: "commentGridPanelID",
						closable:true,
						loadMask: {msg:'댓글화면 구성 중'},
						defaults: {autoScroll:true},
						split: true,
						collapsible: true,
				        animCollapse: false,
				        border:false,
						istoolbar:true,
				        hideHeaders:true
					});
		    		
		    	}
		    	
		    	Ext.getCmp('commentGridPanelID').setData({
						dbtable_uid:record.uid,
						dbtable:'s_board'
					});
			
				//Ext.getCmp('centerBottomPanel').add('commentGridPanelID');
				//Ext.getCmp('centerBottomPanel').activate('commentGridPanelID');
				
				Ext.getCmp('mainToolbarID').viewtype('community');
				//Ext.getCmp('centerRightPanelID').expand(true);
				
	    	//	return;
	    	//}
	    	
		    	if(!Ext.getCmp('boardContentPanel_'+record.uid)){
					var boardContentPanel = new Ext.hansub.board.BoardContentPanel(
											this,
											{
												title:record.name,
												id:'boardContentPanel_'+record.uid,
												closable:true,
												closeAction:'false',
												height:300,
												collapsible: true,								
												border:false,
												split: true,
												data:record								
											}
										);
				}else{
					Ext.getCmp('boardContentPanel_'+record.uid).setContent(record);
				}
				
				Ext.getCmp('centerCenterPanel').add('boardContentPanel_'+record.uid);
				Ext.getCmp('centerCenterPanel').activate('boardContentPanel_'+record.uid);
		
			
			},
			failure:function(response, options){
				islogin = false;
				Ext.MessageBox.alert('오류', '서버에 응답이 없습니다. 잠시 후 다시 접근해 주세요.')
			}
			            	
					
		});
		
		
	}
	
	
	
/**
	login : function(){
			
			if(!this.loginWin){
				this.loginWin = new LoginWindow();
			    this.loginWin.on('login', this.loginState, this);
        	}
    		this.loginWin.show();

	},
	
	logout : function(){
		Ext.Ajax.request({
			url:'./src/api/session/isLogout.php',
			waitMsg: '로그 아웃 중...',
			scope:this,
			success:this.logoutState,
			failure: function(result, request) { 
            	Ext.MessageBox.alert('로그아웃 오류', '로그아웃 시 오류가 발새하였습니다.')
            }
			
		});
		
	},
	
	loginState : function(){
		
		this.menuItem.setText('로그아웃');
		this.menuItem.setHandler(this.logout, this);
		this.loginButton.disable();
		this.logoutButton.enable();		
	},
	logoutState : function(result, reques){
		this.menuItem.setText('로그인');
		this.menuItem.setHandler(this.login, this);
		this.loginButton.enable();
		this.logoutButton.disable();
	}
**/	
	
});

