//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 = '';
WordProb.level=0;
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 () {
	$("#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 answer 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("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("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.divNameArray=["FirstNum0","FirstNum1","FirstNum2","FirstNum3","SecondNum0","SecondNum1","SecondNum2","SecondNum3","Answer3","Carry2","Answer2","Carry1","Answer1","Carry0","Answer0"];
	WordProb.homeFlag= true;
	WordProb.level = parseInt(document.getElementById(level).getAttribute("data"));
	
	WordProb.initializeVariables();
	WordProb.playGame();
}

WordProb.playGame = function () {
	WordProb.questionCtr = 0;
	$("#coverPage").hide();
	$("#levelPage").hide();
	$("#gamePage").show();
	$("#AnswerDiv").show();
	if(WordProb.level==1)
	{
		$("#operatorDiv").text(WordProb.operatorArr[0]);
		var positionArray=[4,0];
		for(var i=0;i<positionArray.length;i++)
			WordProb.divNameArray.splice(positionArray[i],1);
	}
	else
	{
		$("#operatorDiv").text(WordProb.operatorArr[1]);
	}
	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 = 899;
			num2 = 100;
			num3 = 89;
			num4 = 10;
			$("#carryDiv").show();
		} break;
		case 2: {			//for subtraction
			num1 = 6999;
			num2 = 2000;
			num3 = 699;
			num4 = 200;
			$("#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 subUnit1="";
	for(var k=0;k<WordProb.firstNumberArr.length;k++)
		subUnit1=(""+subUnit1+WordProb.firstNumberArr[k]);

	var secondNumber=numArr[1];
	console.log(secondNumber);
	WordProb.secondNumberArr=(""+secondNumber).split("");
	var subUnit2="";
	for(var k=0;k<WordProb.secondNumberArr.length;k++)
		subUnit2=(""+subUnit2+WordProb.secondNumberArr[k]);
		
	if (WordProb.level == 1)
		var answer=firstNumber+secondNumber;
	else
		var answer=firstNumber-secondNumber;
	WordProb.answerArr=(""+answer).split("");
	var ansArraylength=0;
	if(WordProb.questionCtr==4)
		ansArraylength=2;
	else
		ansArraylength=3
	if(WordProb.answerArr!=ansArraylength)
	{
		while(WordProb.answerArr.length!=ansArraylength+1)
		{
			WordProb.answerArr.splice(0,0,0)
		}
	}
	document.getElementById("questionText").innerHTML = subUnit1+" "+ WordProb.unitsArray[WordProb.questionCtr][1]+" "+ WordProb.operator+" " + subUnit2+" "+ WordProb.unitsArray[WordProb.questionCtr][1]+" ";
		
if(WordProb.questionCtr==4)
	{
		if(WordProb.level==1)
			var positionArray=[7,6,5,2];
		else
			var positionArray=[9,8,7,3];
		for(var i=0;i<positionArray.length;i++)
			WordProb.divNameArray.splice(positionArray[i],1);
	}
	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);
		if(i==0)
		{
			for(var j=0;j<2;j++)
			{
			var UnitNameDiv = document.createElement("div");
			UnitNameDiv.setAttribute("id","UnitNameDiv"+j);
			if(WordProb.level==1)
			{
			if(j==0){
				
				UnitNameDiv.setAttribute("class","unitNameStyle nopadding col-sm-2 col-lg-2 col-md-2 col-xs-2 col-xs-offset-1 col-md-offset-1 col-lg-offset-1 col-sm-offset-1");
			}
			else
			{
				UnitNameDiv.setAttribute("class","unitNameStyle nopadding col-sm-6 col-lg-6 col-md-6 col-xs-6");
				if(WordProb.questionCtr==4)
				UnitNameDiv.setAttribute("class","unitNameStyle nopadding col-sm-4 col-lg-4 col-md-4 col-xs-4");
			}
		}
		else
		{
			UnitNameDiv.setAttribute("class","unitNameStyle nopadding col-sm-8 col-lg-8 col-md-8 col-xs-8  col-xs-offset-1 col-md-offset-1 col-lg-offset-1 col-sm-offset-1");
			if(WordProb.questionCtr==4)
			UnitNameDiv.setAttribute("class","unitNameStyle nopadding col-sm-6 col-lg-6 col-md-6 col-xs-6  col-xs-offset-1 col-md-offset-1 col-lg-offset-1 col-sm-offset-1");
		}
			document.getElementById("UnitDiv"+i).appendChild(UnitNameDiv);
			$("#UnitNameDiv"+j).text(WordProb.unitsArray[WordProb.questionCtr][j]);
			if(WordProb.level==2)
			{
				$("#UnitNameDiv0").css({"display":"none"});
				$("#UnitNameDiv1").css({"border-left":  "white solid 0px"});
			}
			}
		}
		else		//numbergrid
		{
			var num=4;
			if(WordProb.questionCtr==4)
			var num=3;
			for(var j=0;j<num;j++)
			{
				var UnitNumDiv = document.createElement("div");
				document.getElementById("UnitDiv"+i).appendChild(UnitNumDiv);
				if(i==1){
					UnitNumDiv.setAttribute("id","Carry"+j);
					$("#Carry"+j).data("numData","0");	
				}
				else if(i==2)
				{
					if (WordProb.level == 1)
					{
						if(j>0)
						UnitNumDiv.setAttribute("id","FirstNum"+j);
						$("#FirstNum"+j).data("numData",WordProb.firstNumberArr[j-1]);
					}
					else
					{
						if(j>=0)
							UnitNumDiv.setAttribute("id","FirstNum"+j);
						$("#FirstNum"+j).data("numData",WordProb.firstNumberArr[j]);
					}
				}
				else if(i==3)
				{
					if (WordProb.level == 1)
					{
						if(j>0)
						UnitNumDiv.setAttribute("id","SecondNum"+j);
						$("#SecondNum"+j).data("numData",WordProb.secondNumberArr[j-1]);
					}
					else
					{
						if(j>=0)
						UnitNumDiv.setAttribute("id","SecondNum"+j);
						$("#SecondNum"+j).data("numData",WordProb.secondNumberArr[j]);
					}
					
				}	
				else
				{
					UnitNumDiv.setAttribute("id","Answer"+j);
					$("#Answer"+j).data("numData",WordProb.answerArr[j]);
					
				}
				if(j<1)
					UnitNumDiv.setAttribute("class","blinkClass LeftNumberStyle nopadding col-sm-2 col-lg-2 col-md-2 col-xs-2 col-xs-offset-1 col-md-offset-1 col-lg-offset-1 col-sm-offset-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"});	
		$(".LeftNumberStyle").css({ "border-right":"white solid 0px"});	
	}	
	$("#" + WordProb.divNameArray[blinkCtr]).addClass("blink_me");
	$("#bottomDiv").show();
}
WordProb.makeFinalAnswerChart = function ()				
{
	document.getElementById('AnsWithUnitDiv').innerHTML="";
	for(var i=0;i<2;i++)		//final answer grid
	{
		var numDiv = document.createElement("div");
		numDiv.setAttribute("id","numAnsDiv"+i);
		numDiv.setAttribute("class","finalAns blinkClass FinalAnsNum nopadding col-sm-3 col-lg-3 col-md-3 col-xs-3 col-xs-offset-1 col-md-offset-1 col-lg-offset-1 col-sm-offset-1");
		document.getElementById('AnsWithUnitDiv').appendChild(numDiv);
		
		var UnitDiv = document.createElement("div");
		UnitDiv.setAttribute("id","UnitAnsDiv"+i);
		UnitDiv.setAttribute("class","finalAns nopadding col-sm-2 col-lg-2 col-md-2 col-xs-2");
		document.getElementById('AnsWithUnitDiv').appendChild(UnitDiv);
		$("#UnitAnsDiv"+i).text(WordProb.unitsArray[WordProb.questionCtr][i]);
	}
	document.getElementById("numAnsDiv0").setAttribute("onclick","WordProb.finalAnsClick()");
}

WordProb.displayInTextBox = function (element) {//inputs the number in selected textbox when user clicks the number on numberpad.
	var number=0;
	var number2=0;
	var ans1="";
	WordProb.attemptFlag = true;
	if(!WordProb.finalAnsFlag){
		WordProb.id = WordProb.divNameArray[blinkCtr];
		number = 1;
	}
	else
	{
		WordProb.id =WordProb.finalAnsDivNameArray[finalAnsBlink];
		if(finalAnsBlink==0)
			number = 1;
		else
		{
			/* number = 3;
			if(WordProb.questionCtr==4)
			number = 2; */
			
			for(var i=1;i<WordProb.answerArr.length;i++)
			{
				ans1=(""+ans1+WordProb.answerArr[i]);
			}
			number=ans1.length;
			number2=parseInt(ans1);
			number2=number2.toString();
		}
			
	}
	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		// enter final ans condition
			{
				finalAnsBlink++;
				WordProb.finalAns();
				if(finalAnsBlink==2)
					WordProb.checkFinalAnswer();
			}
	}
	else if (parseInt($("#" + WordProb.id).text()) == number2)
			WordProb.checkFinalAnswer();
}

WordProb.checkAddAnswer = function ()	//checks the inputed answer is correct or not.
{
	if ($("#" + WordProb.id).text() == $("#" + WordProb.id).data("numData"))
	{
		var num=5;
		if(WordProb.questionCtr==4)
			var num=3;
			
		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(WordProb.questionCtr==4)
			{
				if(blinkCtr==10)
				WordProb.finalAns();
			}
		else
		if(blinkCtr==14)
			WordProb.finalAns();
		$("#numberSystemDiv").css("pointer-events", "auto");
	}
	else
		WordProb.wrongAnswer();
}
WordProb.checkSubAnswer = function ()
{
	var num=8,num2=15,checkblink=16;
	if(WordProb.questionCtr==4)
		var num=6,num2=11,checkblink=12;
	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)
		{
			/* document.getElementById("playSound").src=Utils.Path+'sounds/instructions/thats_right.mp3';
			document.getElementById("playSound").play(); */
			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)
	{
		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 ()
{
/* 	document.getElementById("playSound").src=Utils.Path+'sounds/instructions/Try_again.mp3';
			document.getElementById("playSound").play(); */
	setTimeout(function () {
		$("#numberSystemDiv").css("pointer-events", "auto");
		$("#" + WordProb.id).text("");
	}, 1000);
}
WordProb.finalAnsClick=function()
{
	$("#"+WordProb.finalAnsDivNameArray[0]).text("");
	$("#"+WordProb.finalAnsDivNameArray[1]).text("");
	finalAnsBlink=0;
	$("#buttonValue11,#buttonValue12").css("pointer-events", "none");
	$("#buttonValue11,#buttonValue12").css("opacity", 0.5);
	WordProb.finalAns();
}
WordProb.finalAns=function()
{
	WordProb.finalAnsFlag = true;
	$(".blinkClass").removeClass("blink_me");
	$("#"+WordProb.finalAnsDivNameArray[finalAnsBlink]).addClass("blink_me");
	WordProb.id = WordProb.finalAnsDivNameArray[finalAnsBlink];
}
WordProb.checkFinalAnswer=function()
{
	WordProb.attemptCount++;
	var ans=WordProb.answerArr[0];
	var ans1=WordProb.answerArr[1]+""+WordProb.answerArr[2]+""+WordProb.answerArr[3];
	if(parseInt(ans)==$("#"+WordProb.finalAnsDivNameArray[0]).text() &&
	parseInt(ans1)==$("#"+WordProb.finalAnsDivNameArray[1]).text()
	)
	{
		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
	{
		WordProb.checkFinalAnsFlag++;
		scoredMarks = 0;
		document.getElementById("playSound").src=Utils.Path+'sounds/instructions/Try_again.mp3';
		document.getElementById("playSound").play();
		WordProb.correctWrongModalShow("rongAnsEmoji.png", 2000);

		finalAnsBlink=0;
		WordProb.checkFinalAnsFlag=0;
		WordProb.finalAnsFlag=false;
		$(".blinkClass").removeClass("blink_me");
		$("#" + WordProb.divNameArray[blinkCtr]).addClass("blink_me");
		if(WordProb.questionCtr==4)
			{
				if(blinkCtr==10 || blinkCtr==12)
				WordProb.finalAns();
			}
		else
		if(blinkCtr==14 || blinkCtr==16)
			WordProb.finalAns();
		if (WordProb.wrongAnsTimer) {
			clearTimeout(WordProb.wrongAnsTimer);
			WordProb.wrongAnsTimer = null;
		}
		WordProb.wrongAnsTimer = setTimeout(function () {
			$("#"+WordProb.finalAnsDivNameArray[0]).text("");
			$("#"+WordProb.finalAnsDivNameArray[1]).text("");
		}, 2000);
		$("#buttonValue11,#buttonValue12").css("pointer-events", "none");
	$("#buttonValue11,#buttonValue12").css("opacity", 0.5);
	
	}
}

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").hide();
	$("#levelPage").show();
	$("#endPage").hide();
}
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.gotoHelp = function () {//help for multiplication.
	var i, ctr = 0;
	for (i = 4; i > 2; i--) {
		for (j = 2; j >= 1; j--) {
			ctr++;
			document.getElementById("multDiv" + ctr).innerHTML = eval("splitNum" + i) + " × " + eval("splitNum" + j);
		}
		j = 2;
	}
	$(".arrowDivs").css("visibility", "visible");
}

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

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

WordProb.playAgain = function () {
	WordProb.soundFlag = true;
	$("#acknowledgementDiv").hide();
	$("#endPage").hide();
	$("#gamePage").show();
	//WordProb.nextQuestion();
	WordProb.divNameArray=["FirstNum0","FirstNum1","FirstNum2","FirstNum3","SecondNum0","SecondNum1","SecondNum2","SecondNum3","Answer3","Carry2","Answer2","Carry1","Answer1","Carry0","Answer0"];
	WordProb.initializeVariables();
	WordProb.playGame();
}

