//startingDate: 02-06-2019
var Time = {};
var Utils = {};
Utils.Path = '';
Utils.mobileDeviceFlag = false;
var questionId = 0, startTime = 0, scoredMarks = 0, totalMarks = 0, resId = 0, level = 1, label = '';
var totalJsonQueCount = 580, wordType = "sentence";
Time.level = false;
Time.sttString = "";
$(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("Time");  */
	document.body.style.backgroundImage = "url(" + Utils.Path + "images/skin/Date-N-time_Cover.png" + ")";
	setTimeout(function () {
		Time.init();
	}, 200);
});

Time.init = function () {
	$("#coverPage").show();
	$("#gamePage,#lastPage").hide();
	$(".header").not("#logoDiv").css("visibility", "hidden");
	Time.initializeVariables();
	Time.setAllImages();
	if (Utils.mobileDeviceFlag) {
		Time.level = Android.isPractice();
	}
}

Time.initializeVariables = function () {
	Time.amPmArr = ["AM", "PM"];
	Time.quarterArr = [15, 45];
	Time.questionCtr = 0;
	Time.recordClickFlag = false;
	Time.sttArr = [];
	Time.ansArr = [];
	Time.ans1 = ' ';
	Time.solSet = [];
	Time.ttsArr = [];
	Time.attemptFlag = false;
	Time.ansFoundFlag = false;
	Time.objArr = [];
	Time.correctCounter = 0;
	Time.seconds = 0;
	Time.activityFlag = false;
	Time.playsoundFlag = true;
	Time.possibilityArr = [];
}
Time.setAllImages = function () {
	document.getElementById("clockDiv").style.backgroundImage = "url(" + Utils.Path + 'images/skin/Digital-Clock.png' + ")";
	document.getElementById("calendarDiv").style.backgroundImage = "url(" + Utils.Path + 'images/skin/Calendar.png' + ")";
	document.getElementById("table").style.backgroundImage = "url(" + Utils.Path + 'images/skin/table.png' + ")";
	document.getElementById("home").src = Utils.Path + "images/skin/Home.png";
	document.getElementById("logo").src = Utils.Path + "images/skin/logo.png";
	document.getElementById("sound").src = Utils.Path + "images/skin/Sound.png";
	document.getElementById("playImg").src = Utils.Path + "images/skin/Play.png";
	document.getElementById("next").src = Utils.Path + "images/skin/Next.png";
	document.getElementById("mike").src = Utils.Path + "images/skin/Mic.png";
	document.getElementById("creditImg").src = Utils.Path + "images/skin/Credits.png";
	document.getElementById("replayImg").src = Utils.Path + "images/skin/replay.png";
	document.getElementById("teddy").src = Utils.Path + "images/skin/Taddy_Normal.png";
	document.getElementById("lastPara").innerHTML = Time.hardCodedData.gameOver;
	$("#play").addClass("animated bounceInLeft");
}
Time.playGame = function () {
	document.body.style.backgroundImage = "url(" + Utils.Path + "images/skin/Bg.png" + ")";
	$("#coverPage,#lastPage").hide();
	$("#gamePage,#clockDiv,#question,#teddyDiv").show();
	$(".header").css("visibility", "visible");
	var newStyle = "<style>" +
		"@font-face {  " +
		"font-family: 'loopy';" +
		"src: url('fonts/LOOPY___.ttf') format('truetype');" +
		"}  </style>";
	$("head").append(newStyle);
	$("#timeSpan").css("font-family", "loopy");
	Time.findQuestionAndAnswer();

}

Time.findQuestionAndAnswer = function () {
	var numArr = [], i, obj = {};
	Time.objArr = [];
	Time.possibilityArr = [];
	for (i = 0; i < 5; i++) {
		obj = {};
		Time.rno = Math.floor(Math.random() * Time.questionArr.length);
		while (numArr.includes(Time.rno))
			Time.rno = Math.floor(Math.random() * Time.questionArr.length);
		numArr.push(Time.rno);
		Time.findValues();
		Time.ttsArr = Time.solSet.slice();
		if (Time.rno == 3) {
			Time.ttsArr.splice(1, 1);
			if (Time.randHr == 12 && Time.quarterArr.includes(Time.randMin)) {
				Time.ttsArr.splice((Time.ttsArr.length - 1), 1);
			}
			if (Time.randMin == 0) {
				Time.ttsArr.splice(0, 1);
			}
		}
		randTts = Math.floor(Math.random() * Time.ttsArr.length)
		Time.ansWord = Time.ttsArr[randTts] + ".";
		console.log(Time.solSet);
		obj.question = Time.questionArr[Time.rno].question;
		obj.sound = Time.questionArr[Time.rno].sound;
		obj.ans = Time.ansWord;
		obj.hr = Time.randHr;
		obj.min = Time.randMin;
		obj.amPm = Time.amPm;
		obj.month = Time.month;
		obj.date = Time.date;
		obj.day = Time.day;
		obj.questionId = Time.questionArr[Time.rno].questionId;
		Time.objArr.push(obj);
		Time.possibilityArr.push(Time.ttsArr);
	}
	console.log(Time.objArr);
	console.log(Time.possibilityArr);
	Time.setQuestion();
}

Time.findValues = function () {
	var d, hour, minute, rno, monthNo, dayNo, dateNo, question, randomChoice, date, randTts;
	Time.activityFlag = false;
	Time.randHr = Math.floor(Math.random() * 12 + 1);
	randomChoice = Math.floor(Math.random() * 2);
	if (randomChoice == 0) {
		randQuarter = Math.floor(Math.random() * Time.quarterArr.length);
		Time.randMin = Time.quarterArr[randQuarter];
	}
	else
		Time.randMin = Math.floor(Math.random() * 5) * 10;
	rno = Math.floor(Math.random() * Time.amPmArr.length);
	Time.amPm = Time.amPmArr[rno];
	//document.getElementById("hr").innerHTML=hour;
	//document.getElementById("colon").innerHTML=":";
	//document.getElementById("min").innerHTML=minute;
	//document.getElementById("ap").innerHTML=" "+Time.amPm;
	monthNo = Math.floor(Math.random() * Time.monthArr.length);
	Time.month = Time.monthArr[monthNo];
	if (monthNo < 5) {
		if (monthNo == 0)
			Time.date = Math.floor(Math.random() * 28 + 1);
		else
			Time.date = Math.floor(Math.random() * 30 + 1);
	}
	else
		Time.date = Math.floor(Math.random() * 31 + 1);
	dayNo = Math.floor(Math.random() * Time.daysArr.length);
	Time.day = Time.daysArr[dayNo];
	//document.getElementById("year").innerHTML=2019;
	//document.getElementById("month").innerHTML=Time.month;
	//document.getElementById("date").innerHTML=date;
	//document.getElementById("day").innerHTML=Time.day;
	//question=Time.questionArr[Time.rno].question;
	//questionId=Time.questionArr[Time.rno].questionId;
	//document.getElementById("questionDiv").innerHTML=question;
	if (((((Time.randHr >= 6 && Time.randHr < 7) || (Time.randHr == 7 && Time.randMin == 0)) || ((Time.randHr >= 9 && Time.randHr < 10) || (Time.randHr == 10 && Time.randMin == 0))) && Time.amPm == "AM") || ((((Time.randHr >= 8 && Time.randHr < 9) || (Time.randHr == 9 && Time.randMin == 0)) || ((Time.randHr >= 10 && Time.randHr < 11) || (Time.randHr == 11 && Time.randMin == 0))) && Time.amPm == "PM"))
		Time.activityFlag = true;
	Time.findAnswer();
}

Time.setQuestion = function () {
	var d;
	Time.attemptFlag = false;
	//Time.questionCtr++;
	totalMarks = 0;
	d = new Date();
	startTime = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();

	var question, answer, hour, min, amPm, year, month, date, day;
	$("#mike").removeClass("blink_me");
	$("#mike").prop('src', Utils.Path + "images/skin/Mic.png");
	question = Time.objArr[Time.questionCtr].question;
	Time.ansWord = Time.objArr[Time.questionCtr].ans;
	hour = Time.objArr[Time.questionCtr].hr;
	if (hr < 10)
		$("#timeSpan").css("margin-left", "2.2vw");
	else
		$("#timeSpan").css("margin-left", "1.7vw");
	min = Time.objArr[Time.questionCtr].min;
	amPm = Time.objArr[Time.questionCtr].amPm;
	if (amPm == "AM" && (hour >= 6 && hour < 8))
		document.getElementById("windowDiv").style.backgroundImage = "url(" + Utils.Path + 'images/skin/Window_Morning_1.png' + ")";
	else
		if ((amPm == "AM" && (hour >= 8 && hour < 12)) || amPm == "PM" && hour < 5)
			document.getElementById("windowDiv").style.backgroundImage = "url(" + Utils.Path + 'images/skin/Window_Afternoon.png' + ")";
		else
			if ((amPm == "PM" && (hour >= 5 && hour < 7)))
				document.getElementById("windowDiv").style.backgroundImage = "url(" + Utils.Path + 'images/skin/Window_Evening.png' + ")";
			else
				document.getElementById("windowDiv").style.backgroundImage = "url(" + Utils.Path + 'images/skin/Window_Night.png' + ")";

	year = Time.objArr[Time.questionCtr].year;
	month = Time.objArr[Time.questionCtr].month;
	date = Time.objArr[Time.questionCtr].date;
	day = Time.objArr[Time.questionCtr].day;
	questionId = Time.objArr[Time.questionCtr].questionId;
	document.getElementById("hr").innerHTML = hour;
	document.getElementById("colon").innerHTML = ":";
	if (min < 10)
		document.getElementById("min").innerHTML = "0" + min;
	else
		document.getElementById("min").innerHTML = min;
	document.getElementById("ap").innerHTML = " " + amPm;
	document.getElementById("year").innerHTML = 2019;
	document.getElementById("month").innerHTML = month;
	if (date < 10)
		document.getElementById("date").innerHTML = "0" + date;
	else
		document.getElementById("date").innerHTML = date;
	document.getElementById("day").innerHTML = day;
	document.getElementById("questionDiv").innerHTML = question;
	document.getElementById("itIs").innerHTML = "It is";
	document.getElementById("ansSpan").innerHTML = Time.ansWord;
	Time.playSound();
}

Time.endGame = function () {
	$("#gamePage").hide();
	$("#lastPage").show();
}

Time.findAnswer = function () {
	Time.solSet = [];
	Time.sttArr = [];
	var dateArr = [], answer, remainder, division, rno;
	switch (Time.rno) {
		case 0: Time.solSet.push(Time.month);
			break;
		case 1: {
			answer = Time.date + " " + Time.month;
			Time.solSet.push(answer);
			remainder = Time.date % 10;
			division = Time.date / 10;
			if ((remainder > 0 && remainder < 4) && Math.floor(division) != 1) {
				switch (remainder) {
					case 1: answer = Time.date + "st" + " " + Time.month;
						break;
					case 2: answer = Time.date + "nd" + " " + Time.month;
						break;
					case 3: answer = Time.date + "rd" + " " + Time.month;
						break;
				}
				Time.solSet.push(answer);
			}
			else {
				answer = Time.date + "th" + " " + Time.month;
				Time.solSet.push(answer);
			}
			break;
		}
		case 2: Time.solSet.push(Time.day);
			break;
		case 3: {
			Time.solSet.push(Time.randHr + ' ' + Time.randMin + ' ' + Time.amPm);// document.getElementById("timeSpan").innerHTML;
			Time.solSet.push(Time.randHr + '' + Time.randMin + ' ' + Time.amPm);
			//Time.solSet.push(Time.randHr+' '+Time.randMin);
			if (Time.randHr == 12) {
				//Time.solSet.push(0+""+0+' '+Time.randMin);
				if (Time.amPm == "PM" && Time.randMin == 0) {
					answer = "noon";
					Time.solSet.push(answer);
				}
				else if (Time.amPm == "AM" && Time.randMin == 0) {
					answer = "midnight";
					Time.solSet.push(answer);
				}
			}
			if (((Time.randHr >= 1 && Time.randHr < 4) || Time.randHr == 12) && Time.amPm == "PM") {
				if (Time.randMin != 0)
					answer = Time.randHr + ":" + Time.randMin + " of noon";
				else
					answer = Time.randHr + " of noon";
			}
			else if ((Time.randHr >= 4 && Time.randHr < 8) && Time.amPm == "PM") {
				if (Time.randMin != 0)
					answer = Time.randHr + ":" + Time.randMin + " of evening";
				else
					answer = Time.randHr + " of evening";
			}
			else if (((Time.randHr >= 8 && Time.randHr < 12) && Time.amPm == "PM") || (((Time.randHr >= 1 && Time.randHr < 4) || Time.randHr == 12) && Time.amPm == "AM")) {
				if (Time.randMin != 0)
					answer = Time.randHr + ":" + Time.randMin + " of night";
				else
					answer = Time.randHr + " of night";
			}
			else if (((Time.randHr >= 4 && Time.randHr < 12) && Time.amPm == "AM")) {
				if (Time.randMin != 0)
					answer = Time.randHr + ":" + Time.randMin + " of morning";
				else
					answer = Time.randHr + " of morning";
			}
			Time.solSet.push(answer);

			switch (Time.randMin) {
				case 0: answer = Time.randHr + " " + "o' clock";
					Time.solSet.push(answer);
					answer = Time.randHr + " " + Time.amPm;
					Time.solSet.push(answer)
					break;
				case 10: answer = 10 + " " + "minutes past" + " " + Time.randHr + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = Time.randHr + " " + "hours " + 10 + " minutes";
					Time.solSet.push(answer);
					break;
				case 15: answer = 15 + " " + "minutes past" + " " + Time.randHr + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = "quarter past" + " " + Time.randHr + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = Time.randHr + " " + "hours " + 15 + " minutes";
					Time.solSet.push(answer);
					break;
				case 20: answer = 20 + " " + "minutes past" + " " + Time.randHr + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = Time.randHr + " " + "hours " + 20 + " minutes";
					Time.solSet.push(answer);
					break;
				case 30: answer = 30 + " " + "minutes past" + " " + Time.randHr + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = "half past" + " " + Time.randHr + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = Time.randHr + " " + "hours " + 30 + " minutes";
					Time.solSet.push(answer);
					break;
				case 40: if (Time.randHr == 12)
					answer = 20 + " " + "minutes to" + " " + 1 + " " + Time.amPm;
				else
					answer = 20 + " " + "minutes to" + " " + (Time.randHr + 1) + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = Time.randHr + " " + "hours " + 40 + " minutes";
					Time.solSet.push(answer);
					break;
				case 45: if (Time.randHr == 12) {
					answer = 15 + " " + "minutes to" + " " + 1 + " " + Time.amPm;
					ans1 = 0 + " " + 45 + " " + Time.amPm;
				}
				else {
					answer = 15 + " " + "minutes to" + " " + (Time.randHr + 1) + " " + Time.amPm;
					ans1 = Time.randHr + " " + 45 + " " + Time.amPm;
				}
					Time.solSet.push(answer);
					Time.solSet.push(ans1);
					if (Time.randHr == 12)
						answer = "quarter to" + " " + 1 + " " + Time.amPm;
					else
						answer = "quarter to" + " " + (Time.randHr + 1) + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = Time.randHr + " " + "hours " + 45 + " minutes";
					Time.solSet.push(answer);
					break;
				case 50: if (Time.randHr == 12)
					answer = 10 + " " + "minutes to" + " " + 1 + " " + Time.amPm;
				else
					answer = 10 + " " + "minutes to" + " " + (Time.randHr + 1) + " " + Time.amPm;
					Time.solSet.push(answer);
					answer = Time.randHr + " " + "hours " + 50 + " minutes";
					Time.solSet.push(answer);
					break;
			}
			break;
		}
		case 4: if (Time.activityFlag == false) {
			rno = Math.floor(Math.random() * 2);
			if (Time.amPm == "AM") {
				if (rno == 1)
					Time.randHr = 6;
				else
					Time.randHr = 9;
			}
			else {
				if (rno == 1)
					Time.randHr = 8;
				else
					Time.randHr = 10;
			}
		}

			if (((Time.randHr >= 6 && Time.randHr < 7) || (Time.randHr == 7 && Time.randMin == 0)) && Time.amPm == "AM") {
				answer = "time to wake up";
				Time.solSet.push(answer);
			}
			else if (((Time.randHr >= 9 && Time.randHr < 10) || (Time.randHr == 10 && Time.randMin == 0)) && Time.amPm == "AM") {
				answer = "time to school";
				Time.solSet.push(answer);
			}
			else if (((Time.randHr >= 8 && Time.randHr < 9) || (Time.randHr == 9 && Time.randMin == 0)) && Time.amPm == "PM") {
				answer = "time to dinner";
				Time.solSet.push(answer);
			}
			else if (((Time.randHr >= 10 && Time.randHr < 11) || (Time.randHr == 11 && Time.randMin == 0)) && Time.amPm == "PM") {
				answer = "time to bed";
				Time.solSet.push(answer);
			}
	}
	console.log(Time.solSet);
}


Time.playSound = function () {
	var sound;
	sound = Utils.Path + "sounds/" + Time.objArr[Time.questionCtr].sound;
	if (Time.level) {
		document.getElementById("playSound").src = Utils.Path + "sounds/" + Time.objArr[Time.questionCtr].sound;
		document.getElementById("playSound").play();
	}
	else {
		Time.loadmetaDataFlag = true;
		Time.getDuration(sound);
	}
}

Time.getDuration = function (sound) {
	var duration = 0;
	$('#playSound').prop('src', sound);
	if (Time.loadmetaDataFlag) {
		$('#playSound').on("loadedmetadata", function () {
			Time.loadmetaDataFlag = false;
			$('#playSound').unbind("loadedmetadata");
			duration = $('#playSound').prop('duration');

			Time.playSttAndAns(duration);
		}
		);
	}
	else
		$('#playSound').unbind("loadedmetadata");
}

Time.playSttAndAns = function (duration) {
	var word, source;
	document.getElementById("playSound").play();
	if (Time.playsoundTimer) {
		clearTimeout(Time.playsoundTimer);
		Time.playsoundTimer = null;
	}
	Time.playsoundTimer = setTimeout(function () {
		if (Time.playsoundFlag) {
			Time.playsoundFlag = false;
			document.getElementById("answerDiv").style.visibility = "visible";
			source = Utils.Path + "sounds/instructions/It_is.mp3";
			Time.loadmetaDataFlag = true;
			Time.getDuration(source);
		}
		else {
			if (Utils.mobileDeviceFlag)
				Android.playTts(Time.ansWord, "eng");
			else
				saySomething(Time.ansWord);
			Time.playYourTurnSound();
			//if(Time.yourTurnTime)
		}
	}, 1000 * duration + 800);
}


Time.playYourTurnSound = function () {
	if (Time.playYourTurnTimer) {
		clearTimeout(Time.playYourTurnTimer);
		Time.playYourTurnTimer = null;
	}
	Time.playYourTurnTimer = setTimeout(function () {
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/Now_your_turn.mp3";
		document.getElementById("playSound").play();
	}, 3000);
}

Time.onSoundClick = function () {
	clearTimeout(Time.playsoundTimer);
	clearTimeout(Time.playYourTurnTimer);
	if (Utils.mobileDeviceFlag)
		Android.stopTts();
	else
		stopSomething();
	if (Time.level == false)
		document.getElementById("answerDiv").style.visibility = "visible";
	document.getElementById("playSound").pause();
	document.getElementById("playSound").src = Utils.Path + "sounds/" + Time.objArr[Time.questionCtr].sound;
	document.getElementById("playSound").play();
}

Time.record = function () {
	clearTimeout(Time.playsoundTimer);
	clearTimeout(Time.playYourTurnTimer);
	document.getElementById("playSound").pause();
	$("#sound").css("pointer-events", "none");
	if (Utils.mobileDeviceFlag)
		Android.stopTts();
	else
		stopSomething();
	if (Time.level == false)
		document.getElementById("answerDiv").style.visibility = "visible";
	if (Time.recordClickFlag == false) {
		Time.recordClickFlag = true;
		if (Utils.mobileDeviceFlag)
			Android.startSttArray("eng");
		$("#mike").prop('src', Utils.Path + "images/skin/Stop.png");
		$("#mike").addClass("blink_me");
		if (Time.checkStatus) {
			clearInterval(Time.checkStatus);
			Time.checkStatus = null;
		}
		Time.checkStatus = setInterval(function () {
			if (Utils.mobileDeviceFlag)
				Time.sttString = Android.getSttResult();
			console.log(Time.sttString);
			if ('$$$' !== Time.sttString) {
				clearInterval(Time.checkStatus);
				if (Time.sttString !== "###" && Time.sttString !== "")
					Time.checkAnswer();
				else {
					console.log('Stops');
					$("#sound").css("pointer-events", "auto");
				}
				Time.recordClickFlag = false;
				$("#mike").prop('src', Utils.Path + "images/skin/Mic.png");
				$('#mike').removeClass('blink_me');

			}
		}, 500);
	}
	else {
		Time.recordClickFlag = false;
		if (Utils.mobileDeviceFlag)
			Android.stopStt();
		Time.sttString = "";
		clearInterval(Time.checkStatus);
		$("#mike").prop('src', Utils.Path + "images/skin/Mic.png");
		$("#mike").removeClass("blink_me");
		$("#sound").css("pointer-events", "auto");
	}
}

Time.checkAnswer = function () {
	var i, j, k, counter = 0, splitArr = [], lowercaseString;

	$("#sound").css("pointer-events", "none");
	$("#mike").css("pointer-events", "none");
	Time.attemptFlag = true;
	Time.ansFoundFlag = false;
	totalMarks++;
	//console.log(Time.sttString);
	//Time.sttString=Time.sttString.replace(/(~|`|!|@|#|$|%|^|&|\*|\(|\)|{|}|\[|\]|;|:|\"|'|<|,|\.|>|\?|\/|\\|\||-|_|\+|=)/g," ")
	Time.sttArr = Time.sttString.split(",");
	Time.sttArr.splice(Time.sttArr.length - 1);
	//console.log(Time.sttArr);

	console.log(Time.sttString);
	//alert(Time.sttArr);
	for (k = 0; k < Time.possibilityArr[Time.questionCtr].length; k++) {
		Time.ans = Time.possibilityArr[Time.questionCtr][k].toString();
		Time.ans = regex(Time.ans);
		Time.ansArr = Time.ans.split(" ");
		if (Time.sttArr.includes(Time.ans)) {
			Time.ansFoundFlag = true;
		}
		else {
			for (i = 0; i < Time.sttArr.length; i++) {
				counter = 0;
				Time.sttArr[i] = regex(Time.sttArr[i]);
				console.log(Time.sttArr[i]);
				lowercaseString = Time.sttArr[i].toLowerCase();
				splitArr = lowercaseString.split(" ");
				for (j = 0; j < Time.ansArr.length; j++) {
					if (splitArr.includes(Time.ansArr[j].toLowerCase())) {
						counter++;
					}
				}
				if (counter == Time.ansArr.length) {
					Time.ansFoundFlag = true;
					//alert("correct");
					break;
				}
			}
			if (Time.ansFoundFlag)
				break;
		}
	}
	// alert(Time.sttArr);
	// alert(Time.ansArr);
	if (Time.ansFoundFlag) {
		if (Android.mobileDeviceFlag)
			Android.addLearntData(Time.ansWord, totalJsonQueCount, wordType);
		document.getElementById("teddy").src = Utils.Path + "images/skin/Taddy_Win.png";
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/coorrect_beat.mp3";
		document.getElementById("playSound").play();
		if (Time.nextQueTimer) {
			clearTimeout(Time.nextQueTimer);
			Time.nextQueTimer = null;
		}
		Time.nextQueTimer = setTimeout(function () { Time.nextQuestion(); }, 2000);

	}
	else {
		Time.ansFoundFlag = false;
		document.getElementById("teddy").src = Utils.Path + "images/skin/Taddy_Lose.png";
		document.getElementById("playSound").src = Utils.Path + "sounds/instructions/Try_Again!_Aditi.mp3";
		document.getElementById("playSound").play();
		//alert("wrong");
		setTimeout(function () {
			document.getElementById("teddy").src = Utils.Path + "images/skin/Taddy_Normal.png";
			$("#sound").css("pointer-events", "auto");
			$("#mike").css("pointer-events", "auto");
		}, 2000);

	}
}

Time.nextQuestion = function () {
	Time.attemptFlag = false;
	Time.playsoundFlag = true;
	Time.recordClickFlag = false;
	if (totalMarks == 0)
		scoredMarks = -1;
	else if (Time.ansFoundFlag)
		scoredMarks = 10;
	else
		scoredMarks = 0;
	console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	if (Utils.mobileDeviceFlag)
		Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	document.getElementById("playSound").pause();
	clearTimeout(Time.nextQueTimer);
	clearTimeout(Time.playsoundTimer);
	clearTimeout(Time.playYourTurnTimer);
	clearInterval(Time.checkStatus);
	Time.sttString = "";
	if (Utils.mobileDeviceFlag)
		Android.stopTts();
	else
		stopSomething();
	Time.sttString = "";
	Time.questionCtr++;
	document.getElementById("playSound").pause();
	$("#sound").css("pointer-events", "auto");
	$("#mike").css("pointer-events", "auto");
	document.getElementById("answerDiv").style.visibility = "hidden";
	document.getElementById("teddy").src = Utils.Path + "images/skin/Taddy_Normal.png";
	if (Time.objArr.length == 0 || Time.questionCtr >= 5) {
		Time.endGame();
	}
	else {
		// if(Utils.mobileDeviceFlag)
		// Android.stopTts();
		Time.setQuestion();
	}
}

Time.callHome = function () {
	if (Utils.mobileDeviceFlag)
		Android.stopTts();
	else
		stopSomething();
	if (Time.attemptFlag == true) {
		if (Time.ansFoundFlag)
			scoredMarks = 10;
		console.log(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
		if (Utils.mobileDeviceFlag)
			Android.addScore(resId, questionId, scoredMarks, totalMarks, level, startTime, label);
	}
	location.reload();
}

function regex(str) {
	str = str.replace(/(~|`|!|@|#|$|%|^|&|\(|\)|{|}|\[|\]|;|:|\"|'|<|,|>|\?|\/|\\|\||-|_|=)/g, " ");
	return str.replace(/\./gi, "");
}

Time.showAcknowlwdgement = function () {
	var i = 0, div;
	$("#acknowledgementDiv").empty();
	console.log(Object.keys(Time.AcknowledgementPageData).length)
	for (i = 0; i < Object.keys(Time.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(Time.AcknowledgementPageData)[i] + " : " + Object.values(Time.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 = Time.hardCodedData['createdOn'];
	div.style.marginBottom = "2vh";
	acknowledgementDiv.appendChild(div);
	document.getElementById("acknowledgementDiv").style.display = "block";
}
Time.playAgain = function () {
	$("#acknowledgementDiv").css("display", "none");
	document.getElementById("answerDiv").style.visibility = "hidden";
	Time.questionCtr = 0;
	Time.playGame();
}

function saySomething(whatToSay) {
	if ('speechSynthesis' in window) {
		speech = new SpeechSynthesisUtterance(whatToSay);
		speech.lang = 'en-IN'; //en-US
		//speech.rate=0.7;
		window.speechSynthesis.speak(speech);
	}
	//speech.onend = function() { $("#soundDiv").css("pointer-events","auto"); };
}
function stopSomething() {
	window.speechSynthesis.cancel();
}