var validate = new UserValidateClass();
//找回密码
function checkEmailInput1(thisinput) {
    var re = /^[_\.0-9a-zA-Z-]+[0-9a-zA-Z]@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,3}$/;
    if (thisinput.value.TrimString() == '' || !thisinput.value.match(re) || thisinput.value.split("@")[0].length > 20) {

        SetInfomation('regEmailInfo', '&nbsp;&nbsp;电子邮箱格式不正确。', false);
        SetClassName('regEmailState', 'wrong1');
        SetClassName('nickName', 'inp inw wrong_color');
        return false;
    }
    else {
        SetInfomation('regEmailInfo', '', false);
        SetClassName('regEmailState', 'chenggong1-del');
        SetClassName('nickName', 'inp inw');
    }
    return true;
}
//注册
function CheckPasswordStrengthAndFormat(obj) {
    var ps = new PasswordStrength();
    //ps.update(obj.value);
    validate.checkPasswordInput(obj);
}
function CheckPasswordStrength(obj) {
    SetInfomation("regPassWordInfo", "6～16个字符(数字，字母和下划线组成)。<table cellpadding='0' cellspacing='0' ><tr><td><span class='f12'>密码强度：</span></td><td><div class='mima_a' id='pwdLength'><p>&nbsp;</p></div></td><td><span class='fred f12' id='pwdStrength'>&nbsp;太短</span></td></tr></table>", false);
    var ps = new PasswordStrength();
    ps.update(obj.value);
}

function SetInfomation(id, val, cls) {
    var obj = document.getElementById(id);
    if (obj) {
        if (cls) {
            obj.className = cls;
        }
        if (val) {
            obj.innerHTML = val;
        }
        else {
            obj.innerHTML = '';
        }
    }
}
function SetClassName(id, cls) {
    var obj = document.getElementById(id);
    if (obj) {
        if (cls) {
            obj.className = cls;
        }
    }
}
function IsPast(bool) {
    var obj = document.getElementById('Button2');
    if (bool == true) {
        obj.disabled = "";
    } else {
        obj.disabled = "none";
    }
}
function UserValidateClass() {
    var cls = this;
    this.validateName = function(obj, type) {
        var url_s;
        if (type == 'Company') {
            url_s = "../Company/reg1.aspx?jsaction=seuser&username=" + obj.value;
        } else {
            url_s = "../Person/reg1.aspx?jsaction=seuser&username=" + obj.value;
        }
        $.ajax({
            type: "post",
            dataType: "html",
            url: url_s,
            data: { operate: 'validateusername', username: obj.value },
            success: function(data, textStatus) {
                var response = data.toString();
                if (response == "1") {
                    SetInfomation('regNickNameInfo', '用户名已经存在。', false);
                    $("uname")[0].focus();
                    IsPast(false);
                } else {
                    SetClassName('uname', 'inp inw');
                    SetClassName('regNickNameState', 'chenggong1');
                    SetInfomation('regNickNameInfo', '恭喜，此用户可以注册。', false);
                    IsPast(true);
                }
            }
        });
    };
    this.CheckUserNameFormat = function(val) {
        var result = 0;
        var re = /^[\w|\u4E00-\u9FA5]+$/;
        if (val == '') {
            return 1;
        }
        if (val.GetByteCount() > 20) {
            return 2;
        }
        if (val.GetByteCount() < 4) {
            return 3;
        }
        if (!re.test(val)) {
            return 4;
        }
        return result;
    };
    this.onClickNickNameInput = function() {
        document.getElementById("uname_tmp").style.display = 'none';
        SetClassName('uname', 'inp inw action_color');
        SetClassName('regNickNameState', 'action1');
        SetInfomation('regNickNameInfo', '不超过12个字符(数字，字母和下划线)。', 'action_po_top');

    };
    this.checkNickNameInput = function(thisinput, type) {
        var re = /.*[\u4e00-\u9fa5]+.*$/;
        var count = thisinput.value.length;
        SetClassName('regNickNameState', 'wrong1');
        SetClassName('uname', 'inp inw wrong_color');
        if (count == 0) {
            SetInfomation('regNickNameInfo', '请填写用户名。', false);
            return false;
        }
        else if (count < 4) {
            SetInfomation('regNickNameInfo', '不低于4个字符(数字，字母和下划线)。', false);
            return false;
        }
        else if (count > 12) {
            SetInfomation('regNickNameInfo', '不超过12个字符(数字，字母和下划线)。', false);
            return false;
        }
        else if (thisinput.value.match(re)) {
            SetInfomation('regNickNameInfo', '注册名不可使用汉字。', false);
            return false;
        }
        else {
            cls.validateName(thisinput, type);
            return true;
        }
        return true;
    };
    this.onClickEmailInput = function() {
        SetInfomation('regEmailInfo', '&nbsp;&nbsp;没有电子邮件？推荐搜狐闪电邮箱 ！', false);
        SetClassName('regEmailState', 'action1');
        SetClassName('ctl00_txtemail', 'inp inw action_color');
        SetClassName('nickName', 'inp inw action_color');
    };
    this.CheckEmailFormat = function(val) {
        return /^[_\.0-9a-zA-Z-]+[0-9a-zA-Z]@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,3}$/.test(val);
    };
    this.checkEmailInput = function(thisinput) {
        var re = /^[_\.0-9a-zA-Z-]+[0-9a-zA-Z]@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,3}$/;

        if ((thisinput.value.TrimString() == '')) {
            SetInfomation('regEmailInfo', '&nbsp;&nbsp;请填写电子邮箱。', false);
            SetClassName('regEmailState', 'wrong1');
            SetClassName('ctl00_txtemail', 'inp inw wrong_color');
            return false;

        }
        else if (!thisinput.value.match(re) || thisinput.value.split("@")[0].length > 20) {
            SetInfomation('regEmailInfo', '&nbsp;&nbsp;电子邮箱格式不正确。', false);
            SetClassName('regEmailState', 'wrong1');
            SetClassName('ctl00_txtemail', 'inp inw wrong_color');
            return false;
        }
        else {
            cls.validateMail(thisinput);
            return true;
        }
        return true;
    };
    this.onClickPassInput = function() {
        document.getElementById("pwd_tmp").style.display = 'none';
        SetClassName('pwd', 'inp inw action_color');
        SetClassName('regPassWordState', 'action1');
        SetInfomation('regPassWordInfo', '6～16个字符(数字，字母和下划线组成)。', false);

    };
    this.checkPasswordInput = function(thisinput) {
        var re = /^[\w]+$/;
        var count = thisinput.value.length;
        IsPast(false);
        if (count == 0) {
            SetInfomation('regPassWordInfo', '请填写密码。', false);
            SetClassName('regPassWordState', 'wrong1');
            SetClassName('pwd', 'inp inw wrong_color');
            SetClassName('pwd1', 'inp inw wrong_color');
            return false;
        }
        else if (count < 4) {
            SetInfomation('regPassWordInfo', '建议密码长度大于6，且用数字、字母混搭最安全。', false);
            SetClassName('regPassWordState', 'wrong1');
            SetClassName('pwd', 'inp inw wrong_color');
            SetClassName('pwd1', 'inp inw wrong_color');
        }
        else if (!thisinput.value.match(re)) {
            SetInfomation('regPassWordInfo', '密码只能由数字、字母和下划线组成。', false);
            SetClassName('regPassWordState', 'wrong1');
            SetClassName('pwd', 'inp inw wrong_color');
            SetClassName('pwd1', 'inp inw wrong_color');
            return false;
        }
        else {
            IsPast(true);
            SetClassName('regPassWordState', 'chenggong1');
            SetInfomation('regPassWordInfo', '密码符合要求。', false);
            SetClassName('pwd', 'inp inw');
            SetClassName('pwd1', 'inp inw');
        }
        return true;
    };
    this.onClickCPassInput = function() {
        document.getElementById("pwd1_tmp").style.display = 'none';
        IsPast(false);
        SetInfomation('regCPassWordInfo', '请输入一致密码。', false);
        SetClassName('regCPassWordState', 'action1');
        SetClassName('pwd', 'inp inw action_color');
        SetClassName('pwd1', 'inp inw action_color');
    };
    this.checkChkpassInput = function(thisinput) {
        IsPast(false);
        var oPass = document.getElementById('pwd').value;
        var re = /^[\w]+$/;
        var count = thisinput.value.length;
        if (count == 0) {
            SetInfomation('regCPassWordInfo', '请再输入一遍密码。', false);
            SetClassName('regCPassWordState', 'wrong1');
            SetClassName('pwd', 'inp inw wrong_color');

            SetClassName('pwd1', 'inp inw wrong_color');
            return false;
        }
        else if (thisinput.value != oPass) {
            thisinput.value = '';
            SetInfomation('regCPassWordInfo', '两次输入的密码不一致。', false);
            SetClassName('regCPassWordState', 'wrong1');
            SetClassName('pwd', 'inp inw wrong_color');
            SetClassName('pwd1', 'inp inw wrong_color');
            return false;
        }
        else {
            IsPast(true);
            SetClassName('regCPassWordState', 'chenggong1');
            SetInfomation('regCPassWordInfo', '密码确认一致。', false);
            SetClassName('pwd', 'inp inw');
            SetClassName('pwd1', 'inp inw');
            return true;
        }
        return true;
    };
    this.checkResetpassInput = function(thisinput) {
        var oPass = document.getElementById('pwd1').value;
        var re = /^[\w]+$/;
        var count = thisinput.value.length;
        if (count == 0) {
            SetInfomation('regCPassWordInfo', '请再输入一遍密码。', false);
            SetClassName('regCPassWordState', 'wrong1');
            SetClassName('cpassword', 'inp inw wrong_color');

            SetClassName('ctl00_cpassword', 'inp inw wrong_color');
            return false;
        }
        else if (thisinput.value != oPass) {
            thisinput.value = '';
            SetInfomation('regCPassWordInfo', '两次输入的密码不一致。', false);
            SetClassName('regCPassWordState', 'wrong1');
            SetClassName('cpassword', 'inp inw wrong_color');
            SetClassName('ctl00_cpassword', 'inp inw wrong_color');
            return false;
        }
        else {
            SetClassName('regCPassWordState', 'chenggong1');
            SetInfomation('regCPassWordInfo', '', false);
            SetClassName('cpassword', 'inp inw');
            SetClassName('ctl00_cpassword', 'inp inw');
            return true;
        }
        return true;
    };
    this.questionOnClickInput = function() {
        document.getElementById("question_tmp").style.display = 'none';
        SetInfomation('questionInfo', '找回密码时的重要依据之一：问题。', false);
        SetClassName('questionState', 'action1');
        SetClassName('question', 'inp inw action_color');
    }
    this.questionCheckInput = function(thisInput) {
        var count = thisInput.value.length;
        if (count == 0) {
            SetInfomation('questionInfo', '必填项，请务必牢记该项。', false);
            SetClassName('questionState', 'wrong1');
            SetClassName('question', 'inp inw wrong_color');
            return false;
        } else {
            SetClassName('questionState', 'chenggong1');
            SetInfomation('questionInfo', '请务必牢记该项。', false);
            SetClassName('question', 'inp inw');
            return true;
        }
        return true;
    }
    this.answerOnClickInput = function() {
        document.getElementById("answer_tmp").style.display = 'none';
        SetInfomation('answerInfo', '找回密码时的重要依据之一：答案。', false);
        SetClassName('answerState', 'action1');
        SetClassName('answer', 'inp inw action_color');
    }
    this.answerCheckInput = function(thisInput) {
        var count = thisInput.value.length;
        if (count == 0) {
            SetInfomation('answerInfo', '必填项，请务必牢记该项。', false);
            SetClassName('answerState', 'wrong1');
            SetClassName('answer', 'inp inw wrong_color');
            return false;
        } else {
            SetClassName('answerState', 'chenggong1');
            SetInfomation('answerInfo', '请务必牢记该项。', false);
            SetClassName('answer', 'inp inw');
            return true;
        }
        return true;
    }
    this.checkAuthInput = function(thisinput) {
        var re = /([a-zA-Z0-9]){5}/;
        var count = thisinput.value.TrimString().GetByteCount();
        if ((thisinput.value.TrimString() == '')) {

            SetInfomation('regAuthCodeInfo', '请填写验证码。', false);
            SetClassName('regAuthCodeState', 'wrong1');
            SetClassName('authcode', 'inp inw wrong_color');
            return false;
        }
        else if (!thisinput.value.match(re) || count != 5) {
            SetInfomation('regAuthCodeInfo', '验证码输入不正确。', false);
            SetClassName('regAuthCodeState', 'wrong1');
            SetClassName('authcode', 'inp inw wrong_color');
            return false;
        }
        else {
            SetClassName('regAuthCodeState', 'wu');
            SetInfomation('regAuthCodeInfo', '', false);
            SetClassName('authcode', 'inp inw');
            return true;
        }
        return true;
    };
    this.chkForm1 = function() {
        var r = /^[\w|\u4E00-\u9FA5]+$/;
        var rm = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;
        var re = /^[\w]+$/;
        var recode = /([a-zA-Z0-9]){5}/;
        var nickName = document.getElementById('skinContainer_Template_nickName');
        var email = document.getElementById('skinContainer_Template_txtemail');
        var password = document.getElementById('password');
        var cpassword = document.getElementById('cpassword');
        var authcode = document.getElementById('authcode');
        var isPass = true;
        if (!cls.checkNickNameInput(nickName)) {
            nickName.focus();
            isPass = false;
        }
        if (document.getElementById('regNickNameInfo').className == "wrong") {
            isPass = false;
        }

        if (!cls.checkEmailInput(email)) {
            email.focus();
            isPass = false;
        }
        if (document.getElementById('regEmailInfo').className == "wrong") {
            isPass = false;
        }
        if (!cls.checkPasswordInput(password)) {
            password.focus();
            if (document.all)
                window.event.returnValue = false;
            else
                arguments.callee.caller.arguments[0].preventDefault();
            isPass = false;
        }
        if (!cls.checkChkpassInput(cpassword)) {

            cpassword.focus();
            if (document.all)
                window.event.returnValue = false;
            else
                arguments.callee.caller.arguments[0].preventDefault();
            isPass = false;
        }
        if (!cls.checkAuthInput(authcode)) {
            authcode.focus();

            isPass = false;
        }
        if (isPass) {
            return true;
        }
        else {
            if (document.all)
            { window.event.returnValue = false; }
            else
            { arguments.callee.caller.arguments[0].preventDefault(); }
            return false;
        }
    };
    // SMS短信查询
    this.SmsvalidateName = function(obj) {
        url_s = "http://www.workyi.com/sms/selectcount.aspx?sy=look&smsname=" + obj.value;
        $.ajax({
            type: "post",
            dataType: "html",
            url: url_s,
            data: { operate: 'smsvalidatename', smsname: obj.value },
            success: function(data, textStatus) {
                var response = data.toString();
                SetInfomation('smsCount', response, false);
            }
        });
    };






    //*****************************登录********************************
    this.onfocusInput = function(inp, spanState, spanInfo, info) {
        if (info.toString().length > 0) {
            SetInfomation(spanInfo, info, false);
            SetClassName(spanState, 'action1');
        }
        SetClassName(inp, 'inp inw action_color');
    };
    this.onblurUserNameInput = function(inp) {
        var re = /([a-zA-Z0-9]){4}/;
        var re2 = /.*[\u4e00-\u9fa5]+.*$/;
        if (inp.value == "") {
            SetInfomation('usernameInfo', '请填写用户名。', false);
            SetClassName('usernameState', 'wrong1');
            SetClassName('uname', 'inp inw wrong_color');
        } else if (!inp.value.match(re)) {
            SetInfomation('usernameInfo', '长度不够，最短为4个字符。', false);
            SetClassName('uname', 'inp inw wrong_color')
            SetClassName('usernameState', 'wrong1');
            return false;
        } else {
            SetClassName('usernameState', 'chenggong1-del');
            SetInfomation('usernameInfo', '', false);
            SetClassName('uname', 'inp inw');
        }
    };
    this.onblurPwdInput = function(inp) {
        var count = inp.value.TrimString().GetByteCount();
        if (inp.value == "") {
            SetInfomation('PassWordInfo', '请填写密码。', false);
            SetClassName('ctl00_pwdprompt', 'wrong1');
            SetClassName('userpwd', 'inp inw wrong_color');
        }
        else if (count < 6) {
            SetInfomation('PassWordInfo', '密码太短，最少为6位。', false);
            SetClassName('ctl00_pwdprompt', 'wrong1');
            SetClassName('userpwd', 'inp inw wrong_color');
            return false;
        }
        else if (count > 16) {
            SetInfomation('PassWordInfo', '密码不应超过16个字符。', false);
            SetClassName('ctl00_pwdprompt', 'wrong1');
            SetClassName('userpwd', 'inp inw wrong_color');
            return false;
        }
        else {

            var htmlPwd = document.getElementById("ctl00_pwdprompt").innerHTML;
            if (htmlPwd.indexOf('用户名或密码错误') > 0) {

                SetClassName('ctl00_pwdprompt', 'wrong1');
            }
            else {
                SetInfomation('PassWordInfo', '', false);
                SetClassName('userpwd', 'inp inw');
                SetClassName('ctl00_pwdprompt', 'chenggong1-del');
            }
            SetClassName('userpwd', 'inp inw');
        }
    };
    this.checkAuthInputforLogin = function(thisinput) {
        var re = /([a-zA-Z0-9]){5}/;
        var count = thisinput.value.TrimString().GetByteCount();
        if ((thisinput.value.TrimString() == '')) {

            SetInfomation('vcpromptinfo', '请填写验证码。', false);
            SetClassName('ctl00_vcprompt', 'wrong1');
            SetClassName('validatecode', 'inp inw wrong_color');
            return false;
        }
        else if (!thisinput.value.match(re) || count != 5) {
            SetInfomation('vcpromptinfo', '验证码输入不正确。', false);
            SetClassName('ctl00_vcprompt', 'wrong1');
            SetClassName('validatecode', 'inp inw wrong_color');
            return false;
        }
        else {
            SetClassName('ctl00_vcprompt', 'wu');
            SetInfomation('vcpromptinfo', '', false);
            SetClassName('validatecode', 'inp inw');
            return true;
        }
        return true;
    };
}
function checkLength(which) {
    var maxChars = 64;
    var strChars = which.value.length
    var curr = maxChars - strChars;
    document.getElementById("chLeft").innerHTML = "还剩：" + curr.toString() + "，分 <span style='color:red'>1</span> 条短信发送";
    if (which.value.length > maxChars)
        document.getElementById("chLeft").innerHTML = "超过了<span style='color:red'>" + strChars % 64 + "</span>个字符，分 <span style='color:red'>" + Math.round((strChars / 64.0) + 1) + " </span>条短信发送";
}