//startingDate:15-3-2020
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, unit, digit;
var blinkCtr = 0, remainder;
WordProb.questionCtr = 0;
WordProb.soundFlag = true;
WordProb.instrFlag = true;
WordProb.questionArr = [];
$(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.createNumberDivs(numberSystemDiv);
	WordProb.setAllImages();
	WordProb.createAcknowledgementDivs();
	WordProb.createTableDivs();
	WordProb.createOperatorSpans();
	//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.remainderDivFlag = true;//for creating remainder subdivs.
	digitCtr = 0;//for counting the digits of divident.
	traverse = 0;
	WordProb.stepCtr = 1;//for counting division steps.
	WordProb.highlighter = 1;//for highlighting the divident numbers.
	WordProb.currNum = '';
	WordProb.lenArr = [];
	WordProb.editFieldArr = [];//array for divs to be highlighted.
	WordProb.helpFlag = true;
	WordProb.offsetFlag = 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("questionText").style.backgroundImage = "url(" + Utils.Path + "images/skin/textBlock.png)";
	document.getElementById("questionDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/notebook2.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("continue").src = Utils.Path + "images/skin/continue.png";
	document.getElementById("creditImg").src = Utils.Path + "images/skin/Credits.png";
	document.getElementById("replayImg").src = Utils.Path + "images/skin/Replay.png";
	document.getElementById("helpBtn").src = Utils.Path + "images/skin/help.png";
	document.getElementById("gameOver").innerHTML = WordProb.hardcodedData.gameOver;
}

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

WordProb.makeQuestion = function ()						//generate word Sentence
{
	WordProb.tempArr = [];
	$("#questionDiv").show();
	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.questionCtr) {
		case 1: case 2: {
			randomDivisor = Math.floor(Math.random() * 8 + 2);
			randomAns = Math.floor(Math.random() * 40 + 11);
			WordProb.divident = randomDivisor * randomAns;
			while (WordProb.divident >= 100) {
				randomDivisor = Math.floor(Math.random() * 8 + 2);
				randomAns = Math.floor(Math.random() * 40 + 11);
				WordProb.divident = randomDivisor * randomAns;
			}

		} break;
		case 3: case 4: {
			randomDivisor = Math.floor(Math.random() * 8 + 2);
			randomAns = Math.floor(Math.random() * 40 + 11);
			WordProb.divident = randomDivisor * randomAns;
			while (WordProb.divident < 100) {
				randomDivisor = Math.floor(Math.random() * 8 + 2);
				randomAns = Math.floor(Math.random() * 40 + 11);
				WordProb.divident = randomDivisor * randomAns;
			}
		} break;
		case 5: {
			randomDivisor = Math.floor(Math.random() * 12 + 9);
			randomAns = Math.floor(Math.random() * 40 + 11);
			WordProb.divident = randomDivisor * randomAns;
			while (WordProb.divident < 100) {
				randomDivisor = Math.floor(Math.random() * 8 + 2);
				randomAns = Math.floor(Math.random() * 40 + 11);
				WordProb.divident = randomDivisor * randomAns;
			}

		} break;
	}
	WordProb.answer = randomAns;
	document.getElementById("finalAns").setAttribute("data", WordProb.answer);
	WordProb.divisor = randomDivisor;
	if (String(WordProb.divident).length - String(WordProb.answer).length == 1)
		WordProb.answer = "0" + WordProb.answer;
	else
		if (String(WordProb.divident).length - String(WordProb.answer).length == 2)
			WordProb.answer = "00" + WordProb.answer;
	//console.log(WordProb.answer);
	randomQuestion = Math.floor(Math.random() * (WordProb.questions[WordProb.level - 1].data.length));
	while (WordProb.questionArr.includes(randomQuestion))
		randomQuestion = Math.floor(Math.random() * (WordProb.questions[WordProb.level - 1].data.length));
	WordProb.questionArr.push(randomQuestion)
	temp = WordProb.questions[WordProb.level - 1].data[randomQuestion];
	//console.log(temp);
	WordProb.currentObject = JSON.parse(JSON.stringify(WordProb.questions[WordProb.level - 1].data[randomQuestion]));
	WordProb.sentence = WordProb.currentObject.question;
	given1 = WordProb.currentObject.given[0];
	given2 = WordProb.currentObject.given[1];
	toFind = WordProb.currentObject.toFind;

	//if (WordProb.sentence.indexOf('@') != -1)							//replace @ with first person
	//replaces special characters with values.
	for (i = 0; i < 3; i++) {
		//console.log(WordProb.currentObject);
		randomPerson = Math.floor(Math.random() * WordProb.currentObject.subject.length);
		personArr.push(randomPerson);
		if (i == 0) {
			if (randomQuestion == 5 || randomQuestion == 1) {
				given1 = given1.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
				toFind = toFind.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
				WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subject'][randomPerson]);
				WordProb.sentence = WordProb.sentence.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
			}
			given1 = given1.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
			if (randomQuestion == 3 || randomQuestion == 4)
				WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subject'][randomPerson]);
			// given1 = given1.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subjectPlural'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
		}
		else if (i == 1) {
			given1 = given1.replace("$", WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace("$", WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace("$", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("$", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("$", WordProb.currentObject['subject'][randomPerson]);
		}
		else if (i == 2) {
			given1 = given1.replace("^", WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace("^", WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace("^", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("^", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("^", WordProb.currentObject['subject'][randomPerson]);
		}

		WordProb.currentObject.subject.splice(randomPerson, 1);
	}

	randomObject = Math.floor(Math.random() * WordProb.currentObject.object.length);
	if (randomQuestion <= 4) {
		given1 = given1.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
		given2 = given2.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
		toFind = toFind.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
	}
	else {
		given1 = given1.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
		given2 = given2.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
		toFind = toFind.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
	}

	WordProb.sentence = WordProb.sentence.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
	//WordProb.sentence = WordProb.sentence.replace(/~/gi, WordProb.currentObject['object'][randomObject]);

	randomUnit = Math.floor(Math.random() * WordProb.currentObject.unit.length);
	given1 = given1.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	given2 = given2.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	toFind = toFind.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	WordProb.sentence = WordProb.sentence.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);

	// $("#multCalcDiv").show();
	//document.getElementById("divisor").innerHTML = randomDivisor;
	//document.getElementById("divident").innerHTML = divident;
	if (randomQuestion == 2 || randomQuestion == 5) {
		given1 = given1.replace("!", WordProb.divisor);
		given1 = given1.replace("!", WordProb.divident);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divisor);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divident);

	}
	else {
		given1 = given1.replace("!", WordProb.divident);
		given1 = given1.replace("!", WordProb.divisor);

		//given2 = given2.replace("!", WordProb.number2);
		toFind = toFind.replace("!", WordProb.divisor);
		given2 = given2.replace("!", WordProb.divisor);


		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divident);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divisor);
	}
	// $("#numberSystemDiv").show();
	//document.getElementById("questionText").innerHTML = WordProb.divident + " " + WordProb.operator + " " + randomDivisor;
	splitNum1 = Math.floor(WordProb.number1 / 10) * 10;
	splitNum2 = WordProb.number1 % 10;
	splitNum3 = Math.floor(WordProb.number2 / 10) * 10;
	splitNum4 = WordProb.number2 % 10;
	//WordProb.createSubAnsDivs();
	//WordProb.gotoHelp();
	//WordProb.showCalculation();
	WordProb.createSpans("divident", String(WordProb.divident).length, "dividentSpan", WordProb.divident, true, 1);
	//WordProb.createSpans("divisor", String(randomDivisor).length, "divisorSpan", randomDivisor, true, 1);
	WordProb.editFieldArr.push("divisor");
	document.getElementById("divisor").setAttribute("data", WordProb.divisor);
	WordProb.createSpans("divisonAnsDiv", String(WordProb.answer).length, "ansSpan", WordProb.answer, false, 1);
	$("#" + WordProb.editFieldArr[blinkCtr]).addClass("blink_me");
	WordProb.id = WordProb.editFieldArr[blinkCtr];
	WordProb.hindiText = WordProb.sentence.split(' ');
	WordProb.tempArr.push(given1);
	WordProb.tempArr.push(given2);
	WordProb.tempArr.push(toFind);
	WordProb.createEnglishSentence(questionText, WordProb.hindiText.length);
	if (given2 == "")
		$("#inputDiv5").hide();
	else
		$("#inputDiv5").show();

}

WordProb.createEnglishSentence = function (parentDiv, length) {  //create english word span
	var span, wCnt = 0, index = 0;
	loop1:
	for (var j = 0; j < length;) {
		var wordFoundFlag = false;
		wCnt = 0;
		span = document.createElement("span");
		loop2:
		for (var k = 0; k < WordProb.tempArr.length; k++) {
			var tempArr = [];
			//var correctLang = WordProb.tempArr[k].correctLang.replace(' .', '.');
			tempArr = WordProb.tempArr[k].trim().split(' ');
			loop3:
			for (var i = 0; i < tempArr.length; i++) {
				if (tempArr.includes(WordProb.hindiText[j])) {
					wordFoundFlag = true;
					wCnt++;
					j++;
				}
				else
					wordFoundFlag = false;
				if (wCnt == tempArr.length) {
					//var randomOption = Math.floor(Math.random() * Composition.data[Composition.questionArr[quesCnt]].list[k].option.length);
					//var option = Composition.data[Composition.questionArr[quesCnt]].list[k].option[randomOption].replace(' .', '.');
					$(span).text(WordProb.tempArr[k].trim() + " ");
					$(span).data("originalValue", WordProb.tempArr[k].trim());
					//var correctOption = Composition.data[Composition.questionArr[quesCnt]].list[k].correctLang.replace(' .', '.');
					//$(span).data("value", correctOption.trim());
					wordFoundFlag = true;
					//span.setAttribute("onclick", "Composition.showOptions(this)");
					span.setAttribute("id", 'span' + index);
					$(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
						}
					});
					index++;
					//$(span).css('color', 'cyan');
					break loop2;
				}
			}
		}
		if (wordFoundFlag == false) {
			if (wCnt != 0)
				j = j - wCnt;
			$(span).text(WordProb.hindiText[j] + " ");
			$(span).data("value", WordProb.hindiText[j]);
			$(span).data("originalValue", WordProb.hindiText[j]);
			$(span).data("colorValue", 'white');
			j++;
		}
		parentDiv.appendChild(span);
	}
	//questionId = Composition.data[Composition.questionArr[quesCnt]].questionId;
}


WordProb.checkGiven1 = function (event, ui) {

	if (ui.draggable.text().trim() == given1.trim()) {
		$(ui.draggable).draggable("option", "revert", false);
		$(this).append(ui.draggable.clone());
		$(this).css("background-color", "green");
		$(this).css("color", "white");
		$(this).droppable("disable");

	}
	else
		$(ui.draggable).draggable("option", "revert", true);
}
WordProb.checkGiven2 = function (event, ui) {

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

	}
	else
		$(ui.draggable).draggable("option", "revert", true);
}

WordProb.checkToFind = function (event, ui) {

	if (ui.draggable.text().trim() == toFind.trim()) {
		$(ui.draggable).draggable("option", "revert", false);
		$(this).append(ui.draggable.clone());
		$(this).css("background-color", "green");
		$(this).css("color", "white");
		$(this).droppable("disable");
	}
	else
		$(ui.draggable).draggable("option", "revert", true);
}

WordProb.checkOpr = function (opr) {
	if (document.getElementById(opr).innerHTML == WordProb.currentObject.operation) {
		document.getElementById(opr).style.backgroundColor = "green";
	}
	else {
		document.getElementById(opr).style.backgroundColor = "red";
		setTimeout(function () {
			document.getElementById(opr).style.backgroundColor = "";
		}, 500);
	}
}
//onclick of continue.
WordProb.showCalculation = function () {
	document.getElementById("playSound").pause();
	$("#buttonValue11").css("pointer-events", "none");
	$("#buttonValue11").css("opacity", 0.5);
	$("#buttonValue12").css("opacity", 0.5);
	WordProb.counter++;
	document.getElementById("playSound").pause();
	//$(".dragSpans").draggable("disable");
	$("#continueDiv").hide();
	$(".input").empty();
	$("#ansStep").show();
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").hide();
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").removeClass("animated bounceOutLeft");
	document.getElementById("finalAnsText").innerHTML = WordProb.hardcodedData.finalAns;
	$("#questionDiv").addClass("animated bounceOutLeft");

	setTimeout(function () {
		$("#questionDiv").hide();
		$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").hide();
		$("#questionDiv").removeClass("animated bounceOutLeft");
		$("#AnswerDiv").addClass("animated bounceInRight");
		$("#AnswerDiv").show();
		$("#stepDiv").text(WordProb.hardcodedData.step1 + " " + WordProb.counter + " " + WordProb.hardcodedData.step2);
		$("#stepDiv").text(WordProb.hardcodedData.step1 + " " + WordProb.counter);
		$(".dragSpans").draggable("disable");
		setTimeout(function () {
			$("#nextDiv").show();
			$("#helpDiv").show();
		}, 500);
	}, 700);
	document.getElementById("finalAnsText").innerHTML = WordProb.hardcodedData.finalAns;
	if (WordProb.instrFlag) {
		WordProb.instrTime = setTimeout(function () {
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/instr.mp3";
			document.getElementById("playSound").play();
			WordProb.instrFlag = false;
		}, 1000);
	}
}
//function for creating subdivs in multiplication and remainder divs.
WordProb.createSpans = function (outerDiv, noOfSpans, id, number, flag, num) {
	for (i = num; i <= noOfSpans; i++) {
		span = document.createElement("DIV")
		span.setAttribute("id", id + i);
		if (outerDiv == "multiplication" + WordProb.stepCtr) {
			if (String(number).length < String(parseInt(WordProb.currNum)).length)
				span.setAttribute("class", "nopadding spans editField singleLetter col-xs-2 col-md-2 col-lg-2 col-sm-2 col-xs-offset-2 col-md-offset-2 col-lg-offset-2 col-sm-offset-2");
			else
				span.setAttribute("class", "nopadding spans editField singleLetter col-xs-2 col-md-2 col-lg-2 col-sm-2");
		}
		else
			span.setAttribute("class", "nopadding spans editField singleLetter col-xs-2 col-md-2 col-lg-2 col-sm-2");
		span.setAttribute("data", String(number)[i - 1]);
		span.style.pointerEvents = "none";
		if (flag == true && outerDiv != "remainder" + WordProb.stepCtr)
			WordProb.editFieldArr.push(id + i);
		document.getElementById(outerDiv).appendChild(span)
	}
	if (flag == true && outerDiv == "remainder" + WordProb.stepCtr) {
		for (var j = noOfSpans; j >= num; j--) {
			WordProb.editFieldArr.push(id + j);
		}
	}
}
WordProb.displayInTextBox = function (element) {//inputs the number in selected textbox when user clicks the number on numberpad.
	var number, flag = false;

	if ($("#" + WordProb.id).hasClass("singleLetter")) {
		number = 1;
	} else if (WordProb.id == "finalAns") {
		number = String(WordProb.answer).length;
	}
	else if (WordProb.id == "divisor") {
		number = number = String(WordProb.divisor).length;
	}
	if (WordProb.id == "finalAns") {
		$("#buttonValue11").css("pointer-events", "auto");
		$("#buttonValue11").css("opacity", 1);
		number = String(WordProb.answer).length;
	}
	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");
	document.getElementById("playSound").pause();
	var data;
	WordProb.attemptFlag = true;
	WordProb.checkFlag = false;
	data = parseInt(document.getElementById(WordProb.id).getAttribute("data"));
	if (parseInt(document.getElementById(WordProb.id).innerHTML) == data) {
		WordProb.checkFlag = true;
	}
	else
		WordProb.checkFlag = false;

	if (WordProb.checkFlag) {//if input answer is correct. 
		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");
		$("#" + WordProb.id).css("pointer-events", "none");
		if (!(WordProb.directAnsFlag)) {
			WordProb.highlightTime = setTimeout(function () {
				$("#buttonValue11").css("pointer-events", "none");
				$("#buttonValue11").css("opacity", 0.5);
				$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
				$("#" + WordProb.id).removeClass("blink_me");
				if ($("#" + WordProb.id).parent()[0].id == "divident") {
				}
				blinkCtr++;
				multiplication = parseInt($("#" + WordProb.id).text());
				if (multiplication != 0 && $("#" + WordProb.id).parent()[0].id == "divisonAnsDiv") {
					WordProb.currMultiplier = multiplication;
					WordProb.createSpans("multiplication" + WordProb.stepCtr, String(multiplication * WordProb.divisor).length, "multSpan" + WordProb.stepCtr, multiplication * WordProb.divisor, true, 1)
					$("#solutionStep" + WordProb.stepCtr).css("visibility", "visible");

				}
				else if ($("#" + WordProb.id).parent()[0].id == ("multiplication" + WordProb.stepCtr)) {
					remainder = WordProb.currNum - WordProb.currMultiplier * WordProb.divisor;
					if ((String(parseInt(WordProb.currNum)).length - String(remainder).length == 1))
						remainder = "0" + remainder;
					else if ((String(parseInt(WordProb.currNum)).length - String(remainder).length == 2))
						remainder = "00" + remainder;
					if (WordProb.remainderDivFlag) {
						WordProb.createSpans("remainder" + WordProb.stepCtr, String(parseInt(WordProb.currNum)).length, "remSpan" + WordProb.stepCtr, remainder, true, 1)
						WordProb.remainderDivFlag = false;
					}
				}
				if (blinkCtr >= WordProb.editFieldArr.length) {
					if (WordProb.highlighter <= String(WordProb.divident).length) {
						WordProb.editFieldArr.push("ansSpan" + WordProb.highlighter);
						WordProb.highlightDivident();
					}
					else {
						WordProb.editFieldArr.push("finalAns");

					}
					WordProb.highlighter++;
				}
				WordProb.id = WordProb.editFieldArr[blinkCtr];
				$("#" + WordProb.id).addClass("blink_me");
				if (WordProb.id == "finalAns") {
					child = document.getElementById("remainder" + (WordProb.stepCtr - 1)).children.length
					for (i = 1; i <= child; i++) {
						document.getElementById("remSpan" + (WordProb.stepCtr - 1) + i).style.backgroundColor = "";
					}
				}
				if (WordProb.id == "finalAns") {
					child = document.getElementById("remainder" + 1).children.length
					for (i = 1; i <= child; i++) {
						document.getElementById(("remSpan" + 1) + i).style.backgroundColor = "";
					}
				}
				// if ($("#" + WordProb.id).parent()[0].id == "multiplication1" && String(multiplication * WordProb.divisor).length == 1 && String(WordProb.currNum).length == 2) {
				// 	if (WordProb.offsetFlag) {
				// 		$("#multiplication1").prop("class", "nopadding border height col-xs-6 col-md-6 col-lg-6 col-sm-6 col-xs-offset-1 col-md-offset-1 col-lg-offset-1 col-sm-offset-1")
				// 		WordProb.offsetFlag = false;
				// 	}
				// }
				// if (blinkCtr > 3) {
				// 	digitCtr++;
				// 	if (blinkCtr == 4) {
				// 		$("#" + WordProb.traverseArr[traverse][0]).css("background-color", "pink");
				// 		$("#" + WordProb.traverseArr[traverse][1]).css("background-color", "pink");
				// 		digitCtr = 1;
				// 		traverse++;
				// 	}
				// 	if (digitCtr > WordProb.lenArr[traverse - 1]) {
				// 		digitCtr = 1;
				// 		if (traverse > 0 && traverse < (WordProb.lenArr.length)) {
				// 			$("#" + WordProb.traverseArr[traverse - 1][0]).css("background-color", "");
				// 			$("#" + WordProb.traverseArr[traverse - 1][1]).css("background-color", "");
				// 		}
				// 		if (traverse < (WordProb.lenArr.length - 1)) {
				// 			$("#" + WordProb.traverseArr[traverse][0]).css("background-color", "pink");
				// 			$("#" + WordProb.traverseArr[traverse][1]).css("background-color", "pink");
				// 		}
				// 		//console.log(traverse);
				// 		traverse++;
				// 	}
				// }
				// 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 = "";
			}, 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.id == "finalAns")
		WordProb.finalAnsFlag = true;
	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();
	}
}

WordProb.highlightDivident = function () {
	if ($("#" + WordProb.id).parent()[0].id == "remainder" + WordProb.stepCtr && WordProb.highlighter <= String(WordProb.divident).length + 1) {
		$(".highLighted").css("background-color", "");
		remainder = remainder + String(WordProb.divident)[WordProb.highlighter - 1];
		if (WordProb.highlighter <= String(WordProb.divident).length) {
			WordProb.createSpans("remainder" + WordProb.stepCtr, (WordProb.highlighter + 1), "remSpan" + WordProb.stepCtr, remainder, false, WordProb.highlighter);
			document.getElementById("remSpan" + WordProb.stepCtr + (WordProb.highlighter)).innerHTML = String(WordProb.divident)[WordProb.highlighter - 1];
			WordProb.currNum = remainder;
			WordProb.remainderDivFlag = true;
			num = String(remainder);
			numArr = num.split("");
			ctr = 0;
			for (i = 0; i < String(remainder).length; i++) {
				if (numArr[0] == 0) {
					numArr.splice(0, 1);
					ctr++;
				}
				else
					break;
			}
			setTimeout(function () {
				for (i = ctr + 1; i <= String(remainder).length; i++) {
					document.getElementById("remSpan" + WordProb.stepCtr + i).style.backgroundColor = "pink";

					//WordProb.currNum = WordProb.currNum + $("#dividentSpan" + WordProb.highlighter).text();
					if (i == String(remainder).length)
						WordProb.stepCtr++;
				}
				var temp = String(parseInt(WordProb.currNum)).length;
				//if ($("#remSpan" + (WordProb.stepCtr - 1) + 1).text() == "0")
				temp = WordProb.highlighter - temp + 1;
				// else
				// 	temp = temp + 1;
				if (parseInt(remainder) != 0) {
					$("#minusSign" + (WordProb.stepCtr)).prop("class", "nopadding  col-xs-1 col-md-1 col-lg-1 col-sm-1 col-xs-offset-" + temp + " col-md-offset-" + temp + " col-lg-offset-" + temp + " col-sm-offset-" + temp);
					$("#remainder" + (WordProb.stepCtr)).prop("class", "nopadding height col-xs-6 col-md-6 col-lg-6 col-sm-6 col-xs-offset-" + (temp + 1) + " col-md-offset-" + (temp + 1) + " col-lg-offset-" + (temp + 1) + " col-sm-offset-" + (temp + 1));
				}
			}, 700);
		}
	}
	else {
		document.getElementById("dividentSpan" + WordProb.highlighter).style.backgroundColor = "pink";
		$("#dividentSpan" + WordProb.highlighter).addClass("highLighted");
		WordProb.currNum = WordProb.currNum + $("#dividentSpan" + WordProb.highlighter).text();
	}
}

WordProb.nextQuestion = function () {
	clearTimeout(WordProb.highlightTime);
	document.getElementById("playSound").pause();
	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 () {
	$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
	WordProb.directAnsFlag = false;
	//$("#AnswerDiv").hide();
	$(".inputNum,#finalAns,.input").css("background-color", "white");
	$(".inputNum,#finalAns").css("color", "black");
	$(".editField").css("color", "black");
	$(".editField").text("");
	$(".editField").css("background-color", "");
	$(".editField").css("pointer-events", "auto");
	$(".editField").removeClass("correctClass");
	$(".editField").removeClass("blink_me");
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").show();
	$("#AnswerDiv").hide();
	$("#helpBtn").css("visibility", "hidden");
	$(".input").droppable("enable");
	$("#AnswerDiv").removeClass("animated bounceInRight");
	$(".oprSpans").css("background-color", "white");
	$("#continueDiv").show();
	$(".oprSpans").css("background-color", "white");
	$("#nextDiv").hide();
	$(".editField", ".signs").css("visibility", "visible");
	$("#subAnsDiv").empty();
	$(".height").empty();
	$(".steps").css("visibility", "hidden");
	$("#tableDiv").css("visibility", "hidden");
	$("#questionText").empty();
	$("#helpBtn").css("visibility", "hidden");
}

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.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 () {
	$("#acknowledgementDiv").hide();
	$("#endPage").hide();
	$("#gamePage").show();
	WordProb.questionCtr = 0;
	WordProb.questionArr = [];
	WordProb.instrFlag = true;
	WordProb.resetVariables();
	WordProb.initializeVariables();
	WordProb.makeQuestion();
}



WordProb.showTable = function () {
	if (WordProb.helpFlag) {
		WordProb.helpFlag = false;
		$("#tableDiv").css("visibility", "visible");
		for (i = 1; i <= 10; i++) {
			document.getElementById("tableDiv" + i).innerHTML = WordProb.divisor * i;
		}
	}
	else {
		WordProb.helpFlag = true;
		$("#tableDiv").css("visibility", "hidden");
	}

	// var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
	// arr2 = [2, 4, 6];
	// ctr = 0;
	// for (i = 0; i < arr.length; i++) {
	// 	if (arr2.includes(i)) {
	// 		arr.splice(i - ctr, 1);
	// 		ctr++;
	// 	}

	// }
	// console.log(arr);
}

WordProb.createTableDivs = function () {
	var div, i;
	var parendDiv = document.getElementById("tableDiv");
	for (i = 1; i <= 10; i++) {
		div = document.createElement("div");
		div.setAttribute("id", "tableDiv" + i);
		div.setAttribute("class", "nopadding tables col-xs-12 col-md-12 col-lg-12 col-sm-12");
		parendDiv.appendChild(div);
	}
}

WordProb.createOperatorSpans = function () {//spans for showing operator list.
	var i;
	for (i = 0; i < 2; 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);

	}
}