// JavaScript Document
ContactForm = function(){
	var form = new Ext.form.FormPanel({
		url: 'index.php?module=Contact&task=send',
		renderTo: 'contactForm',
		baseCls: '',
		monitorValid: true,
		defaults: {xtype: 'textfield', width: 250, allowBlank: false, cls: 'contactFormField', blankText: 'Cần nhập liệu'},
		items: [
			{
				fieldLabel: 'Họ Tên',
				name: 'name'
			},{
				fieldLabel: 'E-mail',
				name: 'email',
				vtype: 'email',
				vtypeText: 'E-mail không đúng'
			},{
				fieldLabel: 'Điện Thoại',
				name: 'phone',
				allowBlank: true
			},new Ext.form.ComboBox({
				fieldLabel: 'Gửi Đến',
				hiddenName: 'to',
				editable: false,
				store: new Ext.data.Store({
					autoLoad: true,
					proxy: new Ext.data.HttpProxy({
						url: 'index.php?module=Contact&task=emailStore'						  
					}),
					reader: new Ext.data.JsonReader({
							root: 'results'								
						},
						[
							{name: 'name', type: 'string', mapping: 'name'},
							{name: 'address', type: 'string', mapping: 'address'} 
						]
					)
				}),
				displayField: 'name',
				valueField: 'address',
				triggerAction: 'all',
				mode: 'local'

			}),{
				fieldLabel: 'Tiêu Đề',
				name: 'subject'
			},{
				hideLabel: true,
				xtype: 'textarea',
				name: 'content',
				width: 355,
				height: 200
			}
		],
		buttons: [
			{
				text: 'Gửi',
				formBind: true,
				handler: function(button){
					document.getElementById('contactFormContainer').style.display = 'none';
					document.getElementById('contactMsg').style.display = 'block';
					form.getForm().submit({
						success: function(form, action){
							document.getElementById('contactMsg').innerHTML = action.result.msg;
						},
						failure: function(form, action){
							document.getElementById('contactMsg').innerHTML = action.result.msg;
						}
					});
				}
			}		 
		]
	});
}
