//startingDate:15-3-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 given1, given2, toFind, splitNum1, splitNum2, splitNum3, splitNum4, unit, digit;
var blinkCtr = 0, remainder;
WordProb.questionCtr = 0;
WordProb.correctCnt = 0;
WordProb.skipCtr = 0;
WordProb.seconds = 0;
WordProb.instrFlag = true;
WordProb.directAnsFlag = false;
WordProb.questionArr = [];
$(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.setAllImages();
	WordProb.createTableDivs();
	WordProb.createOperatorSpans();
	WordProb.createStars();
	//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.remainderDivFlag = true;//for creating remainder subdivs.
	digitCtr = 0;//for counting the digits of divident.
	traverse = 0;
	WordProb.stepCtr = 1;//for counting division steps.
	WordProb.highlighter = 1;//for highlighting the divident numbers.
	WordProb.currNum = '';
	remainder = '';
	WordProb.lenArr = [];
	WordProb.randomNumArr = [];
	WordProb.editFieldArr = [];//array for divs to be highlighted.
	WordProb.helpFlag = true;
	WordProb.soundFlag = true;
	WordProb.offsetFlag = true;
	WordProb.eraseFlag = false;
}
WordProb.setAllImages = function () {
	document.getElementById("homeImage").src = Utils.Path + "images/skin/Home.png";
	document.getElementById("next").src = Utils.Path + "images/skin/Skip.png";
	document.getElementById("nextGame").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("questionText").style.backgroundImage = "url(" + Utils.Path + "images/skin/textBlock.png)";
	document.getElementById("questionDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/notebook2.png)";
	document.getElementById("innerDiv").style.backgroundImage = "url(" + Utils.Path + "images/skin/notebook.png)";
	document.getElementById("whatWeKnow").innerHTML = WordProb.hardcodedData.given;
	document.getElementById("findDiv").innerHTML = WordProb.hardcodedData.toFind;
	//document.getElementById("whichWordDiv").innerHTML = WordProb.hardcodedData.whichWord;	
	document.getElementById("whichOperatorDiv").innerHTML = WordProb.hardcodedData.whichOpr;
	document.getElementById("continue").src = Utils.Path + "images/skin/continue.png";
	document.getElementById("helpBtn").src = Utils.Path + "images/skin/help.png";
	document.getElementById("gameOver").innerHTML = WordProb.hardcodedData.gameOver;
}

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/star5.png");
		$(newDiv).append(newImage);
		$("#starDiv").append(newDiv);
	}
	//$("#starDiv").css("display","none");
};
WordProb.playGame = function () {
	WordProb.level = 4;
	WordProb.questionCtr = 0;
	$("#coverPage").hide();
	$("#levelPage").hide();
	$("#gamePage").show();
	document.body.style.backgroundImage = "url(" + Utils.Path + "images/skin/Bg.png)";
	WordProb.popNumbers();
	WordProb.showCalculation();
}

WordProb.popNumbers = function () {
	var carryCtr = 0, borrowCtr = 0, oneCtr = 0, twoCtr = 0, noCarryCtr = 0, noBorrowCtr = 0;
	for (k = 0; k < 5; k++) {
		var questionObj = {}, numArr = [];
		level = 3;
		operator = "÷";
		randomDivisor = Math.floor(Math.random() * 19 + 2);
		randomAns = Math.floor(Math.random() * 40 + 11);
		divident = randomDivisor * randomAns;
		WordProb.answer = randomAns;
		randomQuestion = Math.floor(Math.random() * (WordProb.questions[level].data.length));
		while (WordProb.randomNumArr.includes(randomQuestion))
			randomQuestion = Math.floor(Math.random() * (WordProb.questions[level].data.length));
		WordProb.randomNumArr.push(randomQuestion)
		questionObj["level"] = level;
		questionObj["operator"] = operator;
		questionObj["divident"] = divident;
		questionObj["divisor"] = randomDivisor;
		questionObj["answer"] = randomAns;
		questionObj['randomQue'] = randomQuestion;
		WordProb.questionArr.push(questionObj);
		var result = WordProb.displayQuestion(k);
		questionObj["question"] = result;
	}
	WordProb.totalQue = WordProb.questionArr.length;
	//console.log(WordProb.questionArr);
}

WordProb.displayQuestion = function (queCount)						//generate word Sentence
{
	var randomPerson, randomObject, personArr = [], numArr = [], d;
	WordProb.numberArray = [];
	level = WordProb.questionArr[queCount].level;
	randomQuestion = WordProb.questionArr[queCount].randomQue;
	WordProb.divident = WordProb.questionArr[queCount].divident;
	WordProb.divisor = WordProb.questionArr[queCount].divisor;
	WordProb.currentObject = WordProb.questions[level].data[randomQuestion];
	WordProb.sentence = WordProb.currentObject.question;


	given1 = WordProb.currentObject.given[0];
	given2 = WordProb.currentObject.given[1];
	toFind = WordProb.currentObject.toFind;

	//replaces special characters with values.
	for (i = 0; i < 3; i++) {
		//console.log(WordProb.currentObject);
		randomPerson = Math.floor(Math.random() * WordProb.currentObject.subject.length);
		personArr.push(randomPerson);
		if (i == 0) {
			if (randomQuestion == 5 || randomQuestion == 1) {
				given1 = given1.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
				toFind = toFind.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
				WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subject'][randomPerson]);
				WordProb.sentence = WordProb.sentence.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
			}
			given1 = given1.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
			if (randomQuestion == 3 || randomQuestion == 4)
				WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subject'][randomPerson]);
			// given1 = given1.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subjectPlural'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
		}
		else if (i == 1) {
			given1 = given1.replace("$", WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace("$", WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace("$", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("$", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("$", WordProb.currentObject['subject'][randomPerson]);
		}
		else if (i == 2) {
			given1 = given1.replace("^", WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace("^", WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace("^", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("^", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("^", WordProb.currentObject['subject'][randomPerson]);
		}

		WordProb.currentObject.subject.splice(randomPerson, 1);
	}

	randomObject = Math.floor(Math.random() * WordProb.currentObject.object.length);
	if (randomQuestion <= 4) {
		given1 = given1.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
		given2 = given2.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
		toFind = toFind.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
	}
	else {
		given1 = given1.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
		given2 = given2.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
		toFind = toFind.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
	}

	WordProb.sentence = WordProb.sentence.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
	//WordProb.sentence = WordProb.sentence.replace(/~/gi, WordProb.currentObject['object'][randomObject]);

	randomUnit = Math.floor(Math.random() * WordProb.currentObject.unit.length);
	given1 = given1.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	given2 = given2.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	toFind = toFind.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	WordProb.sentence = WordProb.sentence.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);

	// $("#multCalcDiv").show();
	//document.getElementById("divisor").innerHTML = randomDivisor;
	//document.getElementById("divident").innerHTML = divident;
	if (randomQuestion == 2 || randomQuestion == 5) {
		given1 = given1.replace("!", WordProb.divisor);
		given1 = given1.replace("!", WordProb.divident);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divisor);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divident);

	}
	else {
		given1 = given1.replace("!", WordProb.divident);
		given1 = given1.replace("!", WordProb.divisor);

		//given2 = given2.replace("!", WordProb.number2);
		toFind = toFind.replace("!", WordProb.divisor);
		given2 = given2.replace("!", WordProb.divisor);


		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divident);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divisor);
	}
	return WordProb.sentence;
}

//onclick of continue.
WordProb.showCalculation = function () {

	blinkCtr = 0;
	var d = new Date();
	startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();

	$("#questionText").text(WordProb.questionArr[WordProb.questionCtr].question);

	WordProb.divisor = WordProb.questionArr[WordProb.questionCtr].divisor;
	WordProb.divident = WordProb.questionArr[WordProb.questionCtr].divident;
	WordProb.answer = WordProb.questionArr[WordProb.questionCtr].answer;
	WordProb.level = (WordProb.questionArr[WordProb.questionCtr].level) + 1;
	if (String(WordProb.divident).length - String(WordProb.answer).length == 1)
		WordProb.answer = "0" + WordProb.answer;
	else
		if (String(WordProb.divident).length - String(WordProb.answer).length == 2)
			WordProb.answer = "00" + WordProb.answer;

	$("#buttonValue11").css("pointer-events", "none");
	$("#buttonValue11").css("opacity", 0.5);
	$("#buttonValue12").css("opacity", 0.5);
	WordProb.counter++;
	document.getElementById("playSound").pause();
	$("#continueDiv").hide();
	$(".input").empty();
	$("#ansStep").show();
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").hide();
	document.getElementById("finalAnsText").innerHTML = WordProb.hardcodedData.finalAns;
	$("#questionDiv").hide();
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").hide();
	$("#AnswerDiv").show();
	$("#nextDiv").show();
	//$("#helpDiv").show(); 	


	document.getElementById("finalAnsText").innerHTML = WordProb.hardcodedData.finalAns;
	WordProb.createSpans("divident", String(WordProb.divident).length, "dividentSpan", WordProb.divident, true, 1);
	//WordProb.createSpans("divisor", String(randomDivisor).length, "divisorSpan", randomDivisor, true, 1);
	WordProb.editFieldArr.push("divisor");
	document.getElementById("divisor").setAttribute("data", WordProb.divisor);
	WordProb.createSpans("divisonAnsDiv", String(WordProb.answer).length, "ansSpan", WordProb.answer, false, 1);
	$("#" + WordProb.editFieldArr[blinkCtr]).addClass("blink_me");
	WordProb.id = WordProb.editFieldArr[blinkCtr];
	if (WordProb.instrFlag) {
		src = Utils.Path + "sounds/instructions/instr.mp3";
		WordProb.loadmetaDataFlag = true;
		WordProb.getDuration(src);
		WordProb.instrFlag = false;
	}
	else
		WordProb.startTimer();
}
WordProb.getDuration = function (sound) {
	var duration = 0;
	$('#playSound').prop('src', sound);
	if (WordProb.loadmetaDataFlag) {
		$('#playSound').on("loadedmetadata", function () {
			WordProb.loadmetaDataFlag = false;
			$('#playSound').unbind("loadedmetadata");
			duration = $('#playSound').prop('duration');
			WordProb.playInstr(duration);
		}
		);
	}
	else
		$('#playSound').unbind("loadedmetadata");
}
WordProb.playInstr = function (duration) {
	document.getElementById("playSound").play();
	WordProb.instrTime = setTimeout(function () {
		WordProb.startTimer();
	}, 1000 * duration);
}

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


WordProb.makeQuestion = function ()						//generate word Sentence
{
	WordProb.tempArr = [];
	$("#questionDiv").show();
	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();
	}

	randomDivisor = Math.floor(Math.random() * 19 + 2);
	randomAns = Math.floor(Math.random() * 40 + 11);
	WordProb.divident = randomDivisor * randomAns;
	//WordProb.editFieldArr = ["t1", "u1", "t2", "u2", "a2", "c1", "a1", "finalAns"];
	WordProb.answer = randomAns;
	document.getElementById("finalAns").setAttribute("data", WordProb.answer);
	WordProb.divisor = randomDivisor;
	if (String(WordProb.divident).length - String(WordProb.answer).length == 1)
		WordProb.answer = "0" + WordProb.answer;
	else
		if (String(WordProb.divident).length - String(WordProb.answer).length == 2)
			WordProb.answer = "00" + WordProb.answer;
	//console.log(WordProb.answer);
	randomQuestion = Math.floor(Math.random() * (WordProb.questions[WordProb.level - 1].data.length));
	while (WordProb.questionArr.includes(randomQuestion))
		randomQuestion = Math.floor(Math.random() * (WordProb.questions[WordProb.level - 1].data.length));
	WordProb.questionArr.push(randomQuestion)
	temp = WordProb.questions[WordProb.level - 1].data[randomQuestion];
	//console.log(temp);
	WordProb.currentObject = JSON.parse(JSON.stringify(WordProb.questions[WordProb.level - 1].data[randomQuestion]));
	WordProb.sentence = WordProb.currentObject.question;
	given1 = WordProb.currentObject.given[0];
	given2 = WordProb.currentObject.given[1];
	toFind = WordProb.currentObject.toFind;

	//if (WordProb.sentence.indexOf('@') != -1)							//replace @ with first person
	//replaces special characters with values.
	for (i = 0; i < 3; i++) {
		//console.log(WordProb.currentObject);
		randomPerson = Math.floor(Math.random() * WordProb.currentObject.subject.length);
		personArr.push(randomPerson);
		if (i == 0) {
			if (randomQuestion == 5 || randomQuestion == 1) {
				given1 = given1.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
				toFind = toFind.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
				WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subject'][randomPerson]);
				WordProb.sentence = WordProb.sentence.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
			}
			given1 = given1.replace(/@/gi, WordProb.currentObject['subjectPlural'][randomPerson]);
			if (randomQuestion == 3 || randomQuestion == 4)
				WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subject'][randomPerson]);
			// given1 = given1.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("@", WordProb.currentObject['subjectPlural'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace(/@/gi, WordProb.currentObject['subject'][randomPerson]);
		}
		else if (i == 1) {
			given1 = given1.replace("$", WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace("$", WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace("$", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("$", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("$", WordProb.currentObject['subject'][randomPerson]);
		}
		else if (i == 2) {
			given1 = given1.replace("^", WordProb.currentObject['subject'][randomPerson]);
			given2 = given2.replace("^", WordProb.currentObject['subject'][randomPerson]);
			toFind = toFind.replace("^", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("^", WordProb.currentObject['subject'][randomPerson]);
			WordProb.sentence = WordProb.sentence.replace("^", WordProb.currentObject['subject'][randomPerson]);
		}

		WordProb.currentObject.subject.splice(randomPerson, 1);
	}

	randomObject = Math.floor(Math.random() * WordProb.currentObject.object.length);
	if (randomQuestion <= 4) {
		given1 = given1.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
		given2 = given2.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
		toFind = toFind.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
	}
	else {
		given1 = given1.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
		given2 = given2.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
		toFind = toFind.replace(/~/gi, WordProb.currentObject['object'][randomObject]);
	}

	WordProb.sentence = WordProb.sentence.replace(/~/gi, WordProb.currentObject['objectPlural'][randomObject]);
	//WordProb.sentence = WordProb.sentence.replace(/~/gi, WordProb.currentObject['object'][randomObject]);

	randomUnit = Math.floor(Math.random() * WordProb.currentObject.unit.length);
	given1 = given1.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	given2 = given2.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	toFind = toFind.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);
	WordProb.sentence = WordProb.sentence.replace(/#/gi, WordProb.currentObject['unit'][randomUnit]);

	// $("#multCalcDiv").show();
	//document.getElementById("divisor").innerHTML = randomDivisor;
	//document.getElementById("divident").innerHTML = divident;
	if (randomQuestion == 2 || randomQuestion == 5) {
		given1 = given1.replace("!", WordProb.divisor);
		given1 = given1.replace("!", WordProb.divident);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divisor);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divident);

	}
	else {
		given1 = given1.replace("!", WordProb.divident);
		given1 = given1.replace("!", WordProb.divisor);

		//given2 = given2.replace("!", WordProb.number2);
		toFind = toFind.replace("!", WordProb.divisor);
		given2 = given2.replace("!", WordProb.divisor);


		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divident);
		WordProb.sentence = WordProb.sentence.replace("!", WordProb.divisor);
	}
	// $("#numberSystemDiv").show();
	//document.getElementById("questionText").innerHTML = WordProb.divident + " " + WordProb.operator + " " + randomDivisor;
	splitNum1 = Math.floor(WordProb.number1 / 10) * 10;
	splitNum2 = WordProb.number1 % 10;
	splitNum3 = Math.floor(WordProb.number2 / 10) * 10;
	splitNum4 = WordProb.number2 % 10;
	//WordProb.createSubAnsDivs();
	//WordProb.gotoHelp();
	//WordProb.showCalculation();
	WordProb.createSpans("divident", String(WordProb.divident).length, "dividentSpan", WordProb.divident, true, 1);
	//WordProb.createSpans("divisor", String(randomDivisor).length, "divisorSpan", randomDivisor, true, 1);
	WordProb.editFieldArr.push("divisor");
	document.getElementById("divisor").setAttribute("data", WordProb.divisor);
	WordProb.createSpans("divisonAnsDiv", String(WordProb.answer).length, "ansSpan", WordProb.answer, false, 1);
	$("#" + WordProb.editFieldArr[blinkCtr]).addClass("blink_me");
	WordProb.id = WordProb.editFieldArr[blinkCtr];
	WordProb.hindiText = WordProb.sentence.split(' ');
	WordProb.tempArr.push(given1);
	WordProb.tempArr.push(given2);
	WordProb.tempArr.push(toFind);
	WordProb.createEnglishSentence(questionText, WordProb.hindiText.length);
}


//function for creating subdivs in multiplication and remainder divs.
WordProb.createSpans = function (outerDiv, noOfSpans, id, number, flag, num) {
	for (i = num; i <= noOfSpans; i++) {
		span = document.createElement("DIV")
		span.setAttribute("id", id + i);
		if (outerDiv == "multiplication" + WordProb.stepCtr) {
			if (i == 1)
				if (String(number).length < String(parseInt(WordProb.currNum)).length)
					span.setAttribute("class", "nopadding spans editField singleLetter col-xs-2 col-md-2 col-lg-2 col-sm-2 col-xs-offset-2 col-md-offset-2 col-lg-offset-2 col-sm-offset-2");
				else
					span.setAttribute("class", "nopadding spans editField singleLetter col-xs-2 col-md-2 col-lg-2 col-sm-2");
			else
				span.setAttribute("class", "nopadding spans editField singleLetter col-xs-2 col-md-2 col-lg-2 col-sm-2");
		}
		else
			span.setAttribute("class", "nopadding spans editField singleLetter col-xs-2 col-md-2 col-lg-2 col-sm-2");
		$(span).prop("data", String(number)[i - 1]);
		span.style.pointerEvents = "none";
		if (flag == true && outerDiv != "remainder" + WordProb.stepCtr)
			WordProb.editFieldArr.push(id + i);
		document.getElementById(outerDiv).appendChild(span)
	}
	if (flag == true && outerDiv == "remainder" + WordProb.stepCtr) {
		for (var j = noOfSpans; j >= num; j--) {
			WordProb.editFieldArr.push(id + j);
		}
	}
}
WordProb.displayInTextBox = function (element) {//inputs the number in selected textbox when user clicks the number on numberpad.
	var number, flag = false;
	WordProb.eraseFlag = true;
	document.getElementById("playSound").pause();
	WordProb.clearSound();
	WordProb.startTimer();
	$("#buttonValue11").css("pointer-events", "auto");
	$("#buttonValue11").css("opacity", 1);
	if ($("#" + WordProb.id).hasClass("singleLetter")) {
		number = 1;
	} else if (WordProb.id == "finalAns") {
		number = String(WordProb.answer).length;
	}
	else if (WordProb.id == "divisor") {
		number = String(WordProb.divisor).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");
	var data;
	WordProb.checkFlag = false;
	if (!(WordProb.directAnsFlag)) {
		WordProb.highlightTime = setTimeout(function () {
			$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
			$("#" + WordProb.id).removeClass("blink_me");

			if ($("#" + WordProb.id).parent()[0].id == "divident") {
			}
			blinkCtr++;
			multiplication = parseInt($("#" + WordProb.id).prop("data"));
			if (multiplication != 0 && $("#" + WordProb.id).parent()[0].id == "divisonAnsDiv") {
				WordProb.currMultiplier = multiplication;
				WordProb.createSpans("multiplication" + WordProb.stepCtr, String(multiplication * WordProb.divisor).length, "multSpan" + WordProb.stepCtr, multiplication * WordProb.divisor, true, 1)
				$("#solutionStep" + WordProb.stepCtr).css("visibility", "visible");

			}
			else if ($("#" + WordProb.id).parent()[0].id == ("multiplication" + WordProb.stepCtr)) {
				remainder = WordProb.currNum - WordProb.currMultiplier * WordProb.divisor;
				if (String(parseInt(WordProb.currNum)).length - String(remainder).length == 1)
					remainder = "0" + remainder;
				else if (String(parseInt(WordProb.currNum)).length - String(remainder).length == 2)
					remainder = "00" + remainder;
				if (WordProb.remainderDivFlag) {
					WordProb.createSpans("remainder" + WordProb.stepCtr, String(parseInt(WordProb.currNum)).length, "remSpan" + WordProb.stepCtr, remainder, true, 1)
					WordProb.remainderDivFlag = false;
				}
			}
			if (blinkCtr >= WordProb.editFieldArr.length) {
				if (WordProb.highlighter <= String(WordProb.divident).length) {
					WordProb.editFieldArr.push("ansSpan" + WordProb.highlighter);
					WordProb.highlightDivident();
				}
				else {
					WordProb.editFieldArr.push("finalAns");

				}
				WordProb.highlighter++;
			}
			WordProb.id = WordProb.editFieldArr[blinkCtr];
			$("#" + WordProb.id).addClass("blink_me");

			// if (WordProb.id == "finalAns") {
			// 	child = document.getElementById("remainder" + (WordProb.stepCtr - 1)).children.length
			// 	for (i = 1; i <= child; i++) {
			// 		document.getElementById("remSpan" + (WordProb.stepCtr - 1) + i).style.backgroundColor = "";
			// 	}
			// }
			if (WordProb.id == "finalAns") {
				child = document.getElementById("remainder" + 1).children.length
				for (i = 1; i <= child; i++) {
					document.getElementById(("remSpan" + 1) + i).style.backgroundColor = "";
				}
			}
			//document.getElementById(WordProb.editFieldArr[blinkCtr - 1]).style.backgroundColor = "";
			//document.getElementById(WordProb.editFieldArr[blinkCtr - 1]).style.color = "black";
		}, 500);
	}
	if (WordProb.id == "finalAns") {
		WordProb.attemptFlag = true;
		label = document.getElementById("questionText").innerHTML;
		if (parseInt(document.getElementById(WordProb.id).innerHTML) == WordProb.answer) {
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/thats_right.mp3";
			WordProb.correctCnt++;
			scoredMarks = 10;
			WordProb.correctWrongModalShow("winEmoji.png", 2000);
			document.getElementById(WordProb.id).style.backgroundColor = "green";
		}
		else {
			scoredMarks = 0;
			WordProb.finalAnsFlag = false;
			document.getElementById("playSound").src = Utils.Path + "sounds/instructions/wrongSoundAksharkhadi.mp3";
			WordProb.correctWrongModalShow("rongAnsEmoji.png", 2000);
			document.getElementById(WordProb.id).style.backgroundColor = "red";
		}
		document.getElementById("playSound").play();
		WordProb.questionArr.splice(WordProb.questionCtr, 1);
		setTimeout(function () {
			WordProb.nextQuestion();
		}, 2000);

	}
	WordProb.startTimer();
}

WordProb.highlightDivident = function () {
	if ($("#" + WordProb.id).parent()[0].id == "remainder" + WordProb.stepCtr && WordProb.highlighter <= String(WordProb.divident).length + 1) {
		$(".highLighted").css("background-color", "");
		//remainder = remainder + String(WordProb.divident)[WordProb.highlighter - 1];
		remainder = remainder + document.getElementById("dividentSpan" + WordProb.highlighter).innerHTML
		if (WordProb.highlighter <= String(WordProb.divident).length) {
			WordProb.createSpans("remainder" + WordProb.stepCtr, remainder.length, "remSpan" + WordProb.stepCtr, remainder, false, WordProb.highlighter);
			//document.getElementById("remSpan" + WordProb.stepCtr + (WordProb.highlighter)).innerHTML = String(WordProb.divident)[WordProb.highlighter - 1];
			document.getElementById("remSpan" + WordProb.stepCtr + (WordProb.highlighter)).innerHTML = document.getElementById("dividentSpan" + WordProb.highlighter).innerHTML;
			WordProb.currNum = remainder;
			WordProb.remainderDivFlag = true;
			num = String(remainder);
			numArr = num.split("");
			ctr = 0;
			for (i = 0; i < String(remainder).length; i++) {
				if (numArr[0] == 0) {
					numArr.splice(0, 1);
					ctr++;
				}
				else
					break;
			}
			setTimeout(function () {
				for (i = ctr + 1; i <= String(remainder).length; i++) {
					document.getElementById("remSpan" + WordProb.stepCtr + i).style.backgroundColor = "pink";

					//WordProb.currNum = WordProb.currNum + $("#dividentSpan" + WordProb.highlighter).text();
					if (i == String(remainder).length)
						WordProb.stepCtr++;
				}
				var temp = String(parseInt(WordProb.currNum)).length;
				//if ($("#remSpan" + (WordProb.stepCtr - 1) + 1).text() == "0")
				temp = WordProb.highlighter - temp + 1;
				// else
				// 	temp = temp + 1;
				if (parseInt(remainder) != 0) {
					$("#minusSign" + (WordProb.stepCtr)).prop("class", "nopadding  col-xs-1 col-md-1 col-lg-1 col-sm-1 col-xs-offset-" + temp + " col-md-offset-" + temp + " col-lg-offset-" + temp + " col-sm-offset-" + temp);
					$("#remainder" + (WordProb.stepCtr)).prop("class", "nopadding height col-xs-6 col-md-6 col-lg-6 col-sm-6 col-xs-offset-" + (temp + 1) + " col-md-offset-" + (temp + 1) + " col-lg-offset-" + (temp + 1) + " col-sm-offset-" + (temp + 1));
				}
			}, 500);
		}
	}
	else {
		document.getElementById("dividentSpan" + WordProb.highlighter).style.backgroundColor = "pink";
		$("#dividentSpan" + WordProb.highlighter).addClass("highLighted");
		WordProb.currNum = WordProb.currNum + $("#dividentSpan" + WordProb.highlighter).prop("data");
	}
}

WordProb.nextQuestion = function () {
	if (!WordProb.attemptFlag) {
		WordProb.questionCtr++;
		WordProb.skipCtr++;
	}
	else {
		console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
		if (Utils.mobileDeviceFlag)
			Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	}
	if (WordProb.questionArr.length == 0)
		WordProb.showLastPage();
	else if (WordProb.questionCtr >= WordProb.questionArr.length && WordProb.questionArr.length != 0)
		WordProb.showPopup();
	else {
		WordProb.resetVariables();
		WordProb.initializeVariables();
		WordProb.showCalculation();
	}
}
WordProb.resetVariables = function () {
	$("#numberSystemDiv,#finalAns").css("pointer-events", "auto");
	WordProb.directAnsFlag = false;
	//$("#AnswerDiv").hide();
	$(".inputNum,#finalAns,.input").css("background-color", "white");
	$(".inputNum,#finalAns").css("color", "black");
	$(".editField").css("color", "black");
	$(".editField").text("");
	$(".editField").css("background-color", "");
	//$(".editField").css("pointer-events", "auto");
	$(".editField").removeClass("correctClass");
	$(".editField").removeClass("blink_me");
	$("#GivenDiv,#toFindDiv,#OperatorDiv,#continueDiv").show();
	$("#AnswerDiv").hide();
	$("#helpBtn").css("visibility", "hidden");
	$("#AnswerDiv").removeClass("animated bounceInRight");
	$(".oprSpans").css("background-color", "white");
	$("#continueDiv").show();
	$(".oprSpans").css("background-color", "white");
	$("#nextDiv").hide();
	$(".editField", ".signs").css("visibility", "visible");
	$("#subAnsDiv").empty();
	$(".height").empty();
	$(".steps").css("visibility", "hidden");
	$("#tableDiv").css("visibility", "hidden");
	$("#questionText").empty();
	$("#helpBtn").css("visibility", "hidden");
}

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

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

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

WordProb.clearSound = function () {
	document.getElementById("playSound").pause();
	clearTimeout(WordProb.AnsQuestionTimer);
	clearInterval(WordProb.noResponseTimer);
	clearTimeout(WordProb.timeOut);
	clearTimeout(WordProb.instrTime);
	WordProb.AnsQuestionTimer = null;
	WordProb.timeOut = null;
}

WordProb.showTable = function () {
	if (WordProb.helpFlag) {
		WordProb.helpFlag = false;
		$("#tableDiv").css("visibility", "visible");
		for (i = 1; i <= 10; i++) {
			document.getElementById("tableDiv" + i).innerHTML = WordProb.divisor * i;
		}
	}
	else {
		WordProb.helpFlag = true;
		$("#tableDiv").css("visibility", "hidden");
	}

	// var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
	// arr2 = [2, 4, 6];
	// ctr = 0;
	// for (i = 0; i < arr.length; i++) {
	// 	if (arr2.includes(i)) {
	// 		arr.splice(i - ctr, 1);
	// 		ctr++;
	// 	}

	// }
	// console.log(arr);
}

WordProb.createTableDivs = function () {
	var div, i;
	var parendDiv = document.getElementById("tableDiv");
	for (i = 1; i <= 10; i++) {
		div = document.createElement("div");
		div.setAttribute("id", "tableDiv" + i);
		div.setAttribute("class", "nopadding tables col-xs-12 col-md-12 col-lg-12 col-sm-12");
		parendDiv.appendChild(div);
	}
}

WordProb.createOperatorSpans = function () {//spans for showing operator list.
	var i;
	for (i = 0; i < 2; i++) {
		span = document.createElement("P");
		$(span).prop("id", "oprSpan" + i);
		$(span).prop("class", "oprSpans");
		span.setAttribute("onclick", "WordProb.checkOpr(this.id)");
		$(span).text(WordProb.operatorArr[i]);
		document.getElementById("inputDiv3").append(span);

	}
}

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