Ext.apply( Ext.form.VTypes, {
	password: function( value, field ){
		if ( field.initialPasswordField ){
			var pwd = Ext.getCmp(field.initialPasswordField);
			this.passwordText = 'Confirmation does not match your intial password entry.';
			return ( value == pwd.getValue() );
		}

		this.passwordText = 'Passwords must be at least 5 characters, containing either a number, or a valid special character (!@#$%^&*()-_=+)';
		var hasSpecial = value.match(/[0-9!@#\$%\^&\*\(\)\-_=\+]+/i);
		var hasLength = (value.length >= 5);

		return ( hasSpecial && hasLength );
	}, 
	passwordText: 'Passwords must be at least 5 characters, containing either a number, or a valid special character (!@#$%^&*()-_=+)',
	hideDelay: 0
});

Ext.onReady(function(){
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';
	Ext.apply(Ext.QuickTips.getQuickTip(), {
		showDelay: 250,
		hideDelay: 300,
		dismissDelay: 0 //don't automatically hide quicktip
	});

	var formRequestPanel = new Ext.FormPanel({
		labelWidth: 100, labelAlign: 'right', defaultType: 'textfield', applyTo:'formRequest', frame:false, border:false, bodyStyle:'padding:5px; background-color:transparent;', width:600, monitorValid:true, 
		items: [{
			inputType:'hidden', id: 'action', name: 'action', value:'formRequest' },{
			fieldLabel: 'Name', id: 'nom', name:'nom', width:460, allowBlank:false, validationEvent: 'change' },{
			fieldLabel: 'Telephone', id: 'telephone', name: 'telephone', width:460  },{
			fieldLabel: 'Email', id: 'email', name: 'email', vtype:'email', width:460, allowBlank:false, validationEvent: 'change'  },{
			fieldLabel: 'Message', xtype: 'textarea', name: 'msg', id: 'msg', width:460, height:70, allowBlank:false, validationEvent: 'change'
		}],
		buttons: [{
			text: 'Contact Us!', formBind:true, handler: submitFormRequest
		}]
	});

	function submitFormRequest() {
		formRequestPanel.getForm().submit({
			url:'/corp/dao/dao.php', method:'POST',
			success: function(form, action){
				document.getElementById( 'formRequest' ).style.display = 'none';
				document.getElementById( 'formRequestConfirmation' ).style.display = 'block';
			},
			failure: function( f, a ) {
				notify( 'Error', a.result.msg );
			}
		});
	}

	Ext.QuickTips.init();
});
