//startingDate:3-03-2020
var WordProb = {};
var Utils = {};
Utils.Path = '';
Utils.mobileDeviceFlag = false;
var questionId = 0, startTime = 0, scoredMarks = 0, totalMarks = 10, resId = 0, level = 1, label = '';
var blinkCtr = 0;
var finalAnsBlink = 0;
WordProb.questionCtr = 0;
WordProb.queArr = [];
WordProb.soundFlag = true;//flag for instructions.
WordProb.homeFlag = false;
$(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 () {
	$("#playImg").addClass("pulse");
	$("#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.createNumberDivs(numberSystemDiv);
	WordProb.createLevelDivs();
	WordProb.setAllImages();
}

WordProb.initializeVariables = function () {
	WordProb.finalAnsFlag = false;//for checking final answer or not
	//	WordProb.counter = 1;//counter for steps
	WordProb.checkFlag = false;//for checking whether ans is correct or not.
	WordProb.attemptFlag = false;//for attempt.
	WordProb.attemptCount = 0;//for attempt.
	WordProb.carryFlag = false;//for reverse addition.
	WordProb.borrowFlag = false;//if borrow flag will true.
	WordProb.firstNumberArr = [];//first number split array in question
	WordProb.secondNumberArr = [];//second number split array in question
	WordProb.answerArr = [];//addition of 1st and 2nd number split array 
	WordProb.clickFlag = false;
	WordProb.checkFinalAnsFlag = 0;//check both final ans at a time 
	WordProb.finalRightAns = false; //final ans flag for score
}
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("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("gameOver").innerHTML = WordProb.hardcodedData.gameOver;
	document.getElementById("borrowInstr").innerHTML = WordProb.hardcodedData.borrowInstr;
	document.getElementById("questionMsg").innerHTML = WordProb.modalData.responseMsg;
	document.getElementById("Yes").innerHTML = WordProb.modalData.yes;
	document.getElementById("No").innerHTML = WordProb.modalData.no;
}

WordProb.createLevelDivs = function () {
	var parentDiv, i, div, image;
	parentDiv = document.getElementById("container");
	for (i = 0; i < 2; i++) {
		div = document.createElement("DIV");
		div.setAttribute("id", "levelDiv" + (i + 1));
		div.setAttribute("class", "levelDivs nopadding");
		div.setAttribute("data", (i + 1));
		div.setAttribute("onclick", "WordProb.selectLevel(this.id);");
		//div.innerHTML = WordProb.levelArr[i];
		parentDiv.appendChild(div);
		image = document.createElement("IMG");
		image.setAttribute("id", "levelImg" + (i + 1));
		image.setAttribute("class", "nopadding img-responsive col-xs-12 col-md-12 col-lg-12 col-sm-12")
		div.appendChild(image);
	}
}
WordProb.ShowLevel = function () {
	$(".header").css("visibility", "visible");
	document.body.style.backgroundImage = "url(" + Utils.Path + "images/skin/cover_bg.png)";
	$("#coverPage").hide();
	$("#levelPage").show();
}
WordProb.selectLevel = function (level) {
	WordProb.homeFlag = true;
	WordProb.level = parseInt(document.getElementById(level).getAttribute("data"));
	if (WordProb.level == 1)
		$("#operatorDiv").text(WordProb.operatorArr[0]);
	else {
		$("#operatorDiv").text(WordProb.operatorArr[1]);
	}
	WordProb.initializeVariables();
	WordProb.playGame();
}

WordProb.playGame = function () {
	WordProb.questionCtr = 0;
	$("#coverPage").hide();
	$("#levelPage").hide();
	$("#gamePage").show();
	$("#AnswerDiv").show();
	WordProb.makeQuestion();
}
WordProb.makeQuestion = function ()		//generate word Sentence
{
	var numArr = [], d;
	WordProb.numberArray = [];
	blinkCtr = 0;
	finalAnsBlink = 0;
	WordProb.operator = WordProb.operatorArr[WordProb.level - 1];
	d = new Date();
	startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
	$("#buttonValue11,#buttonValue12").css("pointer-events", "none");
	$("#buttonValue11,#buttonValue12").css("opacity", 0.5);
	switch (WordProb.level) {
		case 1: {			//for addition num1 and num2 for main unit(kg) & subunit(gm)
			num1 = 39999;
			num2 = 10000;
			num3 = 3999;
			num4 = 1000;
			$("#carryDiv").show();
		} break;
		case 2: {			//for subtraction
			num1 = 69999;
			num2 = 20000;
			num3 = 6999;
			num4 = 2000;
			$("#carryDiv").hide();
		} break;
	}
	for (i = 0; i < 2; i++) {
		randomNum = Math.floor(Math.random() * num1 + num2);
		var splitNumber=randomNum;
		splitNumberArr=[];
		splitNumberArr = ("" + splitNumber).split("");
		while (numArr.includes(randomNum) || splitNumberArr.includes("0"))
		{
			randomNum = Math.floor(Math.random() * num1 + num2);
			var splitNumber=randomNum;
			splitNumberArr=[];
			splitNumberArr = ("" + splitNumber).split("");
		}
		numArr.push(randomNum);
	}
	if (WordProb.level == 2) {
		numArr.sort(function (a, b) { return b - a });
	}
	numArr.push(WordProb.level);
	WordProb.queArr[WordProb.questionCtr] = numArr;
	$("#numberSystemDiv").show();
	var firstNumber = numArr[0];
	console.log(firstNumber);
	WordProb.firstNumberArr = ("" + firstNumber).split("");
	var mainUnit1 = WordProb.firstNumberArr[0] + "" + WordProb.firstNumberArr[1] + "" + WordProb.firstNumberArr[2];
	var subUnit1 = WordProb.firstNumberArr[3] + "" + WordProb.firstNumberArr[4];
	WordProb.firstNumberArr.splice(3,0,".");
	var secondNumber = numArr[1];
	console.log(secondNumber);
	WordProb.secondNumberArr = ("" + secondNumber).split("");
	var mainUnit2 = WordProb.secondNumberArr[0] + "" + WordProb.secondNumberArr[1] + "" + WordProb.secondNumberArr[2];
	subUnit2 = WordProb.secondNumberArr[3]+""+WordProb.secondNumberArr[4];
	WordProb.secondNumberArr.splice(3,0,".");
	if (WordProb.level == 1)
		var answer = firstNumber + secondNumber;
	else
		var answer = firstNumber - secondNumber;
	WordProb.answerArr = ("" + answer).split("");
	document.getElementById("questionText").innerHTML = mainUnit1 + "."+ subUnit1 +" " + WordProb.operator + " " + mainUnit2 +"." +subUnit2 + " ";
	WordProb.answerArr.splice(WordProb.answerArr.length-2,0,".");
	WordProb.id = WordProb.divNameArray[blinkCtr];
	WordProb.makeAnswerChart();
	WordProb.makeFinalAnswerChart();
}
WordProb.makeAnswerChart = function ()		//generate word Sentence WordProb.unitsArray
{
	document.getElementById('outerContainer').innerHTML = "";
	for (var i = 0; i < 5; i++)		//kg grid
	{
		var UnitDiv = document.createElement("div");
		UnitDiv.setAttribute("id", "UnitDiv" + i);
		UnitDiv.setAttribute("class", "nopadding col-sm-12 col-lg-12 col-md-12 col-xs-12");
		document.getElementById('outerContainer').appendChild(UnitDiv);
		var num = 6;
		for (var j = 0; j < num; j++) {
			var UnitNumDiv = document.createElement("div");
			document.getElementById("UnitDiv" + i).appendChild(UnitNumDiv);
			if (i == 0) {
				UnitNumDiv.setAttribute("id", "unitName" + j);
				$("#unitName" + j).text(WordProb.unitsArray[j]);
				$("#unitName" + j).css("font-size","2.3vw");
			}
			if (i == 1) {
				if(j<3)
				{
					UnitNumDiv.setAttribute("id", "Carry" + j);
					$("#Carry" + j).data("numData", "0");
				}
				if(j==3)
				{
					UnitNumDiv.setAttribute("id", "Carry1" + j);
					$("#Carry1" + j).text(".");
				}
				else if(j>3) {
					UnitNumDiv.setAttribute("id", "Carry" + (j-1));
					$("#Carry" + (j-1)).data("numData", "0");
				}
			}
			else if (i == 2) {
				if(j<3)
				{
					UnitNumDiv.setAttribute("id", "FirstNum" + j);
					$("#FirstNum" + j).data("numData", WordProb.firstNumberArr[j]);
				}
				if(j==3)
				{
					UnitNumDiv.setAttribute("id", "FirstNum1" + j);
					$("#FirstNum1" + j).text(".");
				}
				else if(j>3) {
					UnitNumDiv.setAttribute("id", "FirstNum" + (j-1));
					$("#FirstNum" + (j-1)).data("numData", WordProb.firstNumberArr[j]);
				}
			}
			else if (i == 3) {
				if(j<3)
				{
					UnitNumDiv.setAttribute("id", "SecondNum" + j);
					$("#SecondNum" + j).data("numData", WordProb.secondNumberArr[j]);
				}
				if(j==3)
				{
					UnitNumDiv.setAttribute("id", "SecondNum1" + j);
					$("#SecondNum1" + j).text(".");
				}
				else if(j>3) {
					UnitNumDiv.setAttribute("id", "SecondNum" + (j-1));
					$("#SecondNum" + (j-1)).data("numData", WordProb.secondNumberArr[j]);
				}
			}
			else if (i == 4) {
				if(j<3)
				{
					UnitNumDiv.setAttribute("id", "Answer" + j);
					$("#Answer" + j).data("numData", WordProb.answerArr[j]);
				}
				if(j==3)
				{
					UnitNumDiv.setAttribute("id", "Answer1" + j);
					$("#Answer1" + j).text(".");
				}
				else if(j>3) {
					UnitNumDiv.setAttribute("id", "Answer" + (j-1));
					$("#Answer" + (j-1)).data("numData", WordProb.answerArr[j]);
				}	
			}
			if (j < 3)
				UnitNumDiv.setAttribute("class","blinkClass LeftNumberStyle nopadding col-sm-2 col-lg-2 col-md-2 col-xs-2");
			else if (j == 3)
				UnitNumDiv.setAttribute("class","blinkClass decimalDiv nopadding col-sm-1 col-lg-1 col-md-1 col-xs-1");
			else
				UnitNumDiv.setAttribute("class","blinkClass RightNumberStyle nopadding col-sm-2 col-lg-2 col-md-2 col-xs-2");
		}
	}
	if (WordProb.level == 2)
		$("#UnitDiv1").css({ "display": "none" });
	$("#" + WordProb.divNameArray[blinkCtr]).addClass("blink_me");
	$("#bottomDiv").show();
}
WordProb.makeFinalAnswerChart = function () {
	document.getElementById('AnsWithUnitDiv').innerHTML = "";
	for (var i = 0; i < 3; i++)		//final answer grid
	{
		var numDiv = document.createElement("div");
		numDiv.setAttribute("id", "numAnsDiv" + i);
		if(i==1)
			numDiv.setAttribute("class", "finalAns blinkClass FinalAnsNumDecimal nopadding col-sm-2 col-lg-2 col-md-2 col-xs-2");
		else
			numDiv.setAttribute("class", "finalAns blinkClass FinalAnsNum nopadding col-sm-3 col-lg-3 col-md-3 col-xs-3 ");
		document.getElementById('AnsWithUnitDiv').appendChild(numDiv);
		if(i==1)
			$("#numAnsDiv1").text(".");
	}
	document.getElementById("numAnsDiv0").setAttribute("onclick", "WordProb.finalAns()");
}

WordProb.displayInTextBox = function (element) {//inputs the number in selected textbox when user clicks the number on numberpad.
	var number=0;
	var number2=0;
	WordProb.attemptFlag = true;
	if (!WordProb.finalAnsFlag) {
		WordProb.id = WordProb.divNameArray[blinkCtr];
		number = 1;
	}
	else {
		WordProb.id = WordProb.finalAnsDivNameArray[finalAnsBlink];
		if (finalAnsBlink == 0)
		{
			
			var decimalArray=(WordProb.answerArr+"").split(".");
			number = 3;
			number2=parseInt(decimalArray[0].split(",").join(""));
			number2=number2.toString();
		}	
		else
			number = 2;
	}
	if (WordProb.id == WordProb.finalAnsDivNameArray[finalAnsBlink]) {
		$("#buttonValue11").css("pointer-events", "auto");
		$("#buttonValue11").css("opacity", 1);
	}

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

		if ($("#" + WordProb.id).text().length == number) {
			if(!WordProb.finalAnsFlag)		//enter single number condition
				{
					if(WordProb.level==1)
						{
							$("#numberSystemDiv").css("pointer-events", "none");
							WordProb.checkAddAnswer();
						}
				else{
					$("#numberSystemDiv").css("pointer-events", "none");
					WordProb.checkSubAnswer();
					/* setTimeout(function () {
						if(blinkCtr>=9)
							$("#responseBoxDiv").show();
					
				}, 500); */
					}
				}
				else
				WordProb.checkFinalAnswer();
	}
	else if (parseInt($("#"+WordProb.id).text())==number2 && (finalAnsBlink == 0))
			WordProb.checkFinalAnswer();
}

WordProb.checkAddAnswer = function ()	//checks the inputed answer is correct or not.
{
	if ($("#" + WordProb.id).text() == $("#" + WordProb.id).data("numData")) {
		var num = 10;
			if (blinkCtr >= num && blinkCtr % 2 == 0) {
			var idNumber = WordProb.id.match(/\d+/);
			//console.log(idNumber);
			var firstNo = parseInt($("#FirstNum" + idNumber[0]).text());
			var secondNo = parseInt($("#SecondNum" + idNumber[0]).text());
			var carryNo = parseInt($("#Carry" + idNumber[0]).data("numData"));
			if ((firstNo + secondNo + carryNo) >= 10) {
				blinkCtr++;
				$("#" + WordProb.divNameArray[blinkCtr]).data("numData", "1");
				WordProb.carryFlag = true;
			}
			else {
				blinkCtr = blinkCtr + 2;
			}
		}
		else {
			blinkCtr++;
		}
		$(".blinkClass").removeClass("blink_me");
		$("#" + WordProb.divNameArray[blinkCtr]).addClass("blink_me");
			if (blinkCtr == 20)
				WordProb.finalAns();
		$("#numberSystemDiv").css("pointer-events", "auto");
	}
	else
		WordProb.wrongAnswer();
}
WordProb.checkSubAnswer = function () {
	var num = 10, num2 = 18, checkblink = 20;
	if (blinkCtr < num) {
		if ($("#" + WordProb.id).text() == $("#" + WordProb.id).data("numData")) {
			blinkCtr++;
			$("#numberSystemDiv").css("pointer-events", "auto");
		}
		else
			WordProb.wrongAnswer();
	}
	else {
		var idNumber = WordProb.id.match(/\d+/);
		console.log(idNumber);
		var firstNo = parseInt($("#FirstNum" + idNumber[0]).text());
		var secondNo = parseInt($("#SecondNum" + idNumber[0]).text());
		if (firstNo < secondNo) {
			WordProb.clickFlag = true;
		}
		else {
			WordProb.clickFlag = false;
		}
		var subAns = firstNo - secondNo;
		if ($("#" + WordProb.id).text() == subAns) {
			blinkCtr = blinkCtr + 2;
			$("#numberSystemDiv").css("pointer-events", "auto");
		}
		else
			WordProb.wrongAnswer();
	}
	WordProb.id = WordProb.divNameArray[blinkCtr];
	$(".blinkClass").removeClass("blink_me");
	$("#" + WordProb.divNameArray[blinkCtr]).addClass("blink_me");

	if (blinkCtr >= num && blinkCtr <= num2) {
		if(WordProb.id!="Answer0")
		{
		WordProb.clickFlag = false;
		WordProb.checkBorrow();
		document.getElementById("questionMsg").innerHTML = WordProb.modalData.responseMsg;
		$("#btnDiv").show();
		$("#responseBoxDiv").show();
		//alert("check borrow fun");
		}
	}
	if (blinkCtr == checkblink)
		WordProb.finalAns();
}
WordProb.checkBorrow = function () {
	var idNumber = WordProb.id.match(/\d+/);
	console.log(idNumber);
	var firstNo = parseInt($("#FirstNum" + idNumber[0]).text());
	var secondNo = parseInt($("#SecondNum" + idNumber[0]).text());
	if (firstNo < secondNo) {
		WordProb.clickFlag = true;
	}
	else {
		WordProb.clickFlag = false;
	}
}
WordProb.wrongAnswer = function () {
	setTimeout(function () {
		$("#numberSystemDiv").css("pointer-events", "auto");
		$("#" + WordProb.id).text("");
	}, 1000);
}
WordProb.finalAns = function () {
	WordProb.finalAnsFlag = true;
	$(".blinkClass").removeClass("blink_me");
	$("#" + WordProb.finalAnsDivNameArray[finalAnsBlink]).addClass("blink_me");
	WordProb.id = WordProb.finalAnsDivNameArray[finalAnsBlink];
}
WordProb.checkFinalAnswer = function () {
	/* var ans = WordProb.answerArr[0] + "" + WordProb.answerArr[1]+""+ WordProb.answerArr[2];
	var ans1 =WordProb.answerArr[4] + "" + WordProb.answerArr[5]; */
	var decimalArray=(WordProb.answerArr+"").split(".");
	for(var i=0;i<decimalArray.length;i++)
	{
		var a=decimalArray[i].split(",").join("");
		if(i==0)
			var ans=a;
		else
			var ans1=a;
	}
	
	if (parseInt(ans) == $("#" + WordProb.finalAnsDivNameArray[finalAnsBlink]).text() ||
		parseInt(ans1) == $("#" + WordProb.finalAnsDivNameArray[finalAnsBlink]).text()
	) {
		//WordProb.checkFinalAnsFlag=0;
		/* document.getElementById("playSound").src=Utils.Path+'sounds/instructions/thats_right.mp3';
		document.getElementById("playSound").play();

		WordProb.correctWrongModalShow("winEmoji.png", 2000); */
		//finalAnsBlink++;
		//	WordProb.finalAns();
		//alert("right ans");
	}
	else {
		WordProb.checkFinalAnsFlag++;
		/* document.getElementById("playSound").src=Utils.Path+'sounds/instructions/Try_again.mp3';
			document.getElementById("playSound").play();
		WordProb.correctWrongModalShow("rongAnsEmoji.png", 2000); */
		$("#buttonValue11,#buttonValue12").css("pointer-events", "none");
		$("#buttonValue11,#buttonValue12").css("opacity", 0.5);

	}
	finalAnsBlink++;
	WordProb.finalAns();
	if (finalAnsBlink == 2) {
		WordProb.attemptCount++;
		if (WordProb.checkFinalAnsFlag == 0) {
			WordProb.finalRightAns = true;
			document.getElementById("playSound").src = Utils.Path + 'sounds/instructions/thats_right.mp3';
			document.getElementById("playSound").play();
			WordProb.correctWrongModalShow("winEmoji.png", 2000);
			if (WordProb.nextQueTimer) {
				clearTimeout(WordProb.nextQueTimer);
				WordProb.nextQueTimer = null;
			}
			WordProb.nextQueTimer = setTimeout(function () {
				WordProb.nextQuestion();
			}, 2010);
		}
		else {
			scoredMarks = 0;
			document.getElementById("playSound").src = Utils.Path + 'sounds/instructions/Try_again.mp3';
			document.getElementById("playSound").play();
			WordProb.correctWrongModalShow("rongAnsEmoji.png", 2000);
			$("#" + WordProb.finalAnsDivNameArray[0]).text("");
			$("#" + WordProb.finalAnsDivNameArray[1]).text("");
			finalAnsBlink = 0;
			WordProb.checkFinalAnsFlag = 0;
			WordProb.finalAnsFlag = false;
			$(".blinkClass").removeClass("blink_me");
			$("#" + WordProb.divNameArray[blinkCtr]).addClass("blink_me");
			if (blinkCtr == 20) {
				WordProb.finalAns();
			}
		}
	}
}

WordProb.correctClick = function () {
	if (WordProb.clickFlag) {
		$("#responseBoxDiv").hide();
		WordProb.transferBorrow();
	}
	else {
		$("#btnDiv").hide();
		document.getElementById("questionMsg").innerHTML = WordProb.modalData.noBorrowmsg;
		setTimeout(function () {
			$("#responseBoxDiv").hide();
		}, 5000);
	}
}
WordProb.wrongClick = function () {
	/* $("#btnDiv").hide();
	WordProb.clickFlag = false;
	WordProb.showMsg(); */
	if (!WordProb.clickFlag) {
		$("#responseBoxDiv").hide();
	}
	else {
		$("#btnDiv").hide();
		document.getElementById("questionMsg").innerHTML = WordProb.modalData.borrowMsg;
		setTimeout(function () {
			$("#responseBoxDiv").hide();
			WordProb.transferBorrow();
		}, 5000);
	}
}
WordProb.transferBorrow = function () {
	$("#numberSystemDiv,#numAnsDiv0").css("pointer-events", "none");
	var idNumber = WordProb.id.match(/\d+/);
	var firstNo = parseInt($("#FirstNum" + idNumber[0]).text());
	firstNo = firstNo + 10;
	var number = parseInt(idNumber[0]);
		$(".blinkClass").removeClass("blink_me");
		$("#FirstNum" + (number - 1)).addClass("blink_me");
	if (WordProb.borrow1) {
		clearTimeout(WordProb.borrow1);
		WordProb.borrow1 = null;
	}
	WordProb.borrow1 = setTimeout(function () {
		$("#FirstNum" + number).text(firstNo);
		$("#FirstNum" + (number)).removeClass("blink_me");
		$("#" + WordProb.divNameArray[blinkCtr]).addClass("blink_me");
		$("#numberSystemDiv,#numAnsDiv0").css("pointer-events", "auto");
	}, 4000);
	var previousNo = parseInt($("#FirstNum" + (number - 1)).text());
	if (WordProb.borrow2) {
		clearTimeout(WordProb.borrow2);
		WordProb.borrow2 = null;
	}
	WordProb.borrow2 = setTimeout(function () {
		$("#FirstNum" + (number - 1)).text(previousNo - 1);
		$("#FirstNum" + (number - 1)).removeClass("blink_me");
		$("#FirstNum" + (number)).addClass("blink_me");
	}, 2000);
}
WordProb.nextQuestion = function () {
	clearTimeout(WordProb.borrow1);
	clearTimeout(WordProb.borrow2);
	WordProb.questionCtr++;
	clearTimeout(WordProb.nextQueTimer);
	if (WordProb.finalRightAns && WordProb.attemptCount == 1)
		scoredMarks = 10;
	else
		scoredMarks = 0;
	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();
		document.getElementById("acknowledgementDiv").innerHTML = "";
		WordProb.createAcknowledgementDivs();
	}
}

WordProb.callHome = function () {//reload.
	clearTimeout(WordProb.nextQueTimer);
	if (WordProb.homeFlag) {
		WordProb.homeFlag = false;

		/* if (!WordProb.attemptFlag) {
			scoredMarks = -1;
		} */
		if (WordProb.attemptFlag) {
			if (WordProb.finalRightAns && WordProb.attemptCount == 1)
				scoredMarks = 10;
			else
				scoredMarks = 0;
			console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
			if (Utils.mobileDeviceFlag)
				Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
		}
		$("#gamePage,#endPage").hide();
		$("#levelPage").show();
	}
	else
		location.reload();
}

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

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

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

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

/* if (previousNo == 0) {
		$("#FirstNum" + (number - 1)).text(9);
		var prePrevious = parseInt($("#FirstNum" + (number - 2)).text());
		if (prePrevious == 0) {
			$("#FirstNum" + (number - 2)).text(9);
			var prePrePrevious = parseInt($("#FirstNum"+(number-3)).text());
			$("#FirstNum" + (number - 3)).text(prePrePrevious - 1);
		}
		else {
			$("#FirstNum" + (number - 2)).text(prePrevious - 1);
		}
	}
	else */