var BanDialog = function(){
  var dialog;
  var form_ban;
  
  return {
  	show: function (channelId, userId) {
 			dialog = this.dialog;
 			if(!dialog){
		    dialog = new Ext.BasicDialog("ban-dlg", { 
		      modal: false, width:350, height:270, shadow:false, draggable: true, resizable: false, collapsible: false, autoTabs:true, shadow: false
		    });
		    dialog.addKeyListener(27, dialog.hide, dialog);
		    BanDialog.initDialog(dialog);
			}
			//dialog.show(ChatLayout.registerBtn.getEl().dom);
			BanDialog.params.channelId = channelId;
			BanDialog.params.userId = userId;
			this.banBtn.enable ();
			dialog.show();
			this.dialog = dialog;
 		},
 		
 		initDialog: function (dialog) {
 			BanDialog.params = new Array ();
 			
 			// Form Login
 			form_ban = new Ext.form.Form({labelAlign: 'top', buttonAlign: 'left', url: '/pages/channel/_json.ban_user.php'});
 			Ext.form.Field.prototype.msgTarget = 'side';
 			var labelWidth = 260;
 			
 			var store = new Ext.data.SimpleStore({
        fields: ['time', 'label'],
        data : 	[[60, '1 ' + locStrings["ban_minute"]], [300, '5 ' + locStrings["ban_minutes"]], [600, '10 '  + locStrings["ban_minutes"]], [1800, '30 '  + locStrings["ban_minutes"]], [3600, '1 '  + locStrings["ban_hour"]],[10800, '3 '  + locStrings["ban_hours"]],[86400, '1 ' + locStrings["ban_day"]]]
    	});
 			
 			var field_reason = new Ext.form.TextField({fieldLabel: locStrings["ban_reason"], name: 'reason',   width:labelWidth});
 			var field_time = new Ext.form.ComboBox({id: "ban_time", fieldLabel: locStrings["ban_time"], name: 'timeLabel', hiddenName: 'time', store: store, displayField:'label', valueField: 'time', value: 60, typeAhead: true, mode: 'local', triggerAction: 'all', forceSelection: true});
 			var field_clearmessages = new Ext.form.Checkbox({fieldLabel: locStrings["ban_clearmessages"], name: 'clearmessages', width:20});
 			
 			
 			form_ban.add(field_time, field_reason, field_clearmessages);
 			this.banBtn = form_ban.addButton({text:locStrings["ban_btn"], type: "submit"}, BanDialog.tryBan, this);
 			form_ban.addButton(locStrings["cancel_btn"], dialog.hide, dialog);
 			form_ban.render ("form-ban");
 		},
 			
 		tryBan: function () {
 			this.banBtn.disable ();
 			form_ban.baseParams = new Array ();
 			form_ban.baseParams.userId = BanDialog.params.userId; 
 			form_ban.baseParams.channelId = BanDialog.params.channelId; 
 			form_ban.baseParams.timeLabel = form_ban.findField("ban_time").lastSelectionText;
 			
 			if (form_ban.isValid()) {
        form_ban.submit({
        	params: {action: 'submit'},
        	success: function (form, action) {
        		dialog.hide ();
        	},
        	failure: function (form, action) {
        		Ext.MessageBox.alert(locStrings["error_title"], action.result.errors[0].message);
        	}
        });
	    }else{
	        Ext.MessageBox.alert(locStrings["error_title"], locStrings["error_need_fields"]);
	    }
 		}
 	}
}();