WJG WBR sandbox
input.css-checkbox {
    display:none;
input.css-checkbox + label.css-label {
    display: inline-block;
    *display: inline;
    vertical-align: middle;
    margin: 0;
    width: 20px;
    height: 20px;
    background-repeat: no-repeat;
    background: url() no-repeat;
    border: none;
    cursor: pointer;
    background-position: -88px 0;
input.css-checkbox:checked + label.css-label {
    background-position: -110px 0;
label.css-label {
    background-image:url();
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
.examOptionButton {
    font:14px/20px'MontserratRegular', Helvetica, Arial, sans-serif;
    color: #444;
.examOptionTitle {
    font:24px'MontserratRegular', Helvetica, Arial, sans-serif;
    color:#222
@media (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) {
    input.css-checkbox + label.css-label {
        background-image: url(@2x.png);
        -webkit-background-size: 176px 22px;
        background-size: 176px 22px;
a{
target-name:new;
target-new:tab;
body{
width:100%;
margin:0;
background-color:#FFFFFF;

#details{
  position:absolute; background:white; border: 1px solid #D1C9C2; border-top: 0; width: 400px; margin: 0 auto; padding:  7px 15px; text-align: left; -webkit-border-bottom-right-radius: 6px; -webkit-border-bottom-left-radius: 6px; -moz-border-radius-bottomright: 6px; -moz-border-radius-bottomleft: 6px; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px;

#content.mw-body{
width:100%;
padding:0;
margin-left:0;
margin:0;
border:none;

#bodyContent{
width:100%;
height:90%;
margin:0;

#chooseQBank{
background-color:#0e83cd;
body{
width:100%;
margin:0;
/*Here's some css for the buttons used to select an exam. (.Curric buttons).
lines comment*/
.round-button {
	width:100px;
	display:inline-block;
	cursor:pointer;
.round-button-circle {
	width: 100%;
	height:0;
	padding-bottom: 100%;
	border-radius: 50%;
	border:0px solid #cfdcec;
	overflow:hidden;
	opacity:50%;
    background: #3C9AD6; 
.round-button p {
	font-family: 'Lato', Calibri, Arial, sans-serif;
	display:block;
	float:left;
	width:100%;
	padding-top:50%;
    padding-bottom:50%;
	line-height:1em;
	margin-top:-0.5em;
	text-align:center;
	color:white;
    font-size:3.2em;
    text-decoration:none;
.round-button p:hover {
	color:#0e83cd;
	transition: background 0.2s, color 0.2s;
.round-button-circle:hover {
	width: 100%;
	height:0;
	padding-bottom: 100%;
	border-radius: 50%;
	border-spacing:5px;
	border:3px solid #0e83cd;
	overflow:hidden;
	box-shadow: 0 0 0 4px #fff;
	transition: background 0.2s, color 0.2s;
    background: white; 

#spacer{
margin:10px
.container > header {
	font-family: 'Lato', Calibri, Arial, sans-serif;
margin: 0 auto;
padding: 2em 1em 2em;
width: 100%;
text-align: center;
background: #fff;
z-index: 999999;
-webkit-backface-visibility: hidden;
border-bottom:none;
margin-bottom:20px;
.container > header h1 {
font-size: 3.625em;
line-height: 1.3;
margin: 0;
font-weight: 300;
color: #aaa;
background: #fff;
border-bottom:none;
.container > header span {
display: block;
font-size: 60%;
-pacity: 0.6;
padding: 0 0 0.6em 0.1em;
border-bottom:none;
.examButtons { 
text-align: center;
margin: 0 auto;
 	padding: 2em 0 3em; }
.boxed{
border:0px solid black !important;
.redBoxed{
border:0px solid #F00 !important;
.answer{display: inline}
.ans_text{
display: inline;
cursor: pointer;
.choice_elim{
-pacity:0.9;
text-decoration:line-through;
.flagged{
color:#FF0000;
.labvalson{
display:visible;
.unboxed{
border:0px;

#go{
width:150px;
height:50px;
background-color:#0f0;
.imageDiv{
margin:5px 5px 5px 5px;
.WBRButton{
font-family:Arial;
float:left;
background-color:#3366CC;
height:40px;
line-height: 15px;
border-radius: 15px;
font-weight:bold;
width:150px;
display: table-cell;
cursor: pointer;
color:#FFFFFF;
text-align: center;
vertical-align: middle;
margin-right:10px;
.WBRImgButton{
font-family:Arial;
float:left;
height:40px;
font-weight:bold;
width:100px;
display: table-cell;
cursor: pointer;
color:#FFFFFF;
text-align: center;
vertical-align: middle;
margin-right:10px;
.WBRImgButton img{
width:auto; 
height:35px;

#globalWrapper{
z-index:-1;

#content{
height:100%;}

#exam{
height:90%;
border:none;
padding:0;

#mw-content-text{
height:100%;}

#navPane{
position:relative; 
float:left;
width:5%;
height:100%;
-verflow-y:scroll; 

#examSpace{
position:relative;
float:right;
width:94%;
height:90%;
-verflow-y:scroll; 

#navBar{
position:relative;
float:right;
width:95%;
background-color:#3366CC;

#bottomBar{
height:40px;
position:relative;
float:right;
width:100%;
background-color:#3366CC;

#pauseButton{
float:right;
margin-bottom:0px;
height:95%;

#stopButton{
float:right;
margin-right: 5%;
height=95%;
margin-bottom:0px;
.navPaneButton{
height:20px;
background-color:#D0D0D0;
padding-top:5px;
font-weight:bold;
text-align: center;
div.answerNoBorder{
border:0px solid #FFF;
div.answerBorder{
border:0px solid #000;
div.explanationHide{
height:0px;
visibility:hidden;
div.explanationShow{
height:auto;
visibility:visible;

#tutorOrExamContainer{
	background-color:#E3E5E5;
function ensureLoggedIn() {
mw.loader.load('mediaWiki.user');
if ($.isEmptyObject(wgUserName)) {
	alert("Please Log In To Continue.");
	window.location.replace(":UserLogin&returnto=User%3AMatt+Pijoan");
} else {
	curriculumType();
function curriculumType() {
	var options = {
		examtype : null,
		timer : null,
		qbank : null,
		searchMethod : null,
		timer : null,
		examType : '',
		timeAmt : 0,
		questionListAll : new Array(),
		numQuestion : null,
		currentQuestion : 0,
		examQuestions : new Array(),
		isParsed : 0,
		answeredRight : 0,
		Question : {
			PageName : null,
			PageAuthor : null,
			Prompt : null,
			RightAnswer : ' ',
			AnswerA : null,
			AnswerB : null,
			AnswerC : null,
			AnswerD : null,
			AnswerE : null,
			AnswerAExp : null,
			AnswerBExp : null,
			AnswerCExp : null,
			AnswerDExp : null,
			AnswerEExp : null,
			selectedAnswer : 'F',
			lastParsed : 0,
			creditReceived : false
	window.exam=options;
	var background_html="Wikidoc Board Review  Please select an exam below";
	$("#chooseQBank").html(background_html);
	var stuffs = "MCAT";
	stuffs += "1";
	stuffs += "2";
	stuffs += "3";
	stuffs += "ABIM";
stuffs+="";
	$("#chooseQBank").html(background_html+"" + stuffs + "");
	$('.Curric').click(options, chooseQBank);
function chooseQBank(event) {
	$("#chooseQBank").remove();//Once the QBank is picked, we'll remove the div that held it.
	$("#exam").show();
	window.exam.examtype = $(this).attr('id');
	var divs = null;
	divs = "Build your own exam!USMLE FormatFlash Cards";
	$("#exam").html(divs);
	$('.stepTwo').click(window.exam, tutorOrExam);
function tutorOrExam(event) {
	window.exam.qbank = $(this).attr('id');
	var buttons = '';
	buttons = "Tutor ModeExam Mode";
	$("#exam").append(buttons);
	$('.ToE').click(window.exam, categoryOrKeyword);
function categoryOrKeyword(event) {
	window.exam.examType = $(this).attr('id');
	var buttons = '';
	buttons = "CategoryKeyword";
	$("#exam").append(buttons);
	$('.CoK').click(window.exam, timerToggle);
function timerToggle(event) {
	window.exam.searchMethod = $(this).attr('id');
	var form = null;
	form = "Enable TimerDisable Timer";
	if ($("#exam").find('#yes').length == 0) {
		$("#exam").append(form);
	$('#yes').click(window.exam, timerDuration);
	if (window.exam.searchMethod === "Category") {
		$('#nop').click(window.exam, countCats);
	} else {
		$('#nop').click(window.exam, Keywords);
function timerDuration(event) {
	window.exam.timer = true;
	var form = null;
	form = "1 Minute10 Minute20 Minutes40 Minutes"
		if ($("#exam").find('#1').length == 0) {
			$("#exam").append(form);
		if (window.exam.searchMethod === "Category") {
			$('.stepFour').click(window.exam, countCats);
		} else {
			$('.stepFour').click(window.exam, Keywords);
function Keywords(event) {
	var stuffs = "ORANDSHOW";
	$("#exam").append(stuffs);
	var orBox = "  ";
	var andBox = "  ";
	$("#formSpace").html(orBox);
	$(".queryString").focus(function () {
		$(".focused").removeClass("focused");
		$(this).parent().addClass("focused");
		$(".queryString").focusout(function () {
			if ($(this).val().length <= 1) {
				$(this).remove();
	$("#orOp").click(function () {
		$("#formSpace").append(orBox);
		$(".queryString").focus(function () {
			$(".focused").removeClass("focused");
			$(this).parent().addClass("focused");
			$(".queryString").focusout(function () {
				if ($(this).val().length <= 1) {
					$(this).remove();
	$("#andOp").click(function () {
		var andBox = "";
		$(".focused").append(andBox);
		$(".queryString").focus(function () {
			$(".focused").removeClass("focused");
			$(this).parent().addClass("focused");
			$(".queryString").focusout(function () {
				if ($(this).val().length <= 1) {
					$(this).remove();
	$("#showQueries").click(window.exam, showQueries);
	function showQueries(event) {
		$("#removeNum").remove();
		window.exam.queries = ;
		window.exam.questionListAll = ;
		window.exam.keyword = {};
		window.exam.keyword.iterator = 0;
		$.each($(".query"), function (index, value) {
			window.exam.queries = "]";
			$.each($(this).children(), function (ind, val) {
				window.exam.queries += "]";
		runQueries(window.exam);
	function runQueries(obj) {
		var api = new mw.Api();
		api.get({
			action : 'ask',
			query : obj.queries,
			format : 'json'
		.always(function (data) {
			$.each(data.query.results, function (index, value) {
				obj.questionListAll.push(value.fulltext);
			if ((obj.keyword.iterator + 1) < obj.queries.length) {
				obj.keyword.iterator++;
				runQueries(obj);
			} else {
				removeDuplicates(obj);
	function removeDuplicates(obj) {
		if (res.Count > 45) {
			obj.maxQ = 45;
		} else {
			obj.maxQ = res.Count;
		var output = "Choose the number of questions you would like to answer. The maximum number of questions you can select is " + obj.maxQ + ".Number of questions:Click here to begin the exam";
		if ($("#exam").find('#numQues').length == 0) {
			$("#exam").append(output);
		} else {
			alert('Please ensure you have valid keywords entered');
		$("#Go").click(obj, TNG);
function TNG(event) {
	window.exam.numQuestion = $("#numQues").val();
	if (window.exam.numQuestion > 0 && window.exam.numQuestion <= 45) {
		loadNextQuestion(window.exam);
	} else {
		alert('Invalid number of questions entered.');
function selectCats() {
	var categories = ;
	var table = null;
	table = "Select All That Apply:"; ;
	if (window.exam.examtype === "MCAT") {
		categories = new Array("Biology", "Cell", "Enzymes", "Microbiology", "Cellular Metabolism", "Reproduction", "Embryology", "Musculoskeletal System", "Digestive System ", "Excretory System", "Respiratory System", "Skin", "Circulatory System", "Immune System", "Homeostasis", "Endocrine System", "Nervous System ", "Genetics", "Evolution", "Organic Chemistry", "Nomenclature", "Bonding/Structure", "Isomers", "Alkanes", "AlkenesAlkynes", "Haloalkanes", "Aromatic Compounds", "Alcohols", "Ethers", "Aldehydes ", "Ketones", "Carboxylic Acid", "Carboxylic Acid Derivatives", "Amines", "Nitrogen Containing Compounds", "Purification", "Spectroscopy", "Separations", "Carbohydrates", "Amino Acids", "Peptides", "Proteins", "Nucleic", "Acids", "Chemistry", "Atomic Structure", "Periodic Table", "Phases", "Gases", "Bonding", "Stoichiometry", "Kinetics", "Thermochemistry", "Phases", "Solutions", "Acids and Bases", "Redox Reactions", "Electrochemistry", "Physics", "Kinematics", "Fluids", "Solids", "Newtonian Mechanics", "Momentum", "Energy", "Thermodynamics", "Electrostatics", "Magnetism", "DC Circuits", "AC Circuits", "Periodic Motion", "Waves", "Sound", "Optics", "Light", "Atomic Phenomena", "Nuclear Phenomena");
		for (var i = 0; i < categories.length; i++) {
			table += "" + categories + "";
			if ((i + 1) % 4 == 0) {
				table += "";
	} else {
		if (window.exam.examtype === "USMLE Step 1") {
			categories = new Array("Anatomy", "Behavioral Science/Psychiatry", "Biochemistry", "Biostatistics/Epidemiology", "Embryology", "Ethics", "Genetics", "Histology", "Immunology", "Microbiology", "Pathology", "Pathophysiology", "Pharmacology", "Physiology");
			categories = new Array("Cardiology", "Dermatology", "Endocrine", "Gastrointestinal", "Genitourinary", "Head and Neck", "Hematology", "Musculoskeletal/Rheumatology", "Neurology", "Oncology", "Pulmonology", "Reproductive", "Renal", "Vascular", "General Principles", "Infectious Disease");
		} else if (window.exam.examtype === "USMLE Step 2 CK") {
			categories = new Array("Internal medicine", "Surgery", "OB/GYN", "Pediatrics", "Psychiatry");
			categories = new Array("Allergy/Immunology", "Cardiovascular", "Dermatology", "Endocrine", "Gastrointestinal", "Hepatology", "Genitourinary", "Head and Neck", "Hematology", "Infectious Disease", "Musculoskeletal/Rheumatology", "Neurology", "Obstetrics and Gynecology", "Oncology", "Ophthalmology", "Pediatrics", "Poisoning", "Preventive Medicine", "Psychiatry", "Respiratory", "Surgery", "Biostatistics/ Epidemiology", "Ethics", "Electrolytes", "Genetics", "Miscellaneous");
		} else if (window.exam.examtype === "USMLE Step 3") {
			categories = new Array("Community Medical Health Center", "Primary Care Office", "Inpatient Facilities", "Emergency Room");
			categories = new Array("Allergy/Immunology", "Cardiovascular", "Dermatology", "Endocrine", "Gastrointestinal", "Hepatology", "Genitourinary", "Head and Neck", "Hematology", "Infectious Disease", "Musculoskeletal/Rheumatology", "Neurology", "Obstetrics and Gynecology", "Oncology", "Ophthalmology", "Pediatrics", "Poisoning", "Preventive Medicine", "Psychiatry", "Respiratory", "Surgery", "Biostatistics/Epidemiology", "Ethics", "Electrolytes", "Genetics", "Miscellaneous");
		} else if (window.exam.examtype === "Board Review") {
			categories = new Array("Adolescent Medicine", "Advanced Heart Failure and Transplant Cardiology", "Allergy & Immunology", "Cardiovascular Disease", "Clinical Cardiac Electrophysiology", "Critical Care Medicine", "Endocrinology", "Diabetes and Metabolism", "Gastroenterology", "Geriatric Medicine", "Hematology", "Hospice & Palliative Medicine", "Hospital Medicine", "Focused Practice", "Infectious Disease", "Internal Medicine", "Interventional Cardiology", "Medical Oncology", "Nephrology", "Pulmonary Disease", "Rheumatology", "Sleep Medicine", "Sports Medicine", "Transplant Hepatology");
			categories = new Array("Anesthesiology", "Dermatology", "Emergency Medicine", "Emergency Medicine/Critical Care Medicine", "Family Medicine", "Medical Genetics", "Neurology", "Nuclear Medicine", "Pediatrics", "Physical Medicine & Rehab", "Preventative Medicine", "Psychiatry");
		table += "Main CategorySub Category";
		if (categories.length >= categories.length) {}
		var table = "Select All That Apply:";
		table += "Main CategorySub Category";
		if (categories.length >= categories.length) {
			for (var i = 0; i < categories.length; i++) {
				if (categories) {
					table += "" + categories + " ( " + exam.arrCounts] + " ) " + categories + " ( " + exam.arrCounts] + " )";
				} else {
					table += "" + categories + " ( " + exam.arrCounts] + " ) ";
		} else {
			for (var i = 0; i < categories.length; i++) {
				if (categories) {
					table += "" + categories + "" + categories + "";
				} else {
					table += "" + categories + "";
		table += "Select All Main CategoriesSelect All Sub CategoriesSecond: Click the Count Question Button below to calculate number of questions available:Count Questions"
		if ($("#exam").find('#SelectAll').length == 0) {
			$("#exam").append(table);
	$("#SelectAll").click(function () {
		if ($("#SelectAll").html() === "Select All Main Categories") {
			$("").each(function () {
				$(this).attr('checked', true);
				$("#SelectAll").html("Clear All Main Categories");
		} else {
			$("").each(function () {
				$(this).attr('checked', false);
				$("#SelectAll").html("Select All Main Categories");
	$("#UnselectAll").click(function () {
		if ($("#UnselectAll").html() === "Select All Sub Categories") {
			$("").each(function () {
				$(this).attr('checked', true);
				$("#UnselectAll").html("Clear All Sub Categories");
		} else {
			$("").each(function () {
				$(this).attr('checked', false);
				$("#UnselectAll").html("Select All Sub Categories");
	$("#CountQ").click(window.exam, selectExamLength);
function selectExamLength(event) {
	var Main = new Array();
	var Sub = new Array();
	if ($(":checked").length > 0 && $(":checked").length > 0) {
		$(":checked").each(function () {
			Main.push($(this).val());
		$(":checked").each(function () {
			Sub.push($(this).val());
		window.exam.mainCat = Main;
		window.exam.subCat = Sub;
		var api = new mw.Api(event, Main, Sub);
		api.get({
			action : 'catcount',
			main : JSON.stringify(Main),
			sub : JSON.stringify(Sub),
			exam : window.exam.examtype,
			format : 'json'
			ok : function (res) {
				if (res.Count > 45) {
					window.exam.maxQ = 45;
				} else {
					window.exam.maxQ = res.Count;
				var output = "Choose the number of questions you would like to answer. The maximum number of questions you can select is " + window.exam.maxQ + ".Number of questions:Click here to begin the exam";
				if ($("#exam").find('#numQues').length == 0) {
					$("#exam").append(output);
				$("#Go").click(window.exam, inputValidation);
	} else {
		alert('Please ensure you have both a main and a sub category selected');
function inputValidation(event) {
	if ($("#numQues").val().length > 0 && parseInt($("#numQues").val(), 10)  0) {
		window.exam.numQuestion = $("#numQues").val();
		var api = new mw.Api();
		api.get({
			action : 'newExam',
			username : mw.user.getName(),
			type : window.exam.examtype,
			format : 'json'
		.done(function (data) {
			window.exam.examid = data.newExam.exam_id;
		$("#exam").html("");
		if (window.exam.timer) {
			window.exam.examTimer = $.timer(function () {
					var rem = parseInt($("#timeRem").html());
					$('#timerBox').css("visibility", "visible");
					$('#timerBox').html(formatTime(rem));
					if (rem == 0) {
						window.exam.examTimer.stop();
						$("#content").click(window.exam, endExam);
					} else {
						var temp = rem - 7;
						$("#timeRem").html(temp.toString());
						if (rem < 0) {
							$("#timeRem").html("0");
				}, 70, false);
			window.exam.examTimer.toggle();
		loadNextQuestion();
	} else {
		alert('Invalid entry in number of questions input');
function loadNextQuestion() {
	window.exam.examQuestions = ;
	if (window.exam.searchMethod === "Category") {
		var api = new mw.Api(window.exam);
		api.get({
			action : 'load',
			main : JSON.stringify(window.exam.mainCat),
			sub : JSON.stringify(window.exam.subCat),
			exam : window.exam.examtype,
			num : window.exam.numQuestion,
			format : 'json'
			ok : function (res) {
				var i = 0;
				window.exam.currentQuestion = 0;
				$.each(res.questions.list, function (key, element) {
					element.PageName = key;
					window.exam.examQuestions = element;
					i++;
				addToNavBar(window.exam);
	} else if (window.exam.searchMethod === "Keyword") {
		var api = new mw.Api(window.exam);
		api.get({
			action : 'load',
			keywords : JSON.stringify(window.exam.questionListAll),
			num : window.exam.numQuestion,
			format : 'json'
			ok : function (res) {
				var i = 0;
				window.exam.currentQuestion = 0;
				$.each(res.questions.list, function (key, element) {
					element.PageName = key;
					window.exam.examQuestions = element;
					i++;
				addToNavBar();
function addToNavBar() {
	$("#exam").html("Finish" + exam.timeAmt.toString() + "");
	$("#back").click(questionNavigation);
	$("#next").click(questionNavigation);
	$("#flag").click(flagQ);
	$("#lab_vals").click(showLabs)
	$("#finish").click(endExam);
	if (window.exam.timer) {
		$("#bodyContent").append("Testing.");
		$("#timerBox").click(function () {
			window.exam.examTimer.toggle();
	$.each(window.exam.examQuestions, function (index, value) {
		$("#navPane").append(" " + (index - -1) + "");
		console.log(index)
		window.exam.examQuestions.creditReceived=false
	$(".navPaneButton").click(questionNavigation);
	$(".navPaneButton:odd").css("background-color", "#3338CC");
	$(".navPaneButton:odd").css("background-color", "#B0B0B0");
	questionDisplay();
function questionDisplay() {
	var obj = new Object();
	obj = window.exam.examQuestions;
	if (obj.isParsed === 0) {
		$("#examSpace").html("");
		parseQuestions();
	} else {
		var htmlStuff = "Question " + (window.exam.currentQuestion - -1) + " / " + (window.exam.examQuestions.length) + "" + "" + obj.Prompt + "" + "";
		if (obj.AnswerA && obj.AnswerA.length > 0) {
			htmlStuff += "" +""+ "" + trimP(obj.AnswerA) + "";
		if (obj.AnswerAExp && obj.AnswerAExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "" + trimP(obj.AnswerAExp) + "";
		if (obj.AnswerB && obj.AnswerB.length > 0) {
			htmlStuff += "" + ""+ "" + trimP(obj.AnswerB) + "";
		if (obj.AnswerBExp && obj.AnswerBExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "" + trimP(obj.AnswerBExp) + "";
		if (obj.AnswerC && obj.AnswerC.length > 0) {
			htmlStuff += "" + "" + "" + trimP(obj.AnswerC) + "";
		if (obj.AnswerCExp && obj.AnswerCExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "" + trimP(obj.AnswerCExp) + "";
		if (obj.AnswerD && obj.AnswerD.length > 0) {
			htmlStuff += "" + "" + "" + trimP(obj.AnswerD) + "";
		if (obj.AnswerDExp && obj.AnswerDExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "" + trimP(obj.AnswerDExp) + "";
		if (obj.AnswerEExp && obj.AnswerE.length > 0) {
			htmlStuff += "" + "" + "" + trimP(obj.AnswerE) + "";
		if (obj.AnswerEExp && obj.AnswerEExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "" + trimP(obj.AnswerEExp) + "";
		$("#examSpace").html(htmlStuff);
		$("#examSpace").prepend("       Analyte    Reference Range        Sodium (Na+)    136-145 mEq/L        Potassium (K+)    3.5-5.0 mEq/L        Chloride (Cl-)    95-105 mEq/L        Bicarbonate (HCO3-)    22-28 mEq/L        Magnesium (Mg2+)    1.5-2.0mEq/L        Calcium (Ca2+)      ");
		if (window.exam.examQuestions.selectedAnswer !== 'F') {
			$("#" + window.exam.examQuestions.selectedAnswer).addClass("boxed");
		$("div.answer").mouseover(function () {
			$(this).css({
				'border' : '0px solid #000'
		}).mouseout(function () {
			$(this).css({
				'border' : '0px solid #FFF'
		$("div.answer").click(answerClicked);
		$('p.ans_text').click(function(){
			$(this).toggleClass('choice_elim')
		$('#highlightable').textHighlighter({
              		color: '#FFFF00'
function questionReview() {
	var obj = new Object();
	obj = window.exam.examQuestions;
	if (obj.isParsed === 0) {
		$("#examSpace").html("");
		parseQuestions();
	} else {
		$("#examSpace").append("Click here to discuss this question!");
		var htmlStuff = "Author: " + obj.PageAuthor + "Question " + (window.exam.currentQuestion - -1) + " / " + (window.exam.examQuestions.length) + "" + obj.Prompt + "";
		if (obj.AnswerA && obj.AnswerA.length > 0) {
			htmlStuff += "  " + obj.AnswerA + "";
		if (obj.AnswerAExp && obj.AnswerAExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerAExp + "";
		if (obj.AnswerB && obj.AnswerB.length > 0) {
			htmlStuff += " " + obj.AnswerB + "";
		if (obj.AnswerBExp && obj.AnswerBExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerBExp + "";
		if (obj.AnswerC && obj.AnswerC.length > 0) {
			htmlStuff += " " + obj.AnswerC + "";
		if (obj.AnswerCExp && obj.AnswerCExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerCExp + "";
		if (obj.AnswerD && obj.AnswerD.length > 0) {
			htmlStuff += " " + obj.AnswerD + "";
		if (obj.AnswerDExp && obj.AnswerDExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerDExp + "";
		if (obj.AnswerEExp && obj.AnswerE.length > 0) {
			htmlStuff += " " + obj.AnswerE + "";
		if (obj.AnswerEExp && obj.AnswerEExp.length > 0 && window.exam.examType === "Tutor") {
			htmlStuff += "&nbsp;&nbsp;&nbsp;&nbsp;" + obj.AnswerEExp + "";
		$("#examSpace").html(htmlStuff);
		addRatyRating(exam);
		if (window.exam.examQuestions.selectedAnswer && window.exam.examQuestions.RightAnswer == window.exam.examQuestions.selectedAnswer) {
			$("#" + window.exam.examQuestions.RightAnswer).addClass("boxed");
		} else {
			$("#" + window.exam.examQuestions.RightAnswer).addClass("redBoxed");
			$("#" + window.exam.examQuestions.RightAnswer).removeClass("answerNoBorder");
			$("#" + window.exam.examQuestions.selectedAnswer).addClass("boxed");
			$("#" + window.exam.examQuestions.selectedAnswer).removeClass("answerNoBorder");
		$("#examSpace").append("The correct answer is: " + window.exam.examQuestions.RightAnswer + "" + window.exam.examQuestions.Explanation + "");
function addRatyRating() {
	addFirstResponses();
	var ratyLayers = "Rate this question!Difficulty: High Yield: Quality: "
		$("#examSpace").prepend(ratyLayers);
	getRating(window.exam.examQuestions.PageName, window.exam);
function addFirstResponses() {
	var api = new mw.Api();
	api.get({
		action : 'firstResponseQuery',
		question : window.exam.examQuestions.PageName,
		format : 'json'
	.done(function (data) {
		if (data.firstResponseQuery.A === null) {
			data.firstResponseQuery.A = 0;
		if (data.firstResponseQuery.B === null) {
			data.firstResponseQuery.B = 0;
		if (data.firstResponseQuery.C === null) {
			data.firstResponseQuery.C = 0;
		if (data.firstResponseQuery.D === null) {
			data.firstResponseQuery.D = 0;
		if (data.firstResponseQuery.E === null) {
			data.firstResponseQuery.E = 0;
		data.firstResponseSum = parseInt(data.firstResponseQuery.A) + parseInt(data.firstResponseQuery.B) + parseInt(data.firstResponseQuery.C) + parseInt(data.firstResponseQuery.D) + parseInt(data.firstResponseQuery.E);
		$("#Ae").append("Selected as first response:" + parseInt((data.firstResponseQuery.A / data.firstResponseSum) - 100).toString() + "%");
		$("#Be").append("Selected as first response:" + parseInt((data.firstResponseQuery.B / data.firstResponseSum) - 100).toString() + "%");
		$("#Ce").append("Selected as first response:" + parseInt((data.firstResponseQuery.C / data.firstResponseSum) - 100).toString() + "%");
		$("#De").append("Selected as first response:" + parseInt((data.firstResponseQuery.D / data.firstResponseSum) - 100).toString() + "%");
		$("#Ee").append("Selected as first response:" + parseInt((data.firstResponseQuery.E / data.firstResponseSum) - 100).toString() + "%");
function answerClicked(event) {
	$(".answer").removeClass("boxed");
	$(event.currentTarget).addClass("boxed");
	$(event.currentTarget.firstChild).prop("checked", true);
	window.exam.examQuestions.selectedAnswer = $("div .boxed").attr("id");
	if ($("#exam").find('#submit').length == 0) {
		$("#examSpace").append("Submit");
		$("#submit").click(window.exam, answerSubmitted);
function getRating(page, exam) {
	var api = new mw.Api();
	api.get({
		action : 'wbrgetrating',
		question : page,
		format : 'json'
		ok : function (res) {
			$("#star1").raty({
				path : '/',
				click : function (score, event) {
					submitRating("difficulty", score, exam.examQuestions.PageName)
				score : res.wbrgetrating.difficulty,
				hints : 
			$("#star1").append("(Avg: " + res.wbrgetrating.difficulty + ", n=" + res.wbrgetrating.diffCount + ")");
			$("#star2").raty({
				path : '/',
				click : function (score, event) {
					submitRating("yield", score, exam.examQuestions.PageName)
				score : res.wbrgetrating.yield,
				hints : 
			$("#star2").append("(Avg: " + res.wbrgetrating.yield + ", n=" + res.wbrgetrating.qualCount + ")");
			$("#star3").raty({
				path : '/',
				click : function (score, event) {
					submitRating("quality", score, exam.examQuestions.PageName)
				score : res.wbrgetrating.quality,
				hints : 
			$("#star3").append("(Avg: " + res.wbrgetrating.quality + ", n=" + res.wbrgetrating.yieldSum + ")");
function answerSubmitted(event) {
	$("#submit").remove();
	if (!window.exam.examQuestions.creditReceived && window.exam.examQuestions.selectedAnswer === String(window.exam.examQuestions.RightAnswer)) {
		console.log("You answered a question correctly")
		window.exam.answeredRight += 1;
		window.exam.examQuestions.creditReceived = true;
	if (window.exam.examType === "Tutor") {
		$(".answerExp").css("height", "auto");
		$(".answerExp").css("visibility", "visible");
		$(".answerExp").each(function () {
			if ($(this).attr('id') === window.exam.examQuestions.RightAnswer + "e") {
				$(this).prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Correct: ");
			} else {
				$(this).prepend("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Incorrect: ");
	$("div.answer").unbind('click');
	var api = new mw.Api();
	api.get({
		action : 'answerQuestion',
		username : mw.user.getName(),
		question : window.exam.examQuestions.PageName,
		selected : window.exam.examQuestions.selectedAnswer,
		examid : window.exam.examid,
		format : 'json'
	.done(function (data) {
		console.log('API result:', data);
	if (window.exam.examType === "Exam") {
		$("#" + window.exam.examQuestions.selectedAnswer).addClass("boxed");
	} else if (window.exam.examType === "Tutor") {
		$("#examSpace").append("The correct answer is: " + window.exam.examQuestions.RightAnswer + "" + window.exam.examQuestions.Explanation + "");
		$("#examSpace").append("Author: " + window.exam.examQuestions.PageAuthor + "Wiki Page:" + window.exam.examQuestions.PageName + "Discuss this question Here");
		$("#" + window.exam.examQuestions.selectedAnswer).addClass("boxed");
		$("#" + window.exam.examQuestions.RightAnswer).addClass("redBoxed");
		addRatyRating(window.exam);
function questionNavigation(event) {
	if ($(this).attr("id") === "back") {
		window.exam.currentQuestion--;
	} else if ($(this).attr("id") === "next") {
		window.exam.currentQuestion++;
	} else if ($(this).attr("class") === "navPaneButton") {
		window.exam.currentQuestion = $(this).attr("id");
	questionDisplay(window.exam);
function questionReviewNavigation(event) {
	if ($(this).attr("id") === "back") {
		window.exam.currentQuestion--;
	} else if ($(this).attr("id") === "next") {
		window.exam.currentQuestion++;
	} else if ($(this).attr("class") === "navPaneButton") {
		window.exam.currentQuestion = $(this).attr("id");
	questionReview(window.exam);
function flagQ(event) {
$("#" + window.exam.currentQuestion).toggleClass("flagged");
function showLabs(event) {
$("#details").stop();
$("#details").slideToggle("slow");
function convolve_bernouli(qprobs){
//takes in an array of probabilities of guessing questions correct
for (var counter = 0; counter < qprobs.length; counter++) {
	//if the loop is in the first iteration, then initialize the array
	if (counter==0){
	    var pdfArray=,qprobs];
	}else{
	    //initialize new Array for pdfs
	    var newpdfArray= ;
	   for (var i = 0; i < pdfArray.length+1; i+=1) {
	        newpdfArray=0;
	    //multiply by ones first
	   for (var i = 0; i < pdfArray.length; i+=1) {
	        newpdfArray+=pdfArray*qprobs; //probability of adding a success
	        newpdfArray+=pdfArray*(1-qprobs);
	    pdfArray=newpdfArray;
console.log(pdfArray);
return(pdfArray);
}//ends convolve_bernouli
function endExam(event) {
	if (window.exam.timer) {
		$('#timerBox').html("");
		$('#timerBox').css("visibility", "hidden");
		window.exam.examTimer.stop();
	$("#examSpace").html("");
	var datas;
	datas = "";
	datas += "You answered " + window.exam.answeredRight + " out of " + window.exam.examQuestions.length + " correctly. Your percentage score is: ";
	var percent = Math.round((window.exam.answeredRight / window.exam.examQuestions.length) - 100);
	testlength=window.exam.examQuestions.length;
	var question_probs=;
	for (var j = 0; j < testlength; j+=1){
    question_probs=Math.random();
	qdist=convolve_bernouli(question_probs);
var myTotal = 0;  //Variable to hold your total
for(var i=0, len=window.exam.answeredRight+1; i<len; i++){
    myTotal += qdist;  //Iterate over your first array and then grab the second element add the values up
	datas += percent + "%Click the Navigation Buttons on the left to review the questions you answered.";
	datas += "You scored in the " + Math.round(myTotal*100) + " percentile. ";
	datas += "";
	var api = new mw.Api();
	api.get({
		action : 'endExam',
		id : window.exam.examid,
		score : percent,
		format : 'json'
	.done(function (data) {
		console.log('API result:', data);
	$("#examSpace").append(datas);
	$(".navPaneButton").unbind('click');
	$(".navPaneButton").click(window.exam, questionReviewNavigation);
	point_labels=;
	for (var j = 0; j < qdist.length; j+=1){
	    point_labels=j.toString();
	var simExamData = {
	                labels : point_labels,
	                datasets : [
				fillColor : "rgba(220,220,220,0.5)",
				strokeColor : "rgba(220,220,220,1)",
				pointColor : "rgba(220,220,220,1)",
				pointStrokeColor : "#fff",
				data : qdist,
				title: "Percent of test takers"
	var newopts = {
	yAxisLabel : "Percent of test takers",
	yAxisFontFamily : "'Arial'",
	yAxisFontSize : 16,
	yAxisFontStyle : "normal",
	yAxisFontColor : "#666",
	xAxisLabel : "Number of correct answers",
	legend : false,
	legendFontFamily : "'Arial'",
	legendFontSize : 12,
	legendFontStyle : "normal",
	legendFontColor : "#666",
	legendBlockSize : 15,
	legendBorders : false,
	legendBordersColor : "#666",
	graphTitle : "Peer Performance",
	graphTitleFontFamily : "'Arial'",
	graphTitleFontSize : 24,
	graphTitleFontStyle : "bold",
	graphTitleFontColor : "#666",
	            // get line chart canvas
	            var simExams = document.getElementById('simExams').getContext('2d');
	            // draw line chart
	            new Chart(simExams).Line(simExamData,newopts);
function submitRating(ratingType, score, page) {
	if (ratingType === "difficulty") {
		var api = new mw.Api();
		api.get({
			action : 'wbrinsertrating',
			username : mw.user.getName(),
			question : page,
			difficulty : score,
			format : 'json'
			ok : function (res) {}
	} else if (ratingType === "yield") {
		var api = new mw.Api();
		api.get({
			action : 'wbrinsertrating',
			username : mw.user.getName(),
			question : page,
			yield : score,
			format : 'json'
			ok : function (res) {}
	} else if (ratingType === "quality") {
		var api = new mw.Api();
		api.get({
			action : 'wbrinsertrating',
			username : mw.user.getName(),
			question : page,
			quality : score,
			format : 'json'
			ok : function (res) {}
function parseQuestions(examObj) {
	var tobeParsed = null;
	var parsed = null;
	var q = examObj.currentQuestion;
	switch (examObj.examQuestions.lastParsed) {
	case 0:
		tobeParsed = examObj.examQuestions.Prompt;
		break;
	case 1:
		tobeParsed = "A. " + examObj.examQuestions.AnswerA;
		break;
	case 2:
		tobeParsed = "B. " + examObj.examQuestions.AnswerB;
		break;
	case 3:
		tobeParsed = "C. " + examObj.examQuestions.AnswerC;
		break;
	case 4:
		tobeParsed = "D. " + examObj.examQuestions.AnswerD;
		break;
	case 5:
		tobeParsed = "E. " + examObj.examQuestions.AnswerE;
		break;
	case 6:
		tobeParsed = examObj.examQuestions.Explanation;
		break;
	case 7:
		tobeParsed = examObj.examQuestions.AnswerAExp;
		break;
	case 8:
		tobeParsed = examObj.examQuestions.AnswerBExp;
		break;
	case 9:
		tobeParsed = examObj.examQuestions.AnswerCExp;
		break;
	case 10:
		tobeParsed = examObj.examQuestions.AnswerDExp;
		break;
	case 11:
		tobeParsed = examObj.examQuestions.AnswerEExp;
		break;
	case 12:
		tobeParsed = examObj.examQuestions.Author
	if (tobeParsed && tobeParsed.length > 0) {
		var api = new mw.Api();
		api.get({
			action : 'parse',
			text : tobeParsed,
			disablepp : 'disablepp',
			format : 'json'
			ok :
			function (html) {
				parsed = html.parse.text;
				switch (examObj.examQuestions.lastParsed) {
				case 0:
					examObj.examQuestions.Prompt = parsed;
					break;
				case 1:
					examObj.examQuestions.AnswerA = parsed;
					break;
				case 2:
					examObj.examQuestions.AnswerB = parsed;
					break;
				case 3:
					examObj.examQuestions.AnswerC = parsed;
					break;
				case 4:
					examObj.examQuestions.AnswerD = parsed;
					break;
				case 5:
					examObj.examQuestions.AnswerE = parsed;
					break;
				case 6:
					examObj.examQuestions.Explanation = parsed;
					break;
				case 7:
					examObj.examQuestions.AnswerAExp = parsed;
					break;
				case 8:
					examObj.examQuestions.AnswerBExp = parsed;
					break;
				case 9:
					examObj.examQuestions.AnswerCExp = parsed;
					break;
				case 10:
					examObj.examQuestions.AnswerDExp = parsed;
					break;
				case 11:
					examObj.examQuestions.AnswerEExp = parsed;
					break;
				case 12:
					examObj.examQuestions.Author = parsed;
					break
				if (examObj.examQuestions.lastParsed < 13) {
					examObj.examQuestions.lastParsed += 1;
					parseQuestions(examObj);
				} else {
					examObj.examQuestions.isParsed = 1;
					questionDisplay(examObj);
	} else {
		if (examObj.examQuestions.lastParsed < 12) {
			examObj.examQuestions.lastParsed += 1;
			parseQuestions(examObj);
		} else {
			examObj.examQuestions.isParsed = 1;
			questionDisplay(examObj);
function countCats(event) {
	window.exam.timeAmt = parseInt($(this).attr("id"), 10) - 6000;
	var temp = window.exam.examtype.replace(/ /g, "_");
	var api = new mw.Api();
	api.get({
		action : 'singlecat',
		exam : temp,
		format : 'json',
		async : false
		ok : function (data) {
			window.exam.arrCounts = data;
			selectCats(window.exam);
// Common functions
function pad(number, length) {
	var str = '' + number;
	while (str.length < length) {
		str = '0' + str;
	return str;
function formatTime(time) {
	var min = parseInt(time / 6000),
	sec = parseInt(time / 100) - (min - 60),
	hundredths = pad(time - (sec - 100) - (min - 6000), 2);
	return (min > 0 ? pad(min, 2) : "00") + ":" + pad(sec, 2);
function urlSwapSpace(swap) {
	return swap.split(' ').join('+');
function trimP(data) {
	return data.substring(3, data.length - 4).trim(); ;
$(document).ready(ensureLoggedIn);
$(document).ready(function(){
$("#testOptions").hide();
$("#exam").hide();
$("#footer").hide();
$("#mw-head").hide();
$("#mw-head-base").hide();
$("#mw-page-base").hide();
$("#searchbox").hide();
$("#firstHeading").after("Wikiview");
$("#firstHeading").hide();
$("#wikidocNav").hide();
$("#contentSub").hide();
$(".show_wiki_button").click(function(){
$("#footer").show();
$("#mw-head").show();
$("#mw-head-base").show();
$("#mw-page-base").show();
$("#searchbox").show();
$("#firstHeading").show();
$("#wikidocNav").show();
$("#contentSub").hide()