
window.onload = init;
var nxtid = 0;
var sc = 1;

	var btnClr = document.getElementById('btnclr1');
	var btnValider = document.getElementById('btn1');
	var btnReponses = document.getElementById('btn2');
	var fillSelect = document.getElementById("crossword").getElementsByClassName("no");

function init() {
	document.getElementById('btn1').onclick = checkAns1;
	document.getElementById('btnclr1').onclick = clear1;
	document.getElementById('btn2').onclick = answer;
	btnReponses.disabled=true;
	btnReponses.setAttribute('style', "color:#D4D0C8");
	btnValider.disabled=true;
	btnValider.setAttribute('style', "color:#D4D0C8");
}
function fillandgo(x) {
	sc = 1
	nxtid+=1;
	console.log(x.value);
	console.log(nxtid);
	document.getElementById("fill1_"+nxtid).value=String(x.value);
	document.getElementById("fill1_"+nxtid).style.Color="White";
	document.getElementById("fill1_"+nxtid).style.fontSize="1em";       
	document.getElementById("fill1_"+nxtid).style.lineHeight=".5em";    
	
	var ac = document.getElementById(x.id);
	ac.setAttribute('style','background-color:#FFFFFF;')

	
	btnValider.disabled=false;
	btnValider.setAttribute('style', "color:#000000");
	if(nxtid>=16) {
		for(var i=1; i<=16; i++) {
			document.getElementById("option"+i).onmousedown = null;
		}
	}
}
function checkAns1() {
	sc = 1
	for(var i=1; i<=fillSelect.length; i++) {
		var correctVal = document.getElementById("fill1_"+i);
		var matchVal = document.getElementById("fill_ans1_"+i);
		if (correctVal.value.toLowerCase()==matchVal.innerHTML) {
			correctVal.style.backgroundColor = "#008000";
			correctVal.style.color = "#FFFFFF";
			correctVal.style.fontWeight = "bold";
		} else {
			correctVal.style.backgroundColor = "red";
			correctVal.style.color = "#FFFFFF";
			correctVal.style.fontWeight = "bold";
		}
	}
	btnReponses.disabled=false;
	btnReponses.setAttribute('style', "color:#000000");
}

function clear1(){
location.reload();
}


function answer() {
	if (sc == 1) {
		for(var i=1; i<=fillSelect.length; i++) {
			var q = document.getElementById("fill1_"+i);
			var a = document.getElementById("e_"+i);
			var option = document.getElementById("option"+i);
					q.setAttribute('hidden','hidden')
					a.removeAttribute('hidden','hidden')
					option.setAttribute('disabled','true')
		}
		btnValider.disabled=true;
		btnValider.setAttribute('style', "color:#D4D0C8");
		sc += 1;
	} else {
		for(var i=1; i<=fillSelect.length; i++) {
			var q = document.getElementById("fill1_"+i);
			var a = document.getElementById("e_"+i);
			var option = document.getElementById("option"+i);
					a.setAttribute('hidden','hidden')
					q.removeAttribute('hidden','hidden')
					option.removeAttribute('disabled')
		}
		sc -= 1;
		btnValider.disabled=false;
		btnValider.setAttribute('style', "color:#000000");
	}
}


function mouseUp(x) {
	var ac = document.getElementById(x);
		ac.removeAttribute('style')
	if(nxtid>=16) {
		for(var i=1; i<=16; i++) {
			document.getElementById("option"+i).onmouseup = null;
		}
	}
}