//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 = 0;//level for addition or subtraction
WordProb.questionCtr = 0;
WordProb.correctCnt = 0;
WordProb.instrFlag = true;
WordProb.questionArr = [];
WordProb.editFieldArr = []
WordProb.skipCtr = 0;
WordProb.seconds = 0;
WordProb.soundFlag = true;//flag for instruction.
WordProb.directAnsFlag = false;//for chkecking whether user has clicked to submit answer directly.
$(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.createNumberDivs(numberSystemDiv);
	WordProb.createStars();
}

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, this flag will be true.
	WordProb.eraseFlag = false;
}
WordProb.setAllImages = function () {//set sources.
	document.getElementById("next").src = Utils.Path + "images/skin/Skip.png";
	document.getElementById("logoImage").src = Utils.Path + "images/skin/logo.png";
	document.getElementById("playImg").src = Utils.Path + "images/skin/playButton.png";
	document.getElementById("nextGame").src = Utils.Path + "images/skin/Next.png";
	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("borrowQuestion").innerHTML = WordProb.borrowData.responseMsg;
	document.getElementById("borrowYes").innerHTML = WordProb.borrowData.yes;
	document.getElementById("borrowNo").innerHTML = WordProb.borrowData.no;
}

WordProb.createStars = function () {//star creation.
	var newImage, newDiv, i, numberOfStars = 5;
	for (i = 1; i <= Math.floor(numberOfStars); i++) {
		newDiv = document.createElement("div");
		newDiv.setAttribute("id", "starDiv" + i);
		newDiv.setAttribute("class", "nopadding stars col-xs-2 col-md-2 col-lg-2 col-sm-2");

		newImage = document.createElement("img");
		newImage.setAttribute("id", "starImg" + i);
		newImage.setAttribute("class", "img-responsive nopadding col-sm-12 col-lg-12 col-md-12 col-xs-12");
		newImage.setAttribute("src", Utils.Path + "images/star5.png");
		$(newDiv).append(newImage);
		$("#starDiv").append(newDiv);
	}
};

WordProb.selectLevel = function (level) {//selects level randomly.(addition/subtrction)
	WordProb.level = Math.floor(Math.random() * 2 + 1);//parseInt(document.getElementById(level).getAttribute("data"));
	WordProb.playGame();
}

WordProb.playGame = function () {
	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.popNumbers();
	WordProb.showCalculation();

}

WordProb.popNumbers = function () {
	var carryCtr = 0, borrowCtr = 0, oneCtr = 0, twoCtr = 0, noCarryCtr = 0, noBorrowCtr = 0;
	for (k = 0; k < 5; k++) {
		var questionObj = {}, numArr = [];
		switch (k) {
			case 0: {
				level = 0;
				operator = WordProb.operatorArr[level];
				num1 = 38;
				num2 = 11;

				number1 = randomNum = Math.floor(Math.random() * num1 + num2);
				number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				while ((number1 == number2) || (number1 % 10 + number2 % 10 >= 10)) {
					number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				}

			} break;
			case 1: {
				level = 0;
				operator = WordProb.operatorArr[level];
				num1 = 38;
				num2 = 11;
				number1 = randomNum = Math.floor(Math.random() * num1 + num2);
				number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				while (number1 == number2 || (number1 % 10 + number2 % 10 < 10)) {
					number1 = randomNum = Math.floor(Math.random() * num1 + num2);
					number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				}
			} break;

			case 2: {
				level = 1;
				operator = WordProb.operatorArr[level];
				num1 = 88;
				num2 = 11
				number1 = randomNum = Math.floor(Math.random() * num1 + num2);
				number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				while (number1 <= number2 || ((number1 % 10) < (number2 % 10))) {
					number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				}
			} break;
			case 3: {
				level = 1;
				operator = WordProb.operatorArr[level];
				num1 = 88;
				num2 = 11
				number1 = randomNum = Math.floor(Math.random() * num1 + num2);
				number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				while (number1 <= number2 || ((number1 % 10) >= (number2 % 10))) {
					number1 = randomNum = Math.floor(Math.random() * num1 + num2);
					number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				}
			} break;
			case 4: {
				level = Math.floor(Math.random() * 2);//addition,subtraction or multiplication.
				operator = WordProb.operatorArr[level];
				if (level == 0) {
					num1 = 38;
					num2 = 11;
					number1 = randomNum = Math.floor(Math.random() * num1 + num2);
					number2 = randomNum = Math.floor(Math.random() * num1 + num2);
				}
				else {

					num1 = 88;
					num2 = 11;
					number1 = randomNum = Math.floor(Math.random() * num1 + num2);
					number2 = randomNum = Math.floor(Math.random() * num1 + num2);
					while (number1 <= number2) {
						number1 = randomNum = Math.floor(Math.random() * num1 + num2);
						number2 = randomNum = Math.floor(Math.random() * num1 + num2);
					}

				}
			} break;
		}
		randomQuestion = Math.floor(Math.random() * (WordProb.questions[level].data.length));
		// randomSub = Math.floor(Math.random() * (WordProb.questions[0].data[0].subject.length));
		// randomOb = Math.floor(Math.random() * (WordProb.questions[0].data[0].object.length));
		// questionObj["subject"] = WordProb.questions[0].data[0].subject[randomSub];
		// questionObj["object"] = WordProb.questions[0].data[0].object[randomOb];
		questionObj["level"] = level;
		questionObj["operator"] = operator;
		questionObj["number1"] = number1;
		questionObj["number2"] = number2;
		questionObj['randomQue'] = randomQuestion;
		WordProb.questionArr.push(questionObj);
		//var result = WordProb.displayQuestion(k);
		//questionObj["question"] = result;
	}
	WordProb.shuffle(WordProb.questionArr);
	WordProb.totalQue = WordProb.questionArr.length;
	console.log(WordProb.questionArr);
}

WordProb.displayQuestion = function (queCount)						//generate word Sentence
{
	var randomPerson, randomObject, personArr = [], numArr = [], d;
	WordProb.numberArray = [];



	//document.getElementById(WordProb.editFieldArr[blinkCtr]).classList.add("blink_me");
	if (WordProb.soundFlag) {//for playing dragging instruction.
		WordProb.soundFlag = false;
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/instruction.mp3";
		document.getElementById("playSound").play();
	}
	level = WordProb.questionArr[queCount].level;
	randomQuestion = WordProb.questionArr[queCount].randomQue;
	WordProb.currentObject = WordProb.questions[level].data[randomQuestion];
	console.log(WordProb.currentObject);
	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.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]);


	//replaces special characters with numbers.
	given1 = given1.replace("!", WordProb.questionArr[queCount].number1);

	given2 = given2.replace("!", WordProb.questionArr[queCount].number2);
	toFind = toFind.replace("!", WordProb.questionArr[queCount].number2);


	WordProb.sentence = WordProb.sentence.replace("!", WordProb.questionArr[queCount].number1);
	WordProb.sentence = WordProb.sentence.replace("!", WordProb.questionArr[queCount].number2);

	WordProb.sentence = WordProb.questionArr[queCount].number1 + WordProb.questionArr[queCount].number2
	console.log(given1);
	console.log(given2);

	//sets question test.

	//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.showCalculation();
	return WordProb.sentence;
}


// WordProb.checkGiven1 = function (event, ui) {

// 	if (ui.draggable.text() == given1) {
// 		$(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() == given2) {
// 		$(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() == toFind) {
// 		$(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);
// }


//onclick of continue.
WordProb.showCalculation = function () {
	blinkCtr = 0;
	var d = new Date();
	startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();

	WordProb.number1 = WordProb.questionArr[WordProb.questionCtr].number1;
	WordProb.number2 = WordProb.questionArr[WordProb.questionCtr].number2;
	WordProb.level = (WordProb.questionArr[WordProb.questionCtr].level) + 1;
	WordProb.operator = WordProb.questionArr[WordProb.questionCtr].operator;
	$("#questionText").text(WordProb.number1 + WordProb.operator + WordProb.number2);
	$(".editField").not("#finalAns").css("pointer-events", "none");
	WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "a1", "finalAns"];
	if (WordProb.level == 1) {
		$("#carryDiv").show();
		if (WordProb.number1 % 10 + WordProb.number2 % 10 >= 10)
			WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "c1", "a1", "finalAns"];
	}
	else {
		$("#carryDiv").hide();
		if (WordProb.number1 % 10 < WordProb.number2 % 10) {
			WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "a1", "finalAns"];
			WordProb.borrowFlag = true;
		}
	}
	$("#" + WordProb.editFieldArr[blinkCtr]).addClass("blink_me");
	$("#numberSystemDiv").show();
	WordProb.id = WordProb.editFieldArr[blinkCtr];
	$("#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");

	$("#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");
	$("#bottomDiv").show();



	//document.getElementById("queText").innerHTML = WordProb.sentence;
	document.getElementById("opr").innerHTML = WordProb.questionArr[WordProb.questionCtr].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;
	}

	if (WordProb.instrFlag) {
		src = Utils.Path + "sounds/instructions/instr.mp3";
		WordProb.loadmetaDataFlag = true;
		WordProb.getDuration(src);
		WordProb.instrFlag = false;
	}
	else
		WordProb.startTimer();
}
WordProb.getDuration = function (sound) {
	var duration = 0;
	$('#playSound').prop('src', sound);
	if (WordProb.loadmetaDataFlag) {
		$('#playSound').on("loadedmetadata", function () {
			WordProb.loadmetaDataFlag = false;
			$('#playSound').unbind("loadedmetadata");
			duration = $('#playSound').prop('duration');
			WordProb.playInstr(duration);
		}
		);
	}
	else
		$('#playSound').unbind("loadedmetadata");
}
WordProb.playInstr = function (duration) {
	document.getElementById("playSound").play();
	WordProb.instrTime = setTimeout(function () {
		WordProb.startTimer();
	}, 1000 * duration);
}

WordProb.startTimer = function () {
	if (WordProb.noResponseTimer) {
		clearInterval(WordProb.noResponseTimer);
		WordProb.noResponseTimer = null;
		WordProb.seconds = 0;
	}
	WordProb.noResponseTimer = setInterval(function () {
		WordProb.seconds++;
		if (WordProb.seconds >= 7) {
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/please_ans_the_ques.mp3";
			document.getElementById("playSound").play();
			clearInterval(WordProb.noResponseTimer);
			WordProb.timeOut = setTimeout(function () {
				WordProb.seconds = 0;
				WordProb.startTimer();
			}, 2000);
		}
	}, 1000);
}

WordProb.displayInTextBox = function (element) {//inputs the number in selected textbox when user clicks the number on numberpad.

	WordProb.clearSound();
	var number, i, span, oldTens, oldUnits, flag = false;
	WordProb.eraseFlag = true;
	$("#buttonValue11").css("pointer-events", "auto");
	$("#buttonValue11").css("opacity", 1);
	if ($("#" + WordProb.id).hasClass("singleLetter")) {
		number = 1;
	} else
		number = 2;
	// if (WordProb.iterationFlag) {
	// 	if (WordProb.id == "t1") {
	// 		if (parseInt($(element).text()) == (parseInt($("#t1").text()) - 1)) {
	// 			document.getElementById(WordProb.id).style.backgroundColor = "green";
	// 			document.getElementById("t1").style.color = "white";
	// 			setTimeout(function () {
	// 				document.getElementById("t1").style.backgroundColor = "";
	// 				document.getElementById("t1").style.color = "black";
	// 			}, 500);
	// 			oldTens = $("#" + WordProb.id).text();
	// 			$("#" + WordProb.id).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(" " + $(element).text());
	// 			$("#t1").css("text-align", "left");
	// 			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);
	// 			setTimeout(function () {
	// 				$("#" + WordProb.id).removeClass("blink_me");
	// 				blinkCtr++;
	// 				WordProb.id = WordProb.editFieldArr[blinkCtr];
	// 				$("#" + WordProb.id).addClass("blink_me");
	// 			}, 500);
	// 		}
	// 		else {
	// 			document.getElementById(WordProb.id).style.backgroundColor = "red";
	// 			flag = true;


	// 		}

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

	// 	}


	// } else {
	if ($("#" + WordProb.id).text().length < number)
		$("#" + WordProb.id).append($(element).text());
	//if ($("#" + WordProb.id).hasClass("autoCheck")) {

	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.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;
	}
	WordProb.checkFlag = true;
	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) {
					$("#borrowResponseDiv").show();
					WordProb.clearSound();
				}
				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.
		WordProb.attemptFlag = true;
		label = document.getElementById("questionText").innerHTML;
		if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.answer) {
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/thats_right.mp3";
			document.getElementById(WordProb.id).style.backgroundColor = "green";
			document.getElementById(WordProb.id).style.color = "white";
			document.getElementById(WordProb.id).style.pointerEvents = "none";
			WordProb.correctCnt++;
			scoredMarks = 10;
			WordProb.correctWrongModalShow("winEmoji.png", 2000);

		}
		else {
			scoredMarks = 0;
			WordProb.finalAnsFlag = false;
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/wrongSoundAksharkhadi.mp3";
			document.getElementById(WordProb.id).style.backgroundColor = "red";
			document.getElementById(WordProb.id).style.color = "white";
			document.getElementById(WordProb.id).style.pointerEvents = "none";
			WordProb.correctWrongModalShow("rongAnsEmoji.png", 2000);
		}
		setTimeout(function () {
			WordProb.nextQuestion();
		}, 2500);
		document.getElementById("playSound").play();
		WordProb.questionArr.splice(WordProb.questionCtr, 1);
	}
	WordProb.startTimer();

}

// 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) {
		WordProb.questionCtr++;
		WordProb.skipCtr++;
	}
	else {
		console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
		if (Utils.mobileDeviceFlag)
			Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	}
	if (WordProb.questionArr.length == 0)
		WordProb.showLastPage();
	else if (WordProb.questionCtr >= WordProb.questionArr.length && WordProb.questionArr.length != 0)
		WordProb.showPopup();
	else {
		WordProb.resetVariables();
		WordProb.initializeVariables();
		WordProb.showCalculation();
	}
}

WordProb.resetVariables = function () {
	WordProb.directAnsFlag = false;
	$("#borrowBtnDiv").show();
	$("#u1").removeClass("animated heartBeat");
	$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
	$("#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")
}

WordProb.showSkippedQuestions = function () {
	$('#responseBoxDiv').hide();
	WordProb.skipFlag = true;
	WordProb.skippedCnt = 0
	WordProb.questionCtr = 0;
	WordProb.resetVariables();
	WordProb.showCalculation();
}
WordProb.showPopup = function () {
	document.getElementById('playSound').pause();
	WordProb.clearSound();
	$('#responseBoxDiv').show();
	$('#questionMsg').text(WordProb.modalData.responseMsg);
	$('#Yes').text(WordProb.modalData.yes);
	$('#No').text(WordProb.modalData.no);
}

WordProb.showLastPage = function () {
	$('#responseBoxDiv').hide();
	WordProb.giveStars();
	document.getElementById('playSound').pause();
	$('#gameOver').text(WordProb.hardcodedData.gameOver);
	document.getElementById('endPage').style.display = "block";
	document.getElementById('gamePage').style.display = "none";
	WordProb.clearSound();
	document.getElementById('nextgameDiv').classList.add('blinker');
	if (WordProb.correctCnt > 0) {
		document.getElementById('playSound').src = "sounds/instructions/star" + WordProb.correctCnt + ".mp3";
		document.getElementById('playSound').play();
	}
	if (Utils.mobileDeviceFlag)
		Android.StudentCertification(WordProb.correctCnt, WordProb.totalQue, "3");
}

WordProb.giveStars = function () {
	var WordProbVar, i, numberOfStars = WordProb.correctCnt;
	WordProbVar = numberOfStars - Math.floor(numberOfStars);
	for (i = 1; i <= Math.floor(numberOfStars); i++)
		document.getElementById("starImg" + i).setAttribute("src", Utils.Path + "images/star1.png");
	$("#starDiv").css("visibility", "visible");
};

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.clearSound = function () {
	document.getElementById("playSound").pause();
	clearTimeout(WordProb.AnsQuestionTimer);
	clearInterval(WordProb.noResponseTimer);
	clearTimeout(WordProb.timeOut);
	WordProb.AnsQuestionTimer = null;
	WordProb.timeOut = null;
}

WordProb.playAgain = function () {
	WordProb.soundFlag = true;
	$("#acknowledgementDiv").hide();
	$("#endPage").hide();
	$("#gamePage").show();
	WordProb.questionCtr = -1;
	WordProb.nextQuestion();
	WordProb.playGame();
}
// 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");
// 	}
// }

WordProb.goNext = function () {
	clearInterval(WordProb.noResponseTimer);
	if (Utils.mobileDeviceFlag)
		Android.GotoNextGame();
}

WordProb.shuffle = function (array) {
	var ctr = array.length, temp, index;
	while (ctr > 0) {
		index = Math.floor(Math.random() * array.length);
		ctr--;
		temp = array[ctr];
		array[ctr] = array[index];
		array[index] = temp;
	}
}
WordProb.correctClick = function () {
	$("#borrowBtnDiv").hide();
	WordProb.clickFlag = true;
	WordProb.showMsg();
}
WordProb.wrongClick = function () {
	$("#borrowBtnDiv").hide();
	WordProb.clickFlag = false;
	WordProb.showMsg();
}
WordProb.showMsg = function () {
	$("#borrowResponseDiv").hide();
	if (WordProb.clickFlag) {
		setTimeout(function () {
			WordProb.transferBorrow();
		}, 1000);
	}
	// if ((WordProb.borrowFlag == true && WordProb.clickFlag == true) || (WordProb.borrowFlag == false && WordProb.clickFlag == false)) {
	// 	document.getElementById("playSound").src = Utils.Path + "sounds/instructions/thats_right.mp3";
	// 	$("#borrowResponseDiv").hide()
	// 	if (WordProb.clickFlag) {
	// 		setTimeout(function () {
	// 			WordProb.transferBorrow();
	// 		}, 2000);
	// 	}
	// }
	// else {
	// 	document.getElementById("playSound").src = Utils.Path + "sounds/instructions/wrong_ans.mp3";
	// 	$("#borrowBtnDiv").hide();
	// 	if (WordProb.borrowFlag) {
	// 		document.getElementById("borrowQuestion").innerHTML = WordProb.borrowData.borrowMsg;
	// 		setTimeout(function () {
	// 			$("#borrowResponseDiv").hide()
	// 			setTimeout(function () {
	// 				WordProb.transferBorrow();
	// 			}, 2000);

	// 		}, 4000);
	// 	} else {
	// 		document.getElementById("borrowQuestion").innerHTML = WordProb.borrowData.noBorrowmsg;
	// 		setTimeout(function () {
	// 			$("#borrowResponseDiv").hide()
	// 		}, 4000);
	// 	}
	// }
	// document.getElementById("playSound").play();
	setTimeout(function () {
		WordProb.startTimer();
	}, 3000);
}

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