/**
 * 로그인 창 Class
 * isFirst : 최초 로그인 여부 확인
 */
Ext.namespace("Ext.hansub.user");

Ext.hansub.user.LoginWindow = function(){
	

  this.cp = new Ext.state.CookieProvider({
       path: "/",
       expires: new Date(new Date().getTime()+(1000*60*60*24*300)), //30 days
       domain: "campingjido.com"
   });
   Ext.state.Manager.setProvider(this.cp);
   cookie_id = this.cp.get("email","");
   cookie_pwd = this.cp.decodeValue(this.cp.get("pwd",""));


	this.idTextField = new Ext.form.TextField({
		fieldLabel: '<font color=blue>e메일주소</font>',
        name: 'email',
        emptyText: '메일주소',
        value: cookie_id,
        anchor:'100%',
        vtype:'email',
        allowBlank:false
	});
	
	this.pwTextField = new Ext.form.TextField({
		fieldLabel: '비밀번호',
        name: 'password',
        value: cookie_pwd,
        anchor: '100%',
        inputType: 'password',
        allowBlank:false
	});


	
	/**
     * logo panel 정의
     */
    var myLogo = new Ext.Panel({
    	region:'center',
    	height:'200',
    	border:false,
        //html: "<img src='./images/login.jpg'><div id=aa></div>" 
        html: "<img src='./images/login.jpg'><div id=aa></div>" 
        //html: "<img src='./images/login_winter.png'><div id=aa></div>" 
    }); 
	


    
    
	
	this.formPanel = new Ext.form.FormPanel({
		id:'loginId',
		region:'south',
		height:75,
        baseCls: 'loginForm',
        style:{padding:'15 20 5 20'},
        labelWidth: 65,
        frame:true,
        defaultType: 'textfield',
        method: 'POST',
        keys: [{
        	key: Ext.EventObject.ENTER,
        	scope:this,
        	fn: this.submit
     	}],
        items: [this.idTextField,this.pwTextField]
        
    });
	
	Ext.hansub.user.LoginWindow.superclass.constructor.call(this, {
		title: '',
		id:'loginWindowID',
		closable:true,
		iconCls:'icon_2',
        width: 300,
        height:360,
        minWidth: 300,
        minHeight: 360,
        layout:'border',
        plain:true,
        modal:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'right',
        items: [myLogo,this.formPanel],
        closeAction: 'hide',

        buttons: [
        	{
	            text: '초간단 회원가입',
	            scope:this,
	            handler: this.join
        	},{
	            text: '로그인',
	            type:'submit',
	            scope:this,
	            handler: this.submit
        	},{
	            text: '닫기',
	            type:'cancel',
	            scope:this,
	            handler: this.cancel
       		}
        ]
	});
	

	
	
	
	//so.addParam("allowScriptAccess", "always" );//"sameDomain");
	//so.write(myLogo.body.id);
	this.on('render',this.loginFormPreset,this);
	
	
};

Ext.extend(Ext.hansub.user.LoginWindow, Ext.Window, {

  loginFormPreset : function(){
//this.cp.set("email","se@naver.com");
//	  this.idTextField.setText("test");
//idTextField.disable();
  },

	submit : function(){
		

		if(this.formPanel.getForm().isValid()){
        	this.formPanel.form.submit(
            {
            	waitMsg: '인증 확인 중...',
            	url:'./src/api/login.php',
            	scope:this,
            	success: function(form, action) {
                  	
            		if(action.result.success){

            this.cp.set("email",this.idTextField.getValue());
            this.cp.set("pwd",this.cp.encodeValue(this.pwTextField.getValue()));
						
						location.reload();
						
            		}else{
            			IS_LOGIN = false;
            			Ext.MessageBox.alert('인증에러', action.result.msg)
            		}
                  						
            	},
            	failure: function(form, action) { 
            		IS_LOGIN = false;
            		Ext.MessageBox.alert('인증에러', action.result.msg)
            	}
            });
            		//loginWindow.close();
		}		
	},
	
	reset : function(){
		this.formPanel.form.reset();
	},
	
	join : function(){
		
		joinWindow = new JoinWindow();
		joinWindow.show();
	},
	
	cancel : function(){
		this.hide();
	}
	





});

