document.domain = "cnedu.cn";
var headUcLogRegObj = {
  url: {
    LOGIN_URL: "iframe://www.cnedu.cn/OtherItem/loginRegister/login.shtml",
    REGISTER_URL: "iframe://www.cnedu.cn/OtherItem/loginRegister/register.shtml",
    UC_TOKEN_URL: "//member.cnedu.cn/ucenter/loginRegister/getUcToken",
    UC_LOGOUT_URL: "//member.cnedu.cn/ucenter/loginRegister/userLogout/",
    UC_CHECKLOGIN_URL: "//member.cnedu.cn/ucenter/loginRegister/checkUserLoginStatus/",
    SYNC_USERINFO_SESSION_URL: "//member.cnedu.cn/member/newLoginRegister/syncUserInfoInSession.shtm"
  },
  obj: {
    DIALOGFIRST: true,
    IFRAME_DIV_HTML_STR: '<div id="floatBoxBg" style="height:' + $(document).height() + 'px;filter:alpha(opacity=0);opacity:0;"></div><div id="floatBox"><div class="contents"></div></div>',
    SITE_TYPE: "cnedu",
    UC_CLIENT_TOKEN: "client_ucToken",
    UC_TOKEN: ""
  }
};
var dialogLoginReg = {
  config: {
    type: "1",
    gotoURL: ""
  }
};

function headUcLoginRegister() { }
headUcLoginRegister.prototype = {
  init: function () {
    var a = this;
    headUcLogRegObj.obj.UC_TOKEN = a.getLocalCookie(headUcLogRegObj.obj.UC_CLIENT_TOKEN);
    if ($("#noLogin").length > 0) {
      if (headUcLogRegObj.obj.UC_TOKEN && headUcLogRegObj.obj.UC_TOKEN != "") {
        a.checkUserLoginStatus()
      } else {
        a.getToken()
      }
    }
  },
  getToken: function () {
    var b = this;
    var a = {
      siteType: headUcLogRegObj.obj.SITE_TYPE
    };
    $.ajax({
      type: "POST",
      url: headUcLogRegObj.url.UC_TOKEN_URL,
      data: a,
      dataType: "jsonp",
      jsonp: "jsonpCallback",
      jsonpCallback: "jsonp1" + Date.parse(new Date()),
      success: function (c) {
        if ("success" == c) {
          headUcLogRegObj.obj.UC_TOKEN = b.getLocalCookie(headUcLogRegObj.obj.UC_CLIENT_TOKEN);
          b.checkUserLoginStatus()
        } else {
          alert("请检查网络是否正常联网！")
        }
      }
    })
  },
  dialogShow: function (d, c, a) {
    ucCloseWin();
    $("body").append(headUcLogRegObj.obj.IFRAME_DIV_HTML_STR);
    d = d.substring(d.indexOf(":") + 1, d.length);
    var b = '<iframe id="frame1" src="' + d + '" width="450px" height="' + (parseInt(a)) + 'px" scrolling="no" allowtransparency="true" frameborder="0" marginheight="0" marginwidth="0"></iframe>';
    $("#floatBox .contents").html(b);
    if (navigator.userAgent.indexOf("TencentTraveler") > 0) {
      $("#frame1").attr("src", d)
    }
    $("#floatBoxBg").show();
    $("#floatBoxBg").animate({
      opacity: "0.3"
    }, "normal");
    $("#floatBox").attr("class", "floatBox from");
    $("#floatBox").css({
      display: "block",
      left: (($(document).width()) / 2 - (parseInt(c) / 2)) + "px",
      top: "50%",
      marginTop: -a + "px",
      width: (parseInt(c) + 2) + "px",
      height: a,
      border: "none",
      background: "none"
    });
    $("#floatBox").animate({
      marginTop: -a / 2 + "px"
    }, "normal")
  },
  logout: function () {
    $.ajax({
      type: "POST",
      url: headUcLogRegObj.url.UC_LOGOUT_URL + headUcLogRegObj.obj.UC_TOKEN,
      dataType: "jsonp",
      jsonp: "jsonpCallback",
      jsonpCallback: "jsonp2" + Date.parse(new Date()),
      success: function (b) {
        if (b.success) {
          var a = window.location.href;
          window.location.href = "//member.cnedu.cn/member/logout.shtm?gotoURL=" + a;
          window.event.returnValue = false
        } else {
          alert("请检查网络是否正常联网！")
        }
      }
    })
  },
  loginMemStyle: function (d) {
    var f = d.item.openCourseNum
      , g = d.item.shopCartNum
      , h = d.nickName || d.memberId || d.name || d.username
      , e = d.iconUrl || logRegObj.obj.VERIFYLOGIN_ICONURL
      , b = d.item.courseInfo
      , c = d.item.hasLearned;
    if (g == "") {
        $(".shopCartNum,#shopCartNum2").hide()
    } else {
        $(".shopCartNum").show().text("(" + g + ")");
        $("#shopCartNum2").show().text(g)
    }
    $(".loginAfter .userAvatar img").attr("src", e);
    $(".loginAfter .user-name").text(h);
    // if (f != "") {
    //     if (c == "Y" || c == true) {
    //         var a = "//elearning.chinaacc.com/interface/courseForHome/continueStudy.shtm?cwareID=" + b.cwareID;
    //         $("#videoFullName").html(b.videoFullName);
    //         $("#continueURL").attr("href", a);
    //         $("#showCourseName").html(b.showCourseName);
    //         $("#hasLearned").show();
    //         $("#noLearned,#noCourse").hide()
    //     } else {
    //         $("#noLearned").show();
    //         $("#noCourseNew,#hasLearned").hide()
    //     }
    //     $(".courseNum").show().text("(" + f + ")")
    // } else {
    //     $("#noCourse").show();
    //     $("#noLearnedNew,#hasLearned").hide()
    // }
    $(".loginBefore").hide();
    $(".loginAfter").show()
},
  checkUserLoginStatus: function () {
    var a = this;
    $.ajax({
      type: "POST",
      url: headUcLogRegObj.url.UC_CHECKLOGIN_URL + headUcLogRegObj.obj.UC_TOKEN,
      data: {
        isNeedInfo: "Y"
      },
      dataType: "jsonp",
      jsonp: "jsonpCallback",
      jsonpCallback: "jsonp3" + Date.parse(new Date()),
      success: function (j) {
        var g = j.result;
        if (g.loginFlag) {
          var h = g.nickName;
          var c = g.iconUrl;
          var e = g.openCourseNum;
          var i = g.shopCartNum;
          var b = g.msgNum;
          var f = g.courseInfo;
          var d = g.hasLearned;
          $("#noLogin").hide();
          $("#yesLogin").show();
          $(".noLoginOther").hide();
          $(".yesLoginOther").show();
          $("#loginName").html(h);
          $("#yesLogin img").attr("src", c);
          if (i == 0) {
            $(".right-n01:first").html("")
          } else {
            $(".right-n01:first").html('<i class="abs h-an an" id="cart">' + i + "</i>")
          }
          if (b > 0) {
            $(".right-n02:first").html('<i class="abs h-an" id="cart2">' + b + "</i>")
          } else {
            $(".right-n02:first").html("")
          }
          a.getUserLevel();
          // a.syncUserInfo();
          return false
        }
      }
    })
  },
  getUserLevel: function () {
    var a = this;
    $.ajax({
      type: "GET",
      url: "//member.cnedu.cn/api/getMemVipLevel.shtm",
      dataType: "jsonp",
      jsonp: "jsonpCallback",
      jsonpCallback: "jsonp5169123478234",
      success: function (b) {
        try {
          var d = $.trim(b.result);
          if (d == 0) {
            $(".header .right-loginh .pop3-t-r .vip").html("您还不是会员")
          } else {
            if (d == 1) {
              $(".header .right-loginh .pop3-t-r .vip").html("您是银卡会员")
            } else {
              if (d == 2) {
                $(".header .right-loginh .pop3-t-r .vip").html("您是金卡会员")
              } else {
                if (d == 3) {
                  $(".header .right-loginh .pop3-t-r .vip").html("您是白金卡会员")
                } else {
                  $(".header .right-loginh .pop3-t-r .vip").html("")
                }
              }
            }
          }
        } catch (c) { }
      }
    })
  },
  getCardCount: function () {
    if ($("#cart")) {
      $.ajax({
        type: "GET",
        url: "//member.cnedu.cn/api/getCardCount.shtm",
        dataType: "jsonp",
        jsonp: "jsonpCallback",
        jsonpCallback: "jsonp9123478235164",
        success: function (b) {
          var a = $.trim(b.result);
          if (a > 0) {
            $("#cart").addClass("an");
            $("#cart").addClass("abs");
            $("#cart").html(a)
          } else {
            $("#cart").removeClass("an");
            $("#cart").removeClass("abs");
            $("#cart").html("")
          }
        }
      })
    }
  },
  syncUserInfo: function () {
    var b = this;
    var a = b.getLocalCookie("sid");
    if (null != a) {
      $.ajax({
        type: "POST",
        url: headUcLogRegObj.url.SYNC_USERINFO_SESSION_URL + "?sid=" + a,
        dataType: "jsonp",
        jsonp: "jsonpCallback",
        jsonpCallback: "jsonp4" + Date.parse(new Date()),
        success: function (c) { }
      })
    }
  },
  getLocalCookie: function (b) {
    var a, c = new RegExp("(^| )" + b + "=([^;]*)(;|$)");
    if (a = document.cookie.match(c)) {
      return unescape(a[2])
    } else {
      return null
    }
  }
};
$(function () {
  $("#yesLogin").hide();
  var e = new headUcLoginRegister();
  e.init();
  var c = window.location.href;

  $(".qp").hover(function () {
    $(this).find(".pop").stop(true, true).slideDown(200);
    $(this).find(".pop2").stop(true, true).slideDown(200);
    $(this).find(".pop3").stop(true, true).slideDown(200);
    $(this).addClass("non")
  }, function () {
    $(this).find(".pop").stop(true, true).slideUp(0);
    $(this).find(".pop2").stop(true, true).slideUp(0);
    $(this).find(".pop3").stop(true, true).slideUp(0);
    $(this).removeClass("non")
  });


  var b = $(".column-loginRegister");
  if (b.length > 0 && (b.is(":visible"))) {
    $(".column-login-after").hover(function () {
      $(this).find(".column-login-after-layer").slideDown(300)
    }, function () {
      $(this).find(".column-login-after-layer").stop().slideUp(300)
    });

    $('.column-login,.column-register').click(function () {
      var targetHref = window.location.href
      // targetHref = encodeURIComponent(targetHref)
      window.location.href = '//www.cnedu.cn/authlogin/?gotoURL=' + targetHref
    })

    CDEL.loginStatus(function (g) {
      if (g.loginFlag) {
        var l = g.nickName,
          h = g.iconUrl,
          j = g.item.shopCartNum,
          k = g.item.msgNum;
        $(".column-login-after .userAvatar img,.column-login-after .column-layer-userAvatar img").attr("src", h);
        $(".column-login-after .column-user-name").text(l);
        if (j > 0) {
          $(".column-top-cart i").text(j).show()
        }
        if (k > 0) {
          $(".column-top-notice i").text(k).show()
        }
        $(".column-login-before").hide();
        $(".column-login-after").show();
        e.loginMemStyle(g)
        var f = CDEL.getCookie("operator");
        if (f && f != "") {
          var i = '<p class="column-kf-login">客服：' + f + "</p>";
          $(".column-login-after").append(i)
        }
      }
      if (typeof columnHeadLoginStatus != "undefined") {
        columnHeadLoginStatus(g)
      }
    }, "Y");
    $(".column-logout, .ucLogoutBtn").click(function () {
      CDEL.logout(function (f) {
        if (f.success) {
          window.location.reload()
        }
      })
    })
  }
});

function ucCloseWin() {
  $("#floatBoxBg").remove();
  $("#floatBox").remove();
  $("select").attr("disabled", "")
}
