<?
include_once("./_common.php");

$g4[title] = "E-mail 地址重复检查";
include_once("$g4[path]/head.sub.php");

$mb_email = trim($mb_email);

if ($member[mb_id]) // 如果修改时发现重复
    $sql = " select mb_email from $g4[member_table] where mb_email = '$mb_email' and mb_id <> '$member[mb_id]' ";
else
    $sql = " select mb_email from $g4[member_table] where mb_email = '$mb_email' ";
$row = sql_fetch($sql);

if ($row[mb_email]) {
    echo <<<HEREDOC
    <script type="text/javascript"> 
        alert("'{$mb_email}'已被其他用户注册使用！"); 
        //opener.fmbform.mb_email_enabled.value = "0"; // 如果弹开新窗口...
        parent.document.getElementById("mb_email_enabled").value = -1;
        window.close();
    </script>
HEREDOC;
} else {
    if (!preg_match("/([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/", $mb_email)) {
        echo <<<HEREDOC
        <script type="text/javascript"> 
            alert("'{$mb_email}'邮件地址格式错误！请重新输入邮件地址"); 
            parent.document.getElementById("mb_email_enabled").value = "";
            window.close();
        </script>
HEREDOC;
    } else {
        echo <<<HEREDOC
        <script type="text/javascript"> 
            alert("'{$mb_email}'可以注册使用！"); 
            parent.document.getElementById("mb_email_enabled").value = 1;
            window.close();
        </script>
HEREDOC;
    }
}

include_once("$g4[path]/tail.sub.php");
?>