var ContactUs = {
	view :null,
	ds: null,
	config: {
		form_path: 'contact_form',
		btn_path: 'sub_btn',
		thank_msg: 'thank_msg',
		form_table: 'form_table'
	},
	contact_form: null,
	
	init: function() {
		Ext.QuickTips.init();
		this.contact_form = new ITechs.QuickForm(this.config.form_path, {unsetErrorsReader: true});
		this.contact_form.on('actioncomplete', this.claerFields, this, true);
		this.contact_form.on('actionfailed', this.display_msg.createDelegate(this, [false]), this, true);
	},
	
	insert: function(){
		if (this.contact_form){
			this.contact_form.submit();
		}
	},
	
	onSendNext: function() {
		this.display_msg(false);
	},
	
	display_msg: function(mode) {
		if (this.success_msg_current && this.success_msg_current == mode) {
			return true;
		}
		if (!this.success_msg) {
			this.success_msg = Ext.getDom(this.config['thank_msg']);
			if (!this.success_msg) return false;
		}
		this.success_msg_current = mode;
		this.success_msg.style.display = mode ? '' : 'none';
		if (!this.form_table) {
			this.form_table = Ext.getDom(this.config['form_table']);
			if (!this.form_table) return false;
		}
		this.form_table.style.display = mode ? 'none' : '';
	},
	
	claerFields: function(){
		this.display_msg(true);
		var l = ContactUs.contact_form.getEl().dom.elements;
		for(var i=0; i<l.length; i++) {
			if (l[i].type == 'button') continue;
			var key = l[i].name.replace(/(?:f\[)(.*)(?:\])/, "$1");
			l[i].value = '';
		}		
	}
};
Ext.onReady(ContactUs.init, ContactUs, true);