//startingDate:15-11-2019
var WordProb = {};
var Utils = {};
Utils.Path = '';
Utils.mobileDeviceFlag = false;
var questionId = 0, startTime = 0, scoredMarks = 0, totalMarks = 10, resId = 0, level = 1, label = '';
var given1, given2, toFind, splitNum1, splitNum2, splitNum3, splitNum4;
var blinkCtr = 0;
WordProb.iterationFlag = false;
//WordProb.level = 2;//level for addition subtraction or multiplication
WordProb.questionCtr = 0;
WordProb.soundFlag = true;//flag for instruction.
$(document).ready(function () {
	$(".se-pre-con").fadeOut("slow");
	if ((navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) && !(window.location.href.includes('http')))
		Utils.mobileDeviceFlag = true;
	/* if(Utils.mobileDeviceFlag) 
		Utils.Path=Android.getMediaPath("WordProb");  */
	setTimeout(function () {
		WordProb.init();
	}, 100);
});

WordProb.init = function () {
	document.title = Object.values(WordProb.AcknowledgementPageData)[0];
	$("#coverPage").show();
	$("#gamePage").hide();
	$("#levelPage").hide();
	$(".header").not("#logo").css("visibility", "hidden");
	document.body.style.backgroundImage = "url(" + Utils.Path + "images/skin/" + WordProb.hardcodedData.coverPage + ")";
	WordProb.initializeVariables();
	//WordProb.createSpans();
	//WordProb.createOperatorSpans();
	WordProb.createNumberDivs(numberSystemDiv);
	WordProb.createLevelDivs();
	WordProb.setAllImages();
	WordProb.createAcknowledgementDivs();
	//Thin Pencil Handwriting.ttf

	// var newStyle = "<style>" +
	// 	"@font-face {  " +
	// 	"font-family: 'loopy';" +
	// 	"src: url('fonts/Snake.ttf') format('truetype');" +
	// 	"}  </style>";
	// $("head").append(newStyle);
	// $("#gamePage").css("font-family", "loopy");
}

WordProb.initializeVariables = function () {//initialization.
	WordProb.finalAnsFlag = false;//for checking final answer or not
	WordProb.counter = 1;//counter for steps
	WordProb.checkFlag = false;//for checking whether answer is correct or not.
	WordProb.attemptFlag = false;//for attempt.
	WordProb.secondFlag = false;//for reverse addition.
	WordProb.borrowFlag = false;//if borrow flag will true.
	scoredMarks = 0;
}
WordProb.setAllImages = function () {
	document.getElementById("homeImage").src = Utils.Path + "images/skin/Home.png";
	document.getElementById("next").src = Utils.Path + "images/skin/Next.png";
	document.getElementById("logoImage").src = Utils.Path + "images/skin/logo.png";
	document.getElementById("playImg").src = Utils.Path + "images/skin/playButton.png";
	document.getElementById("questionDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/textBlock.png)";
	document.getElementById("innerDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/notebook.png)";

	// document.getElementById("whatWeKnow").innerHTML = WordProb.hardcodedData.given;
	// document.getElementById("findDiv").innerHTML = WordProb.hardcodedData.toFind;
	//document.getElementById("whichWordDiv").innerHTML = WordProb.hardcodedData.whichWord;
	// document.getElementById("whichOperatorDiv").innerHTML = WordProb.hardcodedData.whichOpr;
	document.getElementById("levelImg1").src = Utils.Path + "images/skin/jodo.png";
	document.getElementById("levelImg2").src = Utils.Path + "images/skin/ghatav.png";
	//document.getElementById("help").src = Utils.Path + "images/skin/help.png";
	document.getElementById("creditImg").src = Utils.Path + "images/skin/Credits.png";
	document.getElementById("replayImg").src = Utils.Path + "images/skin/Replay.png";
	document.getElementById("operator").innerHTML = WordProb.hardcodedData.multiplySign;
	document.getElementById("multSign").innerHTML = WordProb.hardcodedData.multiplySign;
	document.getElementById("plus1").innerHTML = WordProb.hardcodedData.plusSign;
	document.getElementById("plus2").innerHTML = WordProb.hardcodedData.plusSign;
	document.getElementById("gameOver").innerHTML = WordProb.hardcodedData.gameOver;
	document.getElementById("tensPlace").innerHTML = WordProb.hardcodedData.dahai;
	document.getElementById("unitPlace").innerHTML = WordProb.hardcodedData.ikai;
	document.getElementById("borrowInstr").innerHTML = WordProb.hardcodedData.borrowInstr;

	document.getElementById("questionMsg").innerHTML = WordProb.modalData.responseMsg;
	document.getElementById("Yes").innerHTML = WordProb.modalData.yes;
	document.getElementById("No").innerHTML = WordProb.modalData.no;

}

WordProb.createLevelDivs = function () {
	var parentDiv, i, div, image;
	parentDiv = document.getElementById("container");
	for (i = 0; i < 2; i++) {
		div = document.createElement("DIV");
		div.setAttribute("id", "levelDiv" + (i + 1));
		div.setAttribute("class", "levelDivs nopadding");
		div.setAttribute("data", (i + 1));
		div.setAttribute("onclick", "WordProb.selectLevel(this.id);");
		//div.innerHTML = WordProb.levelArr[i];
		parentDiv.appendChild(div);

		image = document.createElement("IMG");
		image.setAttribute("id", "levelImg" + (i + 1));
		image.setAttribute("class", "nopadding img-responsive col-xs-12 col-md-12 col-lg-12 col-sm-12")
		div.appendChild(image);
	}
}

WordProb.ShowLevel = function () {
	$(".header").css("visibility", "visible");
	document.body.style.backgroundImage = "url(" + Utils.Path + "images/skin/cover_bg.png)";
	$("#coverPage").hide();
	$("#levelPage").show();
}

WordProb.selectLevel = function (level) {
	WordProb.level = parseInt(document.getElementById(level).getAttribute("data"));
	WordProb.playGame();
}

WordProb.createSpans = function () {//spans for question text.
	var i, span;
	for (i = 0; i < 3; i++) {
		span = document.createElement("span");
		$(span).prop("id", "span" + i);
		$(span).prop("class", "dragSpans");
		$(span).draggable({
			revert: "invalid", helper: 'clone', start: function (e, ui) {
				document.getElementById("playSound").pause();
				$(ui.helper).addClass("ui-draggable-helper");//used to change the font size text is drappable
			}
		});
		document.getElementById("questionText").append(span);
	}
}
// WordProb.createOperatorSpans = function () {//spans for showing operator list.
// 	var i;
// 	for (i = 0; i < 4; i++) {
// 		span = document.createElement("P");
// 		$(span).prop("id", "oprSpan" + i);
// 		$(span).prop("class", "oprSpans");
// 		span.setAttribute("onclick", "WordProb.checkOpr(this.id)");
// 		$(span).text(WordProb.operatorArr[i]);
// 		document.getElementById("inputDiv3").append(span);

// 	}
// }

WordProb.playGame = function () {
	WordProb.questionCtr = 0;
	$("#coverPage").hide();
	$("#levelPage").hide();
	$("#gamePage").show();
	document.body.style.backgroundImage = "url(" + Utils.Path + "images/skin/Bg.png)";
	//	document.body.style.backgroundImage = "";
	//	document.body.style.backgroundColor = "white";
	$("#inputDiv1").droppable(
		{
			drop: WordProb.checkGiven1
		});
	$("#inputDiv5").droppable(
		{
			drop: WordProb.checkGiven2
		});
	$("#inputDiv2").droppable(
		{
			drop: WordProb.checkToFind
		});
	WordProb.makeQuestion();
}

WordProb.makeQuestion = function ()						//generate word Sentence
{
	WordProb.questionCtr++;
	var randomPerson, randomObject, personArr = [], numArr = [], d;
	WordProb.numberArray = [];
	blinkCtr = 0;
	WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "a1", "finalAns"];
	$(".editField").not("#finalAns").css("pointer-events", "none");
	WordProb.operator = WordProb.operatorArr[WordProb.level - 1];
	d = new Date();
	startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
	if (WordProb.soundFlag) {//for playing dragging instruction.
		WordProb.soundFlag = false;
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/instruction.mp3";
		document.getElementById("playSound").play();
	}
	switch (WordProb.level) {
		case 1: {
			num1 = 38;
			num2 = 11;
			$("#carryDiv").show();
		} break;
		case 2: {
			num1 = 88;
			num2 = 11;
			$("#carryDiv").hide();
		} break;
		case 3: {
			num1 = 39;
			num2 = 11
		} break;

	}
	for (i = 0; i < 2; i++) {
		randomNum = Math.floor(Math.random() * num1 + num2);
		while (numArr.includes(randomNum))//|| randomNum % 10 == 9
			randomNum = Math.floor(Math.random() * num1 + num2);
		numArr.push(randomNum);
	}
	if (WordProb.level == 2) {
		numArr.sort(function (a, b) { return b - a });
		//$("#carryDiv").hide();

		WordProb.number1 = numArr[0];
		WordProb.number2 = numArr[1];
		if (WordProb.number1 % 10 < WordProb.number2 % 10) {
			WordProb.borrowFlag = true;
			WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "a1", "finalAns"];
			// WordProb.number2 = WordProb.number2 - WordProb.number2 % 10 + 9;
			// if (WordProb.number1 <= WordProb.number2) {
			// 	WordProb.questionCtr--;
			// 	WordProb.makeQuestion();
			// }
		}
	}
	else {
		WordProb.number1 = numArr[0];
		WordProb.number2 = numArr[1];
		if ((WordProb.number1 % 10 + WordProb.number2 % 10) >= 10)
			WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "c1", "a1", "finalAns"];

	}
	$("#" + WordProb.editFieldArr[blinkCtr]).addClass("blink_me");
	$("#numberSystemDiv").show();
	WordProb.id = WordProb.editFieldArr[blinkCtr];
	document.getElementById("questionText").innerHTML = WordProb.number1 + " " + WordProb.operator + " " + WordProb.number2;
	splitNum1 = Math.floor(WordProb.number1 / 10) * 10;
	splitNum2 = WordProb.number1 % 10;
	splitNum3 = Math.floor(WordProb.number2 / 10) * 10;
	splitNum4 = WordProb.number2 % 10;
	WordProb.showCalculation();
}



WordProb.checkGiven1 = function (event, ui) {

	if (ui.draggable.text() == given1) {
		$(this).append(ui.draggable.clone());
		$(this).css("background-color", "green");
		$(this).css("color", "white");
		$(this).droppable("disable");
	}
}
WordProb.checkGiven2 = function (event, ui) {

	if (ui.draggable.text() == given2) {
		$(this).append(ui.draggable.clone());
		$(this).css("background-color", "green");
		$(this).css("color", "white");
		$(this).droppable("disable");
	}
}

WordProb.checkToFind = function (event, ui) {

	if (ui.draggable.text() == toFind) {
		$(this).append(ui.draggable.clone());
		$(this).css("background-color", "green");
		$(this).css("color", "white");
		$(this).droppable("disable");
	}
}
//onclick of continue.
WordProb.showCalculation = function () {
	$("#buttonValue11").css("pointer-events", "none");
	$("#buttonValue11").css("opacity", 0.5);
	$("#buttonValue12").css("opacity", 0.5);
	WordProb.counter++;
	document.getElementById("playSound").pause();
	$(".dragSpans").draggable("disable");
	//$("#bottomDiv").show();
	$("#continueDiv").hide();
	$("#subAnsDiv").hide();
	$(".input").empty();
	if (WordProb.level == 3) {
		$("#ansStep").hide();
		$("#multCalcDiv").show();
		if (Math.floor(WordProb.number1 / 10) == 0) {
			$("#split1Num1").css("visibility", "hidden");
			$("#plus1").css("visibility", "hidden");
		}
		if (Math.floor(WordProb.number2 / 10) == 0) {
			$("#split2Num1").css("visibility", "hidden");
			$("#plus2").css("visibility", "hidden");
		}
	}
	else {
		$("#ansStep").show();
		$("#multCalcDiv").hide();
	}
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").hide();
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").removeClass("animated bounceOutLeft");
	$("#AnswerDiv").show();
	$("#bottomDiv").show();
	document.getElementById("opr").innerHTML = WordProb.operator;
	document.getElementById("carryText").innerHTML = WordProb.hardcodedData.carryText;
	document.getElementById("ansText").innerHTML = WordProb.hardcodedData.ansText;
	document.getElementById("finalAnsText").innerHTML = WordProb.hardcodedData.finalAns;
	switch (WordProb.level) {
		case 1: {
			WordProb.answer = WordProb.number1 + WordProb.number2;
		} break;
		case 2: {
			WordProb.answer = WordProb.number1 - WordProb.number2;
		} break;
	}
}

WordProb.displayInTextBox = function (element) {//inputs the number in selected textbox when user clicks the number on numberpad.
	var number, i, span, oldTens, oldUnits, flag = false;
	if (WordProb.id == "finalAns") {
		$("#buttonValue11").css("pointer-events", "auto");
		$("#buttonValue11").css("opacity", 1);
	}
	if ($("#" + WordProb.id).hasClass("singleLetter")) {
		number = 1;
	} else
		number = 2;

	if ($("#" + WordProb.id).text().length < number)
		$("#" + WordProb.id).append($(element).text());

	if ($("#" + WordProb.id).text().length == number) {
		if (!(flag))
			WordProb.checkAnswer();
	}
	else {
		if (parseInt($("#" + WordProb.id).text()) == WordProb.answer)
			WordProb.checkAnswer();
	}
}

WordProb.checkAnswer = function () {//checks the inputed answer is correct or not.
	$("#numberSystemDiv,#finalAns").css("pointer-events", "none");

	var data;
	WordProb.attemptFlag = true;
	WordProb.checkFlag = false;
	data = parseInt(document.getElementById(WordProb.id).getAttribute("data"));
	switch (data) {
		case -1: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number1 % 10 + 10) {
				WordProb.checkFlag = true;
				$("#u1").addClass("lineThrough");
			}
			else
				WordProb.checkFlag = false;
		} break;
		case 0: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.answer % 10)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 1: {
			if (WordProb.level == 1) {
				num1 = WordProb.number1 % 10;
				num2 = WordProb.number2 % 10;
				num = num1 + num2;
				num = Math.floor(num / 10);
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == num)
					WordProb.checkFlag = true;
				else
					WordProb.checkFlag = false;
			}
			else {
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == Math.floor(WordProb.number1 / 10) - 1) {
					WordProb.checkFlag = true;
					$("#t1").addClass("lineThrough");
				}
				else
					WordProb.checkFlag = false;
			}
		} break;
		case 2: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == Math.floor(WordProb.answer / 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 3: {//for final answer.
			WordProb.finalAnsFlag = true;
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.answer) {
				WordProb.checkFlag = true;
				$("#c1Para").css("pointer-events", "none");
			}
			else
				WordProb.checkFlag = false;
		} break;
		case 11: {
			if (WordProb.secondFlag) {
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number2 % 10) {
					WordProb.checkFlag = true;
					break;
				}
				else {
					if (Math.floor((WordProb.number1 / 10)) == Math.floor(WordProb.number2 / 10)) {
						if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number1 % 10) {
							WordProb.checkFlag = true;
							WordProb.secondFlag = false;
						}
						else
							WordProb.checkFlag = false;
					}

				}
			}
			else {
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number1 % 10) {
					WordProb.checkFlag = true;
				}
				else
					WordProb.checkFlag = false;
			}
		}
			break;
		case 12: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == Math.floor(WordProb.number1 / 10)) {
				WordProb.checkFlag = true;
				WordProb.iterationFlag = true;
			}
			else
				WordProb.checkFlag = false;
			if (WordProb.level == 1)
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == Math.floor(WordProb.number2 / 10)) {
					WordProb.checkFlag = true;
					WordProb.secondFlag = true;
					if (WordProb.number1 / 10 == WordProb.number2 / 10) {
						WordProb.sameDigitFlag = true;
					}
				}


		} break;
		case 21: {
			if (WordProb.secondFlag) {
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number1 % 10) {
					WordProb.checkFlag = true;

				}
				else
					WordProb.checkFlag = false;
			}
			else {
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number2 % 10) {
					WordProb.checkFlag = true;

				}
				else
					WordProb.checkFlag = false;
			}

		} break;
		case 22: {
			if (WordProb.secondFlag) {
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == Math.floor(WordProb.number1 / 10)) {
					WordProb.checkFlag = true;
				}
				else
					WordProb.checkFlag = false;
			}
			else {
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == Math.floor(WordProb.number2 / 10)) {
					WordProb.checkFlag = true;
				}
				else
					WordProb.checkFlag = false;

			}
		} break;
		case 31: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number1)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 32: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number2)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 41: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number1 - (WordProb.number1 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 42: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number1 % 10)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 43: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number2 - WordProb.number2 % 10)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 44: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.number2 % 10)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 51: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == splitNum4 * splitNum2)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 52: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == splitNum4 * splitNum1)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 53: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == splitNum3 * splitNum2)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 54: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == splitNum3 * splitNum1)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
	}
	if (WordProb.checkFlag) {
		document.getElementById(WordProb.id).style.backgroundColor = "green";
		document.getElementById(WordProb.id).style.color = "white";
		document.getElementById(WordProb.id).style.pointerEvents = "none";
		$("#" + WordProb.id).addClass("correctClass");
		//if (!($("#" + WordProb.id).hasClass("autoCheck")) || blinkCtr >= (WordProb.editFieldArr.length - 1))
		//$(".editField").not(".correctClass").css("pointer-events", "auto");
		$("#" + WordProb.id).css("pointer-events", "none");
		//if ($("#" + WordProb.id).hasClass("autoCheck")) {
		if (!(WordProb.directAnsFlag)) {
			setTimeout(function () {
				$("#buttonValue11").css("pointer-events", "none");
				$("#buttonValue11").css("opacity", 0.5);
				$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
				$("#" + WordProb.id).removeClass("blink_me");
				blinkCtr++;
				WordProb.id = WordProb.editFieldArr[blinkCtr];
				$("#" + WordProb.id).addClass("blink_me");
				if (WordProb.id == "a2" && WordProb.level == 2) {
					$("#responseBoxDiv").show();
				}
				document.getElementById(WordProb.editFieldArr[blinkCtr - 1]).style.backgroundColor = "";
				document.getElementById(WordProb.editFieldArr[blinkCtr - 1]).style.color = "black";
			}, 500);
			//}
		}
	}
	else {
		document.getElementById(WordProb.id).style.backgroundColor = "red";
		if (!WordProb.directAnsFlag) {
			setTimeout(function () {
				$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
				document.getElementById(WordProb.id).style.backgroundColor = "";
				document.getElementById(WordProb.id).innerHTML = "";
				//$(".editField").not(".correctClass").css("pointer-events", "auto");
			}, 1000);
		}
		else {
			setTimeout(function () {
				$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
				WordProb.id = WordProb.editFieldArr[blinkCtr];
				$("#" + WordProb.id).addClass("blink_me");
				$("#finalAns").removeClass("blink_me");
				document.getElementById("finalAns").innerHTML = '';
				document.getElementById("finalAns").style.backgroundColor = "";
				WordProb.directAnsFlag = false;
			}, 500);
		}

	}
	if (WordProb.finalAnsFlag) {//if final answer is correct.
		if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.answer) {
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/thats_right.mp3";
			scoredMarks = 10;
			WordProb.correctWrongModalShow("winEmoji.png", 2000);
			setTimeout(function () {
				WordProb.nextQuestion();
			}, 2500);
		}
		else {
			scoredMarks = 0;
			WordProb.finalAnsFlag = false;
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/wrongSoundAksharkhadi.mp3";
			WordProb.correctWrongModalShow("rongAnsEmoji.png", 2000);
			setTimeout(function () {
				$("#subAnsDiv").show();
				if (WordProb.level == 3)
					$("#helpBtn").css("visibility", "visible");
			})
		}
		document.getElementById("playSound").play();
	}
}

// Paragraph.select = function () {                                       //get selected words
// 	selectionFlag = true;
// 	sel = window.getSelection();                            //selected words
// 	for (var i = 0; i < sel.rangeCount; i++) {
// 		Paragraph.startingIndex = (sel.getRangeAt(i).startContainer.parentNode.id.match(/\d+/g).map(Number)).toString();
// 		alert(sel);
// 	}
// 	Paragraph.checkAnswer(sel);
// }

WordProb.nextQuestion = function () {
	if (!WordProb.attemptFlag) {
		scoredMarks = -1;
	}
	console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	if (Utils.mobileDeviceFlag)
		Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	if (WordProb.questionCtr < 5) {
		WordProb.resetVariables();
		WordProb.initializeVariables();
		WordProb.makeQuestion();
	}
	else {
		$("#gamePage").hide();
		$("#endPage").show();
	}
}
WordProb.resetVariables = function () {
	document.getElementById("questionMsg").innerHTML = WordProb.modalData.responseMsg;
	$("#btnDiv").show();
	$("#u1").removeClass("animated heartBeat");
	$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
	//$("#borrowInstr").hide();
	WordProb.directAnsFlag = false;
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").show();
	$("#AnswerDiv").hide();
	$("#subAnsDiv").hide();
	$("#helpBtn").css("visibility", "hidden");
	$(".inputNum,#finalAns,.input").css("background-color", "white");
	$(".inputNum,#finalAns").css("color", "black");
	$(".editField").css("color", "black");
	$(".editField").text("");
	$(".input").droppable("enable");
	$("#AnswerDiv").removeClass("animated bounceInRight");
	$(".editField").css("background-color", "");
	$(".editField").css("pointer-events", "auto");
	$(".editField").removeClass("correctClass");
	$(".editField").removeClass("blink_me");
	$(".oprSpans").css("background-color", "white");
	$("#bottomDiv").hide();
	$("#continueDiv").show();
	$("#carryDiv").show();
	$(".editField", ".signs").css("visibility", "visible");
	$("#split1Num1").css("visibility", "visible");
	$("#plus1").css("visibility", "visible");
	$("#split2Num1").css("visibility", "visible");
	$("#plus2").css("visibility", "visible");
	$(".arrowDivs").css("visibility", "hidden");
	$("#c1Para").css("pointer-events", "auto");
	$(".dragSpans").draggable("enable");
	$("#u1,#t1").removeClass("lineThrough");
	$("#u1,#t1").empty();
	WordProb.iterationFlag = false;
	$("#t1").css("text-align", "center");
}

WordProb.callHome = function () {//reload.
	if (WordProb.attemptFlag) {
		console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
		if (Utils.mobileDeviceFlag)
			Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	}
	location.reload();
}

WordProb.correctWrongModalShow = function (str, duration) {
	document.getElementById("responseImg").src = Utils.Path + "images/skin/" + str;
	document.getElementById("correctWrongModal").style.display = "block";
	setTimeout(function () {
		document.getElementById("correctWrongModal").style.display = "none";
	}, duration);
}

WordProb.gotoHelp = function () {//help for multiplication.
	var i, ctr = 0;
	for (i = 4; i > 2; i--) {
		for (j = 2; j >= 1; j--) {
			ctr++;
			document.getElementById("multDiv" + ctr).innerHTML = eval("splitNum" + i) + " × " + eval("splitNum" + j);
		}
		j = 2;

	}
	$(".arrowDivs").css("visibility", "visible");

}

WordProb.createAcknowledgementDivs = function () {
	var i = 0, div;
	for (i = 0; i < Object.keys(WordProb.AcknowledgementPageData).length; i++) {
		div = document.createElement('div');
		div.className = "fontClass firstLetter col-xs-12 col-sm-12 col-md-12 col-lg-12";
		div.innerHTML = Object.keys(WordProb.AcknowledgementPageData)[i] + " : " + Object.values(WordProb.AcknowledgementPageData)[i];
		acknowledgementDiv.appendChild(div);
	}
	div = document.createElement('div');
	div.className = "fontClass firstLetter col-xs-12 col-sm-12 col-md-12 col-lg-12";
	div.innerHTML = WordProb.hardcodedData['createdOn'];
	div.style.marginBottom = "2vh";
	acknowledgementDiv.appendChild(div);
}

WordProb.showAcknowledgement = function () {
	$("#acknowledgementDiv").show();

}

WordProb.playAgain = function () {
	WordProb.soundFlag = true;
	$("#acknowledgementDiv").hide();
	$("#endPage").hide();
	$("#gamePage").show();
	WordProb.questionCtr = -1;
	WordProb.nextQuestion();
	WordProb.playGame();
}

WordProb.correctClick = function () {
	$("#btnDiv").hide();
	WordProb.clickFlag = true;
	WordProb.showMsg();
}
WordProb.wrongClick = function () {
	$("#btnDiv").hide();
	WordProb.clickFlag = false;
	WordProb.showMsg();
}
WordProb.showMsg = function () {
	if ((WordProb.borrowFlag == true && WordProb.clickFlag == true) || (WordProb.borrowFlag == false && WordProb.clickFlag == false)) {
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/thats_right.mp3";
		$("#responseBoxDiv").hide()
		if (WordProb.borrowFlag) {
			setTimeout(function () {
				WordProb.transferBorrow();
			}, 2000);
		}
	}
	else {
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/wrong_ans.mp3";
		$("#btnDiv").hide();
		if (WordProb.borrowFlag) {
			document.getElementById("questionMsg").innerHTML = WordProb.modalData.borrowMsg;
			setTimeout(function () {
				$("#responseBoxDiv").hide()
				setTimeout(function () {
					WordProb.transferBorrow();
				}, 2000);

			}, 4000);
		} else {
			document.getElementById("questionMsg").innerHTML = WordProb.modalData.noBorrowmsg;
			setTimeout(function () {
				$("#responseBoxDiv").hide()
			}, 4000);
		}
	}
	document.getElementById("playSound").play();
}

WordProb.transferBorrow = function () {
	$("#t1").addClass("animated heartBeat");
	document.getElementById("t1").style.backgroundColor = "green";
	document.getElementById("t1").style.color = "white";
	setTimeout(function () {
		document.getElementById("t1").style.backgroundColor = "";
		document.getElementById("t1").style.color = "black";
	}, 500);
	oldTens = $("#t1").text();
	$("#t1").text("");
	for (i = 0; i < 2; i++) {
		span = document.createElement("span");
		span.setAttribute("id", "tensSpan" + (i + 1));
		$("#t1").append(span);
	}
	$("#tensSpan1").append(" " + oldTens);
	$("#tensSpan1").css("text-decoration", "line-through");
	$("#tensSpan2").append(" " + (oldTens - 1));
	$("#t1").css("text-align", "left");

	setTimeout(function () {
		$("#t1").removeClass("animated heartBeat");
		$("#u1").addClass("animated heartBeat");
		oldUnits = $("#u1").text();
		$("#u1").text("");
		for (i = 0; i < 2; i++) {
			span = document.createElement("span");
			span.setAttribute("id", "unitSpan" + (i + 1));
			$("#u1").append(span);
		}
		$("#unitSpan1").append("1");
		$("#unitSpan1").css("color", "yellow");
		$("#unitSpan2").append(oldUnits);
	}, 1000);
	// setTimeout(function () {
	// 	$("#" + WordProb.id).removeClass("blink_me");
	// 	blinkCtr++;
	// 	WordProb.id = WordProb.editFieldArr[blinkCtr];
	// 	$("#" + WordProb.id).addClass("blink_me");
	// }, 500);
}


// WordProb.checkSelect = function () {
// 	var startId, endId;
// 	if (window.getSelection) {
// 		sel = window.getSelection();
// 		startId = sel.anchorNode.parentElement.id;
// 		endId = sel.extentNode.parentElement.id;
// 		var startCnt = parseInt(startId.match(/\d+/)[0]);
// 		while ("span" + startCnt != endId) {
// 			$("#span" + startCnt).draggable();
// 			startCnt++;
// 		}
// 		$("#span" + startCnt).draggable();
// 	}
// 	else {
// 		alert("noSelect");
// 	}
// }
