	TJ.Admin.DirectoryTreePanel = Ext.extend(Ext.ux.FileTreePanel, {
		rootText: 'files',		
		rootPath: '#+#+#+#',
//		topMenu: true,
		expandOnRender: false,
		frame: false,
		border: false,
		fileText: 'Directory',
		autoScroll:true,
		url:"/en/filemanager:dirs",
		enableUpload:false,
		enableOpen: false,
		enableDD: false,
		showStatus: true,
		initComponent: function(){

			this.reloadBtn = new Ext.Toolbar.Button({
							tooltip: 'Reload',
							iconCls: 'icon-refresh',
							cmd: 'reload',
		                    disabled:true,
							handler: this.doCommand,
							scope: this
						});

			this.expandBtn = new Ext.Toolbar.Button({
							toolTip: 'Expand All',
							iconCls: 'icon-expand-all',
							cmd: 'expand',
		                    disabled:true,
							handler: this.doCommand,
							scope: this
						});
			this.collapseBtn = new Ext.Toolbar.Button({
							toolTip: 'Collapse All',
							iconCls: 'icon-collapse-all',
							cmd: 'collapse',
		                    disabled:true,
							handler: this.doCommand,
							scope: this
						});

			this.renameBtn = new Ext.Toolbar.Button({
							text: 'Rename',
							iconCls: 'icon-pencil',
		                    disabled:true,
							cmd: 'rename',
							handler: this.doCommand,
							scope: this
						});

			this.deleteBtn = new Ext.Toolbar.Button({
							text: 'Delete',
							iconCls: 'icon-cross',
		                    disabled:true,
							cmd: 'delete',
							handler: this.doCommand,
							scope: this
						});

			this.newBtn = new Ext.Toolbar.Button({
							text: 'New',
							iconCls: 'icon-folder-add',
		                    disabled:true,
							cmd: 'newdir',
							handler: this.doCommand,
							scope: this
						});

			this.tbar=[this.reloadBtn,this.expandBtn, this.collapseBtn,'-',this.renameBtn, this.deleteBtn,'-',this.newBtn];
			if (this.showStatus)
				this.bbar =  new Ext.StatusBar({    defaultText: ''});

			TJ.Admin.DirectoryTreePanel.superclass.initComponent.call(this);

			this.getRootDirInfo();
			this.on('newdir',function(tree,node){
				console.log('New Dir',node);

			});
			this.getSelectionModel().on('selectionchange',function(sm,node) {
				var valid=true;
				if(node) {

					var path = node.getPath("text").substring(1);
					if(this.showStatus)
						this.getBottomToolbar().setStatus('Directory:  <b>' + path + '</b>');

					if ( (path == 'files') ||
					     (path == 'files/user') ||
					     (path == 'files/secure') )
						valid=false;
					if(node == this.getRootNode())
						valid=false;
				} else {
					valid=false;
				}
				this.reloadBtn.setDisabled(!node || node.isLeaf());
				this.expandBtn.setDisabled(!node || node.isLeaf());
				this.collapseBtn.setDisabled(!node || node.isLeaf());
				this.newBtn.setDisabled(!node);

				this.renameBtn.setDisabled(!valid );
				this.deleteBtn.setDisabled(!valid);
			},this);

		},
		getRootDirInfo: function(){
			var params ={ cmd: 'info'
						};
			var options = {
				 url: this.url,
				 scope: this,
				 params:{cmd: 'info'},
				 callback: this.rootCallback
				};
			Ext.Ajax.request(options);
		},
		rootCallback:function(options, success, response) {
			o = Ext.decode(response.responseText);
			this.getRootNode().setText(o.path);
			this.getRootNode().attributes.path = o.path;
			this.callbackComplete=true;
			this.postRender();

		},
		doCommand: function(btn){
			var node = this.getSelectionModel().getSelectedNode();
			this.onContextClick({node: node},btn);
		},
		render: function(){
	        TJ.Admin.DirectoryTreePanel.superclass.render.apply(this, arguments);
			this.renderComplete=true;
			this.postRender();
		},
		initialDir: false,
		postRender: function(){
			console.log('pst',this);
			if(this.renderComplete && this.callbackComplete) {
				if(this.initialDir) {
					this.setDirectory(this.initialDir);
				}
				else {
					this.getRootNode().expand();
					this.getRootNode().select();
				}
			}
			return;
		},
		getDirectory: function(){
			var node = this.getSelectionModel().getSelectedNode();
			if(node)
				return node.getPath("text").substring(1);
			return null;
		},
		setDirectory: function(dir){
			if(!this.renderComplete || !  this.callbackComplete) {
				this.initialDir=dir;
			}
			else {
				this.expandPath(dir,'text', function(bSuccess,oLastNode) {
					if(oLastNode)
						oLastNode.select();
				});
				this.initialDir=false;
			}

		}
	});

TJ.Admin.DirectorySelectWindow = Ext.extend(Ext.Window, {
	width: 800,
    constrainHeader:true,				
	height: 500,
	modal: true,
	layout: 'fit',
	title: 'Select Directory',
	closeAction: 'hide',
	initComponent: function() {

		this.fm = new TJ.Admin.FileManagerPanel({selectdir:true});
		this.items=this.fm;


		this.fm.DirTreePanel.getSelectionModel().on('selectionchange',function() {
			var selection = this.fm.DirTreePanel.getDirectory();
			this.selBtn.setDisabled(selection.length===0);
			if(selection.length) {
				this.selBtn.el.dom.setAttribute('title', 'Select directory:  /' + selection);
			} else {
				this.selBtn.el.dom.setAttribute('title', 'Please select a directory');
			}
		},this);
		this.addEvents('select');

			this.selBtn = new Ext.Button({
						text: 'Select Directory',
	                    disabled:true,
						handler: this.select,
						scope: this
					});

			this.closeBtn = new Ext.Button({ text: 'Cancel', handler: function(){ this.hide(); }, scope: this });

		this.buttons = [this.selBtn, this.closeBtn];


		TJ.Admin.DirectorySelectWindow.superclass.initComponent.call(this);

	},
	setValue:function(value) {
		console.log('setvalue',value);
			this.fm.setValue(value);

	},

	select: function() {
		console.log('Do Select');
		this.fireEvent('select', this.fm.DirTreePanel.getDirectory());
	}
});


TJ.Admin.FileGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
					mode:'manager',
					loadMask: true,
					url:"/en/filemanager:dirs",
					viewConfig:{ autoFill: false, forceFit: false},
					errorText: 'Error',
					initValue: false,
					setValue: function(value) {
						this.initValue=value;

					},
					initComponent: function() {
						this.cm = new Ext.grid.ColumnModel([
							{header: "Directory" , sortable: true, dataIndex: 'dir', width: 180, hidden: this.mode =='manager'},
							{header: "Filename", sortable: true, dataIndex: 'name',
							           editor: new Ext.form.TextField({
						               allowBlank: false
							           }),
									   renderer: this.iconRenderer,
									   width: 200
							},
							{header: "Last Modified", sortable: true, renderer: Ext.util.Format.dateRenderer('Y/m/d H:i:s'), dataIndex: 'datelastmodified', width: 120},
							{header: "Size", sortable: true, dataIndex: 'size', renderer: TJ.HumanFileSize, align: 'right', width: 60}
						]);
						this.sm = new Ext.grid.RowSelectionModel({singleSelect: true});
						this.sm.on('rowselect',function(sm,row){this.rowIndex=row;},this);

						this.store = new Ext.data.JsonStore({
							url: (this.mode=='manager') ? "/en/filemanager:files" : "/en/filemanager:review",
							root:   'data',
//							id:		'name',
							fields:["name","datelastmodified","size","ext","dir"]
						});
						this.directory=null;
					this.reloadBtn = new Ext.Toolbar.Button({
							tooltip: 'Reload',
							iconCls: 'icon-refresh',
							cmd: 'reload',
							handler: this.doReload,
							scope: this
						});
					this.openBtn = new Ext.Toolbar.Button({
							text: 'Open',
							tooltip: 'Open in new window',
							iconCls: 'icon-open',
		                    disabled:true,
							handler: this.doOpen,
							scope: this
						});
					this.downloadBtn = new Ext.Toolbar.Button({
							text: 'Download',
							tooltip: 'Download this file',
							iconCls: 'icon-open-download',
		                    disabled:true,
							handler: this.doDownload,
							scope: this
						});


						this.renameBtn = new Ext.Toolbar.Button({
							text: 'Rename',
							iconCls: 'icon-pencil',
		                    disabled:true,
							handler: this.startRename,
							scope: this
						});

						this.deleteBtn = new Ext.Toolbar.Button({
							text: 'Delete',
							iconCls: 'icon-cross',
		                    disabled:true,
							handler: this.doDelete,
							scope: this
						});
						this.publishBtn = new Ext.Toolbar.Button({
							text: 'Publish',
							iconCls: 'icon_application_lightning',
		                    disabled:true,
							handler: this.doPublish,
							scope: this
						});

						this.unzipBtn = new Ext.Toolbar.Button ({
							text: 'Unzip',
							iconCls: 'icon_arrow_out',
		                    disabled:true,
							handler: this.doUnzip,
							scope: this


						});

						this.sm.on('selectionchange',function(sm){
							this.renameBtn.setDisabled(sm.getCount()!=1);
							this.deleteBtn.setDisabled(sm.getCount()!=1);
							this.openBtn.setDisabled(sm.getCount()!=1);
							this.downloadBtn.setDisabled(sm.getCount()!=1);
							this.publishBtn.setDisabled(sm.getCount()!=1);
							this.unzipBtn.setDisabled(true);
							if(sm.getCount()==1) {
								var str= this.getFilename();
								this.publishBtn.setText((str.substr(str.length-7,str.length)=='.review') ? 'Publish':'Unpublish');
								this.unzipBtn.setDisabled( (str.substr(str.length-4,str.length)!='.zip'));
							}
						},this);


						this.tbar=[this.reloadBtn,this.openBtn, this.downloadBtn,'-',this.renameBtn,this.deleteBtn,this.unzipBtn, this.publishBtn];



						TJ.Admin.FileGridPanel.superclass.initComponent.call(this);
						this.store.on({
								update: {scope: this, fn: this.recordUpdate},

								load  : {scope: this, fn: function(){
											if(this.initValue){
												var row=0;
												this.store.each(function(f){
													if( this.initValue == String.format('/{0}/{1}',f.data.dir,f.data.name)) {
														this.getSelectionModel().selectRecords([f]);
														console.log(this.getView(),row);
														this.getView().ensureVisible(row,0,true);
														return false;
													}
													row++;
												},this);
											}
											this.initValue=false;

										}
									}
							},this);
				
						
					},
					iconRenderer: function(name, p,record){
						return '<div class="file-' + record.data.ext + '" style="background: no-repeat; padding-left: 20px;">' + name + '</div>';
					},
	
					getFilename: function() {
						var record = this.selModel.getSelected();
						if(record) {
							return record.data.dir + '/' + record.data.name;
						}
						return null;
					},
					getStatus: function(){
							var count = this.store.getTotalCount();
				            var msg = count === 0 ?
			                'No files to display' :
			                String.format('Displaying {0} files', count);
							return msg;

						},
					doOpen: function(){
						var url = '/en/filemanager:preview?file=' + escape(this.getFilename());
						window.open(url);
					},
					doDownload: function() {
						var url = '/en/filemanager:download?file=' + escape(this.getFilename());
						window.open(url);

					},
					doReload: function(){
						this.store.reload();
					},
					doPublish: function(){
						var record = this.selModel.getSelected();
						if(record) {
							var str = record.data.name;
							if(str.substr(str.length-7,str.length)=='.review')
								record.set('name',str.substr(0,str.length-7));
							else
								record.set('name',str + '.review');
						}
					},
					doUnzip: function(){
						var rec= this.getSelectionModel().getSelected();
						console.log('dounsip',rec);

							Ext.Msg.show({
							   title:'Please confirm',
							   width: 300,
							   msg: 'Are you sure you want unzip this file into this directory.<br/>  This will overwrite any matching files already in this directory and sub-directories.<BR><br> ' + rec.data.dir +'/'+rec.data.name,
							   buttons: Ext.Msg.YESNO,
							   scope: this,
							   fn: function(btn){ if(btn=='yes') {
									var params ={ cmd: 'unzip',
												  file: rec.data.dir+'/'+rec.data.name};
									var options = {
										 url: this.url,
										 record: rec,
										 scope: this,
										 params:params,
										 callback: this.cmdCallback
										};
									Ext.Ajax.request(options);
								 }
							   },
							   icon: Ext.MessageBox.QUESTION
							});


					},
					doDelete: function(){
						var rec= this.getSelectionModel().getSelected();
							Ext.Msg.show({
							   title:'Please confirm',
							   width: 300,
							   msg: 'Are you sure you want to delete this file?<BR> ' + rec.data.dir +'/'+rec.data.name,
							   buttons: Ext.Msg.YESNO,
							   scope: this,
							   fn: function(btn){ if(btn=='yes') {
									var params ={ cmd: 'delete',
												  file: rec.data.dir+'/'+rec.data.name};
									var options = {
										 url: this.url,
										 record: rec,
										 scope: this,
										 params:params,
										 callback: this.cmdCallback
										};
									Ext.Ajax.request(options);
								 }
							   },
							   icon: Ext.MessageBox.QUESTION
							});


					},
					startRename: function(){
		                this.startEditing(this.rowIndex, 0);
					},
					recordUpdate: function(store, record, operation){
						if(operation != Ext.data.Record.EDIT)
							return;

						var	params={	cmd:'rename',
										oldname: record.data.dir+'/'+record.modified.name,
										newname: record.data.dir+'/'+record.data.name};

						var options = {
							 url: this.url,
							 record: record,
							 scope: this,
							 params:params,
							 callback: this.cmdCallback
							};
						Ext.Ajax.request(options);
//						console.log(record);

					},
					cmdCallback:function(options, success, response) {
						// process Ajax success
						if(true === success) {

							// try to decode JSON response
							try {
								o = Ext.decode(response.responseText);
							}
							catch(ex) {
								this.showError(response.responseText);
							}
							if(true === o.success) {
//								console.log('asdf',o);
								switch(options.params.cmd) {
									case 'rename':
										options.record.commit();

										break;
									case 'delete':
										this.store.remove(options.record);
										break;
									case 'unzip':
										this.doReload();
										break;
									default: break;
								}
								if(o.message) {
									TJ.Admin.statusGrid.addMessage({message:o.message});
								}
							}
							else {
								switch(options.params.cmd) {
									case 'rename':
										options.record.reject();
									break;
									case 'delete':
									break;
									case 'unzip':
										break;
									default:
										break;
								}
								this.showError(o.error || response.responseText);
								if(o.error) {
									TJ.Admin.statusGrid.addMessage({message:o.error, code: 2});
								}

							}
						}
						else {
							this.showError(response.responseText);
						}
					},



					render: function(ct,position) {
						TJ.Admin.FileGridPanel.superclass.render.call(this, ct, position);
						if(this.mode=='review')
							this.store.load();
						if(this.initialDir)
							this.setDirectory(this.initialDir);

					},
					setDirectory: function(directory) {
						if(this.mode=='manager') {
							this.store.baseParams={path:directory};
							this.store.load();
							this.directory=directory;
						}
					},
					getDirectory: function(){
						return this.directory;

					}
				,showError:function(msg, title) {
					Ext.Msg.show({
						 title:title || this.errorText
						,msg:Ext.util.Format.ellipsis(msg, this.maxMsgLen)
						,fixCursor:true
						,icon:Ext.Msg.ERROR
						,buttons:Ext.Msg.OK
						,minWidth:1200 > String(msg).length ? 360 : 600
					});
				} // eo function showError

});

	TJ.Admin.FileInfoPanel = Ext.extend(Ext.Panel,{
		title: 'File Info',
		layout: 'fit',
		disabled: true,
		mode: 'file',
		extensions: ['jpg','jpeg','png','gif'],
		initComponent: function(){

			if(this.mode=='dir')
				this.title='Directory Info';

			this.items=this.getForm();

			TJ.Admin.FileInfoPanel.superclass.initComponent.call(this);


		},
		getForm: function(){

			items=[];

			for(lang in TJ.LANGUAGEDESC){
				items.push(	{	xtype: 'textfield',
								anchor:'-20',
					            msgTarget: 'side',
								fieldLabel: 'Caption (' + lang +')',
								name : 'caption_' + lang
				});
			}

			for(lang in TJ.LANGUAGEDESC){
				items.push(	{	xtype: 'textfield',
								anchor:'-20',
					            msgTarget: 'side',
								fieldLabel: 'Credit (' + lang +')',
								name : 'credit_' + lang
				});
			}

					this.saveBtn = new Ext.Toolbar.Button({
							text: 'Save',
							tooltip: 'Save Changes',
							iconCls: 'icon_accept',
							handler: function(button){ 
									this.form.getForm().submit(
											{
												params: {file:this.filename},
												failure: function(form,action) {

													TJ.Admin.ProcessJSONResponse(null,null,action.response);
												},
												success: function(form,action) {
													TJ.Admin.ProcessJSONResponse(null,null,action.response);
												}});},

							scope: this
						});
					this.cancelBtn = new Ext.Toolbar.Button({
							text: 'Cancel',
							tooltip: 'Cancel Changes',
							iconCls: 'icon_cancel',
							handler: function(button){ 
									this.form.getForm().reset();
												},
							scope: this
						});


			this.bbar=['->',this.saveBtn, this.cancelBtn];

			this.form = new Ext.form.FormPanel ({
				title:  (this.mode=='file') ? 'Select File':'Select Directory',
				url:"/en/filemanager:savefileinfo",
				items:  items,
				trackResetOnLoad: true,
				frame: true,
				border: false

			});
			return this.form;




		},
		filename: '',
		setFile: function(file,iconCls){
			this.setDisabled(true);
			this.form.items.each(function(f){f.setValue('');});

			if(file==='') {
				this.form.setTitle('Select File','icon_page_white_text');
				this.filename=file;
			}else 
			if(this.extensions.indexOf(file.split('.').pop()) >=0) {
					this.form.setTitle(file,iconCls||'icon_page_white_text');
					this.filename=file;
					
					var options = {
						 url: "/en/filemanager:getfileinfo",
						 params: {file:this.filename},
						 scope: this,
						 callback: this.fileInfoCallback
						};
					Ext.Ajax.request(options);

			} else {
				this.form.setTitle('File info not supported for this type','icon_page_white_delete');
			}
		},
		setDir: function(dir) {
			this.setDisabled(true);
			this.form.setTitle(dir,'icon_folder');
			this.form.items.each(function(f){f.setValue('');});

			this.filename=dir;
			var options = {
				 url: "/en/filemanager:getfileinfo",
				 params: {file:this.filename},
				 scope: this,
				 callback: this.fileInfoCallback
				};
			Ext.Ajax.request(options);

		},
		fileInfoCallback: function(options,success,response){
			if(success) {

				res=TJ.Admin.ProcessJSONResponse(options,success,response);
				if(res.data){
					this.form.getForm().setValues(Ext.decode(res.data));
				}
				this.setDisabled(false);
			}
		}
	});

	TJ.Admin.FileUploadPanel2 = Ext.extend(Ext.ux.PluploadPanel,{
			url: TJ.LANGUAGESS + 'filemanager:upload',
			path:'/files',
			runtimes: 'html5,browserplus,silverlight,html4',
			flash_swf_url: '/lib/external/script/extcomp3.2.1/plupload.v0.1/plupload/js/plupload.flash.swf',
			silverlight_xap_url: '/lib/external/script/extcomp3.2.1/plupload.v0.1/plupload/js/plupload.silverlight.xap',
			runtime_visible: true,
			setPath: function(path) {
				this.path=path;
			},
		    listeners: {
		        beforestart: function(uploadpanel) {
					this.uploader.settings.url=TJ.LANGUAGESS + 'filemanager:upload?path=' + this.path;
		        }
			}

	});

	Ext.reg('tjfileuploadpanel',TJ.Admin.FileUploadPanel2);

/*
	TJ.Admin.FileUploadPanel = Ext.extend(Ext.ux.UploadPanel, {
		url:"/en/filemanager:dirs"
		,title: 'Upload'
		,maxFileSize:16777216
		,initComponent: function(){
			TJ.Admin.FileUploadPanel.superclass.initComponent.call(this);
			this.uploader.progressUrl='/en/filemanager:progress';
		}
	});
*/

	TJ.Admin.FilePreviewPanel = Ext.extend(Ext.Panel,{
		title: 'Preview',
		layout: 'fit',
		extensions: ['jpg','jpeg','gif','png','pdf'],
		initComponent: function() {
			this.previewId= Ext.id();
			this.preview = new TJ.comp.IFramePanel( { 
											border: false

												});

			this.items = this.preview;

			this.sizeBtn = new Ext.CycleButton({
				showText: true,
				prependText: 'Max File Size: ',
				itemIndex:0,
				defaults: {iconCls:'icon_table'},
				items: [	
						{ value:100*1024,	text: '100KB'},
						{ value:250*1024,	text: '250KB', checked:true },
						{ value:1024*1024,	text: '1MB' },
						{ value:2048*1024,	text: '2MB' },
						{ value:5192*1024,	text: '5MB' }
				]
			});

			this.tbar  = [ this.sizeBtn];
			TJ.Admin.FilePreviewPanel.superclass.initComponent.call(this);
			this.sizeBtn.on('change',function(b,i){
				this.setFile(this.file);
			},this);


		},
		file:'',
		setFile: function(file) {
			this.file=file;
			this.preview.setSrc('/en/filemanager:preview?file=' + escape(file) + '&max=' +				escape(this.sizeBtn.activeItem.value));
		}
	});

TJ.Admin.FileManagerPanel = Ext.extend(Ext.Panel, {
	layout: 'border',
	mode : 'manager',
	setValue: function(val) {
		this.DirTreePanel.setDirectory(val);
		this.FileGridPanel.setValue(val);

	},
	initComponent: function(){


		this.FilePreviewPanel = new TJ.Admin.FilePreviewPanel();
		this.FileGridPanel = new TJ.Admin.FileGridPanel({showStatus:false, mode: this.mode});
		if(this.mode == 'manager') {
			this.DirTreePanel = new TJ.Admin.DirectoryTreePanel({showStatus:false});
			this.FileUploadPanel = new TJ.Admin.FileUploadPanel2({
					title: 'Upload',
					addButtonCls: 'icon_add',
					uploadButtonCls: 'icon_arrow_up',
					cancelButtonCls: 'icon_stop',
					deleteButtonCls: 'icon_cross'
			});	

			this.FileInfoPanel = new TJ.Admin.FileInfoPanel();

			this.DirInfoPanel = new TJ.Admin.FileInfoPanel({mode:'dir'});
		
			this.DirTreePanel.getSelectionModel().on('selectionchange',function() {this.FileUploadPanel.setPath(this.DirTreePanel.getDirectory());
																	  this.FileGridPanel.setDirectory(this.DirTreePanel.getDirectory());
																		this.getBottomToolbar().setStatus('Directory:  <b>/' + this.DirTreePanel.getDirectory() + '</b>');
																		this.DirInfoPanel.setDir(this.DirTreePanel.getDirectory());
//																		this.DirInfoPanel.ownerCt.activate(this.DirInfoPanel);
																		this.FileInfoPanel.setFile('');
																 	 },this);
		
//			this.FileUploadPanel.on('allfinished',function(){ this.FileGridPanel.store.reload();},this);		
			this.FileUploadPanel.on('uploadcomplete',function(){ this.FileGridPanel.store.reload();},this);		
		
		}

///		this.uploadPanel = new Ext.Panel({title: 'Upload'});



		this.FileGridPanel.getSelectionModel().on('selectionchange', function(sm){ 
			if(sm.getCount()>0){
				this.getBottomToolbar().setStatus('File:  <b>/' + this.FileGridPanel.getFilename() + '</b>');
				this.FilePreviewPanel.setFile(this.FileGridPanel.getFilename() );
				this.FileInfoPanel.setFile(this.FileGridPanel.getFilename());
//				this.FileInfoPanel.ownerCt.activate(this.FileInfoPanel);
			}else {
				this.FileInfoPanel.setFile('');
//				this.DirInfoPanel.ownerCt.activate(this.DirInfoPanel);
			}

		},this);
			

		if(this.mode == 'manager') {

		this.items = [ { region: 'west',
						 layout: 'fit',
						 items: this.DirTreePanel,
						 width: 272,
 						 split: true,
						 frame: false,
						border: false
						},
						{	region: 'center',
							layout: 'fit',
							items: this.FileGridPanel,
							frame: false, border: false
						},
/*						{ region: 'east',
							width: 240,

							split: true,
							frame: false, border: false,
							xtype: 'tabpanel',
							activeTab: 0,
//						  collapsible: true,
//						  collapsed: this.selectfile,
							items: [	
									this.FileInfoPanel,
									this.DirInfoPanel//,
//									this.FileUploadPanel
								 										
							  ]

						},
*/						{ region: 'south',
						  height: 200,
						  split: true,
						  frame: false,	border: false,
						  title: 'Preview File',
						  collapsible: true,
						  collapsed: false,//this.selectfile,
						  items: [	
									this.FilePreviewPanel,
									this.FileInfoPanel,
									this.DirInfoPanel,
									this.FileUploadPanel

						  ],
							xtype:'tabpanel', activeTab: 0

						  }];
		}else{
		this.items = [ 	{	region: 'center',
							layout: 'fit',
							items: this.FileGridPanel,
							frame: false, border: false
						},
						{ region: 'south',
						  height: 200,
						  split: true,
						  frame: false, border: false,
						  layout: 'fit',
						  title: 'Preview File',
						  collapsible: true,
						  collapsed: this.selectfile,
						  items: this.FilePreviewPanel
						  }];
		}

		this.bbar =  new Ext.StatusBar({defaultText: ''});
		TJ.Admin.FileManagerPanel.superclass.initComponent.call(this);
//		this.items=[];
	},
	getSelectedFilename: function() {
		return this.FileGridPanel.getFilename();
	}

});

Ext.reg('tjadmin_filemanagerpanel',TJ.Admin.FileManagerPanel);

	TJ.Admin.FileSelectWindow = Ext.extend(Ext.Window,{
		width: 800,
		height: 500,
                constrainHeader:true,				
		modal: true,
		layout: 'fit',
		title: 'Select File',
		closeAction: 'hide',
		callback: null,
		initComponent: function() {
			this.fm = new TJ.Admin.FileManagerPanel({selectfile:true});
//			console.log(this.initialValue);
			this.items =this.fm;

			this.addEvents('select');
			this.selBtn = new Ext.Button({
						text: 'Select File',
	                    disabled:true,
						handler: this.select,
						scope: this
					});

			this.closeBtn = new Ext.Button({ text: 'Cancel', handler: function(){ this.hide(); }, scope: this });

		this.buttons = [this.selBtn, this.closeBtn];
			
			
			TJ.Admin.FileSelectWindow.superclass.initComponent.call(this);

			this.fm.FileGridPanel.selModel.on('selectionchange', function(sm){ 
				
				this.selBtn.setDisabled(sm.getCount()===0);
				if(sm.getCount()) {
					this.selBtn.el.dom.setAttribute('title', 'Select file:  /' + this.fm.getSelectedFilename());
				} else {
					this.selBtn.el.dom.setAttribute('title', 'Please select a file');
				}

				
				},this);


		},
		show: function(callback){
			if(callback)
				this.callback=callback;
			TJ.Admin.FileSelectWindow.superclass.show.call(this);

		},

		setValue:function(value) {
			this.fm.setValue(value);

		},
		select: function() {
//			console.log(this.fm.getSelectedFilename());
			this.fireEvent('select', this.fm.getSelectedFilename());
			if(this.callback) {
				this.hide();
				this.callback(this.fm.getSelectedFilename());
				this.callback=null;


			}
		}
	});
