var base_url = "https://quark.earthchaos.com/"; var language_values = { "request_err": "Uncompleted request error", "map_select_location": "Select your location", "err_email_jseval_1": "The Email is required", "err_email_jseval_2": "The Email format is invalid ( e.g.: yourname@yourdomain.com)", "invalid_accounttoken": "Invalid account token", "security_token_err_1": "The Security Token is required.", "security_token_err_2": "The Security Token should be exactly 32 characters long.", "security_word_err_1": "The Secret Word is required.", "security_word_err_2": "The Secret Word must be at least 10 characters long.", "setpassword_err_1": "The Password is required.", "setpassword_err_2": "The Password must be at least 6 characters long.", "register_err_agreement": "Please, read our policies and check the box" }; var forms_arr = ["handles_login", "handles_resetword", "handles_saveword", "handles_register", "handles_recoverypass", "handles_setpassword", "handles_prelogin", "checkEmail","handles_logrefresh"]; var volstatus = {"v":1,"m":0.6,"x":0.6}; var logged_list_exists = false; var effx = false; var rf = ""; var rf_params = ""; var rf_replace = ""; var sw_replace = ""; var cf = true; function general_jxs(response, form) { console.log("form " + form.attr("id")); f = form.attr("id"); var obj; try { obj = JSON.parse(response); } catch (exception) { obj = null; } console.log("rf (must)1: " + rf); if (obj) { console.log(obj); var sccmsg = form.find(".sccmsg"); if (obj.scrq) { console.log("obj.scrq " + form.attr("id")); sw_replace = f; if (obj.success) { setTimeout(function () { console.log("Call init_secretword"); init_secretword(); }, 3000); } else { init_secretword(); } } if (obj.token) { console.log("obj.token " + form.attr("id")); c = form.children(":nth-child(1)"); x = form.children("input[name='form_token']"); a = ""; if (!x.length) { c.before(a); } else { x.val(obj.token); } console.log("rf (must): " + rf); console.log(x); console.log(typeof (eval(rf))); console.log(typeof (eval(rf)) === 'function'); if (1 && typeof (eval(rf)) === 'function') { if ((rf !== "init_secretword")) { eval(rf)(rf_params); } if (rf !== "panel_getdata") { process_form(form); } } else { if (b(rf)) { console.log("Invalid function: " + rf); } } } obj_success(obj, form); obj_error(obj, form); } else { ref = form.attr("id"); if (b(ref)) { gjxs = String(ref) + "_jxs"; if (typeof (window[gjxs]) === 'function') { eval(gjxs)(response, form); } } } } function obj_success(obj, form) { console.log("obj.success " + form.attr("id")); if (obj.success) { console.log("rf"); console.log(rf); var fx = b(forms_arr.indexOf(rf) > -1); console.log("fx: " + fx); if (b(rf_params) && b(rf) && fx) { var sccmsg = form.find(".sccmsg");/* sccmsg.removeClass("errmsg").clearQueue().hide().html(function () { return obj.success; }).slideDown({duration: 500, complete: function () { $(this).delay(5000).slideUp({duration: 500, complete: function () { $(this).dequeue(); var fw = form.parents(".form_wrapper"); if (fw.length) { fw.slideUp({duration: 500, complete: function () { effx = false; general_jxsuccess(obj, form); } }); } else { effx = false; general_jxsuccess(obj, form); } } }); } }); */ sccmsg.removeClass("errmsg").stop().clearQueue().hide().html(function () { return obj.success; }).append("
").slideDown({duration: 500, complete: function () { $(this).find(".msdelay").hide("slide", {direction: "right"}, 2000, function () { sccmsg.slideUp({duration: 500, complete: function () { $(this).dequeue(); effx = false; var fw = form.parents(".form_wrapper"); if (fw.length) { fw.slideUp({duration: 500, complete: function () { effx = false; general_jxsuccess(obj, form); } }); } else { effx = false; general_jxsuccess(obj, form); } } }); $(this).remove(); }); } }); } $("input:hidden[name='form_token']").remove(); rf_params = ""; rf = ""; } } function obj_error(obj, form) { if (obj.error) { $.each(obj.error, function (index, value) { if (index === "account") { wrel(); } var elm = ".errmsg[itemscope='" + index + "']"; e = form.find(elm); if (e.length === 0) { e = form.find(".errmsg").last(); if (e.length === 0) { e = form.find(".sccmsg"); e.addClass("errmsg"); } } e.html(value); msg_eff(e); }); } } function general_jxe(form) { sc = form.find(".sccmsg"); sc.addClass("errmsg").html(language_values["request_err"]); msg_eff(sc); } function general_jxsuccess(obj, form) { console.log("F: general_jxsuccess"); ref = form.attr("id"); if (b(ref)) { rf_replace = ref; gjxs = String(ref) + "_jxs"; console.log("JXS: " + gjxs); if (typeof (window[gjxs]) === 'function') { eval(gjxs)(obj, form); } else { p = form.parents(".accWindow"); if (p.length) { panel_getdata(p); } } } } function toggle_form(form_id) { f = b(form_id) ? $("#" + form_id) : $("form"); th = f.parents("*[itemscope=thover]"); th.find(">.form_wrapper").unbind().hide(); th.find(">*:first-child:not(.form_wrapper)").unbind().each(function () { var fc = $(this); var frw = fc.parent().find(".form_wrapper:not(.hidden)"); if (frw.length) { fc.addClass("show_form").click(function () { console.log(fc); etgl(frw); fc.toggleClass("show_form"); }).mouseenter(function () { $(this).effect("highlight"); }); } }); $(".smallinfo").addClass("transition").unbind().click(function () { $(this).toggleClass("smclicked"); }); setTimeout(smclicked_out, 1500); } function smclicked_out() { $(".smallinfo").each(function () { var zoom = $(this).find("span.glyphicon-zoom-in"); if (!zoom.length) { var xh = $(this).html(); $(this).html(xh + ''); } }); } function etgl(frw) { frw.each(function () { var frwe = $(this); frwe.slideToggle({duration: 400, complete: function () { if (frwe.css("display") === "block") { var fchk = frwe.find("form").attr("id") + "_open"; console.log(fchk); if (typeof (window[fchk]) === 'function') { eval(fchk)(frwe.find("form")); } else { console.log("NO FNC: " + fchk); } } }}); }); } function screen_rez() { strx = $(window).width() + " / " + $(window).height(); $("#screen_rez").html(function () { return strx; }); benchmark_toggle(); } function wrel() { console.log("F: wrel"); window.location.reload(); } function goacc() { console.log("F: goacc"); window.location = "account"; } function gohome() { console.log("F: gohome"); window.location = base_url; } function benchmark_toggle() { $("#benchmark_toggle").click(function () { var bm = $("#benchmark"); if (bm.css("display") === "none") { bm.slideDown(300); } else if (bm.css("display") === "block") { bm.slideUp(300); } }); $("#benchmark").hide(); setTimeout(sescountdown, 1000); } function sescountdown() { s = parseInt($("#sesTime").html()); /* if (s < 60) { b = $("#benchmark"); if (b.css("display") === "none") { b.slideDown(300); } } */ $("#sesTime").html(s - 1); s = $("#stdTime").attr("title"); $("#stdTime").attr("title", parseInt(s) + 1); s = $("#stdTime").attr("title") * 1000; d = new Date(s); $("#stdTime").html(date2str(d, "yyyy-MM-dd hh:mm:ss") + " Europe/Bucharest"); setTimeout(sescountdown, 1000); } function date2str(x, y) { var z = { M: x.getMonth() + 1, d: x.getDate(), h: x.getHours(), m: x.getMinutes(), s: x.getSeconds() }; y = y.replace(/(M+|d+|h+|m+|s+)/g, function (v) { return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1))).slice(-2); }); return y.replace(/(y+)/g, function (v) { return x.getFullYear().toString().slice(-v.length); }); } var envsnd_timer; function play_env() { var sndpath_env = '/web_assets/sound/env.mp3'; var sndpath_eff = '/web_assets/sound/click.mp3#t=0.179'; var envsnd_embedTag = ''; $('body').append(''); $('body').append(''); playenv(envsnd_embedTag); envsnd_timer = setInterval(playenv, 30000, envsnd_embedTag); $("body").click(function () { var eff_embedTag = ''; playeff(eff_embedTag); }); volctrl(envsnd_embedTag); } function playenv(embedTag) { if (volstatus.v) { $(".sndenv").html(embedTag); var obj = $(".sndenv").find('audio'); obj[0].volume = volstatus.m; } } function playeff(embedTag) { if (volstatus.v) { $(".sndeff").html(embedTag); var obj = $(".sndeff").find('audio'); obj[0].volume = volstatus.x; } } function volctrl(embedTag) { var options = {direction: "right"}; var volpanel = $("#volctrl").find(".panel"); volpanel.hide(); $(".volpan").click(function () { if (volpanel.css("display") === "none") { $("#volpan").toggle("slide", options, "fast", function () { volpanel.toggle("slide", options, "fast"); }); } else if (volpanel.css("display") === "block") { volpanel.toggle("slide", options, "fast", function () { $("#volpan").toggle("slide", options, "fast"); }); } }); $(".volOnOff").click(function () { volstatus.v = volstatus.v ? 0 : 1; if (volstatus.v) { clearTimeout(envsnd_timer); playenv(embedTag); envsnd_timer = setInterval(playenv, 30000, embedTag); } else { var x = $("#sndenv"); if (x[0] !== null) { x[0].pause(); } } ajax_call("setvolstatus", {volstatus: volstatus.v}, volctrl_jxs, volctrl_jxe, $("#volctrl")); }); $("#vol_music").slider({ orientation: "vertical", range: "min", min: 0, max: 100, value: (volstatus.m * 100), tooltip: 'always', slide: function (event, ui) { var obj = $(".sndenv").find('audio'); obj[0].volume = ui.value * 0.01; }, stop: function (event, ui) { ajax_call("setvolstatus", {sndenv: ui.value}, volctrl_jxs, volctrl_jxe, $("#volctrl")); } }); $("#vol_music").slider("value"); $("#vol_effx").slider({ orientation: "vertical", range: "min", min: 0, max: 100, value: (volstatus.x * 100), tooltip: 'always', slide: function (event, ui) { var obj = $(".sndeff").find('audio'); obj[0].volume = ui.value * 0.01; }, stop: function (event, ui) { ajax_call("setvolstatus", {sndeff: ui.value}, volctrl_jxs, volctrl_jxe, $("#volctrl")); } }); $("#vol_effx").slider("value"); } function volctrl_jxs(response, params) { var obj = JSON.parse(response); if (obj.v !== null) { vol = params.find(".volOnOff").find(".fa"); vol.removeClass("fa-volume-off").removeClass("fa-volume-up"); vol.addClass((obj.v === 1) ? "fa-volume-up" : "fa-volume-off"); volstatus.v = obj.v; } if (obj.m !== null) { vol = $(".sndenv").find('audio'); vol[0].volume = obj.m; volstatus.m = obj.m; } if (obj.x !== null) { vol = $(".sndeff").find('audio'); vol[0].volume = obj.x; volstatus.x = obj.x; } } function volctrl_jxe(params) { } /** * @syntax b(ex) * @param ex expression * @returns {Boolean} */ function b(ex) { return Boolean(ex); } function msg_eff(elem, mdelay) { mdelay = b(mdelay) ? mdelay : 1000; zx = elem.queue(); if (zx && !zx.length) { effx = true; elem.stop().clearQueue().hide().append("").slideDown({duration: 500, complete: function () { $(this).find(".msdelay").hide("slide", {direction: "right"}, mdelay, function () { elem.slideUp({duration: 500, complete: function () { $(this).dequeue(); effx = false; } }); $(this).remove(); }); } }); } } function validateEmail(sEmail) { var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; if (filter.test(sEmail)) { return true; } else { return false; } } function ajax_call(urlSentTo, json_postdata, successjx, errorjx, params) { if (!effx) { var sc = params.find(".sccmsg"); if (!sc.length) { params.append(""); } $.ajax({ type: "post", url: base_url + "calljx/" + urlSentTo, data: json_postdata, async: true, cache: false, success: function (response) { if (response === "reload") { window.location.reload(); } else { successjx(response, params); } }, error: function () { errorjx(params); } }); } } /** * @syntax formtoken(form) * @description * Checks if the form has token. * @param {string} form * The form element. * @returns false If there is no form token, token value If there is form token * */ function formtoken(form) { var t = form.find("input[name='form_token']"); var r = false; if (t.length) { var o = 0; $.each(t, function () { if (o) { $(this).remove(); o++; } else { r = $(this).val() + ""; } }); } return r; } function process_form(t) { console.log("process form"); f = t.attr("id"); fx = (forms_arr.indexOf(f) > -1) ? true : function () { console.log("Not in forms_arr: " + f); return false; }; fc = (typeof (window[f]) === 'function') ? true : function () { console.log("Invalid function: " + f); return false; }; k = t.children(); tk = k.find(".reqtkn"); tkx = (tk.length === 1) ? true : function () { console.log("Not .reqtkn in form: " + f); return false; }; rf = f; rf_params = t; console.log("rf: " + rf); if ((b(f) && fx && tkx && fc) || (f === "panel_getdata") || (f === "init_secretword")) { k.clearQueue(); k.stop(); k.find("input[type=submit]").attr("disabled", "disabled"); k.find(".input-submit").toggleClass("input-disabled", true); var tkn_val = formtoken(t); if (!tkn_val) { console.log("request_token"); request_token(tk); } else { var fchk = f + "_jseval"; console.log("fchk: " + fchk); var evalx = true; if (typeof (window[fchk]) === 'function') { evalx = eval(fchk)(t); } if (evalx) { send_form(t); } else { console.log("returned false, an error message should be set"); } } } else { console.log("ERR: process_form"); } } function send_form(form) { console.log("commit (cf): "); console.log(cf); if (!cf) { return; } var urlSentTo = form.attr("action"); var json_postdata = set_json(form); if (!json_postdata.form_token) { urlSentTo = "set_token"; } console.log("urlSentTo: " + urlSentTo); f = form.attr("id"); if ((f === "init_secretword")) { console.log("FORM: init_secretword"); console.log(json_postdata); } ajax_call(urlSentTo, json_postdata, general_jxs, general_jxe, form); } function set_json(form) { var json_postdata = form.serializeArray().reduce(function (obj, item) { obj[item.name] = item.value; return obj; }, {}); if (!json_postdata.a) { try { json_postdata["a"] = form.attr("id"); } catch (exception) { console.log("No proper form ID"); } } if (!json_postdata.f) { try { json_postdata["f"] = form.attr("itemscope"); } catch (exception) { console.log("No proper form itemscope"); } } return json_postdata; } function jf(e, err_key) { var r = false; var mf = e.parents("form"); var msg_e = mf.find(".errmsg[itemscope='" + e.attr("name") + "']"); if (!msg_e.length) { a = "