Ext.namespace("Ext.hansub.camping");

Ext.hansub.camping.AddCampingContentWindow = function(config){
	
	this.config = config;
	this.isRegionLoad = false;
	this.isGroupLoad = false;
	
	this.radioData1= [
						{name:'power',O:0,N:1,X:2},
						{name:'barbecue',O:3,N:4,X:5},
						{name:'water',O:6,N:7,X:8},
						{name:'internet',O:9,N:10,X:11},
						{name:'toilet',O:12,N:13,X:14},
						{name:'shower',O:15,N:16,X:17},
						{name:'store',O:18,N:19,X:20},
						{name:'sink',O:21,N:22,X:23},
						{name:'playground',O:24,N:25,X:26},
						{name:'withcampingcar',O:27,N:28,X:29},
						
						
		
					];
	
	this.radioData2= [
						
						{name:'waterplay',O:0,N:1,X:2},
						{name:'swimming',O:3,N:4,X:5},
						{name:'fishing',O:6,N:7,X:8},
						{name:'mtb',O:9,N:10,X:11},
						{name:'mountain',O:12,N:13,X:14},
						{name:'ski',O:15,N:16,X:17}
						
		
					];
	
	this.camping_list_uid = this.config.data.camping_list_uid;
	
	this.region1Store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url:'./src/api/Interface.php'		
		}),
		baseParams:{
			'class':'Camping',
			'method':'getRegion1List'
			
		},
	  	reader: new Ext.data.JsonReader(
	  		{
	   			root:'data'
			},
	  		[{name: 'camping_region1_uid', mapping:'camping_region1_uid'}, {name: 'name', mapping:'name'}])
	 
	 });
	 
	// this.itemStore.load();

	this.region1ComboBox = new Ext.form.ComboBox({		
		//hideLabel: true,
		fieldLabel: '위치',
		anchor:'100%',
		store:this.region1Store,
		displayField:'name',
        editable:false,
        hiddenName:'camping_region1_uid',
       	valueField:'camping_region1_uid',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'시/도 선택',
        allowBlank:false,
        selectOnFocus:true
    });
	
	
	this.region2Store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url:'./src/api/Interface.php'		
		}),
		baseParams:{
			'class':'Camping',
			'method':'getRegion2List'
			
		},
	  	reader: new Ext.data.JsonReader(
	  		{
	   			root:'data'
			},
	  		[{name: 'camping_region2_uid', mapping:'camping_region2_uid'}, {name: 'name', mapping:'name'}])
	 
	 });
	 
	// this.itemStore.load();

	this.region2ComboBox = new Ext.form.ComboBox({		
		hideLabel: true,
		fieldLabel: '위치',
		anchor:'100%',
		store:this.region2Store,
		displayField:'name',
        editable:false,
        hiddenName:'camping_region2_uid',
       	valueField:'camping_region2_uid',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'시/군 선택',
        allowBlank:false,
        selectOnFocus:true
    });
	
		
	this.nameTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '이름',
		blankText:'캠핑장 이름을 입력해 주세요',
		emptyText :'캠핑장 이름을 입력해 주세요',
		name: 'name',
        anchor:'100%',
        allowBlank:false
	});
	
	this.descTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '설명',
		blankText:'간단한 캠핑장  설명을 입력해 주세요',
		emptyText :'간단한 캠핑장  설명을 입력해 주세요',
		name: 'description',
        anchor:'100%',
        allowBlank:true
	});
	
	this.reservationTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '예약 URL',
		blankText:'예약 페이지 주소(http://)를 입력해 주세요.',
		emptyText :'예약 페이지 주소(http://)를 입력해 주세요.',
		name: 'reservationurl',
        anchor:'100%',
        allowBlank:true
	});
	
	this.telTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '연락처',
		blankText:'연락처를 입력해주세요',
		emptyText :'연락처를 입력해주세요',
		anchor:'100%',
		name: 'tel',
        allowBlank:true
	});
	
	this.homeTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '홈페이지',
		blankText:'홈페이지를 입력해주세요',
		emptyText :'홈페이지를 입력해주세요',
		anchor:'100%',
		name: 'homepage',
        allowBlank:true
	});
	
	
	this.addressTextField = new Ext.form.TextField({
		hideLabel: true,
		fieldLabel: '주소',
		blankText:'캠핑장 주소를 입력해주세요',
		emptyText :'캠핑장 주소를 입력해주세요',
		name: 'address',
        anchor:'100%',
        allowBlank:false
	});
	
	this.capacityTextField = new Ext.form.TextField({
		
		fieldLabel: '최대수용',
		blankText:'최대수용',
		//emptyText :'최대수용',
		name: 'capacity',
        anchor:'100%',
        allowBlank:true
	});
	
	
	
	var locationStore = new Ext.data.SimpleStore({
        fields: ['location', 'name'],
        data : [['산/계곡','산/계곡'],['호수/강','호수/강'],['휴양림', '휴양림'],['해변/바다', '해변/바다'],['기타', '기타']]
    });

	this.locationComboBox = new Ext.form.ComboBox({
		//hideLabel: true,
		fieldLabel: '주변환경',
		anchor:'100%',
		blankText:'주변환경',
		emptyText :'주변환경',
		store:locationStore,
		displayField:'name',
        editable:false,
        hiddenName:'location',
       	valueField:'location',
        typeAhead: true,
        triggerAction: 'all',
        allowBlank:true,
        selectOnFocus:true,
        typeAhead: true,
        mode: 'local'
    });
	
	var landStore = new Ext.data.SimpleStore({
        fields: ['landtype', 'name'],
        data : [['잔디','잔디'],['노지','노지'],['파쇄석', '파쇄석'],['데크', '데크'],['마사토', '마사토'],['모래', '모래']]
    });

	this.landtypeComboBox = new Ext.form.ComboBox({
		//hideLabel: true,
		fieldLabel: '노면상태',
		anchor:'100%',
		blankText:'노면상태',
		emptyText :'노면상태',
		store:landStore,
		displayField:'name',
        editable:false,
        hiddenName:'landtype',
       	valueField:'landtype',
        typeAhead: true,
        triggerAction: 'all',
        allowBlank:true,
        selectOnFocus:true,
        typeAhead: true,
        mode: 'local'
    });
	
	var reservationStore = new Ext.data.SimpleStore({
        fields: ['reservationtype', 'name'],
        data : [['현장예약','현장예약'],['전화예약','전화예약'],['온라인예약', '온라인예약']]
    });

	this.reservationComboBox = new Ext.form.ComboBox({
		//hideLabel: true,
		fieldLabel: '예약방식',
		anchor:'100%',
		blankText:'예약방식',
		emptyText :'예약방식',
		store:reservationStore,
		displayField:'name',
        editable:false,
        hiddenName:'reservationtype',
       	valueField:'reservationtype',
        typeAhead: true,
        triggerAction: 'all',
        allowBlank:true,
        selectOnFocus:true,
        typeAhead: true,
        mode: 'local'
    });
	
	
	
	this.contentHtmlEditor = new Ext.form.HtmlEditor({
		//fieldLabel: '내용',
		hideLabel: true,
		fontFamilies : ['맑은 고딕','돋움체'],
        name: 'content',
        border:false,
        width:400,
        height : 300, 
        anchor:'100%',
        enableAlignments:false,
        //enableColors:false,
        enableFont:false,
        //enableFontSize :false,
        //enableFormat :false,
        enableLinks :false,
        enableSourceEdit:false,
        enableLists :false,
        plugins:[ new Ext.ux.plugins.HtmlEditorImageInsert({
                    text: '이미지 주소로 등록',
                    iconCls: 'editor_url_img',
                    scope: this,
                    handler: this.imgURL
                }),new Ext.ux.plugins.HtmlEditorImageInsert({
                    text: '이미지 업로드',
                    iconCls: 'editor_upload_img',
                    scope: this,
                    handler: this.upload
                })]

        //allowBlank:false
	});
	
	

	
	
	this.firstCheckboxGroup = new Ext.form.RadioGroup({
			itemCls: 'x-check-group-alt',
            fieldLabel: '시설',
            allowBlank: false,
            anchor: '95%',
            items: [{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '전기', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', id:'power_1',name: 'power', inputValue: 'O'},
                    {boxLabel: '확인안됨', id:'power_2', name: 'power', inputValue: '?', checked: true},
					{boxLabel: '미지원', id:'power_3', name: 'power', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '화로', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'barbecue', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'barbecue', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'barbecue', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '온수', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'water', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'water', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'water', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '인터넷', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'internet', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'internet', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'internet', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '화장실', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'toilet', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'toilet', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'toilet', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '샤워', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'shower', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'shower', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'shower', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '매점', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'store', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'store', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'store', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '계수대', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'sink', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'sink', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'sink', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '운동장', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'playground', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'playground', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'playground', inputValue: 'X'}
                ]
            },{
                columnWidth: '.2',
                items: [
                    {xtype: 'label', text: '텐트옆주차', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'withcampingcar', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'withcampingcar', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'withcampingcar', inputValue: 'X'}
                ]
            }]
	});
	
	
	
	
	this.thirdCheckboxGroup = new Ext.form.RadioGroup({
			itemCls: 'x-check-group-alt',
            fieldLabel: '환경',
            allowBlank: false,
            anchor: '95%',
            items: [{
                columnWidth: '.16',
                items: [
                    {xtype: 'label', text: '물놀이', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'waterplay', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'waterplay', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'waterplay', inputValue: 'X'}
                ]
            },{
                columnWidth: '.16',
                items: [
                    {xtype: 'label', text: '수영', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'swimming', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'swimming', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'swimming', inputValue: 'X'}
                ]
            },{
                columnWidth: '.16',
                items: [
                    {xtype: 'label', text: '낚시', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'fishing', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'fishing', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'fishing', inputValue: 'X'}
                ]
            },{
                columnWidth: '.16',
                items: [
                    {xtype: 'label', text: 'MTB', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'mtb', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'mtb', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'mtb', inputValue: 'X'}
                ]
            },{
                columnWidth: '.16',
                items: [
                    {xtype: 'label', text: '등산', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'mountain', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'mountain', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'mountain', inputValue: 'X'}
                ]
            },{
                columnWidth: '.16',
                items: [
                    {xtype: 'label', text: '스키', cls:'x-form-check-group-label', anchor:'-15'},
                    {boxLabel: '지원', name: 'ski', inputValue: 'O'},
                    {boxLabel: '확인안됨', name: 'ski', inputValue: '?', checked: true},
					{boxLabel: '미지원', name: 'ski', inputValue: 'X'}
                ]
            }]
	});
	
	
	
	
	
	/**
		//itemCls: 'x-check-group-alt',
		fieldLabel: '샤워장',
		layout:'column',
		border:false,
      	items: [	{
				                columnWidth:.15,
				                layout: 'form',
				                
				                border:false,
				                items: [{
									   	boxLabel: '지원',
										name: 'shower',
										inputValue: 'O'
										}]
				          },{
				                columnWidth:.15,
				                layout: 'form',
				                
				                border:false,
				                items: [{
									   	boxLabel: '지원',
										name: 'shower',
										inputValue: 'O'
										}]
				          },{
				                columnWidth:.15,
				                layout: 'form',
				                
				                border:false,
				                items: [{
									   	boxLabel: '확인안됨', name: 'shower', inputValue: '?',   checked: true
										}]
				          },{
				                columnWidth:.15,
				                layout: 'form',
				                
				                border:false,
				                items: [{
									   	boxLabel: '지원안됨', name: 'shower', inputValue: 'X'
										}]
				          }
                   
                ]
           

	});
**/
	
	
	/**
	this.contentHtmlEditor.tb.add({
                //itemId : 'htmlEditorImage',
                cls : 'x-btn-icon x-edit-insertimage',
                enableToggle: false,
                scope: this,
                handler:function(){ this.imgURL; },
                clickEvent:'mousedown',
                tabIndex:-1
            });
            **/
	/**
	this.contentHtmlEditor = new Ext.form.TextArea({
		fieldLabel: '내용 작성',
        name: 'content',
        anchor:'100%',
        width:250,
        height : 300, 
        allowBlank:false
	});
	**/
	
	// rowaction
	this.rowAction = new Ext.ux.grid.RowActions({
		header:'',
		autoWidth:false,
		scope:this,
		allowRule:true,
		resizeable:false,
		width:150,
		actions:[
					/**
					{
						iconCls:'row_preview',
						text:'미리보기',
						qtip:'선택된 이미지를 미리보기 합니다.',
						scope:this,
						callback:this.priview
					},**/
					{
						iconCls:'row_add',
						text:'내용에 표시',
						qtip:'이미지를 작성 내용에 표시합니다.',
						scope:this,
						callback:this.insertImg
					},{
						iconCls:'row_delete',
						text:'삭제',
						qtip:'선택된 이미지를 삭제합니다.',
						scope:this,
						callback:this.deleteImg
					}
				]

	});
	
	this.filedata = new Ext.data.Store({ 
			proxy : new Ext.data.HttpProxy({
		    	url : './src/api/Interface.php',
		       	method : 'POST'
		       	
		    }),
		    baseParams : {
				'class':'Camping',
				method:'getCampingFile'
			},
		    
		    reader: new Ext.data.JsonReader({ 
	            root: 'rows', 
	            totalProperty: 'count',
	            id:'uid'
	        }, [ 
	        	{name: 'uid', mapping:'uid', type: 'string'},
	        	{name: 's_user_uid', mapping: 's_user_uid', type: 'string'},
	        	{name: 'name', mapping: 'name', type: 'string'},
	        	{name: 'realname', mapping: 'realname', type: 'string'},
	        	{name: 'content', mapping: 'content', type: 'string'},
	        	{name: 'regdate', mapping: 'regdate', type: 'string'}
	        	
	        ])
	    })
	/**
	this.fileUpload = new Ext.Toolbar.Button({
    	text:'이미지 업로드 하기',
		iconCls:'new_win_icon',
		scope:this,
		handler:this.upload
    });
 
    
    
	this.fileUploadMenu = new Ext.menu.Menu({
		scope:this,
        items:[this.fileUpload]
	});
    **/
	this.pagingBar = new Ext.PagingToolbar({
	        pageSize: 5,
	        store: this.filedata,
	       	displayInfo: true,
	        displayMsg: '{0} - {1} of {2}',
	        autoWidth:true,
	        emptyMsg: "내용이 없습니다."
      
    });
	this.uploadGridPanel = new Ext.grid.GridPanel({
		id:'uploadGridPanelID',
		title: NAME+'님께서 업로드한 이미지',
		height:175,
		width:'auto',
		border:true,
		hideHeaders:true,
		columns : [
					{header: "업로드된 이미지", width: 110, sortable: true,dataIndex: 'name'},
					/**,
					{header: "내용", width: 250, sortable: true,dataIndex: 'content'},
					{header: "설명", width: 300, sortable: true,dataIndex: 'content'},
					**/
		            this.rowAction
		        ],
        ds : this.filedata,
        bbar : this.pagingBar,
	    plugins:this.rowAction
	    //tbar : [this.fileUpload,'-']
  	});
  	
  	this.uploadGridPanel.getSelectionModel().on('rowselect', this.selectRowImg, this);

	
	this.imgPanel = new Ext.Panel({
									title:'미리보기',
									height:175,
									border:true
						      });
	
	//this.nameTextField
	this.formPanel = new Ext.form.FormPanel({
		//labelAlign: 'top',
        labelWidth: 60,
        //baseCls: 'form',      
        frame:true,
        method: 'POST',
        bodyStyle:'padding:5px 5px 0',
	    //bodyStyle:'background-color: #e4e4e4',
        items: [{
		            layout:'column',//this.locationComboBox
		            //bodyStyle:'padding:5px 5px 0;background-color: #e4e4e4',
		            border:false,
		            items:[{
				                columnWidth:.5,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.nameTextField]
				          },{
				                columnWidth:.5,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.reservationTextField]
				          }]
			},{
					layout:'column',//this.locationComboBox
		            border:false,
		            items:[{
				                columnWidth:.5,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.telTextField]
				          },{
				                columnWidth:.5,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.homeTextField]
				          }]
		    },{
					layout:'column',//this.locationComboBox
		            border:false,
		            items:[{
				                columnWidth:.3,
				                layout: 'form',
				                bodyStyle:'padding:0px 0px 0 10',
				                border:false,
				                items: [this.region1ComboBox]
				          },{
				                columnWidth:.2,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.region2ComboBox]
				          },{
				                columnWidth:.5,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.addressTextField]
				          }]
		    },{
					layout:'column',//this.locationComboBox
		            border:false,
		            items:[{
				                columnWidth:.25,
				                layout: 'form',
				                bodyStyle:'padding:0px 0px 0 10',
				                border:false,
				                items: [this.locationComboBox]
				          },{
				                columnWidth:.25,
				                layout: 'form',
				                bodyStyle:'padding:0px 5px 0 10',
				                border:false,
				                items: [this.landtypeComboBox]
				          },{
				                columnWidth:.25,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.capacityTextField]
				          },{
				                columnWidth:.25,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.reservationComboBox]
				          }]
		    },{
		            layout:'column',//this.locationComboBox
		            //bodyStyle:'padding:5px 5px 0;background-color: #e4e4e4',
		            border:false,
		            items:[{
				                columnWidth:1,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 10',
				                border:false,
				                items: [this.descTextField]
				          }]
			},{
					layout:'column',//this.locationComboBox
		            border:false,
		            items:[{
				                columnWidth:1,
				                layout: 'form',
				                bodyStyle:'padding:0px 0px 0 10',
				                border:false,
				                items: [this.firstCheckboxGroup]
				          }]
		    },{
					layout:'column',//this.locationComboBox
		            border:false,
		            items:[{
				                columnWidth:1,
				                layout: 'form',
				                bodyStyle:'padding:0px 0px 0 10',
				                border:false,
				                items: [this.thirdCheckboxGroup]
				          }]
		    }
        ]/**, this.thirdCheckboxGroup
		{
            xtype:'tabpanel',
            plain:true,
            activeTab: 0,
            height:550,
           
            deferredRender: false,
            defaults:{bodyStyle:'padding:10px'},
            items:[{
                title:'캠핑장 설명',
                layout:'form',
                items: [this.contentHtmlEditor
				        ,{
				            layout:'column',
				            border:false,
				            
				            items:[{
						                columnWidth:.8,
						                layout: 'form',
						                bodyStyle:'background-color: #e4e4e4',
						                border:false,
						                items: [this.uploadGridPanel]
						            },{
						                columnWidth:.2,
						                layout: 'form',
						                bodyStyle:'background-color: #e4e4e4',
						                border:false,
						                items: [this.imgPanel]
						          }]
				        }]
            },{
              

                items: [{
				            layout:'column',//this.locationComboBox
				            //bodyStyle:'padding:5px 5px 0;background-color: #e4e4e4',
				            border:false,
				            items:[{
						                columnWidth:1,
						                layout: 'form',
						                bodyStyle:'padding:0px 5px 10',
						                border:false,
						                items: [this.telTextField]
						          }]
				        },{
				            layout:'column',
							bodyStyle:'padding:0px 5px 10',
							//xtype:'fieldset',
				            //title: '캠핑장 위치 정보',this.telTextField
							autoHeight: true,
				            items:[{	columnWidth:.3,
						                layout: 'form',
						               	//bodyStyle:'padding:0px 5px 10',
						                border:false,
						                items: [this.region1ComboBox]
									},{	columnWidth:.2,
						                layout: 'form',
						               	//bodyStyle:'padding:0px 5px 10',
						                border:false,
						                items: [this.region2ComboBox]
									},{	columnWidth:0.3,
						                layout: 'form',
						               	//bodyStyle:'padding:0px 5px 10',
						                border:false,
						                items: [this.addressTextField]
									}]
       				 },{
            layout:'form',
			bodyStyle:'padding:0px 5px 10',
			//xtype:'fieldset',
            //title: '캠핑장  환경 및 시설',
			autoHeight: true,
            //border:false,
            //bodyStyle:'padding:5px 5px 0;background-color: #e4e4e4',
            items:[
					this.capacityTextField,
					this.locationComboBox,
					this.powerComboBox,
					this.waterComboBox,
					this.internetComboBox,
					this.showerCheckboxGroup
					]
        }]
            }]
        }
		
		
		
		
		
		
        ]
        
        **/
        
        
        
        
        //[this.categoryComboBox,this.nameTextField ,this.contentHtmlEditor]
        
        
        
        //items: [this.itemComboBox, this.nameTextField, this.contentHtmlEditor ]       
    });
    
    this.config.buttons = [
    	
        {
            text: '저장',
            type:'submit',
            scope:this,
            handler: this.submit
        },{
            text: '취소',
            type:'cancel',
            scope:this,
            handler: this.cancel
        }];
    this.config.items = this.formPanel;
    this.config.layout = 'fit';
    this.config.closable = true;
    this.config.plain = true;
    this.config.modal = true;
    this.config.buttonAlign ='right';
    this.config.closeAction ='close';
    
    
	
	Ext.hansub.camping.AddCampingContentWindow.superclass.constructor.call(this, this.config);
	this.on('hide',this.init,this);
	this.uploadGridPanel.on('rowdblclick', this.dbClick, this);
	
	
	this.filedata.on("beforeload", function(store, options){
		
		if(this.config.data){
			this.filedata.baseParams.camping_list_uid =  this.config.data.uid;
		}
		
	},this);
	
	//this.filedata.load();
	this.filedata.load({
			params:{
					start:0,
					limit:5
			}
	});
	
	this.region1ComboBox.on("select", function(combo, record, index){
		
		this.region2Store.load({
			params:{
					camping_region1_uid:this.region1ComboBox.getValue()
			}
			});
				
	},this);
	
	this.region1Store.load();

	
	
	this.region1Store.on('load',function(){
		
		this.isRegionLoad = true;
		if (this.isRegionLoad && this.isGroupLoad) {
			this.loadCampingData();
		}
	
		
	},this);
	
	this.region2Store.on('load',function(){
		if (this.isLoadData) {
			this.region2ComboBox.setValue(this.config.data.camping_region2_uid);
		}
		this.isLoadData = false;
		
	},this);
	
	this.thirdCheckboxGroup.on('render',function(){
		this.isGroupLoad = true;

		if (this.isRegionLoad && this.isGroupLoad) {

			this.loadCampingData();
		}
		
		
	},this);
	
};

Ext.extend(Ext.hansub.camping.AddCampingContentWindow, Ext.Window, {


	
	load : function(camping_list_uid){
		this.camping_list_uid = camping_list_uid;
	},

	loadCampingData : function (){
		if(!this.camping_list_uid){
			return;
		}
		Ext.Ajax.request({
			url: './src/api/Interface.php',
			params:{
							'class':'Camping',
							method:'getCamping',
							camping_list_uid: this.camping_list_uid
							
						},
			waitMsg:'캠핑장 정보 로딩 중',
			scope:this,
			success:function(response, options){
				
				var campingData = Ext.decode(response.responseText);
				
				if(campingData.success){
					this.isLoadData = true;

					this.setData(campingData.data);
            		
            	}else{
            		Ext.MessageBox.alert('캠핑장 정보 에러', campingData.msg)
            	}
			},
			failure:function(response, options){
				Ext.MessageBox.alert('캠핑장 정보 에러', '에러가 발생하였습니다.')
			}
			            	
					
		});
	},

	dbClick : function (grid, index, e){
		
		records = grid.getStore().getAt(index);
		this.insertImg(grid, records, '', '');
	},
	
	insertImg : function(grid, records, action, groupId){
		//Ext.getCmp('addBoardContentWindowID').contentHtmlEditor.setValue(Ext.getCmp('addBoardContentWindowID').contentHtmlEditor.getValue()+"<br><img width='400' src=./images/upload/"+records.data.realname+"><br>");
		
		Ext.getCmp('addBoardContentWindowID').contentHtmlEditor.relayCmd('insertimage', "./images/upload/"+records.data.realname);
		
		
	},
	
	selectRowImg:function(sm, index, record){
		
		
		
		Ext.DomHelper.overwrite(this.imgPanel.body, {tag: 'img', src: './images/upload/'+record.data.realname, width: '150', height: '150'});
		this.imgPanel.setTitle(record.data.name);
		//alert(record.data.realname);
		
		
	},
	
	
	deleteImg : function(grid, records, action, groupId){
		
		//record.data.uid//realname
		Ext.Msg.show({
			title:'삭제 확인',
			scope:this,
			msg: records.data.name +'을 삭제 하시겠습니까 ?',
			buttons:Ext.Msg.YESNO,
			icon:Ext.MessageBox.QUESTION,
			fn:function(btn, text){
				if(btn == 'yes'){
					
					Ext.Ajax.request({
						url: './src/api/Interface.php',
						params:{
							'class':'Board',
							'method':'deleteFile',
							'uid': records.data.uid,
							'realname': records.data.realname
						},
						waitMsg:'등록된 이미지를 삭제합니다.',
						scope:this,
						success:function(response, options){
							
							Ext.getCmp('uploadGridPanelID').getStore().reload();
							//grid.ds.reload();
							//this.filedata.reload();
							
											
						},
						failure:function(response, options){
							Ext.MessageBox.alert('ERROR', '이미지 삭제에 오류가 발생하였습니다.');
						}
						            	
								
					});
				}
			}
		});
		
	},
	
	// 값 설정
	setData : function(data){
		data.parentID = this.config.data.parentID;
		this.config.data = data;
		
		this.nameTextField.setValue(this.config.data.name);	
		this.telTextField.setValue(this.config.data.tel);
		this.descTextField.setValue(this.config.data.description);
		this.homeTextField.setValue(this.config.data.homepage);
		this.addressTextField.setValue(this.config.data.address);
		this.capacityTextField.setValue(this.config.data.capacity);
		this.reservationTextField.setValue(this.config.data.reservationurl);
		
		
		this.locationComboBox.setValue(this.config.data.location);
		this.landtypeComboBox.setValue(this.config.data.landtype);
		this.reservationComboBox.setValue(this.config.data.reservationtype);
		
		this.region1ComboBox.setValue(this.config.data.camping_region1_uid);
		this.region2Store.load({
			params:{
					camping_region1_uid:this.config.data.camping_region1_uid
			}
		});

		this.setRadio1("power",this.config.data.power);
		this.setRadio1("barbecue",this.config.data.barbecue);
		this.setRadio1("water",this.config.data.water);
		this.setRadio1("internet",this.config.data.internet);
		this.setRadio1("toilet",this.config.data.toilet);
		this.setRadio1("shower",this.config.data.shower);
		this.setRadio1("store",this.config.data.store);
		this.setRadio1("sink",this.config.data.sink);
		this.setRadio1("playground",this.config.data.playground);
		this.setRadio1("withcampingcar",this.config.data.withcampingcar);
		this.setRadio2("waterplay",this.config.data.waterplay);
		this.setRadio2("swimming",this.config.data.swimming);
		this.setRadio2("fishing",this.config.data.fishing);
		this.setRadio2("mtb",this.config.data.mtb);
		this.setRadio2("mountain",this.config.data.mountain);
		this.setRadio2("ski",this.config.data.ski);


	},
	
	setRadio1 : function(name, value){
		
		if(value == '?'){
			value = 'N';
		}
		if(value == 'ㅿ'){
			value = 'O';
		}
		if(value == ''){
			value = 'N';
		}
		size = this.radioData1.length;
		
		for(i=0;i<size;i++){
			
			if(this.radioData1[i].name == name){
				index = eval("this.radioData1[i]."+value);			
				this.firstCheckboxGroup.items.items[index].setValue(true)
				return;
			}
			
		}
		
		//alert(this.firstCheckboxGroup.items.items[3].setValue(true));
		//alert(this.firstCheckboxGroup.items[0].items[0].getName());
	
	},
	setRadio2 : function(name, value){
		
		if(value == '?'){
			value = 'N';
		}
		size = this.radioData2.length;
		
		for(i=0;i<size;i++){
			
			if(this.radioData2[i].name == name){
				index = eval("this.radioData2[i]."+value);			
				this.thirdCheckboxGroup.items.items[index].setValue(true)
			}
			
		}
		
		//alert(this.firstCheckboxGroup.items.items[3].setValue(true));
		//alert(this.firstCheckboxGroup.items[0].items[0].getName());
	
	},
	
	submit : function(){
		
		
		if(this.formPanel.getForm().isValid()){
			this.formPanel.form.submit(
			{	waitMsg: '캠핑장 등록 중...',
				url:'./src/api/Interface.php',
				params :{
							'class':'Camping',
							method:'addCamping',
							camping_list_uid:this.camping_list_uid
							
						},
				scope:this,
				success: function(form, action) {
                  	if(action.result.success){
                  		
						if(this.config.data.parentID != 'campingGridID'){
                  			//Ext.getCmp(this.config.data.parentID).destroy();
							Ext.getCmp('centerCenterPanel').remove(this.config.data.parentID);
							
							
						}
						Ext.getCmp('campingGridID').reload();;
                  		this.close();
						
                  	}else{
                  		Ext.MessageBox.alert('Error', 'Error')
                  	}
  										
				},
				failure: function(form, action) { 
					Ext.MessageBox.alert('Error', 'Error')
				}
			});
            		
		}
		
	},
	
	cancel : function(){
		this.hide();
	},
	
	init : function(){
		

	},
	
	setModify : function(record){
		/**
		this.mode = 'modify';
		this.uid = record.get('id');
		this.nameTextField.setValue(record.get('name'));
		this.contentHtmlEditor.setValue(record.get('content'));
		**/
	},
	
	imgURL : function(){
		
		this.imgURLField =  new Ext.form.TextField({
			name:'url',
			fieldLabel: '주소 입력',
			allowBlank:true
		});
		this.imgURLField.setValue("http://");
		
		var fp = new Ext.FormPanel({
		        fileUpload: true,
		        width: 500,
		        frame: true,
		        autoHeight: true,
		        bodyStyle: 'padding: 10px 10px 0 10px;',
		        labelWidth: 65,
		        defaults: {
		            anchor: '95%',
		            allowBlank: false,
		            msgTarget: 'side'
		        },
		        items: [this.imgURLField],
		        buttons: [{
		            text: '이미지 추가',
		            scope: this,
		            handler: function(){
		            	
		            	this.contentHtmlEditor.relayCmd('insertimage', this.imgURLField.getValue());
		                //this.contentHtmlEditor.setValue(this.contentHtmlEditor.getValue()+"<br><img width='400' src="+this.imgURLField.getValue()+"><br>");
		            	this.urlWindow.close();
		            
		                
		            }
		        }]
		    });
		//this.uploadWindow.add(fp);
		
		this.urlWindow = new Ext.Window({
			title:'이미지 주소 직접 입력',
			modal:true,
			width:500,
			model:true,
			items:fp
			
		});
		
		this.urlWindow.show();
	},
	
	upload : function(){
		
				
			
		this.fileUploadField =  new Ext.form.FileUploadField({
			emptyText: '업로드 파일을 선택해 주세요.(이미지 파일만 가능합니다)',
		    fieldLabel: '이미지',
		    name: 'file',
		    buttonCfg: {
			    text: '',
			    iconCls: 'upload-icon'
		    }			
		});

		
		var fp = new Ext.FormPanel({
		        fileUpload: true,
		        width: 500,
		        frame: true,
		        autoHeight: true,
		        bodyStyle: 'padding: 10px 10px 0 10px;',
		        labelWidth: 65,
		        defaults: {
		            anchor: '95%',
		            allowBlank: false,
		            msgTarget: 'side'
		        },
		        items: [this.fileUploadField],
		        buttons: [{
		            text: '업로드',
		            scope: this,
		            handler: function(){
		                if(fp.getForm().isValid()){
			                fp.getForm().submit({
			                    waitMsg: '이미지 업로드 중 입니다....',
								url:'./src/api/Interface.php',
								params :{
											'class':'Camping',
											method:'uploadFile',
											camping_uid:this.config.data.uid
											
										},
								scope:this,
			                    success: function(fp, o){
			                    	this.config.data.s_board_uid = o.result.s_board_uid;
			                    	
			                    	this.contentHtmlEditor.relayCmd('insertimage', "./images/upload/"+o.result.realname);
			                    	//this.contentHtmlEditor.setValue(this.contentHtmlEditor.getValue()+"<br><img width='400' src=./images/upload/"+o.result.realname+"><br>"); 
			                    	/**
			                    	Ext.Msg.show({
							            title: '성공', 
							            msg: '"'+o.result.name+ '" 파일 업로드가 성공했습니다.',
							            minWidth: 200,
							            modal: true,
							            icon: Ext.Msg.INFO,
							            buttons: Ext.Msg.OK
							        });
							        **/
							        this.uploadWindow.close();
									this.filedata.reload();
			                    },
			                    failure:function(fp,o){
			                    	Ext.Msg.show({
							            title: '실패', 
							            msg:o.result.realname,
							            minWidth: 200,
							            modal: true,
							            icon: Ext.Msg.INFO,
							            buttons: Ext.Msg.OK
							        });
			                    }
			                    
			                });
		                }
		            }
		        }]
		    });
		//this.uploadWindow.add(fp);
		
		this.uploadWindow = new Ext.Window({
			title:'이미지 업로드',
			modal:true,
			width:500,
			model:true,
			items:fp
			
		});
		
		this.uploadWindow.show();
		
		
	}

});

