﻿/******************************************************************/
//共用参数
/******************************************************************/
var RedirectUrl = "";

/******************************************************************/
//博客圈子用户登录验证
/******************************************************************/
function CheckBlogLogin(userName, userPwd, url, verifyCode) {
    var l = new Array();
    l["name"] = userName;
    l["pwd"] = userPwd;
    RedirectUrl = url;
    _error_msg_show("正在登录，请稍候...", null, 'smile', "登录");
    jQuery.ajax({
        type: "POST",
        contentType: "application/json",
        data: "{userName:'" + userName + "',userPwd:'" + userPwd + "',verifyCode:'" + verifyCode + "' }",
        dataType: "json",
        url: "/Service/ShareService.asmx/CheckBlogLogin",
        success: function(result) {
            onCheckLoginSuccess(result.d, l);

        }
    });

}
function CheckSubSiteLogin(userName, userPwd, url, verifyCode) {
    var l = new Array();
    l["name"] = userName;
    l["pwd"] = userPwd;
    RedirectUrl = url;
    _error_msg_show("正在登录，请稍候...", null, 'smile', "登录");
    jQuery.ajax({
        type: "POST",
        contentType: "application/json",
        data: "{userName:'" + userName + "',userPwd:'" + userPwd + "',verifyCode:'" + verifyCode + "' }",
        dataType: "json",
        url: "/Service/ShareService.asmx/CheckSubSiteLogin",
        success: function(result) {
            onCheckLoginSuccess(result.d, l);

        }
    });
}

function onCheckLoginSuccess(result, l) {
    if (result == "0") {
        _error_msg_show("帐号输入有误!", '', 'forbid', "登录失败");
    }
    else if (result == "2") {
        _error_msg_show("该帐号已被禁止登录，请联系管理员!", '', 'forbid', "登录失败");
    }
    else if (result == "3") {
        _error_msg_show("该帐号已被删除，请联系管理员!", '', 'forbid', "登录失败");
    }
    else if (result == "4") {
        _error_msg_show("序列号不合法，用户不能登录，请联系系统管理员!", '', 'forbid', "登录失败");
    }
    else if (result == "5") {
        _error_msg_show("系统管理员设置暂时所有用户不能登录，请联系系统管理员!", '', 'forbid', "登录失败");
    }
    else if (result == "6") {
        _error_msg_show("验证码有误，请重新输入!", '', 'forbid', "登录失败");
    }
    else if (result == "8") {
        _error_msg_show("你所关联的单位用户需要管理员审核，暂时不能登录!", '', 'forbid', "登录失败");
    }
    else if (result == "-1") {
        _error_msg_show("你不是子网站管理员，不能登录!", '', 'forbid', "登录失败");
    }
    else if (result == "7") {
        openWindow("/OperationManage/SelectUnitMemberForLogin.aspx?name=" + l["name"], 500, 300, "选择关联单位用户", true);
    }
    else {
        top.location.href = RedirectUrl;
    }
}

/******************************************************************/
//系统管理员用户登录验证
/******************************************************************/
function CheckSystemLogin(userName, userPwd, url, verifyCode) {
    var l = new Array();
    l["name"] = userName;
    l["pwd"] = userPwd;
    RedirectUrl = url;
    _error_msg_show("正在登录，请稍候...", null, 'smile', "登录");
    jQuery.ajax({
        type: "POST",
        contentType: "application/json",
        data: "{userName:'" + userName + "',userPwd:'" + userPwd + "',verifyCode:'" + verifyCode + "' }",
        dataType: "json",
        url: "/Service/SystemService.asmx/CheckSystemLogin",
        success: function(result) {
            onCheckSystemLoginSuccess(result.d, l);

        }
    });
}

function onCheckSystemLoginSuccess(result, l) {
    if (result == "0") {
        _error_msg_show("帐号输入有误!", '', 'forbid', "登录失败");
    }
    else if (result == "2") {
        _error_msg_show("该帐号已被禁止登录，请联系管理员!", '', 'forbid', "登录失败");
    }
    else if (result == "4") {
        _error_msg_show("验证码有误，请重新输入!", '', 'forbid', "登录失败");
    }
    else if (result == "6") {
        _error_msg_show("当前管理员没有关联用户，不能登录!", '', 'forbid', "登录失败");
    }
    else if (result == "8") {
        _error_msg_show("你所关联的单位用户需要管理员审核，暂时不能登录!", '', 'forbid', "登录失败");
    }
    else if (result == "7") {
        openWindow("/OperationManage/SelectUnitMemberForLogin.aspx?name=" + l["name"], 500, 300, "选择关联单位用户", true);
    }
    else//登录成功
    {
        var url = document.location.search.substr(1);
        var u = url.request("ReturnUrl");
        openWindow("/SystemManage/AdminUserLoginNav.aspx?returnUrl=" + u, 300, 180, "系统管理员登录导向", true);
    }
}

function openWindow(_sUrl, _sWidth, _sHeight, _sTitle, _sScroll) {
    var oEdit = new dialog();
    oEdit.init();
    oEdit.set('title', _sTitle ? _sTitle : "系统提示信息");
    oEdit.set('width', _sWidth);
    oEdit.set('height', _sHeight);
    oEdit.open(_sUrl, _sScroll ? 'no' : 'yes');
}

/******************************************************************/
//加载系统标签
/******************************************************************/
function InitSystemTagData(adminId) {
    jQuery.ajax({
        type: "POST",
        contentType: "application/json",
        data: "{adminId:'" + adminId + "' }",
        dataType: "json",
        url: "/Service/SystemService.asmx/GetTagByAdminId",
        success: function(result) {
            jQuery("#hidTags").val(result.d);

        }
    });
}
