global $mainframe;
                JFactory::getLanguage()->load('com_user');
                $this->execPieceByName('ff_InitLib');
		$user 		= clone(JFactory::getUser());
		$pathway 	=& $mainframe->getPathway();
		$config		=& JFactory::getConfig();
		$authorize	=& JFactory::getACL();
		$document   =& JFactory::getDocument();

		// If user registration is not allowed, show 403 not authorized.
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		if ($usersConfig->get('allowUserRegistration') == '0') {
			echo '<script>alert("Access forbidden");history.go(-1);</script>';
			return;
		} else {

			// Initialize new usertype setting
			$newUsertype = $usersConfig->get( 'new_usertype' );
			if (!$newUsertype) {
				$newUsertype = 'Registered';
			}

			// Bind the post array to the user object
			$post = array(
				'name' => ff_getSubmit('name'), 
				'username' => ff_getSubmit('username'), 
				'email' => ff_getSubmit('email'), 
				'password' => ff_getSubmit('bfSubsPassword'), 
				'password2' => ff_getSubmit('bfSubsPassword2'), 
				'task' => 'register_save',
	 			'id' => '0',
	 			'gid' => '0',
				);
		
			if (!$user->bind( $post, 'usertype' )) {
				echo '<script>alert("'.addslashes($user->getError()).'");history.go(-1);</script>';
				return;
			} else {

				// Set some initial user values
				$user->set('id', 0);
				$user->set('usertype', '');
				$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));

				$date =& JFactory::getDate();
				$user->set('registerDate', $date->toMySQL());

				// If user activation is turned on, we need to set the activation information
				$useractivation = $usersConfig->get( 'useractivation' );
				if ($useractivation == '1')
				{
					jimport('joomla.user.helper');
					$user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
					$user->set('block', '1');
				}

				// If there was an error with registration, set the message and display form
				if ( !$user->save() )
				{
					echo '<script>alert("'.addslashes(JText::_( $user->getError())).'");history.go(-1);</script>';
					return;
				} else {

					$db		=& JFactory::getDBO();

					$name 		= $user->get('name');
					$email 		= $user->get('email');
					$username 	= $user->get('username');

					JFactory::getDBO()->setQuery("Update #__facileforms_records Set user_id = '".$user->get('id')."', username = ".JFactory::getDBO()->Quote($username).", user_full_name = ".JFactory::getDBO()->Quote($name)." Where id = '".$this->record_id."'");
					JFactory::getDBO()->query();
				}

			}

		}