JoinWindow = function() {
	this.formPanel = new Ext.form.FormPanel({
		autoScroll: true,
		defaultType: 'textfield',
		labelWidth: 120,
		labelAlign: 'right',
		fileUpload:true,
		items: [
			{
				name: 'name',
				fieldLabel: 'Full Name',
				allowBlank: false,
				minLength: 5,
				width: 250
			},
			{
				name: 'username',
				fieldLabel: 'Username',
				allowBlank: false,
				vtype: 'alphanum',
				minLength: 5,
				width: 250
			},
			{
				name: 'password',
				fieldLabel: 'Password',
				allowBlank: false,
				minLength: 6,
				maxLength: 35,
				inputType: 'password',
				width: 250
			},
			{
				name: 'confirm_password',
				fieldLabel: 'Confirm Password',
				allowBlank: false,
				minLength: 6,
				maxLength: 35,
				inputType: 'password',
				width: 250
			},
			{
				name: 'email',
				fieldLabel: 'Email',
				minLength: 3,
				allowBlank:false,
				vtype: 'email',
				width: 250
			},
			{
				name: 'aim',
				fieldLabel: 'AIM',
				width: 250
			},
			{
				name: 'windows_live',
				fieldLabel: 'Window Live',
				width: 250
			},
			{
				name: 'birthdate',
				fieldLabel: 'Birthdate',
				xtype: 'datefield'
			},
			{
				name: 'residence',
				fieldLabel: 'Residence',
				width: 250
			},
			{
				name: 'activities',
				fieldLabel: 'Activities',
				xtype: 'textarea',
				width: 250
			},
			{
				name: 'interests',
				fieldLabel: 'Interests',
				xtype: 'textarea',
				width: 250
			},
			{
				name: 'statement',
				fieldLabel: 'About Me',
				xtype: 'textarea',
				width: 250
			},
			new Ext.form.FieldSet({
				autoHeight: true,
				defaultType: 'textfield',
				title: 'Location',
				labelWidth: 120,
				items: [
					{
						fieldLabel: 'City',
						width: 250,
						allowBlank: false,
						name: 'city'
					},
					{
						fieldLabel: 'State/Province',
						width: 250,
						name: 'state'
					},
					{
						fieldLabel: 'Zip/Postal Code',
						width: 250,
						name: 'postalcode',
						vtype: 'alphanumMask'
					},
					{
						xtype: 'combo',
						name: 'country',
						store: CountryData,
						value: 'UNITED STATES',
						forceSelection: true,
						allowBlank: false,
						minChars: 0,
						triggerAction: 'all',
						fieldLabel: 'Country',
						style: 'text-align: left;',
						width: 250
					}
				]
			}),
			new Ext.form.FieldSet({
				autoHeight: true,
				defaultType: 'textfield',
				title: 'Favorites',
				labelWidth: 120,
				items: [
					{
						name: 'music',
						fieldLabel: 'Music',
						width: 250
					},
					{
						name: 'tvshows',
						fieldLabel: 'TV Shows',
						width: 250
					},
					{
						name: 'movie',
						fieldLabel: 'Movies',
						width: 250
					},
					{
						name: 'books',
						fieldLabel: 'Books',
						width: 250
					},
					{
						name: 'quotes',
						fieldLabel: 'Quote',
						width: 250
					}
				]
			}),
			new Ext.form.FieldSet({
				autoHeight: true,
				defaultType: 'textfield',
				title: 'Avatar',
				labelWidth: 120,
				items: [
					{
						name: 'avatar_title',
						fieldLabel: 'Title',
						width: 250
					},
					{
						name: 'avatar_artist_comments',
						fieldLabel: 'Comments',
						xtype: 'textarea',
						width: 250
					},
					{
						name: 'avatar_keywords',
						fieldLabel: 'Keywords',
						xtype: 'textarea',
						width: 250
					},
					{
						name: 'avatar_image',
						fieldLabel: 'File',
						inputType: 'file',
						width: 250
					}
				]
			})
		],
		bbar: [
			{
				text: 'Register',
				handler: this.saveProfile,
				scope: this
			},
			{
				text: 'Cancel',
				handler: function() {
					this.close();
				},
				scope: this
			}
		]
	});
	JoinWindow.superclass.constructor.call(this,{
		id: 'profile-editor',
		width: 500,
		height: 500,
		modal: true,
		layout: 'fit',
		title: 'Register',
		items: [ this.formPanel ]
	});
	this.on('close',function() {
		if ( $('home_video_player') ) {
			$('home_video_player').show();
			$('home_video_player_blank').hide();
		}
	});
};
Ext.extend(JoinWindow,Ext.Window,{
	saveProfile: function() {
		this.formPanel.getForm().submit({
			waitMsg: 'Registering...',
                	waitTitle: 'Registration',
			url: HOME_DIR+'user_profiles/join',
			success: function(f,a) {
				if ( a.result.success ) {
					Ext.Msg.alert('Profile Saved','Your information has been saved successfully<br />You will receive a confirmation Email shortly with a validation link.<br />Please click on the validation link to activate your account.<br />Please check your spam box, your confirmation email may have gone there.');
					this.close();
				}
				else {
					Ext.Msg.show({
						title: 'Error!',
						msg: a.result.error.reasons,
						buttons: Ext.MessageBox.OK,
						icon: Ext.Msg.ERROR
					});
				}
			},
			failure: function(f,a) {
				if( a.failureType == Ext.form.Action.CLIENT_INVALID) {
					Ext.Msg.show({
						title: 'Error!',
						msg: 'Please fill in all required fields.',
						buttons: Ext.MessageBox.OK,
						icon: Ext.Msg.ERROR
					});
				}
				else {
					Ext.Msg.show({
						title: 'Error!',
						msg: a.result.error.reasons,
						buttons: Ext.MessageBox.OK,
						icon: Ext.Msg.ERROR
					});
				}
			},
			scope: this

		});
	}
});
Ext.onReady(function() {
      Ext.QuickTips.init();
});
var join_win = null;
function joinNow() {
	join_win = new JoinWindow();
	if ( $('home_video_player') ) {
		$('home_video_player').hide();
		$('home_video_player_blank').show();
	}
	join_win.show();
}
function validated() {
	Ext.Msg.show({
	   title:'Account Validated',
	   msg: 'Thank you for validating your account<br />You may now log in using the form on the home page.',
	   buttons: Ext.Msg.OK,
	   fn: function() {
		   document.location.href = HOME_DIR;
	   }
	});
}
function notvalidated() {
	Ext.Msg.show({
	   title:'Validation Error',
	   msg: 'Sorry, there was an error validating your account.',
	   buttons: Ext.Msg.OK,
	   fn: function() {
		   document.location.href = HOME_DIR;
	   }
	});
}

