function fb_connect_create_account()
{
    global $config, $db, $plugin_config;
    $this_config = $plugin_config['protect']['fb_connect'];
    $testmode = $this_config['testmode'];
    // Check create account is allowed
    if (!$this_config['newaccount']) {
        header("Location: " . $config['root_url'] . "/signup.php?fb=manual");
        exit;
    }
    // Check login to Facebook
    $fbuserid = fb_connect_get_fbuser();
    if (!$fbuserid) {
        header("Location: " . $config['root_url'] . "/signup.php?fb=cancel");
        exit;
    }
    // Check there is not already a linked account
    list($l, $p) = fb_connect_check_logged_in();
    if (strlen($l) && strlen($p)) {
        header("Location: " . $config['root_url'] . "/login.php");
        exit;
    }
    // Check facebook email is available, that it is not proxied (too long), and not already exists in aMember
    if (!$_SESSION['fbme']['email'] || strlen($_SESSION['fbme']['email']) > 64 || $config['unique_email'] && $db->users_find_by_string($_SESSION['fbme']['email'], 'email', 1)) {
        if ($testmode == 1) {
            $db->log_error("fb_connect: Create account aborted: Has a proxied email, no email address or email already exists ({$_SESSION['fbme']['email']})");
        }
        header("Location: " . $config['root_url'] . "/signup.php?fb=email");
        exit;
    }
    // Ok, now we can create the account
    $vars = array();
    $vars['name_f'] = $_SESSION['fbme']['first_name'];
    $vars['name_l'] = $_SESSION['fbme']['last_name'];
    $vars['email'] = $_SESSION['fbme']['email'];
    $vars['login'] = generate_login($vars);
    $vars['pass'] = $vars['pass0'] = $vars['pass1'] = generate_password($vars);
    if ($GLOBALS['_LANG_SELECTED'] != get_default_lang()) {
        $vars['selected_lang'] = $GLOBALS['_LANG_SELECTED'];
    }
    $member_id = $db->add_pending_user($vars);
    $db->query("UPDATE {$db->config['prefix']}members SET fbuserid = '{$fbuserid}' WHERE member_id = '{$member_id}' LIMIT 1");
    $db->log_error("fb_connect: Created aMember account for Facebook user ({$fbuserid}) - " . print_r($vars, 1));
    $is_affiliate = '0';
    //only member newsletters
    if ($db->get_signup_threads_c($is_affiliate)) {
        $db->subscribe_member($member_id, $is_affiliate);
    }
    if ($config['auto_login_after_signup']) {
        $_SESSION['_amember_login'] = $vars['login'];
        $_SESSION['_amember_pass'] = $vars['pass'];
    }
    // Now add Facebook product subscripton, if set
    if ($this_config['newaccountproduct']) {
        $fb_product =& get_product($this_config['newaccountproduct']);
        $fb_payment = array('member_id' => $member_id, 'product_id' => $fb_product->config['product_id'], 'completed' => 0, 'paysys_id' => 'free', 'begin_date' => $begin_date = date('Y-m-d'), 'expire_date' => $fb_product->get_expire($begin_date));
        $db->add_payment($fb_payment);
        if ($testmode == 1) {
            $db->log_error("fb_connect: Added subscription (product #{$this_config['newaccountproduct']} ) for Facebook user ({$fbuserid}), login = {$vars['login']}");
        }
        // Now go to thanks page...
        $payment_id = $GLOBALS['_amember_added_payment_id'];
        $vcode = md5($payment_id . $begin_date . $member_id);
        header("Location: " . $config['root_url'] . "/plugins/protect/fb_connect/thanks.php?payment_id={$payment_id}&vcode={$vcode}");
        exit;
    }
    // Account only - go to member page...
    header("Location: " . $config['root_url'] . "/member.php");
    exit;
}
" onblur="<?php 
    echo 'if(this.value==\'\'){this.value=\'Password\'}';
    ?>
" />
              		</p>
                            </div>
                    <a href="<?php 
    echo $this->_tpl_vars['base_url'];
    ?>
members/login.php" class="forgot_pass">Forgot password?</a>
					<input type="hidden" value="1" name="remember_login">
           </form>
        </div>
		<div id="fb_login_btn" style="float: left; width: 180px; margin-left: 40px;margin-top:-8px">
		<?php 
    $fbuser = fb_connect_get_fbuser();
    if (!$fbuser) {
        echo '<p style="margin:1em 0;text-align:center;">
				<fb:login-button size="medium" autologoutlink="true" perms="email,publish_stream">Signup with Facebook</fb:login-button>
			</p>';
    }
    ?>
		</div>
        <div id="d_register_button_login">
            <a class="button_l" onclick="submit_login();"><span>Login</span></a>

        </div>
        <div id="d_register_button_reg"><a href="<?php 
    echo $this->_tpl_vars['base_url'];
    ?>
members/signup.php" class="button_r"><span>Register Now</span></a></div>