function generateSubscribeForm()
{
	Ext.getCmp('formsubmit-win').show('content');
}

Ext.ns('Newsletter');

Newsletter.Form = Ext.extend(Ext.form.FormPanel, {
	border:false,
	frame:true,
	shim:true,
	labelWidth:85,
	headerAsText:true,
	hideCollapseTool:true,
	id:'emailForm',
	url:'source/formSubmit.php',
	constructor:function(config){
		config = config || {};
		config.listeners = config.listeners || {};
		Ext.applyIf(config.listeners, {
			actioncomplete:function() {
			},
			actionFailed:function() {
			}
		});
		Newsletter.Form.superclass.constructor.call(this,config);
	},
	initComponent:function() {
		var config = {
			defaultType:'textfield',
			monitorValid:true,
			items:[{
				name:'firstName',
				fieldLabel:'First Name',
				allowBlank:false,
				blankText:'Please enter your First Name',
				id:'firstNameTextField',
				height:19,
				style:'margin-top:2px; margin-left:5px;',
				layout:'form'
			},
			{
				name:'lastName',
				fieldLabel:'Last Name',
				allowBlank:false,
				blankText:'Please enter your Last Name',
				id:'lastNameTextField',
				height:19,
				style:'margin-top:2px; margin-left:5px;',
				layout:'form'
			},
			{
				name:'emailAddress',
				fieldLabel:'Email Address',
				allowBlank:false,
				blankText:'Please enter your Email Address',
				id:'emailTextField',
				height:19,
				style:'margin-top:2px; margin-left:5px;',
				regex:new RegExp('^([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$'),
				regexText:'Please enter a valid email address',
				validationDelay:'1500',
				vType:'email',
				invalidText:'Please enter a valid email address',
				layout:'form'
			},
			{
			    xtype:'fieldset',
				title: 'Optional - Check the services that interest you:',
				autoHeight: true,
				layout: 'form',
				items: [{
					xtype: 'checkboxgroup',
					fieldLabel: 'Service Areas',
					items: [
						{boxLabel: 'Family', name: 'familyBox'},
						{boxLabel: 'Student', name: 'studentBox'},
						{boxLabel: 'Individual', name: 'individualBox'},
						{boxLabel: 'Organization', name: 'organizationBox'}
					]
				}]
			}],
			buttons:[{
				text:'Subscribe',
				formBind:true,
				scope:this,
				width:30,
				handler:this.submit
			}]
		};

		Ext.apply(this, Ext.apply(this.initialConfig, config));

		Newsletter.Form.superclass.initComponent.apply(this,arguments);
	},
	onRender:function() {
		Newsletter.Form.superclass.onRender.apply(this, arguments);
		this.getForm().waitMsgTarget = this.getEl();
	},
	submit:function() {
		this.getForm().submit({
			url:this.url,
			scope:this,
			success:this.onSuccess,
			failure:this.onFailure,
			waitMsg:'Saving...'
		});
	},
	onSuccess:function(form,action) {
        Ext.getCmp('formsubmit-form').getForm().reset();
		Ext.getCmp('formsubmit-win').hide();
		Ext.Msg.show({
			title:'Success',
			msg:'Congratulations! You have successfully subscribed to the Launch E-Newsletter! <br /><br />Launch is committed to protecting the privacy of each person who visits our site or receives our E-newsletters. As such, we will not share your personal information with third parties. <br /><br />If at any point you no longer wish to receive our E-newsletter, simply send an email to enewsletter@preparingforlaunch.com with "unsubscribe" in the subject line.',
			modal:true,
			icon:Ext.Msg.INFO,
			buttons:Ext.Msg.OK
		});
	},
	onFailure:function(form, action) {
		Ext.getCmp('formsubmit-form').getForm().reset();
		Ext.getCmp('formsubmit-win').hide();
	    this.showError(action.result.error || action.response.responseText);
    },
    showError:function(msg, title) {
		title = title || 'Error';
		Ext.Msg.show({
			title:title,
			msg:msg,
			modal:true,
			icon:Ext.Msg.ERROR,
			buttons:Ext.Msg.OK
		});
	}
});

Ext.reg('newsletterForm', Newsletter.Form);

Ext.BLANK_IMAGE_URL= './ext/resources/images/default/s.gif';

Ext.onReady(function() {
	Ext.QuickTips.init();

	Ext.form.Field.prototype.msgTarget = 'side';

	var win = new Ext.Window({
		id:'formsubmit-win',
		title:'E-Newsletter Subscription',
		layout:'form',
		width:495,
		height:220,
		closeAction:'hide',
		headerAsText:true,
		closeAction:'hide',
		modal:true,
		shim:true,
		items:{id:'formsubmit-form', xtype:'newsletterForm'}
	});
});
