/* START global js_head_defer */
function setCookieWT(cname, cvalue) {
    var expires =
      document.cookie.indexOf(cname) === -1
        ? new Date(
            new Date().setTime(new Date().getTime() + 30 * 24 * 60 * 60 * 1000)
          ) // 30 days
        : unescape(document.cookie).split("expireDate=")[1]; // split out date to reuse
    document.cookie =
      cname +
      "=" +
      cvalue +
      ";" +
      expires +
      "; domain=idcgames.com; path=/; SameSite=Strict; Secure";
  }

  function saveGames(games) {
    if (games && games != "null") {
      //concat fixed error with single element not being an array
      let gamesObject = [];
      try {
        let gamesAux = JSON.parse(games);
        gamesObject = gamesObject.concat(gamesAux);
        sessionStorage.setItem(
          "games",
          gamesObject.map((x) => x.IDJUEGO)
        );
      } catch (e) {
        console.log("Error parsing user games:", e); // error in the above string (in this case, yes)!
      }
    } else {
      sessionStorage.removeItem("games");
    }
  }
  function saveSession(data) {
    if (data.keep == true) {
      setCookie("id", data.id, 365);
      setCookie("currency", data.currency, 365);
      setCookie("simbol", data.simbol, 365);
      setCookie("nick", encodeURIComponent(data.nick), 365);
      setCookie("token", data.token, 365);
      setCookie("email", data.email || "", 365);
      localStorage.setItem("games", data.games);
      if (typeof data.purchased != "undefined") {
        localStorage.setItem("games", data.purchased);
      }
    } else {
      document.cookie = "id=" + data.id + ";domain=idcgames.com";
      document.cookie = "currency=" + data.currency + ";domain=idcgames.com";
      document.cookie = "simbol=" + data.simbol + ";domain=idcgames.com";
      document.cookie = "nick=" + data.nick + ";domain=idcgames.com";
      document.cookie = "token=" + data.token + ";domain=idcgames.com";
      document.cookie = "email=" + data.token + ";domain=idcgames.com";
      localStorage.setItem("games", data.games);
      if (typeof data.purchased != "undefined") {
        localStorage.setItem("games", data.purchased);
      }
    }
  }
  function deleteSession() {
    setCookie("id", "", 0);
    setCookie("coins", "", 0);
    setCookie("currency", "", 0);
    setCookie("nick", "", 0);
    setCookie("token", "", 0);
    setCookie("email", "", 0);
    setCookie("lastLogin", "", 0);
    localStorage.clear();
    sessionStorage.clear();
  }
  /****************************************************************************************************************************/
  /*************************************************  LOGIN, REGISTER, CHECK  *************************************************/
  /****************************************************************************************************************************/
  function notLogged() {
    if (loadSession("token") == false) {
      if (isCef() > 0) {
        (async function () {
          await CefSharp.BindObjectAsync("cefDotNet", "bound");
          cefDotNet.notLogged();
        })();
      }
      console.log("NotLogged");
    }
  }

  function getCurrentDate() {
    let today = new Date();
    let dd = String(today.getDate()).padStart(2, "0");
    let mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
    let yyyy = today.getFullYear();

    today = mm + "/" + dd + "/" + yyyy;
    return today;
  }

  function saveLastLogin() {
    let today = getCurrentDate();

    if (getCookie("lastLogin") != today) {
      setCookie("lastLogin", today, 1);
    }
  }
  function showUserLoggedIn() {
    $(".cUserName").text(loadSession("nick"));
    $(".cUserNameIcon").attr("title", loadSession("nick"));
    $(".cCoins").text(loadSession("coins"));
    $(".logged").show();
    $(".unlogged").hide();
    $(".modal.show").click();
    if (window.IDCGamesFriendsSidebar) {
      IDCGamesFriendsSidebar.fill();
    }
    if (window.IDCGamesFriends) {
      IDCGamesFriends.fill();
    }
  }

  function showUserLoggedOut() {
    $(".cUserName").text("");
    $(".cUserNameIcon").attr("title", "");
    $(".cCoins").text();
    $(".logged").hide();
    $(".unlogged").show();
    $(".runLogOff").click();
    notLogged();
    if (window.IDCGamesFriendsSidebar) {
      IDCGamesFriendsSidebar.close();
      IDCGamesFriendsSidebar.empty();
    }
    if (window.IDCGamesFriends) {
      IDCGamesFriends.empty();
    }
  }

  function loginSocial(loginRes) {
    console.log("Login Social");
    if (loginRes.rc == 200) {
      saveSession(loginRes.data);
      showUserLoggedIn();
      isSuccess = loginRes.data.token;
      $(".runLogIn").click();

      if (loginRes.txt == "OK" && isCef() == 0) {
        window.location.replace(
          "https://idcgames.com/ar/extra/شكرا"
        );
      }
      if (isCef() > 0) {
        try {
          (async function () {
            await CefSharp.BindObjectAsync("cefDotNet", "bound");
            cefDotNet.login(JSON.stringify(loginRes));
          })(loginRes);
          window.location.replace(
            "https://idcgames.com/ar/info/مكتبة"
          );
        } catch (err) {
          console.log(err);
        }
      }
    } else {
      showUserLoggedOut();
    }
  }
  function loginToken(token, typelog = "") {
    var isSuccess;
    isSuccess = false;
    if (isCef() > 0) {
      var referer = "LAUNCHER";
    } else {
      var referer = "WEB-" + lastG + " (" + document.baseURI + ")";
    }
    if (token != "") {
      $.ajax({
        type: "POST",
        url: "/unilogin/token.php",
        data:
          "token=" +
          token +
          "&game=" +
          lastG +
          "&cReferer=" +
          referer +
          "&cFun=loginToken",
        dataType: "text",
        async: true,
        success: function (json) {
          var result = JSON.parse(json);
          if (result.rc == 200) {
            saveSession(result.data);
            showUserLoggedIn();
            saveLastLogin();
            isSuccess = result.data.token;
            $(".runLogIn").click();
            if (typelog == "NEW+IDC+USER") {
              if (isCef() > 0) {
                window.location.replace("/");
              } else {
                window.location.replace(
                  "https://idcgames.com/ar/extra/شكرا"
                );
              }
            }
          } else {
            showUserLoggedOut();
          }
        },
      });
    }
    return isSuccess;
  }

  function getUserData(token) {
    var isSuccess;
    isSuccess = false;
    if (token != "") {
      $.ajax({
        type: "POST",
        url: "/unilogin/getUserData.php",
        data: "token=" + token,
        dataType: "text",
        async: false,
        success: function (json) {
          var result;
          try {
            result = JSON.parse(json);
          } catch (e) {
            result = { rc: -1 };
            console.log("Error parsing user data in getUserData:", e);
          }
          if (result.rc == 200) {
            saveSession(result.data);
            showUserLoggedIn();
          } else {
            deleteSession();
            showUserLoggedOut();
            res = {
              rc: 404,
              txt: "KO",
              data: {},
            };
          }
        },
      });
    }
    return isSuccess;
  }

  function login(user, pass, keep, gameId, cbSuccess, cbError1, cbError2) {
    var res = {};
    if (isCef() > 0) {
      var referer = "LAUNCHER";
    } else {
      var referer = "WEB-" + lastG + " (" + document.baseURI + ")";
    }
    if (gameId == "") {
      gameId = lastG;
    }
    $.ajax({
      type: "POST",
      url: "/unilogin/token.php",
      data:
        "cNick=" +
        encodeURIComponent(user) +
        "&cPassword=" +
        encodeURIComponent(pass) +
        "&game=" +
        gameId +
        "&keep=" +
        keep +
        "&cReferer=" +
        referer +
        "&cFun=login",
      dataType: "text",
      async: true,
      error: function (objeto, quepaso, otroobj) {
        lastE = quepaso;
        res = {
          rc: 500,
          txt: "KO",
          data: {},
        };
        if (cbError2) cbError2(res);
      },
      success: function (json) {
        res = JSON.parse(json);
        if (res.rc == 200) {
          saveSession(res.data);
          showUserLoggedIn();
          saveLastLogin();
          if (cbSuccess) cbSuccess(res);
        } else {
          setCookie("id", "", 0);
          setCookie("coins", "", 0);
          setCookie("currency", "", 0);
          setCookie("nick", "", 0);
          setCookie("token", "", 0);
          localStorage.clear();
          sessionStorage.clear();
          res = {
            rc: 404,
            txt: "KO",
            data: {},
          };
          if (cbError1) cbError1(res);
        }
      },
    });
  }

  function registrar(user, email, pass, otp, keep, cbSuccess, cbError) {
    /* Pixels */
    !(function (f, b, e, v, n, t, s) {
      if (f.fbq) return;
      n = f.fbq = function () {
        n.callMethod
          ? n.callMethod.apply(n, arguments)
          : n.queue.push(arguments);
      };
      if (!f._fbq) f._fbq = n;
      n.push = n;
      n.loaded = !0;
      n.version = "2.0";
      n.queue = [];
      t = b.createElement(e);
      t.async = !0;
      t.src = v;
      s = b.getElementsByTagName(e)[0];
      s.parentNode.insertBefore(t, s);
    })(
      window,
      document,
      "script",
      "https://connect.facebook.net/en_US/fbevents.js"
    );
    fbq("init", "373165389547779");
    fbq("track", "PageView");
    $("head").append(
      '<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=373165389547779&ev=PageView&noscript=1"/></noscript>'
    );
    !(function (_window, _document) {
      var OB_ADV_ID = "007fa6d25c29709bd4b3476c0d44ef432b";
      if (_window.obApi) {
        var toArray = function (object) {
          return Object.prototype.toString.call(object) === "[object Array]"
            ? object
            : [object];
        };
        _window.obApi.marketerId = toArray(_window.obApi.marketerId).concat(
          toArray(OB_ADV_ID)
        );
        return;
      }
      var api = (window.obApi = function () {
        api.dispatch
          ? api.dispatch.apply(api, arguments)
          : api.queue.push(arguments);
      });
      api.version = "1.1";
      api.loaded = true;
      api.marketerId = OB_ADV_ID;
      api.queue = [];
      var tag = document.createElement("script");
      tag.async = true;
      tag.src = "//amplify.outbrain.com/cp/obtp.js";
      tag.type = "text/javascript";
      var script = _document.getElementsByTagName("script")[0];
      script.parentNode.insertBefore(tag, script);
    })(window, document);
    obApi("track", "PAGE_VIEW");
    /* End Pixels */
    var res = {};
    var cLogTrace = "";
    if (isCef() > 0) {
      var referer = "LAUNCHER";
    } else {
      var referer = "WEB-" + lastG + " (" + document.baseURI + ")";
      if (typeof platform == "object") {
        var cLogTrace =
          window.innerWidth +
          "x" +
          window.innerHeight +
          ";" +
          platform.os.family +
          " " +
          platform.os.version +
          " x" +
          platform.os.architecture +
          ";" +
          platform.name +
          ":" +
          platform.version;
      }
    }
    $.ajax({
      type: "POST",
      url: "/unilogin/api_web/tokenRegisterOtp.php",
      data:
        "cNick=" +
        encodeURIComponent(user) +
        "&cEmail=" +
        email +
        "&cPassword=" +
        encodeURIComponent(pass) +
        "&cOtp=" +
        otp +
        "&game=" +
        lastG +
        "&keep=" +
        keep +
        "&game=" +
        lastG +
        "&cReferer=" +
        referer +
        "&cFun=registrar&cLogTrace=" +
        cLogTrace,
      dataType: "text",
      async: true,
      error: function (objeto, quepaso, otroobj) {
        lastE = quepaso;
        res = {
          rc: 500,
          txt: "KO",
          data: {},
        };
        if (cbError) cbError(res);
      },
      success: function (json) {
        res = JSON.parse(json);
        if (res.rc == 200) {
          saveSession(res.data);
          if (getCookie("utm_source") == "facebook") {
            fbq("track", "CompleteRegistration");
          } else if (getCookie("utm_source") == "outbrain" && lastG == 135) {
            obApi("track", "City Battle Event Conversion");
          }
          gtag("event", "download", {
            event_category: "game",
            event_label: "adsense",
            value: "1",
          });

          if (cbSuccess) cbSuccess(res);
        } else {
          deleteSession();
          // res = {
          // 	"rc": res.rc,
          // 	"txt": "KO",
          // 	"data": {}
          // };

          if (cbError) cbError(res);
        }
      },
    });
    // return res;
  }
  /****************************************************************************************************************************/
  /*************************************************  GAMES (PLAY, REGISTER)  *************************************************/
  /****************************************************************************************************************************/
  function registrarGame(game_id) {
    var res = {};
    if (isCef() > 0) {
      var referer = "LAUNCHER";
    } else {
      var referer = "WEB-" + lastG + " (" + document.baseURI + ")";
    }
    $.ajax({
      type: "POST",
      url: "/unilogin/registro.game.php",
      data:
        "token=" +
        loadSession("token") +
        "&game=" +
        game_id +
        "&cReferer=" +
        referer +
        "&cFun=registrarGame",
      dataType: "text",
      async: true,
      error: function (objeto, quepaso, otroobj) {
        lastE = quepaso;
        var res = {
          rc: 500,
          txt: "KO",
          data: {},
        };
        return res;
      },
      success: function (json) {
        var result = JSON.parse(json);
        if (result.txt == "OK") {
          loginToken(loadSession("token"));
          if (getCookie("utm_source") == "facebook") {
            fbq("track", "CompleteRegistration");
          } else if (getCookie("utm_source") == "outbrain") {
            obApi("track", "City Battle Event Conversion");
          }
          gtag("event", "download", {
            event_category: "game",
            event_label: "adsense",
            value: "1",
          });
        }
        if (result.rc == 200) {
          return result;
        }
      },
    });
  }
  function playGame(game_id) {
    lastG = game_id;
    document.cookie = "lastG=" + lastG + ";domain=idcgames.com";
    if (isCef() > 0) {
      try {
        (async function () {
          await CefSharp.BindObjectAsync("cefDotNet", "bound");
          cefDotNet.play(game_id.toString());
        })(game_id);
      } catch (e) {
        $.ajax({
          type: "POST",
          url:
            "https://" +
            getLanguageUrl() +
            "/assets/config/" +
            game_id +
            ".json",
          data: "",
          dataType: "text",
          async: true,
          success: function (json) {
            var result = JSON.parse(json);
            if (
              typeof result.game_seo != "undefined" &&
              result.game_seo != ""
            ) {
              window.location.assign("/" + result.game_seo);
            }
          },
        });
      }
    } else {
      registrarGame(game_id);
      // var gameUrl = "/the-saviors-gang/";
      // if( gameUrl == "//") gameUrl = "/";
      var gameUrl = "/";
      window.location.assign(gameUrl + "ar/extra/شكرا");
    }
  }
  function isCef() {
    var i = 0;
    $.each(cefList, function (index, value) {
      if (navigator.userAgent.indexOf(value) > 0) {
        i = index;
      }
    });
    return i;
  }
  /****************************************************************************************************************************/
  /********************************************************  DOWNLOAD  ********************************************************/
  /****************************************************************************************************************************/
  function getDownload() {
    var id = "";
    if (loadSession("token") != false) {
      $.ajax({
        type: "POST",
        url: "/unilogin/launcher.php",
        data: "token=" + loadSession("token"),
        dataType: "text",
        async: true,
        success: function (json) {
          var result = JSON.parse(json);
          if (typeof result.data != "undefined") {
            id = result.data;
          }
          $.ajax({
            url:
              "https://" +
              getLanguageUrl() +
              "/launcher/IDCUpdater.exe",
            method: "GET",
            xhrFields: {
              responseType: "blob",
            },
            success: function (data) {
              var a = document.createElement("a");
              var url = window.URL.createObjectURL(data);
              a.href = url;
              a.download = "IDC-Games-launcher-V2" + id + ".exe";
              document.body.append(a);
              a.click();
              a.remove();
              window.URL.revokeObjectURL(url);
            },
          });
        },
      });
    }
  }
  /****************************************************************************************************************************/
  /*********************************************************  SOCIAL  *********************************************************/
  /****************************************************************************************************************************/
  var socialData = {};
  function socialAct(item, target) {
    var texto = item.extra;
    target.removeClass("socialAct");
    item.token = loadSession("token");
    item.extra = encodeURIComponent(texto);
    var result = { data: null, rc: 500, txt: "KO" };
    if (item.act == "comment" && item.extra == "") {
      $(".txtComment").addClass("alert");
      $(".txtComment").addClass("alert-danger");
      setTimeout(function () {
        $(".txtComment").removeClass("alert");
        $(".txtComment").removeClass("alert-danger");
        target.html("أضف تعليقا");
        target.addClass("socialAct");
      }, 2000);
      return false;
    }
    if (loadSession("token") != false) {
      $.ajax({
        type: "POST",
        url: "/unilogin/action.php",
        data: item,
        dataType: "text",
        async: true,
        success: function (json) {
          result = JSON.parse(json);
          if (result.rc == 200) {
            target.html('<i class="fas fa-check-circle"></i>');
            var thisid = item.type + "_" + item.id;
            var last = item.last;
            var votes = {
              like: $(".like-number[data-id='" + thisid + "']").text() * 1,
              dislike:
                $(".dislike-number[data-id='" + thisid + "']").text() * 1,
            };
            if (last != "") {
              votes[last] = votes[last] - 1;
            }
            if (item.act == "like") {
              votes.like++;
            }
            if (item.act == "dislike") {
              votes.dislike++;
            }
            $(".like-number[data-id='" + thisid + "']").text(votes.like);
            $(".dislike-number[data-id='" + thisid + "']").text(votes.dislike);
            target.siblings().removeClass("active");
            target.addClass("active");
            if (
              $(".like-number[data-id='" + thisid + "']").text() * 1 >=
              $(".dislike-number[data-id='" + thisid + "']").text() * 1
            ) {
              $(".like-number[data-id='" + thisid + "']")
                .parent(".countVotes")
                .addClass("text-primary");
              $(".like-number[data-id='" + thisid + "']")
                .parent(".countVotes")
                .removeClass("text-secondary");
              $(".dislike-number[data-id='" + thisid + "']")
                .parent(".countVotes")
                .addClass("text-secondary");
              $(".dislike-number[data-id='" + thisid + "']")
                .parent(".countVotes")
                .removeClass("text-primary");
            } else {
              $(".dislike-number[data-id='" + thisid + "']")
                .parent(".countVotes")
                .addClass("text-primary");
              $(".dislike-number[data-id='" + thisid + "']")
                .parent(".countVotes")
                .removeClass("text-secondary");
              $(".like-number[data-id='" + thisid + "']")
                .parent(".countVotes")
                .addClass("text-secondary");
              $(".like-number[data-id='" + thisid + "']")
                .parent(".countVotes")
                .removeClass("text-primary");
            }

            var dt = new Date();
            var dateT = `${dt.getFullYear().toString().padStart(4, "0")}-${dt
              .getDate()
              .toString()
              .padStart(2, "0")}-${(dt.getMonth() + 1)
              .toString()
              .padStart(2, "0")} ${dt
              .getHours()
              .toString()
              .padStart(2, "0")}:${dt
              .getMinutes()
              .toString()
              .padStart(2, "0")}:${dt
              .getSeconds()
              .toString()
              .padStart(2, "0")}`;
            if (item.act == "like") {
              var write =
                '<div class="d-flex flex-row pb-3" data-nick="' +
                loadSession("nick") +
                '"><div class="col-auto p-0"><img src="https://cdn8.idcgames.com/img/default/bg-artwork-small.jpg" class="img-user" alt="user" title="User profile"></div><div class="col-11"><div><a class="fontSecondarySmall">' +
                loadSession("nick") +
                '</a><span class="text-secondary pl-3">' +
                dateT +
                '</span></div><p class="">' +
                texto +
                '</p><div class="border-bottom border-green-lighter mb-3"><p class="liked text-primary"><i class="fas fa-thumbs-up pr-2"></i>' +
                loadSession("nick") +
                " </p></div></div></div>";
            } else {
              var write =
                '<div class="d-flex flex-row pb-3" data-nick="' +
                loadSession("nick") +
                '"><div class="col-auto p-0"><img src="https://cdn8.idcgames.com/img/default/bg-artwork-small.jpg" class="img-user" alt="user" title="User profile"></div><div class="col-11"><div><a class="fontSecondarySmall">' +
                loadSession("nick") +
                '</a><span class="text-secondary pl-3">' +
                dateT +
                '</span></div><p class="">' +
                texto +
                '</p><div class="border-bottom border-green-lighter mb-3"><p class="disliked text-secondary"><i class="fas fa-thumbs-down pr-2"></i>' +
                loadSession("nick") +
                " </p></div></div></div>";
            }
            $(".postComments")
              .find("[data-nick='" + loadSession("nick") + "']")
              .remove();
            $(".postComments").append(write);
            localStorage.setItem(
              item.type + "_" + item.id,
              JSON.stringify(item)
            );
            setTimeout(function () {
              target.html("أضف تعليقا");
              target.addClass("socialAct");
            }, 5000);
          } else {
            console.log("ACTION KO");
            target.html('<i class="fas fa-exclamation-triangle"></i>');
            setTimeout(function () {
              target.html("أضف تعليقا");
              target.addClass("socialAct");
            }, 5000);
          }
          return result;
        },
        error: function (objeto, quepaso, otroobj) {
          lastE = quepaso;
          target.html('<i class="fas fa-exclamation-triangle"></i>');
          setTimeout(function () {
            target.html("أضف تعليقا");
            target.addClass("socialAct");
          }, 5000);
        },
      });
    } else {
      $("[data-target='.loginModal']:first").click();
      $("body").on("click", ".runLogIn", function () {
        socialAct(item, target);
      });
    }
    return result;
  }
  var socialData = {};
  function getSocialData(json) {
    $.ajax({
      type: "POST",
      url: "/unilogin/getSocialData.php",
      data: json,
      dataType: "text",
      async: true,
      success: function (res) {
        if (res != "") {
          socialData = JSON.parse(res);
          $.each(socialData, function (index, value) {
            if (typeof value == "object") {
              var likeNum = value.like_count;
              var dislikeNum = value.dislike_count;
              $(".like-number[data-id='" + index + "']").text(likeNum);
              $(".dislike-number[data-id='" + index + "']").text(dislikeNum);
              if (
                $(".like-number[data-id='" + index + "']").text() * 1 >=
                $(".dislike-number[data-id='" + index + "']").text() * 1
              ) {
                $(".like-number[data-id='" + index + "']")
                  .parent(".countVotes")
                  .addClass("text-primary");
                $(".like-number[data-id='" + index + "']")
                  .parent(".countVotes")
                  .removeClass("text-secondary");
                $(".dislike-number[data-id='" + index + "']")
                  .parent(".countVotes")
                  .addClass("text-secondary");
                $(".dislike-number[data-id='" + index + "']")
                  .parent(".countVotes")
                  .removeClass("text-primary");
              } else {
                $(".dislike-number[data-id='" + index + "']")
                  .parent(".countVotes")
                  .addClass("text-primary");
                $(".dislike-number[data-id='" + index + "']")
                  .parent(".countVotes")
                  .removeClass("text-secondary");
                $(".like-number[data-id='" + index + "']")
                  .parent(".countVotes")
                  .addClass("text-secondary");
                $(".like-number[data-id='" + index + "']")
                  .parent(".countVotes")
                  .removeClass("text-primary");
              }
              var comments = [];
              if (typeof value.comments != "undefined") {
                var comments = JSON.parse(value.comments);
              }
              $(".postComments").html("");
              $.each(comments[language], function (index, value) {
                var fecha = value.DateTime.substr(0, 16);
                if (value.Vote == "1") {
                  var write =
                    '<div class="d-flex flex-row pb-3" data-nick="' +
                    value.NickName +
                    '"><div class="col-auto p-0"><img src="https://cdn8.idcgames.com/img/default/bg-artwork-small.jpg" class="img-user" alt="user" title="User profile"></div><div class="col-11"><div><a class="fontSecondarySmall">' +
                    value.NickName +
                    '</a><span class="text-secondary pl-3">' +
                    fecha +
                    '</span></div><p class="">' +
                    value.Text +
                    '</p><div class="border-bottom border-green-lighter mb-3"><p class="liked text-primary"><i class="fas fa-thumbs-up pr-2"></i>' +
                    value.NickName +
                    " </p></div></div></div>";
                } else {
                  var write =
                    '<div class="d-flex flex-row pb-3" data-nick="' +
                    value.NickName +
                    '"><div class="col-auto p-0"><img src="https://cdn8.idcgames.com/img/default/bg-artwork-small.jpg" class="img-user" alt="user" title="User profile"></div><div class="col-11"><div><a class="fontSecondarySmall">' +
                    value.NickName +
                    '</a><span class="text-secondary pl-3">' +
                    fecha +
                    '</span></div><p class="">' +
                    value.Text +
                    '</p><div class="border-bottom border-green-lighter mb-3"><p class="disliked text-secondary"><i class="fas fa-thumbs-down pr-2"></i>' +
                    value.NickName +
                    " </p></div></div></div>";
                }
                $(".postComments").append(write);
              });
            } else {
              $(".like-number[data-id='" + index + "']").text("0");
              $(".dislike-number[data-id='" + index + "']").text("0");
            }
          });
        }
      },
    });
  }
  function loadUserGames(cb) {
    $.ajax({
      type: "POST",
      url: "/unilogin/listarUserJuegos.php",
      data: "token=" + loadSession("token"),
      dataType: "text",
      async: true,
      success: function (e) {
        try {
          var userData = JSON.parse(e);
        } catch (e) {
          //deleteSession();
          localStorage.setItem("games", "[]");
          if (cb) cb();
          return false;
        }
        if (userData.rc == 200) {
          if (userData.data.length > 0) {
            localStorage.setItem(
              "games",
              JSON.stringify(userData.data.filter((x) => x.IDJUEGO !== 0))
            );
            if (cb) cb();
            return true;
          }
        } else if (userData.rc == 404) {
          localStorage.setItem("games", "[]");
          if (cb) cb();
          return false;
        } else {
          //deleteSession();
          localStorage.setItem("games", "[]");
          if (cb) cb();
          return false;
        }
      },
      error: function (e) {
        if (cb) cb();
      },
    });
  }
  function loadUserWishGames(cb) {
    $.ajax({
      type: "POST",
      url: "/unilogin/listarUserWishedJuegos.php",
      data: "token=" + loadSession("token"),
      dataType: "text",
      async: true,
      success: function (e) {
        try {
          var userData = JSON.parse(e);
        } catch (e) {
          //deleteSession();
          localStorage.setItem("wish_games", "[]");
          if (cb) cb();
          return false;
        }
        if (userData.rc == 200) {
          if (userData.data.length > 0) {
            localStorage.setItem(
              "wish_games",
              JSON.stringify(userData.data.filter((x) => x.IDJUEGO !== 0))
            );
            if (cb) cb();
            return true;
          }
        } else if (userData.rc == 404) {
          localStorage.setItem("wish_games", "[]");
          if (cb) cb();
          return false;
        } else {
          //deleteSession();
          localStorage.setItem("wish_games", "[]");
          if (cb) cb();
          return false;
        }
      },
      error: function (e) {
        if (cb) cb();
      },
    });
  }
  function makeWishRequest(id_idcgame, id_dlc, crear, cbSuccess, cbError) {
    var res = {};
    if (isCef() > 0) {
      var referer = "LAUNCHER";
    } else {
      var referer = "WEB-" + lastG + " (" + document.baseURI + ")";
    }
    $.ajax({
      type: "POST",
      url: "/unilogin/crearUserWishJuego.php",
      data: `token=${loadSession(
        "token"
      )}&iIDJuego=${id_idcgame}&iIDDlc=${id_dlc}&cReferer=${referer}&crear=${crear}`,
      dataType: "text",
      async: true,
      error: function (objeto, quepaso, otroobj) {
        lastE = quepaso;
        res = {
          rc: 500,
          txt: "KO",
          data: {},
        };

        if (cbError) cbError(res, lastE);
      },
      success: function (json) {
        res = (json && JSON.parse(json)) || false;
        if (res.rc == 200) {
          if (cbSuccess) cbSuccess(res);
        } else {
          if (cbError) cbError(res);
        }
      },
    });
  }
/* END global js_head_defer */
