/**
*  将 ajax_guo check_user & check_char 合并!!!!
*/

function ajaxFunction() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
function ajaxSel($url, url_name, y_id) {
    var s_url = $url + "?conn=" + url_name;
    var ajax = ajaxFunction();
    ajax.open("GET", s_url, true);
    ajax.onreadystatechange = function () {
        if (ajax.readyState == 4) {
            document.getElementById(y_id).innerHTML = ajax.responseText;
        }
    }
    ajax.send(null);
}

function Ajax_Guo($url, x_id, y_id) {
    var s_value = document.getElementById(x_id).value;
    if (s_value != '') {
        ajaxSel($url, s_value, y_id);
    }
}

function Get_center(userid) {
    var url = ""; //"http://bm.gamebean.com/get_center.php?id=" + userid;
    var ajax = ajaxFunction();
    ajax.open("GET", url, true);
    ajax.send(null);
}

function Check_user() {
    var user_a = document.getElementById("user").value;
    var pwd_a = document.getElementById("pwd").value;
    var yan_a = document.getElementById("yan").value;
    var jgpattern = /^[A-Za-z0-9_]+$/;
    var _jgpattern = /^[\w]+$/;
    if (!jgpattern.test(user_a)) {
        alert("用户名格式不正确");
        return false;
    }
    if (!_jgpattern.test(pwd_a)) {
        alert("密码格式不正确");
        return false;
    }
    if (user_a == '') {
        alert("请填写用户名");
        return false;
    } else if (pwd_a == '') {
        alert("密码不能为空");
        return false;
    } else if (yan_a == '') {
        alert("请填写验证码");
        return false;
    } else {
        return true;
    }

}

function CheckChar(url, x_id, y_id) {
    var ss = document.getElementById(x_id).value;
    var jgpattern = /^[a-z0-9]+$/;
    if (ss == '') {
        document.getElementById(y_id).innerHTML = "<font color='red'>请填写注册账号</font>";
        return false;
    } else {
        if (ss.length > 5 && ss.length < 21) {
            if (!jgpattern.test(ss)) {
                document.getElementById(x_id).value = "";
                document.getElementById(y_id).innerHTML = "<font color='red'>注册用户名称只能为小写字母，数字或是下划线</font>";
                return false;
            } else {
                Ajax_Guo(url, x_id, y_id);
            }
        } else {
            document.getElementById(x_id).value = "";
            document.getElementById(y_id).innerHTML = "<font color='red'>注册用户名称长度应为6到20位</font>";
            return false;
        }
    }
}

function vEmail() {
    var str = document.getElementById('email').value;
    if (str.length == 0) {
        document.getElementById("email3").innerHTML = "<font color='red'>邮箱不能为空</font>";
        return false;
    }
    var rule = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (rule.test(str)) {
        document.getElementById("email3").innerHTML = "<font color='#0EEB77'>邮箱填写正确</font>";
        return true;
    } else {
        document.getElementById('email').value = "";
        document.getElementById("email3").innerHTML = "<font color='red'>请输入有效邮箱</font>";
        return false;
    }
}

function pw_y(u_id, y_id) {
    var pw_value = document.getElementById(u_id).value;
    var jgpattern = /^[A-Za-z0-9_]+$/;
    if (pw_value == null || pw_value == '') {
        document.getElementById(y_id).innerHTML = "<font color='red'>密码不能为空</font>";
    } else {
        if (jgpattern.test(pw_value)) {
            if (pw_value.length >= 6 && pw_value.length <= 20) {
                document.getElementById(y_id).innerHTML = "<font color='#0EEB77'>密码填写正确</font>";
            } else {
                document.getElementById(u_id).value = "";
                document.getElementById(y_id).innerHTML = "<font color='red'>密码的长度只能为6到20位</font>";
            }
        } else {
            document.getElementById(u_id).value = "";
            document.getElementById(y_id).innerHTML = "<font color='red'>密码只能为数字，字母，下划线组成</font>";
        }
    }
}

function repw_y(x_id, u_id, y_id) {
    var pw_value = document.getElementById(x_id).value;
    var repw_value = document.getElementById(u_id).value;
    var jgpattern = /^[A-Za-z0-9_]+$/;
    if (repw_value == null || repw_value == '') {
        document.getElementById(y_id).innerHTML = "<font color='red'>密码不能为空</font>";
    } else {
        if (jgpattern.test(pw_value)) {
            if (pw_value.length >= 6 && pw_value.length <= 20) {
                if (pw_value == repw_value) {
                    document.getElementById(y_id).innerHTML = "<font color='#0EEB77'>密码填写正确</font>";
                } else {
                    document.getElementById(y_id).innerHTML = "<font color='red'>两次密码填写不同</font>";
                }
            } else {
                document.getElementById(u_id).value = "";
                document.getElementById(y_id).innerHTML = "<font color='red'>密码的长度只能为6到20位</font>";
            }
        } else {
            document.getElementById(u_id).value = "";
            document.getElementById(y_id).innerHTML = "<font color='red'>密码只能为数字，字母组成</font>";
        }
    }
}

function CKform() {
    if (document.xiugai_frm.check_name.value == 2) {
        alert("用户名已经存在！");
        return false;
    } else {
        if (document.xiugai_frm.username.value !== "" && document.xiugai_frm.pwd.value !== "") {
            if (document.xiugai_frm.pwd.value !== document.xiugai_frm.repwd.value) {
                alert("两次密码填写不一致");
                return false;
            } else {
                return true;
            }
        } else {
            alert("注册信息填写不完全，请确认");
            return false;
        }

    }
}