/*
* $Id: preferences.js 634 2008-07-29 02:11:41Z lukejee $

*/
Ext.namespace('NGMP.preferences');

NGMP.preferences.PreferencesModule = function(A) {
	if (!A)
		A = {};

	this.personalButton = new Ext.Button({
		iconCls:'icon-personal',
		text:LANG_personal_details,
		enableToggle:true,
		pressed:true,
		toggleGroup:'preferences',
		toggleHandler:this.showPanel,
		scope:this
	});

	this.mailButton = new Ext.Button({
		iconCls:'icon-mail',
		text:LANG_mail,
		enableToggle:true,
		toggleGroup:'preferences',
		toggleHandler:this.showPanel,
		scope:this
	});

	this.antispamButton = new Ext.Button({
		iconCls:'icon-spam',
		text:LANG_anti_spam + ' ' + LANG_settings,
		enableToggle:true,
		toggleGroup:'preferences',
		toggleHandler:this.showPanel,
		scope:this
	});

	this.tbar = [this.personalButton, this.mailButton,this.antispamButton];

	this.widthNameField = 100;
	this.widthLeftColumn = 250;
	this.widthRightColumn = 253;
	this.widthInputSeparator = 3;
	this.widthExtraField = 50;
	this.separator = ':';

		
	this.formAccount = new Ext.form.TextField({
		fieldLabel:LANG_account,
		name:'account',
		disabled:true,
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formPassword = new Ext.form.TextField({
		fieldLabel:LANG_password,
		inputType:'password',
		name:'password',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formPassword2 = new Ext.form.TextField({
		fieldLabel:LANG_verify_password,
		inputType:'password',
		name:'password2',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});

	this.formFirstName = new Ext.form.TextField({
		fieldLabel: LANG_name,
		name:'first_name',
		id:'first_name',
		alllowBlank:false,
		width:this.widthLeftColumn - (this.widthNameField + this.widthExtraField + (2*this.widthInputSeparator))
	});

	this.formMiddleName = new Ext.form.TextField({
		fieldLabel:'',
		name:'middle_name',
		labelSeparator:null,
		hideLabel:true,
		width:this.widthExtraField,
		style:'margin-left:'+this.widthInputSeparator+'px;'
	});

	this.formLastName = new Ext.form.TextField({
		fieldLabel:'',
		name:'last_name',
		labelSeparator:null,
		hideLabel:true,
		width:this.widthLeftColumn - (this.widthNameField+this.widthExtraField+(2*this.widthInputSeparator)),
		allowBlank:false,
		style:'margin-left:' + this.widthInputSeparator+'px;'
	});

	this.formTitle = new Ext.form.TextField({
		fieldLabel:LANG_contact_title,
		name:'title',
		labelSeparator:this.separator,
		width:126
	});

	this.formInitials = new Ext.form.TextField({
		fieldLabel:'',
		name:'initials',
		labelSeparator:null,
		hideLabel:true,
		width:127,
		style:'margin-left: '+this.widthInputSeparator + 'px;'
	});

	this.formSexMale = new Ext.form.Radio({
		name:'sex',
		fieldLabel:LANG_sex,
		labelSeparator:this.separator,
		boxLabel:LANG_male,
		checked:true,
		inputValue:'M',
		dataIndex:'sexM',
		width:75
	});

	this.formSexFemale = new Ext.form.Radio({
		name:'sex',
		fieldLabel:LANG_female,
		labelSeparator:null,
		hideLabel:true,
		inputValue:'F',
		dataIndex:'sexF',
		width:75,
		height:20
	});

	this.formBirthday = new Ext.form.DateField({
		fieldLabel:LANG_birthday,
		name:'birthday',
		format: NGMP.preferences.settings.date_format,
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formEmail = new Ext.form.TextField({
		fieldLabel: LANG_email,
		name:'email',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formEmail2 = new Ext.form.TextField({
		fieldLabel: LANG_email + '2',
		name:'email2',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formEmail3 = new Ext.form.TextField({
		fieldLabel: LANG_email + '3',
		name:'email3',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formIM = new Ext.form.TextField({
		fieldLabel: LANG_im,
		name:'im',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formIM2 = new Ext.form.TextField({
		fieldLabel: LANG_im + '2',
		name:'im2',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formIM3 = new Ext.form.TextField({
		fieldLabel: LANG_im + '3',
		name:'im3',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formPhone = new Ext.form.TextField({
		fieldLabel: LANG_phone,
		name:'phone',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formPhoneWork = new Ext.form.TextField({
		fieldLabel: LANG_phone_work,
		name:'phone_work',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formFax = new Ext.form.TextField({
		fieldLabel: LANG_fax,
		name:'fax',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formMobile = new Ext.form.TextField({
		fieldLabel: LANG_mobile,
		name:'mobile',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});
	this.formFaxWork = new Ext.form.TextField({
		fieldLabel: LANG_fax_work,
		name:'fax_work',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});
	this.formMobileWork = new Ext.form.TextField({
		fieldLabel: LANG_mobile_work,
		name:'mobile_work',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});
	this.formStreetAddress = new Ext.form.TextField({
		fieldLabel: LANG_street_address,
		name:'street_address',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formZipCode = new Ext.form.TextField({
		fieldLabel: LANG_zip_code,
		name:'zip_code',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formCity = new Ext.form.TextField({
		fieldLabel: LANG_city,
		name:'city',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formState = new Ext.form.TextField({
		fieldLabel: LANG_state,
		name:'state',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formCountry = new Ext.form.TextField({
		fieldLabel: LANG_country,
		name:'country',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formCompany = new Ext.form.TextField({
		fieldLabel: LANG_company,
		name:'company',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});
	this.formDepartment = new Ext.form.TextField({
		fieldLabel: LANG_department,
		name:'department',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});
	this.formFunction = new Ext.form.TextField({
		fieldLabel: LANG_work_function,
		name:'work_function',
		labelSeparator:this.separator,
		width:this.widthRightColumn
	});

	this.formRealName = new Ext.form.TextField({
		fieldLabel: LANG_displayed_name,
		name:'real_name',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formReplyTo = new Ext.form.TextField({
		fieldLabel: LANG_reply_to,
		name:'reply_to',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formSortEmailBy = new Ext.form.ComboBox({
		fieldLabel: LANG_sort_email_by,
		hiddenName:'sort_mail_by',
		value:'received',
		store: new Ext.data.SimpleStore({
			fields:['value', 'text'],
			data:[
				['received', LANG_received],
				['subject', LANG_subject],
				['from', LANG_from]
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		listWidth: this.widthLeftColumn,
		width:this.widthLeftColumn,
		labelSeparator:this.separator
	});
	this.formLanguage = new Ext.form.ComboBox({
		fieldLabel:LANG_language,
		hiddenName:'language',
		value:'en_us',
		store: new Ext.data.SimpleStore({
		fields:[{name:'value'}, {name:'text'}],
			data:[
				['en_us', LANG_en_us],
				['zh_cn', LANG_zh_cn],
				['zh_tw', LANG_zh_tw]
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		listWidth: this.widthLeftColumn,
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});
	this.formInboxRefreshRate = new Ext.form.ComboBox({
		fieldLabel:LANG_inbox_refresh_rate,
		hiddenName:'inbox_refresh_rate',
		value:20,
		store: new Ext.data.SimpleStore({
			fields:['value', 'text'],
			data:[
				[-1, LANG_disable],
				[1, '1 '+LANG_minute],
				[5, '5 '+LANG_minutes],
				[10,'10 ' + LANG_minutes],
				[20, '20 ' + LANG_minutes],
				[30, '30 ' + LANG_minutes],
				[60, '1 ' + LANG_hour]
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		labelSeparator:this.separator,
		listWidth: this.widthLeftColumn,
		width:this.widthLeftColumn
	});
	this.formRowsPerPage = new Ext.form.ComboBox({
		fieldLabel:LANG_number_of_messages_to_display,
		hiddenName:'rpp',
		value:25,
		store: new Ext.data.SimpleStore({
			fields:['value', 'text'],
			data:[
				[10, '10'],
				[25, '25'],
				[50, '50'],
				[100, '100'],
				[200, '200']
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		labelSeparator:this.separator,
		listWidth: this.widthLeftColumn,
		width:this.widthLeftColumn
	});
	this.formTimeFormat = new Ext.form.ComboBox({
		fieldLabel:LANG_time_format,
		hiddenName:'time_format',
		value:'H:i',
		store: new Ext.data.SimpleStore({
			fields:['value', 'text'],
			data:[
				['h:i A', '12 '+LANG_hour],
				['H:i', '24 '+LANG_hour]
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		labelSeparator:this.separator,
		listWidth: this.widthLeftColumn,
		width:this.widthLeftColumn
	});
	this.formDateFormat = new Ext.form.ComboBox({
		fieldLabel:LANG_date_format,
		hiddenName:'date_format',
		value:'Y-m-d',
		store: new Ext.data.SimpleStore({
			fields:['value', 'text'],
			data:[
				['Y-m-d', LANG_y_m_d],
				['d-m-Y', LANG_d_m_y],
				['m-d-Y', LANG_m_d_y],
				['Y-d-m', LANG_y_d_m]
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		labelSeparator:this.separator,
		listWidth: this.widthLeftColumn,
		width:this.widthLeftColumn
	});

	this.formTimeZone = new Ext.form.ComboBox({
		fieldLabel:LANG_time_zone,
		hiddenName:'time_zone',
		value:'',
		store: new Ext.data.SimpleStore({
			fields:['value', 'text'],
			data:[
				['', LANG_select],
				['asia/shanghai', '+0800: '+LANG_asia+'/'+LANG_shanghai]
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		labelSeparator:this.separator,
		listWidth: this.widthLeftColumn,
		width:this.widthLeftColumn
	});

	this.formBlockImages = new Ext.form.ComboBox({
		fieldLabel:LANG_block_images_in_email_messages,
		hiddenName:'block_images',
		value:1,
		store: new Ext.data.SimpleStore({
			fields:['value','text'],
			data:[
				[0, LANG_display_for_any_message],
				[1, LANG_display_for_trusted_users_in_addressbook],
				[2, LANG_block_all]
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		listWidth: this.widthLeftColumn,
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});

	this.formAutoDeleteTrash = new Ext.form.Checkbox({
		fieldLabel:LANG_auto_delete_trash,
		name:'auto_delete_trash',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});

	this.formDeleteTrashOnLogout = new Ext.form.Checkbox({
		fieldLabel:LANG_delete_trash_on_logout,
		name:'delete_trash_on_logout',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});

	this.formHtmlEditor = new Ext.form.Checkbox({
		fieldLabel:LANG_html_email_editor,
		name:'html_email_editor',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});

	this.formEmailSignature = new Ext.form.HtmlEditor({
		fieldLabel:LANG_email_signature,
		name:'html_email_signature',
		labelSeparator:this.separator,
		height:80,
		width:398
	});

	this.formEmailEncryption = new Ext.form.ComboBox({
		fieldLabel:LANG_enable_mail_encryption,
		hiddenName:'mail_encryption',
		value:0,
		store: new Ext.data.SimpleStore({
			fields:['value','text'],
			data:[
				[0, LANG_disable],
				[1, LANG_enable]
			]
		}),
		displayField:'text',
		valueField:'value',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		listWidth: this.widthLeftColumn,
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});

	this.formEmailForward = new Ext.form.TextField({
		fieldLabel:LANG_forward_to_address,
		name:'email_forward',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});

	this.formAutoReplyMessage = new Ext.form.HtmlEditor({
		fieldLabel:LANG_autoreply_message,
		name:'email_autoreply_message',
		labelSeparator:this.separator,
		width:this.widthLeftColumn
	});

	this.accountFieldset = {
		xtype:'fieldset',
		title:LANG_account,
		autoHeight:true,
		border:true,
		collapsed:false,
		defaults:{border:false, layout:'table'},
		items:[{
			defaults:{border:false, layout:'form'},
			items:[{items:[this.formAccount]}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{items:[this.formPassword]}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{items:[this.formPassword2]}]
		},{
			defaults:{border:false, layout:'form'},
			items:[{items:[this.formLanguage]}]
		}]
	};

	this.personalFieldset = {
		xtype:'fieldset',
		title:LANG_personal_details,
		autoHeight:true,
		collapsed:false,
		border:true,
		defaults:{border:false, layout:'table'},
		items:[{
			defaults:{border:false, layout:'form'},
			items:[{
				items:[this.formFirstName]
			},{
				items:[this.formMiddleName]
			},{
				items:[this.formLastName]
			}]
		},{
			defaults:{border:false},
			items:[{
				layout:'form',
				items:[this.formTitle]
			},{
				layout:'form',
				items:[this.formInitials]
			}]
		},{
			defaults:{border:false},
			items:[{
				layout:'form',
				items:[this.formBirthday]
			}]
		}]
	};

	this.addressFieldset = {
		xtype:'fieldset',
		title:LANG_address,
		autoHeight:true,
		collapsed:false,
		border:true,
		defaults:{border:false, layout:'table'},
		items:[{
			defaults:{border:false},
			items:[{
				layout:'form',
				items:[this.formStreetAddress]
			}]
		},{
			defaults:{border:false},
			items:[{
				layout:'form',
				items:[this.formZipCode]
			}]
		},{
			defaults:{border:false},
			items:[{
				layout:'form',
				items:[this.formCity]
			}]
		},{
			defaults:{border:false},
			items:[{
				layout:'form',
				items:[this.formState]
			}]
		},{
			defaults:{border:false},
			items:[{
				layout:'form',
				items:[this.formCountry]
			}]
		}]
	};

	this.contactFieldset = {
		xtype:'fieldset',
		title:LANG_contact,
		autoHeight:true,
		border:true,
		collapsed:false,
		defaults:{border:false, layout:'table'},
		items:[{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formEmail]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formEmail2]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formEmail3]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formIM]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formIM2]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formIM3]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formPhone]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formFax]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formMobile]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formPhoneWork]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formFaxWork]}]
		},{
			defaults:{border:false},
			items:[{layout:'form', items:[this.formMobileWork]}]
		}]
	};

	this.workFieldset = {
		xtype:'fieldset',
		title:LANG_work,
		autoHeight:true,
		collapsed: false,
		border:true,
		defaults:{border:false, layout:'table'},
		items:[{
			defaults:{border:false}, items:[{layout:'form', items:[this.formCompany]}]
		},{
			defaults:{border:false}, items:[{layout:'form', items:[this.formDepartment]}]
		},{
			defaults:{border:false}, items:[{layout:'form', items:[this.formFunction]}]
		}]
	};

	this.webmailPreferencesFieldset = {
		xtype:'fieldset',
		title:LANG_webmail_preferences,
		autoHeight:true,
		collapsed:false,
		border:true,
		labelWidth: 180,
		defaults:{border:false, layout:'table'},
		items:[
			this.formRealName,this.formReplyTo, this.formSortEmailBy,
		this.formInboxRefreshRate,
		this.formRowsPerPage,
		this.formTimeFormat,
		this.formDateFormat,
		this.formTimeZone,
		this.formBlockImages,
		{
			defaults:{border:false},
			items:[{ layout:'form', items:[this.formAutoDeleteTrash] }]
		},{
			defaults:{border:false},
			items:[{ layout:'form', items:[this.formDeleteTrashOnLogout] }]
		},{
			defaults:{border:false},
			items:[{ layout:'form', items:[this.formHtmlEditor] }]
		}, this.formEmailSignature
		]
	};
	this.mailSettingsFieldset = {
		xtype:'fieldset',
		title:LANG_mail_settings,
		autoHeight:true,
		collapsed:false,
		labelWidth: 120,
		border:true,
		defaults:{border:false, layout:'table'},
		items:[
			this.formEmailForward,
			this.formAutoReplyMessage
		]
	};

	
	this.personalFormPanel = new Ext.form.FormPanel({
		url:'ngmp.php',
		border:false,
		baseParams: {
			func:'prefPersonal'
		},
		bodyStyle:'padding: 5px 5px 5px 5px',
		layout:'column',
		defaults:{border:false},
		items:[{
			columnWidth:0.5,
			defaults:{border:false},
			items:[this.accountFieldset,this.personalFieldset,this.addressFieldset]
		},{
			columnWidth:0.5,
			style:'margin-left:5px;',
			defaults:{border:false},
			items:[this.contactFieldset, this.workFieldset]
		}],
		buttons: [
			new Ext.Button({
				text:LANG_save,
				handler:function() {
					this.personalFormPanel.getForm().submit({
						params:{
							action:'update'
						}
					});
				},
				scope:this
			}),
			new Ext.Button({
				text:LANG_cancel,
				handler:function() {
					this.personalFormPanel.form.load();
				},
				scope:this
			})
		]
	});

	this.personalFormPanel.on('show', function() {
		this.personalFormPanel.load();
	},this);

	this.formWhiteListAddress = new Ext.form.TextField({
		fieldLabel:LANG_email,
		vtype:'email'
	});

	this.gridWhitelist = new NGMP.grid.GridPanel({
		height:250,
		title:LANG_trusted_senders,
		tbar:[LANG_email,this.formWhiteListAddress,{
			iconCls:'icon-add',
			text:LANG_add,
			handler:function() {
				if (this.formWhiteListAddress.validate()) {
					this.gridWhitelist.store.baseParams.add_id = this.formWhiteListAddress.getValue();
					this.gridWhitelist.store.reload();
					delete this.gridWhitelist.store.baseParams.add_id;
				}
			},
			scope:this
		},'-',{
			text:LANG_delete,
			iconCls:'icon-delete',
			handler:function() {
				if (this.gridWhitelist.selModel.selections.keys.length ===1) {
					this.gridWhitelist.store.baseParams.delete_id = this.gridWhitelist.selModel.selections.keys[0];
					this.gridWhitelist.store.reload();
					delete this.gridWhitelist.store.baseParams.delete_id;
				}

			},
			scope:this
		}],
		store: new NGMP.data.JsonStore({
			url:'ngmp.php',
			baseParams:{
				func:'prefWhitelist'
			},
			root:'results',
			id:'id',
			fields:['id', 'value']
		}),
		columns:[{
			header:LANG_email,
			dataIndex:'value'
		}],
		view: new Ext.grid.GridView({
			autoFit:true,
			forceFit:true
	  	}),
		loadMask:{
			msg:LANG_loading
		},
		sm: new Ext.grid.RowSelectionModel({singleSelect:true})
	});

	this.formBlackListAddress = new Ext.form.TextField({
		fieldLabel:LANG_email,
		vtype:'email'
	});

	this.gridBlacklist = new NGMP.grid.GridPanel({
		height:250,
		title:LANG_blacklist_senders,
		tbar:[LANG_email, this.formBlackListAddress,{
			iconCls:'icon-add',
			text:LANG_add,
			handler:function() {
				if (this.formBlackListAddress.validate()) {
					this.gridBlacklist.store.baseParams.add_id = this.formBlackListAddress.getValue();
					this.gridBlacklist.store.reload();
					delete this.gridBlacklist.store.baseParams.add_id;
				}
			},
			scope:this
		},{
			text:LANG_delete,
			iconCls:'icon-delete',
			handler:function() {
				if (this.gridBlacklist.selModel.selections.keys.length ===1) {
					this.gridBlacklist.store.baseParams.delete_id = this.gridBlacklist.selModel.selections.keys[0];
					this.gridBlacklist.store.reload();
					delete this.gridBlackList.store.baseParams.delete_id;
				}
			},
			scope:this
		}],
		store: new NGMP.data.JsonStore({
			url:'ngmp.php',
			baseParams:{
				func:'prefBlacklist'
			},
			root:'results',
			id:'id',
			fields:['id', 'value']
		}),
		columns:[{
			header:LANG_email,
			dataIndex:'value'
		}],
		view: new Ext.grid.GridView({
			autoFit:true,
			forceFit:true
	  	}),
		loadMask:{
			msg:LANG_loading
		},
		sm: new Ext.grid.RowSelectionModel({singleSelect:true})
	});

	this.formResetAntispamDB = new Ext.form.Checkbox({
		fieldLabel:LANG_reset_antispam,
		fieldDescription:LANG_reset_antispam_description,
		name:'reset_antispam_db'
	});

	this.formSkipAntispamCheck = new Ext.form.Checkbox({
		fieldLabel:LANG_bypass_spam_check,
		fieldDescription:LANG_bypass_spam_check_description,
		name:'bypass_spam_check'
	});

	this.formSpamAction = new Ext.form.ComboBox({
		fieldLabel:LANG_spam_action,
		fieldDescription:LANG_spam_action_description,
		hiddenName:'spam_action',
		store: new Ext.data.SimpleStore({
			id:'value',
			fields:['value','text'],
			data:[
				['move_to_spam_folder', LANG_move_to_spam_folder],
				['delete', LANG_delete]
			]
		}),
		displayField:'text',
		valueField:'value',
		value:'move_to_spam_folder',
		mode:'local',
		triggerAction:'all',
		editable:false,
		selectOnFocus:true,
		forceSelection:true,
		allowBlank:false,
		listWidth:200
	});

	this.formSpamMessageSizeLimit = new Ext.form.NumberField({
		fieldLabel:LANG_message_size_limit,
		fieldDescription:LANG_spam_message_size_limit_description,
		name:'message_size_limit'
	});

	this.formWhiteListOnly = new Ext.form.Checkbox({
		fieldLabel:LANG_whitelist_only,
		fieldDescription:LANG_whitelist_only_description,
		name:'whitelist_only'
	});

	this.saFieldset = {
		xtype:'fieldset',
		title:LANG_spam + ' ' + LANG_settings,
		autoHeight:true,
		collapsed:false,
		border:true,
		layout:'ngmp_form',
		labelWidth:250,
		items:[
			this.formResetAntispamDB,
			this.formWhiteListOnly,
			this.formSkipAntispamCheck,
			this.formSpamAction,
			this.formSpamMessageSizeLimit
		]
	};

	this.antispamFormPanel = new Ext.form.FormPanel({
		url:'ngmp.php',
		border:false,
		baseParams:{
			func:'prefAntispam'
		},
		bodyStyle:'padding:5px 5px 5px 5px;',
		layout:'column',
		defaults:{border:false},
		items:[{
			columnWidth:0.5,
			items:[this.saFieldset]
		},{
			columnWidth:0.5,
			style:'margin-left:5px;',
			items:[this.gridWhitelist, this.gridBlacklist]
		}],
		buttons:[{
			text:LANG_save,
			handler:function() {
				this.antispamFormPanel.form.submit({
					params:{save:true}
				});
			},
			scope:this
		},{
			text:LANG_cancel,
	 		handler:function() {
				this.antispamFormPanel.form.reset();
	 		},
			scope:this
		}]
	});

	this.antispamFormPanel.on('show', function() {
		this.antispamFormPanel.load();
		this.gridWhitelist.store.reload();
		this.gridBlacklist.store.reload();
	},this);


	this.mailFormPanel = new Ext.form.FormPanel({
		url:'ngmp.php',
		border:false,
		baseParams:{
			func:'prefMail'
		},
		bodyStyle:'padding:5px 5px 5px 5px',
		layout:'column',
		defaults:{border:false},
		items:[{
			columnWidth:0.5,
			defaults:{border:false},
			items:[this.webmailPreferencesFieldset]
		},{
			columnWidth:0.5,
			style:'margin-left:5px;',
			defaults:{border:false},
			items:[this.mailSettingsFieldset]
		}],
		buttons:[
			new Ext.Button({
				text:LANG_save,
				handler:function() {
					this.mailFormPanel.getForm().submit({
						params:{
							action:'update'
						}
					});
				},
				scope:this
			}),
			new Ext.Button({
				text:LANG_cancel,
				handler:function() {
					this.personalFormPanel.load();
				},
				scope:this
			})
		]
	});

	this.items = [this.personalFormPanel, this.mailFormPanel, this.antispamFormPanel];

	NGMP.preferences.PreferencesModule.superclass.constructor.call(this,A);
};
Ext.extend(NGMP.preferences.PreferencesModule,Ext.Panel, {
	layout:'card',
	activeItem: 0,
	showPanel:function(A, B) {
		if (B) {
			switch (A) {
				case this.personalButton:
					this.getLayout().setActiveItem(this.personalFormPanel);
					break;
				case this.mailButton :
					this.getLayout().setActiveItem(this.mailFormPanel);
					break;
				case this.antispamButton:
					this.getLayout().setActiveItem(this.antispamFormPanel);
					break;
				default:
					break;
			}
		}
		this.doLayout();
	}
});
NGMP.moduleManager.addModule('preferences', NGMP.preferences.PreferencesModule, {
	title:LANG_preferences,
	iconCls:'icon-preferences'
});
