

JoinWindow = 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);
	
	Ext.apply(Ext.form.VTypes, {

	    password : function(val, field) {
	        if (field.initialPassField) {
	            var pwd = Ext.getCmp(field.initialPassField);
	            return (val == pwd.getValue());
	        }
	        return true;
	    },
	
	    passwordText : '패스워드가 맞지 않습니다.'

	});

	
	this.nameTextField = new Ext.form.TextField({
		fieldLabel: '이름',
		emptyText:'실명 또는 닉네임 ~',
        name: 'name',
        anchor:'100%',
        allowBlank:false
	});
	
	this.emailTextField = new Ext.form.TextField({
		fieldLabel: '<font color=blue>이메일주소</font>',
		emptyText:'로그인 할때 아이디로 사용됩니다.',
        name: 'email',
        anchor:'100%',
        vtype:'email',
        allowBlank:false
	});
	
	this.phoneTextField = new Ext.form.TextField({
		fieldLabel: '<font color=blue>핸드폰번호</font>',
		emptyText:'Mobile 접속 시 연결됩니다.',
		name: 'phone',
        anchor:'100%',
        allowBlank:false
	});
	
	this.passwordTextField = new Ext.form.TextField({
		id:'password',
		fieldLabel: '패스워드',
        name: 'password',
        anchor:'100%',
        inputType: 'password',
        allowBlank:false
	});
	
	this.password2TextField = new Ext.form.TextField({
		fieldLabel: '패스워드 확인',
        name: 'password2',
        anchor:'100%',
        inputType: 'password',
        vtype: 'password',
        initialPassField: 'password',
        allowBlank:false
	});
	
	this.descriptionTextField = new Ext.form.TextField({
		fieldLabel: '가입인사',
		name: 'description',
		height:50,
        anchor:'100%',
        allowBlank:false
	});	
	
	
	var store = new Ext.data.SimpleStore({
        fields: ['agreement', 'name'],
        data : [['N','아니요.'],['Y', '네 ~공유하겠습니다']]
    });

	this.agreementComboBox = new Ext.form.ComboBox({
		fieldLabel: '약관 동의여부',
		anchor:'100%',
		store:store,
		displayField:'name',
        editable:false,
        hiddenName:'agreement',
       	valueField:'agreement',
        typeAhead: true,
        triggerAction: 'all',
        allowBlank:false,
        selectOnFocus:true,
        typeAhead: true,
        mode: 'local'
    });
    
    
	
   
    
	
	this.formPanel = new Ext.form.FormPanel({
		frame: true,       
        labelWidth: 100,
        width: 350,
        bodyStyle: 'padding:0 10px 0;',
     
        keys: [{
        	key: Ext.EventObject.ENTER,
        	scope:this,
        	fn: this.submit
     	}],
     	//items: [this.nameTextField,this.emailTextField,this.passwordTextField,this.password2TextField]
     	
     	items: [{
            layout: 'form',
            border: false,
            defaults: {
                //columnWidth: '.5',
                border: false
            },
            
            items: [{
                bodyStyle: 'padding-right:5px;',
                items:         {
                    xtype:'fieldset',
                    title: '사용자 정보',
                    autoHeight: true,
                    defaultType: 'textfield',
                    items: [
	                    this.nameTextField,
          						this.phoneTextField,
	                    this.emailTextField,
	                    this.passwordTextField,
	                    this.password2TextField,
	                    this.descriptionTextField
                    ]
                }
            }]
        },{
            

            
            xtype:'fieldset',
            title: '반갑습니다',
            autoHeight: true,
            layout: 'form',
            items: [{
                xtype: 'textarea',
                hideLabel:true,
                anchor: '100%',
                height:100,
				value:'안녕하세요. 캠핑지도에서는 캠핑장 정보공유뿐만 아니라 자신의 캠핑장 정복지 목록을 관리 할 수 있도록 제공하고 있습니다. 캠퍼님의 정보 공유을 부탁드리며 언제든지 개선이 필요한 사항을 알려주시면 최대한 반영하도록 노력하겠습니다. 감사합니다^^.',
                readOnly:true
            }]
        }]
     	
        
    });
	
	JoinWindow.superclass.constructor.call(this, {
		title: '캠지 회원가입',
		id:'JoinWindowID',
		closable:true,
		iconCls:'add',
        width: 400,
        height:450,
        minWidth: 400,
        minHeight: 450,
        layout: 'fit',
        resizeable:false,
        plain:true,
        modal:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'right',
        items: this.formPanel,
        //closeAction: 'hide',
        buttons: [
        {
            text: '확인',
            type:'submit',
            scope:this,
            handler: this.submit
        },{
            text: '취소',
            type:'cancel',
            scope:this,
            handler: this.cancel
        }]
	});
	
	
	
};

Ext.extend(JoinWindow, Ext.Window, {

	submit : function(){
		//var loginWindow = Ext.getCmp('loginWindow');
		if(this.formPanel.getForm().isValid()){
			this.formPanel.form.submit(
			{	waitMsg: '항목 등록 중...',
				url:'./src/api/Interface.php',
				params :{
							'class':'User',
							method:'joinUser'
							
						},
				scope:this,
				success: function(form, action) {
					if(action.result.success){
            this.cp.set("email",this.emailTextField.getValue());
            this.cp.set("pwd",this.cp.encodeValue(this.passwordTextField.getValue()));
						
						location.reload();
						//this.hide();


						//this.hide();
						//this.formPanel.getForm().reset();
            /*
        		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();
          	*/


					}else{
            			Ext.MessageBox.alert('회원가입 오류', action.result.msg)
            		}
					
  										
				},
				failure: function(form, action) { 
					Ext.MessageBox.alert('알림', action.result.msg)
				}
			});
            		//loginWindow.close();
		}
		
	},
	
	cancel : function(){
		this.close();
	}
	





});

