//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 = '',scoreFlag = false;
WordProb.level=0;
var blinkCtr = 0;
var finalAnsBlink=0;
WordProb.questionCtr = 0;
WordProb.seconds=0;
WordProb.total_No_of_Questions=5;
WordProb.correctCounter=0;
WordProb.queArr=[];
WordProb.soundFlag = true;//flag for instructions.
WordProb.queArrTemp=[];
$(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,#homeAndLogoDiv").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.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("nextImg").src = Utils.Path + "images/skin/Next.png";
	document.getElementById("skipImg").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("questionDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/textBlock.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.playGame = function () {
	WordProb.questionCtr = 0;
	document.body.style.backgroundImage = "url(" + Utils.Path + "images/skin/cover_bg.png)";
	$("#coverPage").hide();
	$("#homeButton").hide();
	$("#gamePage,#homeAndLogoDiv").show();
	$("#AnswerDiv").show();
	WordProb.populate();
	WordProb.makeQuestion();
	clearInterval(WordProb.noResponseTimer);
	clearTimeout(WordProb.timeOut);
	WordProb.seconds=0;
	WordProb.startTimer();
}
WordProb.populate=function()
{
	for(var i=0;i<5;i++)
	{
		WordProb.level=Math.floor(Math.random()*2+1);
	var numArr = [];
	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 (var j = 0; j < 2; j++) {
		randomNum = Math.floor(Math.random() * num1 + num2);
		if(i==4)
			randomNum = Math.floor(Math.random() * num3 + num4);
		var splitNumber=randomNum;
		splitNumberArr=[];
		splitNumberArr = ("" + splitNumber).split("");
		while (numArr.includes(randomNum) || splitNumberArr.includes("0"))
		{
		randomNum = Math.floor(Math.random() * num1 + num2);
			if(i==4)
				randomNum = Math.floor(Math.random() * num3 + num4);
		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);
	numArr.push(i);
	WordProb.queArr[i]=numArr;
	//WordProb.queArr[i]=0;
	}	
}
WordProb.makeQuestion = function ()						//generate word Sentence
{
	WordProb.queArrTemp=[];
	for(var i=0;i<WordProb.queArr.length;i++)
		WordProb.queArrTemp.push(WordProb.queArr[i]);
	var d;
	WordProb.attemptCount = 0;//for attempt.
	scoreFlag = false;
	d = new Date();
	startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
	WordProb.numberArray = [];
	blinkCtr = 0;
	finalAnsBlink=0;
	WordProb.divNameArray=["FirstNum0","FirstNum1","FirstNum2","FirstNum3","SecondNum0","SecondNum1","SecondNum2","SecondNum3","Answer3","Carry2","Answer2","Carry1","Answer1","Carry0","Answer0"];
	if(WordProb.queArr[WordProb.questionCtr][2]==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.operator = WordProb.operatorArr[(WordProb.queArr[WordProb.questionCtr][2]) - 1];
	
$("#buttonValue11,#buttonValue12").css("pointer-events", "none");
	$("#buttonValue11,#buttonValue12").css("opacity", 0.5);
	
	
	$("#numberSystemDiv").show();
	var firstNumber=WordProb.queArr[WordProb.questionCtr][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=WordProb.queArr[WordProb.questionCtr][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.queArr[WordProb.questionCtr][2] == 1)
		var answer=firstNumber+secondNumber;
	else
		var answer=firstNumber-secondNumber;
	WordProb.answerArr=(""+answer).split("");
	var ansArraylength=0;
	if(WordProb.queArr[WordProb.questionCtr][3]==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.queArr[WordProb.questionCtr][3]==4)
	{
		if(WordProb.queArr[WordProb.questionCtr][2]==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.queArr[WordProb.questionCtr][2]==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.queArr[WordProb.questionCtr][3]==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.queArr[WordProb.questionCtr][3]==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.queArr[WordProb.questionCtr][2]==2)
			{
				$("#UnitNameDiv0").css({"display":"none"});
				$("#UnitNameDiv1").css({"border-left":  "white solid 0px"});
			}
			}
		}
		else		//numbergrid
		{
			var num=4;
			if(WordProb.queArr[WordProb.questionCtr][3]==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.queArr[WordProb.questionCtr][2] == 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.queArr[WordProb.questionCtr][2] == 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.queArr[WordProb.questionCtr][2]==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.
	document.getElementById("playSound").pause();
	clearInterval(WordProb.noResponseTimer);
	clearTimeout(WordProb.timeOut);
	WordProb.seconds=0;
	WordProb.startTimer();
	WordProb.attemptCount++;
	if(	WordProb.attemptCount==1)
		WordProb.queArrTemp.splice(WordProb.questionCtr,1);
	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
		{
			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)
			{
				if(WordProb.queArr[WordProb.questionCtr][2]==1)
				{
					$("#numberSystemDiv").css("pointer-events", "none");
					WordProb.checkAddAnswer();
				}
				else
				{
					$("#numberSystemDiv").css("pointer-events", "none");
					WordProb.checkSubAnswer();
				}
			}
		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.queArr[WordProb.questionCtr][3]==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.queArr[WordProb.questionCtr][3]==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.queArr[WordProb.questionCtr][3]==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;
		if(WordProb.divNameArray[blinkCtr]!="Answer0")
		{
			WordProb.checkBorrow();
			document.getElementById("questionMsg").innerHTML = WordProb.modalData.responseMsg;
			$("#btnDiv").show();
			$("#responseBoxDivBorrow").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()
{
	document.getElementById("playSound").pause();
	clearInterval(WordProb.noResponseTimer);
	clearTimeout(WordProb.timeOut);
	WordProb.seconds=0;
	WordProb.startTimer();
	$("#"+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()
{
	scoreFlag = true;
	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.checkFinalAnsFlag=0;
		scoredMarks = 10;
		WordProb.correctCounter++;
		WordProb.finalRightAns=true;
		document.getElementById("playSound").src=Utils.Path+'sounds/instructions/thats_right.mp3';
		document.getElementById("playSound").play();
		WordProb.correctWrongModalShow("winEmoji.png", 2000);
	}
	else
	{
		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.finalAnsFlag=false;
		$(".blinkClass").removeClass("blink_me");
		$("#" + WordProb.divNameArray[blinkCtr]).addClass("blink_me");
		if(WordProb.queArr[WordProb.questionCtr][3]==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.scoreFunction();
	if (WordProb.nextQueTimer) {
		clearTimeout(WordProb.nextQueTimer);
		WordProb.nextQueTimer = null;
	}
	WordProb.nextQueTimer = setTimeout(function () {
		WordProb.nextQuestion();
	}, 2010);
}

WordProb.correctClick = function () {
	/* if(WordProb.clickFlag)
	{ */
		$("#responseBoxDivBorrow").hide();
		WordProb.transferBorrow();
	/* }
	else{
		$("#btnDiv").hide();
		document.getElementById("questionMsg").innerHTML = WordProb.modalData.noBorrowmsg;
		setTimeout(function () {
			$("#responseBoxDivBorrow").hide();
		}, 5000);
	} */
}
WordProb.wrongClick = function () {
	/* if(!WordProb.clickFlag)
	{ */
		$("#responseBoxDivBorrow").hide();
	/* }
	else{
		$("#btnDiv").hide();

		document.getElementById("questionMsg").innerHTML = WordProb.modalData.borrowMsg;
		setTimeout(function () {
			$("#responseBoxDivBorrow").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 () {
	document.getElementById("playSound").pause();
	clearTimeout(WordProb.borrow1);
	clearTimeout(WordProb.borrow2);
	clearInterval(WordProb.noResponseTimer);
	clearTimeout(WordProb.timeOut);
	WordProb.seconds=0;
	WordProb.startTimer();
	if(WordProb.attemptFlag)
	{
		WordProb.queArr=[];
		for(var i=0;i<WordProb.queArrTemp.length;i++)
		{
			WordProb.queArr.push(WordProb.queArrTemp[i]);
		}
	}
	if(scoreFlag!=true)
	{
		WordProb.questionCtr++;
	}
	if(WordProb.queArr.length==0)
	{
		WordProb.gameOver();
	}
	else if(WordProb.questionCtr==WordProb.queArr.length)
	{
		clearInterval(WordProb.noResponseTimer);
		document.getElementById("responseBoxDiv").style.display="block";
		document.getElementById("NoA").innerHTML=WordProb.AssessmentModel.no;
		document.getElementById("YesA").innerHTML=WordProb.AssessmentModel.yes;
		document.getElementById("questionMsgA").innerHTML=WordProb.AssessmentModel.responseMsg;
	}
	else
	{
		WordProb.initializeVariables();
		WordProb.makeQuestion();
	}
}
WordProb.scoreFunction=function()
{
console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	if (Utils.mobileDeviceFlag)
		Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
}
WordProb.gameOver=function()
{
	document.getElementById("playSound").pause();
	clearInterval(WordProb.noResponseTimer);
	clearTimeout(WordProb.timeOut);
	WordProb.seconds=0;
	$("#gamePage").hide();
	$("#endPage").show();
	$("#responseBoxDiv").hide();
	$("#nextImg").addClass("blink_me");
	document.getElementById("acknowledgementDiv").innerHTML="";
	WordProb.createAcknowledgementDivs();
	WordProb.createStars();
	WordProb.giveStars();
}
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.showSkippedQuestions=function()
{
	document.getElementById("responseBoxDiv").style.display="none";
	WordProb.questionCtr = 0;
	WordProb.makeQuestion();
}

//function which creates star divs
WordProb.createStars=function()
{
	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/star1.png");
		$(newDiv).append(newImage);
		$("#starDiv").append(newDiv);
	}
};

WordProb.giveStars=function()
{
	var fractionVar,i,temp; 
	var numberOfStars=0;
	ans=WordProb.total_No_of_Questions/5;
	temp=WordProb.correctCounter/ans;
	numberOfStars=Math.floor(temp);
	temp=Math.round(temp);
	console.log(numberOfStars);
	console.log(temp);
	for(i=1;i<=Math.floor(numberOfStars);i++)
	document.getElementById("starImg"+i).setAttribute("src",Utils.Path+"images/star2.png");
	/* if(temp>numberOfStars)
	document.getElementById("starImg"+i).setAttribute("src",Utils.Path+"images/halfStar.png"); */
	$("#starDiv").css("visibility","visible");
	if(numberOfStars!=0)
	{
	document.getElementById("playSound").src=Utils.Path+"sounds/instructions/"+"Star"+numberOfStars+".mp3";
	document.getElementById("playSound").play();
	}
	console.log(WordProb.correctCounter,WordProb.total_No_of_Questions,"1");
	if(Utils.mobileDeviceFlag)
		Android.StudentCertification(WordProb.correctCounter,WordProb.total_No_of_Questions,"1");
};

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

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);
			if(WordProb.timeOut)
			{
				clearTimeout(WordProb.timeOut);
				WordProb.timeOut=null;
			}
				WordProb.timeOut=setTimeout(function()
			{
				WordProb.seconds=0;
				WordProb.startTimer();
			},2000);
		}
	},1000);
};