var srvID = "";
var userID = "";
var ifrm;
jQuery(function ($) {
    $('[data-rel=tooltip]').tooltip();
    $('[data-rel=popover]').popover({ html: true });

    $(document).on('click', 'th input:checkbox', function () {
        var that = this;
        $(this).closest('table').find('tr > td:first-child input:checkbox')
			    .each(function () {
			        this.checked = that.checked;
			        $(this).closest('tr').toggleClass('selected');
			    });
    });
});
function resize_r() {
//    var s = 0;
//    var ss = $(window.parent.document).find('iframe[id=' + ifrm + ']');
//    var l = $(window.parent.document).height() - ss.offset().top;
//    var t = $(document).height();
//    if (l > t) {
//        s = l;
//    }
//    else {
//        s = $(document).height();
//    }
//    $($(window.parent.document).find('iframe[id=' + ifrm + ']')).height(s);
//    window.parent.sidebar_r();
}
function ClickEvent() {
    $('[data-rel=tooltip]').tooltip();
    $('[data-rel=popover]').popover({ html: true });
}
function LoadData() {
    $.ajax({
        url: "../Handlers/system/user.aspx?Method=GetBinding&user=" + escape(userID),
        type: "post",
        cache: false,
        success: function (msg) {
            if (msg != "false") {
                $("#Phone").val(msg);
                $("#bangding").hide();
                $("#yibang").show();
                $("#div_yzm").hide();
                $("#btn_Bang").hide();
                $("#Phone").attr("readonly", "readonly");
            } else {
                $("#Phone").val("");
                $("#bangding").show();
                $("#yibang").hide();
                $("#div_yzm").show();
                $("#btn_Bang").show();
                $("#Phone").removeAttr("readonly", "readonly");
            }
        },
        error: function () {
            layer.msg('网络错误,请稍后再试！', 2, 5);
        }
    });
}
function Binding() {
    var phone = $("#Phone").val();
    if (validatemobile(phone)) {
        $("#span_yz").show();
        $("#Phone").focus();
        return;
    }
    var yzm = "";
    var l = layer.load('正在绑定....');
    $.ajax({
        type: "post",
        url: "../Handlers/system/user.aspx?Method=Binding&user=" + userID + "&srvid=" + srvID + "&phone=" + phone + "&yzm=" + yzm,
        cache: false,
        success: function (msg) {
            if (msg == "success") {
                layer.close(l);
                layer.msg('绑定成功！', 2, 1);
                LoadData();
            }
            if (msg == "exist") {
                layer.msg('该手机号已经绑定到其他帐号，不能再次绑定，请解绑原账号后再进行绑定！', 2, 5);
            }
            if (msg == "have") {
                layer.msg('绑定失败，该手机已绑定当前账号！', 2, 5);
            }
            if (msg == "nobindinf") {
                layer.msg('绑定失败，输入信息有误！', 2, 5);
            }
            if (msg == "noyzm") {
                layer.msg('验证码输入有误，请重新绑定！', 2, 5);
            }
            if (msg == "error") {
                layer.msg('网络错误，请稍后再试！', 2, 5);
            }
            layer.close(l);
        },
        error: function () {
            layer.msg('网络请求错误!', 3, 5);
            layer.close(l);
        }
    });
}
function validatemobile(mobile) {
    var regu = /^1[3,4,5,7,8]\d{9}$/;
    var re = new RegExp(regu);
    if (!re.test(mobile)) {
        return true;
    } else {
        return false;
    }
}
function iniParms() {
    var coks = document.cookie.substring(document.cookie.indexOf('userinf_tcwl'));
    var ary = coks.split(';');
    var ary1 = ary[0].split('=');
    if (!ary1[2]) {
        $('html').empty();
        return;
    }
    userID = ary1[2].split('&')[0];
    srvID = ary1[3];
    var s = window.location.href.split('=');
    if (s.length == 4) {
        ifrm = s[3];
    }
    resize_r();
    LoadData();
}    