﻿Math["uuid"] = (function() { var CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"["split"](""); return function(len, radix) { var chars = CHARS, uuid = [], rnd = Math["random"]; radix = radix || chars["length"]; if (len) { for (var i = 0; i < len; i++) { uuid[i] = chars[0 | rnd() * radix]; }; } else { var r; uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-"; uuid[14] = "4"; for (var i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | rnd() * 16; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf]; }; }; }; return uuid["join"](""); }; })(); function rc4Encrypt(key, pt) { s = new Array(); for (var i = 0; i < 256; i++) { s[i] = i; }; var j = 0; var x; for (i = 0; i < 256; i++) { j = (j + s[i] + key["charCodeAt"](i % key["length"])) % 256; x = s[i]; s[i] = s[j]; s[j] = x; }; i = 0; j = 0; var ct = ""; for (var y = 0; y < pt["length"]; y++) { i = (i + 1) % 256; j = (j + s[i]) % 256; x = s[i]; s[i] = s[j]; s[j] = x; ct += String["fromCharCode"](pt["charCodeAt"](y) ^ s[(s[i] + s[j]) % 256]); }; return ct; }; function rc4Decrypt(key, ct) { return rc4Encrypt(key, ct); }; function hexEncode(data) { var b16_digits = "0123456789abcdef"; var b16_map = new Array(); for (var i = 0; i < 256; i++) { b16_map[i] = b16_digits["charAt"](i >> 4) + b16_digits["charAt"](i & 15); }; var result = new Array(); for (var i = 0; i < data["length"]; i++) { result[i] = b16_map[data["charCodeAt"](i)]; }; return result["join"](""); }; function hexDecode(data) { var b16_digits = "0123456789abcdef"; var b16_map = new Array(); for (var i = 0; i < 256; i++) { b16_map[b16_digits["charAt"](i >> 4) + b16_digits["charAt"](i & 15)] = String["fromCharCode"](i); }; if (!data["match"](/^[a-f0-9]*$/i)) { return false; }; if (data["length"] % 2) { data = "0" + data; }; var result = new Array(); var j = 0; for (var i = 0; i < data["length"]; i += 2) { result[j++] = b16_map[data["substr"](i, 2)]; }; return result["join"](""); }; var totalAnswered = 0; var totalQuestions = 7; var totalCorrect = 0; var totalCorrectPercent = 0; var oldTotalCorrectPercent = 0; var iid = Math["uuid"](); var ended = false; var qz = null; function refreshScores() { { oldTotalCorrectPercent = totalCorrectPercent; totalCorrectPercent = Math["round"]((100 / totalQuestions) * totalCorrect); var percentLabel = totalCorrectPercent + "%"; var percentColorLabel = "score" + totalCorrectPercent; var percentColorLabelClass = (totalCorrectPercent == 100) ? "score100" : "score" + Math["floor"](totalCorrectPercent / 10) + "0"; $(".percentColorLabel")["removeClass"]("score00 score10 score20 score30 score40 score50 score60 score70 score80 score90 score100")["addClass"](percentColorLabelClass); $(".totalCorrectLabel")["text"](totalCorrect); $(".totalAnsweredLabel")["text"](totalAnswered); $(".totalWrongLabel")["text"](totalAnswered - totalCorrect); var scoreFrom = { property: oldTotalCorrectPercent }; var scoreTo = { property: totalCorrectPercent }; jQuery(scoreFrom)["animate"](scoreTo, { duration: 1000, step: function() { if (!isNaN(this["property"])) { $(".percentColorLabel")["text"](Math["round"](this["property"]) + "%"); $(".percentLabel")["text"](Math["round"](this["property"]) + "%"); }; }, complete: function() { $(".percentLabel")["text"](percentLabel); $(".percentColorLabel")["text"](percentLabel); if (totalCorrectPercent >= 70 && totalCorrectPercent < 100) { $(".scoreMessage")["text"]("Well Done!"); $(".scoreMessageAnimated")["slideDown"](200); }; if (totalCorrectPercent == 100) { $(".scoreMessage")["text"]("Perfect!"); $(".scoreMessageAnimated")["slideDown"](200); }; } }); if (totalAnswered > 6) { $(".quizEndBlock")["show"](); }; }; }; function checkAnswer(source, panelId) { var panel = $("#" + panelId); if (panel["hasClass"]("hide")) { var qs = panel["attr"]("qs"); var index = source["attr"]("index"); var qd = jsonParse(rc4Decrypt(qs, hexDecode(panel["attr"]("qd")))); var selectionIndex = $(source)["attr"]("index"); var correctIndex = qd["correctAnswerId"]; var isCorrect = (selectionIndex == correctIndex); var answerBlocks = [null, panel["find"](".answer1"), panel["find"](".answer2"), panel["find"](".answer3"), panel["find"](".answer4")]; var correctAnswer = answerBlocks[correctIndex]["find"](".answerText")["css"]("color", "#008800")["html"](); var selectColour = (isCorrect) ? "#008800" : "#880000"; var selectedAnswer = answerBlocks[selectionIndex]["find"](".answerText")["css"]("color", selectColour)["html"](); var resultImage = (isCorrect) ? "\x3Cimg src=\x22/content/images/tick.png\x22 alt=\x22\x22 /\x3E" : "\x3Cimg src=\x22/content/images/cross.png\x22 alt=\x22\x22 /\x3E"; panel["find"](".questionIndex")["html"](panel["find"](".questionIndex")["html"]() + resultImage); answerBlocks[selectionIndex]["find"](".answerButton")["addClass"](isCorrect ? "correctAnswer" : "wrongAnswer"); $(panel)["find"](".questionInfoAnswer")["html"]("\x3Cb\x3ECorrect Answer:\x3C/b\x3E " + correctAnswer); if (isCorrect) { totalCorrect++; }; panel["addClass"]("reveal")["removeClass"]("hide"); totalAnswered++; refreshScores(); var infoText = panel["find"](".questionInfoMore")["attr"]("content"); if (infoText) { panel["find"](".questionInfoMore")["html"]("\x3Cp class=\x22moreInfoText\x22\x3E" + rc4Decrypt(qs, hexDecode(infoText)) + "\x3C/p\x3E")["slideDown"]("3000", "linear"); }; if ($("#slidingResultPanel")["length"] > 0) { var offset = 70; var startTop = $("#slidingResultPanel")["position"]()["top"]; var endTop = panel["position"]()["top"] + offset; var speed = Math["abs"](endTop - startTop); $("#slidingResultPanel")["stop"]()["animate"]({ top: endTop }, speed, "easeOutQuart"); }; $["ajax"]({ type: "POST", url: ajaxRoot + "/quiz-actions/submit-answer", data: "quizId=" + qz + "\x26instanceId=" + iid + "\x26questionId=" + qs + "\x26index=" + index + "\x26result=" + isCorrect, datatype: "text" }); reportEventWithValue("Quiz", "Answer", qz, parseInt(index)); if (!ended && totalAnswered == totalQuestions) { endQuiz(); }; }; }; function startQuiz(quizSource) { $(".totalQuestionsLabel")["text"](totalQuestions); refreshScores(); $["ajax"]({ type: "POST", url: ajaxRoot + "/quiz-actions/submit-start", data: "quizId=" + qz + "\x26instanceId=" + iid + "\x26source=" + quizSource, datatype: "text" }); reportEvent("Quiz", "Start", qz); }; function endQuiz() { ended = true; $["ajax"]({ type: "POST", url: ajaxRoot + "/quiz-actions/submit-end", data: "quizId=" + qz + "\x26instanceId=" + iid + "\x26totalCorrect=" + totalCorrect, datatype: "text" }); reportEventWithValue("Quiz", "End", qz, totalCorrectPercent); onQuizEnd(totalCorrectPercent); }; function applyRoundedCorners() { if (typeof document["body"]["style"]["maxHeight"] !== "undefined") { $(".questionBlock, #slidingResultPanel")["rcorner"]({ backgroundImage: "/Content/Images/Boxes/corners-question-block.png", radius: "5px", positionOffset: "-1px" }); $(".question, .questionInfo")["rcorner"]({ backgroundImage: "/Content/Images/Boxes/corners-question.png", radius: "5px", positionOffset: "-1px" }); $(".answer")["rcorner"]({ backgroundImage: "/Content/Images/Boxes/corners-answer.png", radius: "5px", positionOffset: "-1px" }); $(".quizFooter")["rcorner"]({ backgroundImage: "/Content/Images/Boxes/corners-summary.png", radius: "5px", positionOffset: "-1px" }); $(".footerInfoItem")["rcorner"]({ backgroundImage: "/Content/Images/Boxes/corners-summary-content.png", radius: "5px", positionOffset: "-1px" }); }; };
