//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, unit, digit;
var blinkCtr = 0;
WordProb.iterationFlag = false;
WordProb.level = 0;//level for addition or subtraction
WordProb.questionCtr = 0;
WordProb.soundFlag = true;//flag for instruction.
WordProb.instrFlag = true;
WordProb.subCtr1 = WordProb.subCtr2 = WordProb.subCtr3 = WordProb.subCtr4 = 0;
$(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.createLevelDivs();
	WordProb.setAllImages();
	WordProb.createAcknowledgementDivs();
	//Thin Pencil Handwriting.ttf

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

WordProb.initializeVariables = function () {//initialization.
	WordProb.finalAnsFlag = false;//for checking final answer or not
	WordProb.counter = 1;//counter for steps
	WordProb.checkFlag = false;//for checking whether answer is correct or not.
	WordProb.attemptFlag = false;//for attempt.
	WordProb.secondFlag = false;//for reverse addition.
	WordProb.borrowFlag = false;//if borrow flag will true.
	digitCtr = 0;
	traverse = 0;
	WordProb.lenArr = [];
	WordProb.splitNumArr = [];
	scoredMarks = 0;
}
WordProb.setAllImages = function () {
	document.getElementById("homeImage").src = Utils.Path + "images/skin/Home.png";
	document.getElementById("next").src = Utils.Path + "images/skin/Next.png";
	document.getElementById("logoImage").src = Utils.Path + "images/skin/logo.png";
	document.getElementById("playImg").src = Utils.Path + "images/skin/playButton.png";
	document.getElementById("questionDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/textBlock.png)";
	document.getElementById("innerDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/notebook.png)";
	//document.getElementById("levelImg1").src = Utils.Path + "images/skin/jodo.png";
	//document.getElementById("levelImg2").src = Utils.Path + "images/skin/ghatav.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("unitPlace").innerHTML = WordProb.hardcodedData.ikai;
	document.getElementById("tensPlace").innerHTML = WordProb.hardcodedData.dahai;
	document.getElementById("hundrdPlace").innerHTML = WordProb.hardcodedData.sekada;
	document.getElementById("thousandPlace").innerHTML = WordProb.hardcodedData.hajar;
	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 () {//for addition/subtraction selection.
	var parentDiv, i, div, image;
	parentDiv = document.getElementById("container");
	for (i = 0; i < 2; i++) {
		div = document.createElement("DIV");
		div.setAttribute("id", "levelDiv" + (i + 1));
		div.setAttribute("class", "levelDivs nopadding");
		div.setAttribute("data", (i + 1));
		div.setAttribute("onclick", "WordProb.selectLevel(this.id);");
		parentDiv.appendChild(div);

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

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

WordProb.selectLevel = function (level) {//when user selects level.(addition/subtrction)
	WordProb.level = parseInt(document.getElementById(level).getAttribute("data"));
	WordProb.playGame();
}

WordProb.createSpans = function () {//spans for question text.
	var i, span;
	for (i = 0; i < 3; i++) {
		span = document.createElement("span");
		$(span).prop("id", "span" + i);
		$(span).prop("class", "dragSpans");
		$(span).draggable({
			revert: "invalid", helper: 'clone', start: function (e, ui) {
				document.getElementById("playSound").pause();
				$(ui.helper).addClass("ui-draggable-helper");//used to change the font size text is drappable
			}
		});
		document.getElementById("questionText").append(span);
	}
}


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

	}
	for (i = 0; i < 2; i++) {
		randomNum = Math.floor(Math.random() * num1 + num2);
		while (numArr.includes(randomNum))//|| randomNum % 10 == 9
			randomNum = Math.floor(Math.random() * num1 + num2);
		numArr.push(randomNum);
	}
	if (WordProb.level == 2) {
		numArr.sort(function (a, b) { return b - a });
		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"];
		}
	}
	else {
		WordProb.number1 = numArr[0];
		WordProb.number2 = numArr[1];
		if ((WordProb.number1 % 10 + WordProb.number2 % 10) >= 10)
			WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "c1", "a1", "finalAns"];
		WordProb.answer = WordProb.number1 * WordProb.number2;

	}

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


	if (WordProb.level == 3) {
		WordProb.editFieldArr = ["t1", "u1", "t2", "u2"];
		for (i = 1; i <= 5; i++) {
			switch (i) {
				case 1: len = String(splitNum2 * splitNum4).length;
					WordProb.lenArr.push(len);
					break;
				case 2: len = String(splitNum1 * splitNum4).length;
					WordProb.lenArr.push(len);

					break;
				case 3: len = String(splitNum3 * splitNum2).length;
					WordProb.lenArr.push(len);
					break;
				case 4: len = String(splitNum3 * splitNum1).length;
					WordProb.lenArr.push(len);
					break;
				case 5: len = String(WordProb.answer).length;
					WordProb.lenArr.push(len);
					break;

			}
			if (i < 5)
				for (j = 5 - len; j <= 4; j++) {
					WordProb.editFieldArr.push("subAnsDiv" + i + j);

				}
			else
				for (j = 4; j >= (5 - len); j--) {
					WordProb.editFieldArr.push("subAnsDiv" + i + j);
				}

		}
		WordProb.editFieldArr.push("finalAns");
		//console.log(WordProb.editFieldArr);
		//WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "subAnsDiv1", "subAnsDiv2", "subAnsDiv3", "subAnsDiv4", "finalAns"];
		WordProb.ansArr = [Math.floor(WordProb.number1 / 10), WordProb.number1 % 10, Math.floor(WordProb.number2 / 10), WordProb.number2 % 10, splitNum2 * splitNum4, splitNum1 * splitNum4, splitNum3 * splitNum2, splitNum1 * splitNum3, WordProb.answer]

	}
	WordProb.createSubAnsDivs();
	WordProb.gotoHelp();
	WordProb.showCalculation();
}



WordProb.checkGiven1 = function (event, ui) {

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

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

WordProb.checkToFind = function (event, ui) {

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

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).hasClass("singleLetter")) {
		number = 1;
	} else {
		number = String(WordProb.ansArr[blinkCtr]).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"));
	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: {//checks final answer's units place.
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.answer % 10)
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 1: {//checks carry.
			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: {//checks final answers tens place
			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: {//checks first numbers unit place.
			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: {//check first numbers tens place
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == Math.floor(WordProb.number1 / 10)) {
				WordProb.checkFlag = true;
				WordProb.iterationFlag = true;
			}
			else
				WordProb.checkFlag = false;
			if (WordProb.level == 1)
				if (parseInt(document.getElementById(WordProb.id).innerHTML) == Math.floor(WordProb.number2 / 10)) {
					WordProb.checkFlag = true;
					WordProb.secondFlag = true;
					if (WordProb.number1 / 10 == WordProb.number2 / 10) {
						WordProb.sameDigitFlag = true;
					}
				}


		} break;
		case 21: {//checks second numbers units place.
			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: {//checks second numbers tens place.
			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: {//for multiplication....
			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;
		case 513: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum2 * splitNum4 / 10 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 514: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum2 * splitNum4 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 522: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum1 * splitNum4 / 100 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 523: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum1 * splitNum4 / 10 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 524: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum1 * splitNum4 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 532: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum3 * splitNum2 / 100 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 533: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum3 * splitNum2 / 10 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 534: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum3 * splitNum2 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 541: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum1 * splitNum3 / 1000 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 542: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum1 * splitNum3 / 100 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 543: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum1 * splitNum3 / 10 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 544: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(splitNum1 * splitNum3 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 551: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(WordProb.answer / 1000 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 552: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(WordProb.answer / 100 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 553: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(WordProb.answer / 10 % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;
		case 554: {
			if (parseInt(document.getElementById(WordProb.id).innerHTML) == parseInt(WordProb.answer % 10))
				WordProb.checkFlag = true;
			else
				WordProb.checkFlag = false;
		} break;


	}
	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)) {
			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 (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++;
					}
				}
				$("#" + WordProb.id).parent().css("visibility", "visible");
				if (WordProb.id == "a2" && WordProb.level == 2) {
					$("#responseBoxDiv").show();
				}
				if (WordProb.editFieldArr[blinkCtr - 1] != "u2")
					document.getElementById(WordProb.editFieldArr[blinkCtr - 1]).style.backgroundColor = "";
				document.getElementById(WordProb.editFieldArr[blinkCtr - 1]).style.color = "black";
				if (WordProb.editFieldArr[blinkCtr - 1] == "subAnsDiv24" || WordProb.editFieldArr[blinkCtr - 1] == "subAnsDiv34" || WordProb.editFieldArr[blinkCtr - 1] == "subAnsDiv43" || WordProb.editFieldArr[blinkCtr - 1] == "subAnsDiv44") {
					document.getElementById(WordProb.editFieldArr[blinkCtr - 1]).style.color = "red";
				}
			}, 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.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.nextQuestion = function () {
	if (!WordProb.attemptFlag) {
		scoredMarks = -1;
	}
	console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	if (Utils.mobileDeviceFlag)
		Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	if (WordProb.questionCtr < 5) {
		WordProb.resetVariables();
		WordProb.initializeVariables();
		WordProb.makeQuestion();
	}
	else {
		$("#gamePage").hide();
		$("#endPage").show();
	}
}
WordProb.resetVariables = function () {
	document.getElementById("questionMsg").innerHTML = WordProb.modalData.responseMsg;
	$("#btnDiv").show();
	$("#u1").removeClass("animated heartBeat");
	$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
	WordProb.directAnsFlag = false;
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").show();
	$("#AnswerDiv").hide();
	//$("#subAnsDiv").hide();
	$("#helpBtn").css("visibility", "hidden");
	$(".inputNum,#finalAns,.input").css("background-color", "white");
	$(".inputNum,#finalAns").css("color", "black");
	$(".editField").css("color", "black");
	$(".editField").text("");
	$(".input").droppable("enable");
	$("#AnswerDiv").removeClass("animated bounceInRight");
	$(".editField").css("background-color", "");
	$(".editField").css("pointer-events", "auto");
	$(".editField").removeClass("correctClass");
	$(".editField").removeClass("blink_me");
	$(".oprSpans").css("background-color", "white");
	$("#bottomDiv").hide();
	$("#continueDiv").show();
	$("#carryDiv").show();
	$(".editField", ".signs").css("visibility", "visible");
	$("#split1Num1").css("visibility", "visible");
	$("#plus1").css("visibility", "visible");
	$("#split2Num1").css("visibility", "visible");
	$("#plus2").css("visibility", "visible");
	$(".arrowDivs").css("visibility", "hidden");
	$("#c1Para").css("pointer-events", "auto");
	$(".dragSpans").draggable("enable");
	$("#u1,#t1").removeClass("lineThrough");
	$("#u1,#t1").empty();
	WordProb.iterationFlag = false;
	$("#t1").css("text-align", "center");
	$("#subAnsDiv").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, j;
	WordProb.splitNumArr.push(eval("splitNum2") + "×" + eval("splitNum4"));
	WordProb.splitNumArr.push(eval("splitNum1") + "×" + eval("splitNum4"));
	WordProb.splitNumArr.push(eval("splitNum3") + "×" + eval("splitNum2"));
	WordProb.splitNumArr.push(eval("splitNum3") + "×" + eval("splitNum1"));

	for (i = 1; i <= 4; i++) {
		for (j = 1; j <= WordProb.splitNumArr[i - 1].length; j++) {
			document.getElementById("numSpan" + i + j).innerHTML = WordProb.splitNumArr[i - 1][j - 1];
			if ((i > 1 && j == 2) || (i == 4 && j == 5))

				document.getElementById("numSpan" + i + j).style.color = "red";
		}
	}
	// document.getElementById("multDiv1").innerHTML = eval("splitNum2") + " × " + eval("splitNum4");
	// document.getElementById("multDiv2").innerHTML = eval("splitNum1") + " × " + eval("splitNum4");
	// document.getElementById("multDiv3").innerHTML = eval("splitNum3") + " × " + eval("splitNum2");
	// document.getElementById("multDiv4").innerHTML = eval("splitNum3") + " × " + eval("splitNum1");
	// document.getElementById("multDiv5").innerHTML = WordProb.hardcodedData.ansText;

	//$(".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;
	WordProb.instrFlag = 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");
// 	}
// }


WordProb.createSubAnsDivs = function () {
	var div, parentDiv, i, numOfSpans;
	length1 = String(WordProb.number1).length;
	length2 = String(WordProb.number2).length;
	num = length1 * length2 + 1;
	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 multDivs col-xs-2 col-md-2 col-lg-2 col-sm-2");
		div.appendChild(multDiv);
		if (i < num) {
			if (i == 1)
				numOfSpans = 3;
			else
				numOfSpans = 4;
			if (i == 4)
				numOfSpans = 5;
			for (k = 1; k <= numOfSpans; k++) {
				span = document.createElement("SPAN");
				span.setAttribute("id", "numSpan" + i + k);
				span.setAttribute("class", "multSpans");
				multDiv.appendChild(span)
			}
		}


		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);
		for (j = 1; j <= 5; j++) {
			subAnsDiv = document.createElement("DIV");
			subAnsDiv.setAttribute("id", "subAnsDiv" + i + j);
			subAnsDiv.setAttribute("class", "subAnsDivs singleLetter editField nopadding col-xs-2 col-md-2 col-lg-2 col-sm-2");
			subAnsDiv.setAttribute("data", "5" + i + j);
			subAnsDiv.setAttribute("onclick", "WordProb.showNumbers(this.id);");
			subAnsDiv.style.pointerEvents = "none";
			div.appendChild(subAnsDiv);
		}
		// $(".border").css("height", "7vh");
		// $(".inputNum").css("height", "5vh");
		// $(".inputNum").css("line-height", "6vh");
	}
}
