//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.setAllImages();
	//WordProb.createSpans();
	WordProb.createOperatorSpans();
	WordProb.createNumberDivs(numberSystemDiv);
	WordProb.createLevelDivs();
	WordProb.createAcknowledgementDivs();
}

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.
}
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("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("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("questionText").style.backgroundImage = "url(" + Utils.Path + "images/skin/textBlock.png)";
	document.getElementById("innerDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/notebook.png)";
	document.getElementById("questionDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/notebook2.png)";
	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;
	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);
	}
}

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

WordProb.selectLevel = function (level) {
	WordProb.level = Math.floor(Math.random() * 2 + 1);//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 < 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);

	}
}

WordProb.playGame = function () {
	WordProb.questionCtr = 0;
	$("#coverPage").hide();
	$("#levelPage").hide();
	$("#gamePage").show();
	$(".header").css("visibility", "visible");
	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.tempArr = [];
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.makeQuestion = function ()						//generate word Sentence
{
	WordProb.questionCtr++;
	var randomPerson, randomObject, personArr = [], numArr = [], d;
	WordProb.numberArray = [];
	blinkCtr = 0;
	$(".editField").not("#finalAns").css("pointer-events", "none");
	WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "a1", "finalAns"];

	//document.getElementById(WordProb.editFieldArr[blinkCtr]).classList.add("blink_me");
	WordProb.level = 2;// Math.floor(Math.random() * 2 + 1);//addition,subtraction or multiplication.
	WordProb.operator = WordProb.operatorArr[WordProb.level - 1];
	d = new Date();
	startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();

	//console.log(WordProb.sentence);
	if (WordProb.soundFlag) {//for playing dragging instruction.
		WordProb.soundFlag = false;
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/instruction.mp3";
		document.getElementById("playSound").play();
	}
	randomQuestion = Math.floor(Math.random() * (WordProb.questions[WordProb.level - 1].data.length));
	temp = WordProb.questions[WordProb.level - 1][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) {
			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(/@/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);
	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['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]);
	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"];
			// if (WordProb.number1 % 10 >= WordProb.number2 % 10) {
			// 	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"];
	}
	//replaces special characters with numbers.
	given1 = given1.replace("!", WordProb.number1);

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


	WordProb.sentence = WordProb.sentence.replace("!", WordProb.number1);
	WordProb.sentence = WordProb.sentence.replace("!", WordProb.number2);

	//console.log(given1);
	//console.log(given2);

	//sets question test.
	/* $("#span0").text(given1);
	$("#span1").text(given2);
	$("#span2").text(toFind); */
	//document.getElementById("questionText").innerHTML = WordProb.number1 + " " + WordProb.operator + " " + WordProb.number2;
	//$("#stepDiv").text(WordProb.hardcodedData.step1 + " " + WordProb.counter + " " + WordProb.hardcodedData.step2);
	//$("#stepDiv").text(WordProb.hardcodedData.step1 + " " + WordProb.counter);

	splitNum1 = Math.floor(WordProb.number1 / 10) * 10;
	splitNum2 = WordProb.number1 % 10;
	splitNum3 = Math.floor(WordProb.number2 / 10) * 10;
	splitNum4 = WordProb.number2 % 10;

	if (WordProb.level == 3) {
		$("#subAnsDiv").empty();
		WordProb.createSubAnsDivs();
	}
	$("#" + WordProb.editFieldArr[blinkCtr]).addClass("blink_me");
	$("#numberSystemDiv").show();
	WordProb.id = WordProb.editFieldArr[blinkCtr];
	//WordProb.showCalculation();
	WordProb.hindiText = WordProb.sentence.split(' ');
	WordProb.tempArr.push(given1);
	WordProb.tempArr.push(given2);
	WordProb.tempArr.push(toFind);
	WordProb.createEnglishSentence(questionText, WordProb.hindiText.length);
}
//creates divs for answer if the level is multiplication.
WordProb.createSubAnsDivs = function () {
	var div, parentDiv, i;
	length1 = String(WordProb.number1).length;
	length2 = String(WordProb.number2).length;
	num = length1 * length2;
	parentDiv = document.getElementById("subAnsDiv");
	for (i = 1; i <= num; i++) {
		if (!splitNum1)
			i += 2;
		div = document.createElement("DIV");
		div.setAttribute("id", "subDiv" + (i));
		if (i % 2 == 1)
			div.style.backgroundColor = "bisque";
		else
			div.style.backgroundColor = "beige";
		div.setAttribute("class", "subDivs nopadding col-xs-12 col-md-12 col-lg-12 col-sm-12");
		parentDiv.appendChild(div);

		multDiv = document.createElement("DIV");
		multDiv.setAttribute("id", "multDiv" + (i));
		multDiv.setAttribute("class", "nopadding col-xs-4 col-md-4 col-lg-4 col-sm-4");
		div.appendChild(multDiv);

		arrowDiv = document.createElement("DIV");
		arrowDiv.setAttribute("id", "arrowDiv" + (i));
		arrowDiv.setAttribute("class", "arrowDivs nopadding col-xs-2 col-md-2 col-lg-2 col-sm-2");
		arrowDiv.innerHTML = "-->";
		div.appendChild(arrowDiv);

		subAnsDiv = document.createElement("DIV");
		subAnsDiv.setAttribute("id", "subAnsDiv" + (i));
		subAnsDiv.setAttribute("class", "subAnsDivs nopadding col-xs-6 col-md-6 col-lg-6 col-sm-6");
		subAnsDiv.setAttribute("data", "5" + i);
		subAnsDiv.setAttribute("onclick", "WordProb.showNumbers(this.id);");
		div.appendChild(subAnsDiv);

		// $(".border").css("height", "7vh");
		// $(".inputNum").css("height", "5vh");
		// $(".inputNum").css("line-height", "6vh");
	}
}


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 () {
	$("#buttonValue11").css("pointer-events", "none");
	$("#buttonValue11").css("opacity", 0.5);
	$("#buttonValue12").css("opacity", 0.5);
	WordProb.counter++;
	document.getElementById("playSound").pause();
	//$("#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();
	}
	$("#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 () {
			$("#bottomDiv").show();
		}, 500);
	}, 700);


	//document.getElementById("queText").innerHTML = WordProb.sentence;
	document.getElementById("opr").innerHTML = WordProb.operator;
	document.getElementById("carryText").innerHTML = WordProb.hardcodedData.carryText;
	document.getElementById("ansText").innerHTML = WordProb.hardcodedData.ansText;
	// document.getElementById("t1").innerHTML = Math.floor(WordProb.number1 / 10);
	// document.getElementById("u1").innerHTML = WordProb.number1 % 10;
	// document.getElementById("t2").innerHTML = Math.floor(WordProb.number2 / 10);
	// document.getElementById("u2").innerHTML = WordProb.number2 % 10;
	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;
		case 3: {
			WordProb.answer = WordProb.number1 * WordProb.number2;
			carry = Math.floor(((WordProb.number1 % 10) * (WordProb.number2 % 10)) / 10);
			document.getElementById("c1Para").setAttribute("data", carry);
		} break;
	}

	//console.log(WordProb.answer);
}

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.
	var data;
	WordProb.attemptFlag = true;
	WordProb.checkFlag = false;
	$("#numberSystemDiv,#finalAns").css("pointer-events", "none");
	// if (!($("#" + WordProb.id).hasClass("autoCheck"))) {
	// 	setTimeout(function () {
	// 		$("#numberSystemDiv").addClass("animated zoomOut");
	// 		$("#numberSystemDiv").removeClass("animated zoomOut");
	// 		$("#numberSystemDiv").hide();
	// 	}, 500);
	// }
	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;
				}


		} 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 () {
	$("#btnDiv").show();
	WordProb.directAnsFlag = false;
	$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
	//$("#borrowInstr").hide();
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").show();
	$("#questionDiv").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");
	$(".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");
	$(".editField").removeClass("blink_me");
	$("#questionText").empty();
}



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++;
			// if (!(eval("splitNum" + i))) {
			// 	i++;
			// 	ctr += 2;
			//}
			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 = 0;
	WordProb.resetVariables();
	WordProb.initializeVariables();
	WordProb.makeQuestion();
}

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");
// 	}
// }



