FractionAdd = {}; //namespace
var Utils ={};
Utils.Path = " ";
//global variable 
var resId = 0, questionId = 0, startTime = 0, scoredMarks = 0, totalMarks = 10, label =null, level = 1, scoreFlag = false,blinkCtr=0,finalAnsBlink = 0;
$(document).ready(function () {
    $(".se-pre-con").fadeOut("slow");
   if ((navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i))&& !(window.location.href.includes('http')))
        Utils.mobileDeviceFlag = true;
    /* if (Utils.mobileDeviceFlag)
        Utils.Path = Android.getMediaPath("Fraction Addition"); */
    setTimeout(function () { FractionAdd.Initilize(); }, 200);
});

FractionAdd.Initilize = function(){
    FractionAdd.setImage();
	document.title = FractionAdd.hardcoded.title;
    $("#nextStep").addClass("pulse");
    $("#homeDiv").css('visibility','hidden');
    $("#widget").hide();
    $("#gamePage").hide();
    $("#endPage").hide();
    FractionAdd.variableInitilization();
    FractionAdd.createAcknowledgementDivs();
}
FractionAdd.setImage = function(){ //set all images
    document.body.style.backgroundImage = "url('images/skin/Cover.png')";
    document.getElementById("homeImg").src = Utils.Path+"images/skin/Home.png";
    document.getElementById("logoImg").src = Utils.Path+"images/skin/logo.png";
    document.getElementById("nextStep").src = Utils.Path+"images/skin/Play.png";
    document.getElementById("soundImg").src = Utils.Path+"images/skin/Sound.png";
    document.getElementById("nextImg").src = Utils.Path+"images/skin/continue.png";
    document.getElementById("playAgain").src=Utils.Path+"images/skin/replay.png";
    document.getElementById("creditImg").src=Utils.Path+"images/skin/Credits.png";
    document.getElementById("innerQuesDivId").style.backgroundImage = Utils.Path+"url('images/skin/title.png')";
    document.getElementById("givenFindData").style.backgroundImage = Utils.Path+"url('images/skin/tape.png')";
    document.getElementById("digitalQuesDiv").style.backgroundImage = Utils.Path+"url('images/skin/text_space.png')";
    document.getElementById("numberDiv").style.backgroundImage = Utils.Path+"url('images/skin/image_space.png')";
    document.getElementById("gameOver").innerHTML = FractionAdd.hardcoded.gameOver;
    document.getElementById("carryDiv").innerHTML = FractionAdd.hardcoded.carry;
    document.getElementById("ansText").innerHTML = FractionAdd.hardcoded.ansText;
    document.getElementById("finalAnsText").innerHTML = FractionAdd.hardcoded.finalAns;
    document.getElementById("Yes").innerHTML = FractionAdd.modalData.yes;
	document.getElementById("No").innerHTML = FractionAdd.modalData.no;
}
FractionAdd.variableInitilization = function(){ // initilizes all variables
    FractionAdd.finalQuesArray = []; //contains 5 question data to show
    FractionAdd.splitedQuesArray = [];
    FractionAdd.firstNumArr=[]; //splited first number
    FractionAdd.secondNumArr=[]; //splited second number
    FractionAdd.answerArr=[]; //splited calculated ans
    FractionAdd.clickedOperator; //clicked operator 
    FractionAdd.currentCounter = 0; //ques Number
    FractionAdd.currentQues = 0 ; //ques from json array 
    FractionAdd.levelNum = 0;
    FractionAdd.wrongDragTimer;
    FractionAdd.correctDragTimer;
    FractionAdd.nextQueTimer;
    FractionAdd.id ; //contain blink class's id
    FractionAdd.soundFlag = false;
    FractionAdd.nextFlag = false;
    FractionAdd.carryFlag = false;
    FractionAdd.finalAnsFlag =false;
    FractionAdd.clickFlag = false;
    FractionAdd.instructionFlag = true;
    FractionAdd.attemptCount = 0;
    FractionAdd.checkFinalAnsFlag = 0;
    FractionAdd.quesSentense="";
    FractionAdd.givenMsg1 = " ";
    FractionAdd.givenMsg2 = " ";
    FractionAdd.findMsg = " ";
}
FractionAdd.startGame = function(){
    document.body.style.backgroundImage = "url('images/skin/BG1.png')";
    $("#homeDiv").css('visibility','visible');
    $("#widget").show();
    $("#gamePage").show();
    $("#playGame").hide();
    numberKey();
    FractionAdd.playGame();
}
FractionAdd.playGame = function(){
    FractionAdd.calculateValue();
}
FractionAdd.calculateValue = function(){ //calculat 5 unique ques
    var jsonObj = {},upperValue,lowerValue,upDecimalVal,lowDecimalVal;
    while(FractionAdd.finalQuesArray.length < 5){
       upperValue = Math.floor(Math.random()*(50-20)+20);
       lowerValue = Math.floor(Math.random()*(upperValue-10)+10);
       upDecimalVal = Math.floor(Math.random()*(10-0)+0);
       lowDecimalVal = Math.floor(Math.random()*upDecimalVal);
       jsonObj['upperValue']= upperValue;
       jsonObj['lowerValue'] = lowerValue;
       jsonObj['upDecimalVal'] = upDecimalVal;
       jsonObj['lowDecimalVal'] = lowDecimalVal;
       FractionAdd.finalQuesArray.push(jsonObj);
       jsonObj = {};
    }
    console.log(FractionAdd.finalQuesArray);
    FractionAdd.createQues();
} 

FractionAdd.createQues = function(){
    var randomNum = [],randomNo;
    scoreFlag = false;
    FractionAdd.currentQues = Math.floor(Math.random()*FractionAdd.quesDataArray.length);
    questionId = FractionAdd.quesDataArray[FractionAdd.currentQues].questionId;
    while(randomNum.length<2){ //random to find unique subject/object
        var randomNo = Math.floor(Math.random()*FractionAdd.quesDataArray[FractionAdd.currentQues].subjectSingular.length);
        if(randomNum.indexOf(randomNo)==-1){
            randomNum.push(randomNo);
        }
    }
   // FractionAdd.levelNum = Math.floor(Math.random()*2);
    FractionAdd.quesSentense = FractionAdd.quesDataArray[FractionAdd.currentQues].question;
    FractionAdd.givenMsg1 = FractionAdd.quesDataArray[FractionAdd.currentQues].given[0];
    FractionAdd.givenMsg2 =  FractionAdd.quesDataArray[FractionAdd.currentQues].given[1];
    //first replacement
    FractionAdd.quesSentense = FractionAdd.quesSentense.replace('!',FractionAdd.quesDataArray[FractionAdd.currentQues].subjectSingular[randomNum[0]]);
    FractionAdd.quesSentense = FractionAdd.quesSentense.replace('~',FractionAdd.quesDataArray[FractionAdd.currentQues].subjectSingular[randomNum[1]]);
    FractionAdd.givenMsg1 = FractionAdd.givenMsg1.replace('!',FractionAdd.quesDataArray[FractionAdd.currentQues].subjectSingular[randomNum[0]]);
    FractionAdd.givenMsg2 = FractionAdd.givenMsg2.replace('~',FractionAdd.quesDataArray[FractionAdd.currentQues].subjectSingular[randomNum[1]]);

    //second replacement
    FractionAdd.quesSentense = FractionAdd.quesSentense.replace('@',FractionAdd.finalQuesArray[FractionAdd.currentCounter].upperValue + "." +FractionAdd.finalQuesArray[FractionAdd.currentCounter].upDecimalVal);
    FractionAdd.quesSentense = FractionAdd.quesSentense.replace('$',FractionAdd.finalQuesArray[FractionAdd.currentCounter].lowerValue + "." +FractionAdd.finalQuesArray[FractionAdd.currentCounter].lowDecimalVal);
    FractionAdd.givenMsg1 = FractionAdd.givenMsg1.replace('@',FractionAdd.finalQuesArray[FractionAdd.currentCounter].upperValue + "." +FractionAdd.finalQuesArray[FractionAdd.currentCounter].upDecimalVal);
    FractionAdd.givenMsg2 = FractionAdd.givenMsg2.replace('$',FractionAdd.finalQuesArray[FractionAdd.currentCounter].lowerValue + "." +FractionAdd.finalQuesArray[FractionAdd.currentCounter].lowDecimalVal);

    FractionAdd.findMsg =FractionAdd.quesDataArray[FractionAdd.currentQues].toFind;
     if(FractionAdd.currentQues == 7 ||FractionAdd.currentQues == 5){
        FractionAdd.findMsg = FractionAdd.findMsg.replace('!',FractionAdd.quesDataArray[FractionAdd.currentQues].subjectSingular[randomNum[0]]);
        
        FractionAdd.findMsg = FractionAdd.findMsg.replace('~',FractionAdd.quesDataArray[FractionAdd.currentQues].subjectSingular[randomNum[1]]);

     }
    FractionAdd.splitedQuesArray.push(FractionAdd.givenMsg1);
    FractionAdd.splitedQuesArray.push(FractionAdd.givenMsg2);
    FractionAdd.splitedQuesArray.push(FractionAdd.findMsg);

    FractionAdd.createDiv();
}
FractionAdd.createDiv = function(){
    if(FractionAdd.instructionFlag)
        FractionAdd.playInstruction();
     FractionAdd.nextFlag = true;
    var quesSpanTag,i,j,dropDivTag;
   for(i=0;i<3;i++){
    quesSpanTag = document.createElement("span");
    quesSpanTag.setAttribute("id","quesSpanId"+i);
    quesSpanTag.setAttribute("class","noPadding spanClass dragDiv");
    quesSpanTag.innerHTML = FractionAdd.splitedQuesArray[i]+" ";
    document.getElementById("innerQuesDivId").appendChild(quesSpanTag);
   } 
   $(function () {  //function for Drag 
    $(".dragDiv").draggable({
        helper:'clone',
        revert: "invalid",
        appendTo: 'body',
       /*  zIndex:"1",
       containment:"html", */
       start: function (event,ui) {
        document.getElementById("playSound").pause();
        $(ui.helper).addClass("ui-draggable-helper");
       }
    });
});
 for(j=0;j<7;j++){
    dropDivTag = document.createElement("div");
    dropDivTag.setAttribute("id","dropDivId"+j);
    dropDivTag.setAttribute("class","noPadding textDivClass col-sm-11 col-md-11 col-lg-11 col-xs-11");
    if(j==0)
        dropDivTag.innerHTML = FractionAdd.hardcoded.givenMsg;
    else if(j==3){
        dropDivTag.innerHTML = FractionAdd.hardcoded.findMsg;
        $(dropDivTag).css('top','4vh');
    }
    else if(j==5){
        dropDivTag.innerHTML = FractionAdd.hardcoded.operation;
        $(dropDivTag).css('top','5vh');}
    else if(j==6){
        for(var i=0;i<2;i++){
            var operatorDiv = document.createElement("div");
            operatorDiv.setAttribute("id","operatorDiv"+i);
            operatorDiv.setAttribute("class","noPadding operatorDivClass  col-sm-1 col-xs-1 col-lg-1 col-md-1 col-sm-offset-1 col-xs-offset-1 col-md-offset-1 col-lg-offset-1");
            operatorDiv.setAttribute("onclick","FractionAdd.selectOperator(this.id)");
            operatorDiv.setAttribute("data",i);
            operatorDiv.innerHTML = FractionAdd.hardcoded.sign[i];
            dropDivTag.appendChild(operatorDiv);
        }
    }
    else{
        dropDivTag.setAttribute("class","noPadding dropDiv blankDivClass col-sm-11 col-md-11 col-lg-11 col-xs-11");
        if(j==1)
            $(dropDivTag).data("data",FractionAdd.givenMsg1+" ");
        else if(j==2)
            $(dropDivTag).data("data",FractionAdd.givenMsg2+" ");
        else{
             $(dropDivTag).data("data",FractionAdd.findMsg+" ");
             $(dropDivTag).css('top','5vh');
        }
    }
    document.getElementById("givenFindData").appendChild(dropDivTag);
    $(function(){    // Drop function
        $(".dropDiv").droppable(
        {     
            drop: FractionAdd.dropText 
            
        });
    });
 }
   
}
FractionAdd.dropText = function(event,ui){
    clearTimeout(FractionAdd.wrongDragTimer);
    clearTimeout(FractionAdd.correctDragTimer);
    document.getElementById("playSound").pause();
    var draggedData ,droppedData , dragImg,draggedID;
    scoreFlag = true;
    dragImg  = ui.draggable;
    draggedID = ui.draggable;
    draggedData = ui.draggable.text();
    droppedData = $(this).data("data");
    if(draggedData == droppedData)
     {
        $(this).append(draggedData);
        $(this).addClass('animated flash');
        document.getElementById("playSound").src="sounds/instructions/correct.mp3";
        document.getElementById("playSound").play();
		$(this).css("background-color", "rgb(36 123 36)");
		$(this).css("color", "white");
        $(this).css("font-size", "1.8vw");
        $(this).css("line-height", "7vh");
        $(this).css("font-weight", "bold");
        $(this).droppable({
            disabled: true
          });
          $(ui.draggable).draggable("disable");
          if(FractionAdd.correctDragTimer){
            clearTimeout(FractionAdd.correctDragTimer);
            FractionAdd.correctDragTimer = null;
        }
        FractionAdd.correctDragTimer = setTimeout(function(){
          $(".flash").removeClass('animated flash');
        },300);
     }
     else{
         $(this).css('border',"2px solid red");
         $(this).addClass('animated shake');
         document.getElementById("playSound").src="sounds/instructions/wrongSound.mp3";
         document.getElementById("playSound").play();
         if(FractionAdd.wrongDragTimer){
             clearTimeout(FractionAdd.wrongDragTimer);
             FractionAdd.wrongDragTimer = null;
         }
         FractionAdd.wrongDragTimer = setTimeout(function(){
            $(".shake").css('border',"3px solid rgb(36, 12, 156)");
            $(".shake").removeClass('animated shake');
         },300);
     }
		
}

FractionAdd.playInstruction = function(){ //play Instruction
    if(!FractionAdd.soundFlag)
        document.getElementById("playSound").src="sounds/instructions/dragInstruction.mp3";
    else
        document.getElementById("playSound").src = "sounds/instructions/selectNoInstruction.mp3";

        document.getElementById("playSound").play();
}

FractionAdd.nextQues = function(){ //next Question
 document.getElementById("playSound").pause();
 $("#numberDiv").css("pointer-events", "auto");
 $("#soundImg").css("pointer-events","auto");
 clearTimeout(FractionAdd.nextQueTimer);
 $("#nextImg").removeClass("bounce");
 $(".operatorDivClass").css('pointer-events','auto');
 if(FractionAdd.nextFlag){
     document.getElementById("nextImg").src="images/skin/Next.png";
     FractionAdd.showDigitalQues();
 }
  else{
      FractionAdd.currentCounter++;
      if(!scoreFlag)
          scoredMarks = -1
       FractionAdd.scoreFunction();
      if(FractionAdd.currentCounter<5){
        FractionAdd.finalAnsFlag = false;
        blinkCtr = 0;
        finalAnsBlink = 0;
             document.getElementById("nextImg").src="images/skin/continue.png";
             document.getElementById("innerQuesDivId").innerHTML = " ";
             document.getElementById("outerDivID").innerHTML = " ";
             document.getElementById("finalOuterDiv").innerHTML = " ";
             $("#digitalProblemQues").hide();
             FractionAdd.splitedQuesArray = [];
            $("#wordProblemQues").show();
              FractionAdd.createQues();
      }
      else{
          FractionAdd.gameOver();
      }
  }
}

FractionAdd.selectOperator = function(clickedId){ //when click on plus and minus
    
    if(FractionAdd.btncolorChangeTimer){
        clearTimeout(FractionAdd.btncolorChangeTimer);
        FractionAdd.btncolorChangeTimer = null;
    }
    var clickedSign = document.getElementById(clickedId).getAttribute("data");
    if(clickedSign == FractionAdd.quesDataArray[FractionAdd.currentQues].data){
        document.getElementById(clickedId).style.backgroundColor = "green";
        $("#nextImg").addClass("bounce");
        $(".operatorDivClass").css('pointer-events','none');
    }
    else{
        document.getElementById(clickedId).style.backgroundColor = "red";

        FractionAdd.btncolorChangeTimer  = setTimeout(function(){
            document.getElementById(clickedId).style.backgroundColor = "white";
        },200);
    }
   
    document.getElementById("operatorDiv").innerHTML = FractionAdd.hardcoded.sign[FractionAdd.clickedOperator];
 }
FractionAdd.showDigitalQues = function(){ //second screen
    FractionAdd.soundFlag = true;
   if(FractionAdd.instructionFlag)
     FractionAdd.playInstruction();
     FractionAdd.instructionFlag = false;
    document.getElementById("givenFindData").innerHTML = " ";
     $("#wordProblemQues").hide();
     document.getElementById("operatorDiv").innerHTML = FractionAdd.hardcoded.sign[FractionAdd.quesDataArray[FractionAdd.currentQues].data];
     $("#digitalProblemQues").show();
     $("#digitalProblemQues").css("pointer-events","auto");
     $(".dragDiv").draggable({
        disabled: true
      });
    FractionAdd.makeQues();
    FractionAdd.createAnsStep();
 }
FractionAdd.makeQues = function(){ //Digital quesMake
  var firstNum,secondNum,answer,number1,number2,decimal1,decimal2;
  blinkCtr = 0
    FractionAdd.nextFlag = false;
    $(".editDiv").not("#finalaAnsDivId"+1).css("pointer-events", "none");
    number1 = FractionAdd.finalQuesArray[FractionAdd.currentCounter].upperValue;
    number2 = FractionAdd.finalQuesArray[FractionAdd.currentCounter].lowerValue;
    decimal1 = FractionAdd.finalQuesArray[FractionAdd.currentCounter].upDecimalVal;
    decimal2 = FractionAdd.finalQuesArray[FractionAdd.currentCounter].lowDecimalVal;
   firstNum = number1+""+ decimal1;
   secondNum = number2+""+decimal2;
    FractionAdd.firstNumArr = firstNum.split("");
    FractionAdd.secondNumArr = secondNum.split("");
    if(FractionAdd.quesDataArray[FractionAdd.currentQues].data == 0)
      answer = parseInt(firstNum) + parseInt(secondNum) ;
    else
        answer = parseInt(firstNum) - parseInt(secondNum) ;
    FractionAdd.answerArr = (answer.toString()).split("");
    FractionAdd.answerArr.splice(FractionAdd.answerArr.length-1,0,".");
}
FractionAdd.createAnsStep = function(){
    for (var i = 0; i < 5; i++)		//ans step Grid
	{
		var UnitDiv = document.createElement("div");
		UnitDiv.setAttribute("id", "UnitDiv" + i);
		UnitDiv.setAttribute("class", "noPadding fontStyleClass col-sm-12 col-lg-12 col-md-12 col-xs-12");
		document.getElementById('outerDivID').appendChild(UnitDiv);
		var num = 4;
		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(FractionAdd.hardcoded.msgArray[j]);
                if(j==0 || j==1 || j==3)
                   $("#unitName"+j).css('color',"#d7e22e");
			}
			if (i == 1) {
				if(j<2)
				{
					UnitNumDiv.setAttribute("id", "Carry" + j);
					$("#Carry" + j).data("numData", "0");
				}
				if(j==2)
				{
					UnitNumDiv.setAttribute("id", "Carry1" + j);
					$("#Carry1" + j).text(".");

				}
				else if(j>2) {
					UnitNumDiv.setAttribute("id", "Carry" + (j-1));
					$("#Carry" + (j-1)).data("numData", "0");
				}
			}
			else if (i == 2) {
				if(j<2)
				{
					UnitNumDiv.setAttribute("id", "FirstNum" + j);
					$("#FirstNum" + j).data("numData", FractionAdd.firstNumArr[j]);
				}
				if(j==2)
				{
					UnitNumDiv.setAttribute("id", "FirstNum1" + j);
					$("#FirstNum1" + j).text(".");
				}
				else if(j>2) {
					UnitNumDiv.setAttribute("id", "FirstNum" + (j-1));
					$("#FirstNum" + (j-1)).data("numData", FractionAdd.firstNumArr[j-1]);
				}
			}
			else if (i == 3) {
				if(j<2)
				{
					UnitNumDiv.setAttribute("id", "SecondNum" + j);
					$("#SecondNum" + j).data("numData", FractionAdd.secondNumArr[j]);
				}
				if(j==2)
				{
					UnitNumDiv.setAttribute("id", "SecondNum1" + j);
					$("#SecondNum1" + j).text(".");
                   
				}
				else if(j>2) {
					UnitNumDiv.setAttribute("id", "SecondNum" + (j-1));
					$("#SecondNum" + (j-1)).data("numData", FractionAdd.secondNumArr[j-1]);
				}
			}
			else if (i == 4) {
				if(j<2)
				{
					UnitNumDiv.setAttribute("id", "Answer" + j);
					$("#Answer" + j).data("numData", FractionAdd.answerArr[j]);
				}
				if(j==2)
				{
					UnitNumDiv.setAttribute("id", "Answer1" + j);
					$("#Answer1" + j).text(".");
				}
				else if(j>2) {
					UnitNumDiv.setAttribute("id", "Answer" + (j-1));
					$("#Answer" + (j-1)).data("numData", FractionAdd.answerArr[j]);
				}	
			}
			if (j < 2)
				UnitNumDiv.setAttribute("class","blinkClass leftNumberStyle noPadding col-sm-3 col-lg-3 col-md-3 col-xs-3");
			else
                UnitNumDiv.setAttribute("class","blinkClass rightNumberStyle noPadding col-sm-3 col-lg-3 col-md-3 col-xs-3");
		}
    }

    for (var i = 0; i < 4; i++)		//final answer grid
    {
        var numDiv = document.createElement("div");
        numDiv.setAttribute("id", "numAnsDiv" + i);
        numDiv.setAttribute("class", "noPadding blinkClass finalBorderClass finalAnsStyle col-sm-3 col-lg-3 col-md-3 col-xs-3");
        document.getElementById('finalOuterDiv').appendChild(numDiv);
        if (i == 1)
            $("#numAnsDiv1").text(".");
        if (i == 3) {
            document.getElementById("numAnsDiv" + i).innerHTML = FractionAdd.quesDataArray[FractionAdd.currentQues].unit;
            $("#numAnsDiv" + i).css('font-size', "2vw");
            $("#numAnsDiv" + i).css("line-height", "8vh");
            $("#numAnsDiv" + i).css("border", "0px solid greenish");

        }
    }
    document.getElementById("numAnsDiv0").setAttribute("onclick", "FractionAdd.finalAns()");
    $("#" + FractionAdd.divNameArray[blinkCtr]).addClass("blink_me");
}
function displayNumber(Number){ //when click on the numberPad
    var numCount = 0,numCount1 = 0,ansNumArray = [];
    document.getElementById("playSound").pause();
    if(!FractionAdd.finalAnsFlag){
        FractionAdd.id = FractionAdd.divNameArray[blinkCtr];
        numCount = 1;
    }
    else{
        FractionAdd.id = FractionAdd.finalAnsDivNameArray[finalAnsBlink];
        if(finalAnsBlink == 0){
            ansNumArray = (FractionAdd.answerArr+"").split(".");
            numCount = ansNumArray.length;
            numCount1=parseInt(ansNumArray[0].split(",").join(""));
            numCount1=numCount1.toString();
        }
        else
          numCount = 1;
    }

	if ($("#" + FractionAdd.id).text().length < numCount)
    $("#" + FractionAdd.id).append($(Number).text());

    if ($("#" + FractionAdd.id).text().length == numCount) {
        if(!FractionAdd.finalAnsFlag)		//enter single number condition
            {
                if(FractionAdd.quesDataArray[FractionAdd.currentQues].data== 0)
                    {
                        $("#numberDiv").css("pointer-events", "none");
                        FractionAdd.checkAddAnswer();
                    }
            else{
                $("#numberDiv").css("pointer-events", "none");
                FractionAdd.checkSubAnswer();
                }
            }
            else
            FractionAdd.checkFinalAnswer();
    }
     else if (parseInt($("#"+FractionAdd.id).text())==numCount1 && (finalAnsBlink == 0))
        FractionAdd.checkFinalAnswer();
}
FractionAdd.checkAddAnswer = function(){ //ans for addition
    if ($("#" + FractionAdd.id).text() == $("#" + FractionAdd.id).data("numData")) {
		var num = 6;
			if (blinkCtr >= num && blinkCtr % 2 == 0) {
			var idNumber = FractionAdd.id.match(/\d+/);
			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++;
				$("#" + FractionAdd.divNameArray[blinkCtr]).data("numData", "1");
				FractionAdd.carryFlag = true;
			}
			else {
				blinkCtr = blinkCtr + 2;
			}
		}
		else {
			blinkCtr++;
		}
		$(".blinkClass").removeClass("blink_me");
		$("#" + FractionAdd.divNameArray[blinkCtr]).addClass("blink_me");
			if (blinkCtr == 12)
				FractionAdd.finalAns();
		$("#numberDiv").css("pointer-events", "auto");
	}
	else
		FractionAdd.wrongAnswer();
}
FractionAdd.checkSubAnswer = function(){ //ans for sub
    var num = 6, num2 = 10, checkblink = 12;
	if (blinkCtr < num) {
		if ($("#" + FractionAdd.id).text() == $("#" + FractionAdd.id).data("numData")) {
			blinkCtr++;
			$("#numberDiv").css("pointer-events", "auto");
		}
		else
			FractionAdd.wrongAnswer();
	}
	else {
		var idNumber = FractionAdd.id.match(/\d+/);
		var firstNo = parseInt($("#FirstNum" + idNumber[0]).text());
		var secondNo = parseInt($("#SecondNum" + idNumber[0]).text());
		if (firstNo < secondNo) {
			FractionAdd.clickFlag = true;
		}
		else {
			FractionAdd.clickFlag = false;
		}
		var subAns = firstNo - secondNo;
		if ($("#" + FractionAdd.id).text() == subAns) {
			blinkCtr = blinkCtr + 2;
			$("#numberDiv").css("pointer-events", "auto");
		}
		else
			FractionAdd.wrongAnswer();
	}
	FractionAdd.id = FractionAdd.divNameArray[blinkCtr];
	$(".blinkClass").removeClass("blink_me");
	$("#" + FractionAdd.divNameArray[blinkCtr]).addClass("blink_me");

	if (blinkCtr >= num && blinkCtr <= num2) {
        if(FractionAdd.divNameArray[blinkCtr] != "Answer0"){
		FractionAdd.clickFlag = false;
		FractionAdd.checkBorrow();
		document.getElementById("questionMsg").innerHTML = FractionAdd.modalData.responseMsg;
		$("#btnDiv").show();
		$("#responseBoxDiv").show();
     }
	}
	if (blinkCtr == checkblink)
		FractionAdd.finalAns();
}
FractionAdd.checkFinalAnswer = function(){ //final ans 
    scoreFlag = true;
	var decimalArray=(FractionAdd.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) == $("#" + FractionAdd.finalAnsDivNameArray[finalAnsBlink]).text() ||
		parseInt(ans1) == $("#" + FractionAdd.finalAnsDivNameArray[finalAnsBlink]).text()
	) {
		
	}
	else {
		FractionAdd.checkFinalAnsFlag++;
		$("#buttonValue11,#buttonValue12").css("pointer-events", "none");
		$("#buttonValue11,#buttonValue12").css("opacity", 0.5);
    }
	finalAnsBlink++;
	FractionAdd.finalAns();
	if (finalAnsBlink == 2) {
		FractionAdd.attemptCount++;
		if (FractionAdd.checkFinalAnsFlag == 0) {
            $("#soundImg").css("pointer-events","none");
			FractionAdd.finalRightAns = true;
			document.getElementById("playSound").src = Utils.Path + 'sounds/instructions/Cheering.mp3';
			document.getElementById("playSound").play();
            FractionAdd.correctWrongModalShow("Perfect.png", 2000);
            scoredMarks = 10;
			if (FractionAdd.nextQueTimer) {
				clearTimeout(FractionAdd.nextQueTimer);
				FractionAdd.nextQueTimer = null;
			}
			FractionAdd.nextQueTimer = setTimeout(function () {
				FractionAdd.nextQues();
			}, 4000);
		}
		else {
			scoredMarks = 0;
            $("#soundImg").css("pointer-events","none");
			document.getElementById("playSound").src = Utils.Path + 'sounds/instructions/wrongSound.mp3';
			document.getElementById("playSound").play();
			FractionAdd.correctWrongModalShow("wrongEmoji.png", 2000);
			$("#" + FractionAdd.finalAnsDivNameArray[0]).text("");
			$("#" + FractionAdd.finalAnsDivNameArray[1]).text("");
			finalAnsBlink = 0;
			FractionAdd.checkFinalAnsFlag = 0;
			FractionAdd.finalAnsFlag = false;
			$(".blinkClass").removeClass("blink_me");
			$("#" + FractionAdd.divNameArray[blinkCtr]).addClass("blink_me");
			if (blinkCtr == 12) {
				FractionAdd.finalAns();
			}
		}
	}
}
FractionAdd.finalAns = function () {
	FractionAdd.finalAnsFlag = true;
	$(".blinkClass").removeClass("blink_me");
	$("#" + FractionAdd.finalAnsDivNameArray[finalAnsBlink]).addClass("blink_me");
	FractionAdd.id = FractionAdd.finalAnsDivNameArray[finalAnsBlink];
}
FractionAdd.checkBorrow = function () {
	var idNumber = FractionAdd.id.match(/\d+/);
	var firstNo = parseInt($("#FirstNum" + idNumber[0]).text());
	var secondNo = parseInt($("#SecondNum" + idNumber[0]).text());
	if (firstNo < secondNo) {
		FractionAdd.clickFlag = true;
	}
	else {
		FractionAdd.clickFlag = false;
	}
}
FractionAdd.wrongAnswer = function () {
	setTimeout(function () {
		$("#numberDiv").css("pointer-events", "auto");
		$("#" + FractionAdd.id).text("");
	}, 1000);
}
FractionAdd.correctWrongModalShow = function (str, duration) { 
    $("#soundImg").css("pointer-events","none");
    document.getElementById("responseImg").src = Utils.Path + "images/skin/" + str;
    $("#responseDiv").addClass('animated zoomIn');
	document.getElementById("correctWrongModal").style.display = "block";
	setTimeout(function () {
        document.getElementById("correctWrongModal").style.display = "none";
        $("#responseDiv").removeClass('animated zoomIn');
	}, duration);
}
FractionAdd.correctClick = function () {
	if (FractionAdd.clickFlag) {
		$("#responseBoxDiv").hide();
		FractionAdd.transferBorrow();
	}
	else {
		$("#btnDiv").hide();
		document.getElementById("questionMsg").innerHTML = FractionAdd.modalData.noBorrowmsg;
		setTimeout(function () {
			$("#responseBoxDiv").hide();
		}, 5000);
	}
}
FractionAdd.wrongClick = function () {
	if (!FractionAdd.clickFlag) {
		$("#responseBoxDiv").hide();
	}
	else {
		$("#btnDiv").hide();
		document.getElementById("questionMsg").innerHTML = FractionAdd.modalData.borrowMsg;
		setTimeout(function () {
			$("#responseBoxDiv").hide();
			FractionAdd.transferBorrow();
		}, 5000);
	}
}
FractionAdd.transferBorrow = function () {
	var idNumber = FractionAdd.id.match(/\d+/);
    var firstNo = parseInt($("#FirstNum" + idNumber[0]).text());
	firstNo = firstNo + 10;
	var number = parseInt(idNumber[0]);
	$("#FirstNum" + number).text(firstNo);
	var previousNo = parseInt($("#FirstNum" + (number - 1)).text());
	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
		$("#FirstNum" + (number - 1)).text(previousNo - 1);
}
FractionAdd.replayGame = function(){ //play game again
    document.getElementById("playSound").pause();
    $("#numberDiv").css("pointer-events", "auto");
     $("#digitalProblemQues").hide();
     $("#wordProblemQues").show();
     $("#endPage").hide();
     $("#gamePage").show();
     document.getElementById("nextImg").src="images/skin/continue.png";
     document.getElementById("innerQuesDivId").innerHTML = " ";
     document.getElementById("givenFindData").innerHTML = " ";
    // document.getElementById("innerQuesDivId").innerHTML = " ";
             document.getElementById("outerDivID").innerHTML = " ";
             document.getElementById("finalOuterDiv").innerHTML = " ";
     FractionAdd.variableInitilization();
     FractionAdd.playGame();
}
FractionAdd.gameOver = function(){
    document.getElementById("playSound").pause();
    clearTimeout(FractionAdd.nextQueTimer);
    $("#gamePage").hide();
    $("#endPage").show();
    $("#acknowledgementDiv").hide();
}
FractionAdd.goHome = function(){
    document.getElementById("playSound").pause();
    location.reload();
}
FractionAdd.createAcknowledgementDivs = function () {
    var i = 0, div;
    for (i = 0; i < Object.keys(FractionAdd.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(FractionAdd.AcknowledgementPageData)[i] + " : " + Object.values(FractionAdd.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.style.marginBottom = "2vh";
    acknowledgementDiv.appendChild(div);
}
FractionAdd.showAcknowledgement = function () {
    $("#acknowledgementDiv").show();
}
FractionAdd.scoreFunction = function () {
    console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
    if (Utils.mobileDeviceFlag) {
        Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime);
    }
}