/*-------------------------------------------------------------------------
This code is copyrighted to BIS : Begeleid Individueel Studeren,
a department of Ministerie Vlaamse Gemeenschap, 2002-2003.
Developping was done in co-operation with Education Services:
tel. +32(0)3/227 02 06 / fax. +32(0)3/227 32 65 info@educationservices.be
-------------------------------------------------------------------------*/


// hw_fillblanks.js, versie 1.3, 12 november 2002
// dit script corrigeert case sensitive
// script voor talen 
// aanpassing 1.3 : feedback initially hidden en met layout
// aanpassing 3.0 : initial popup of the feedback disabled
// 2003-03-25: Implementation of the Self Correction button
// 2003-03-25: Implementation of the Layered Feedback
// 2004-04-28: 3.5.3: Self Correction displays only the first 
//                          correct answer (Bram Esposito)
 

//------------------- Declaring variables ---------------------------------
var currFB = 0;
var FBLocked = true;
//-------------------------------------------------------------------------
 
 
//---------------------- Zelf-correctie - 25-03-2003 ----------------------
//		Functie wordt aangeroepen vanuit Lectora door 
//		de correctieknop. Dit aan de hand van volgende
//		code: javascript:self_correct(); in een weblink.
//		Wat doet deze knop/functie? 
//		De cursist klikt op de verbeter knop om de juiste 
//		antwoorden te laten staan en enkel door te gaan 
//		met de foute oefeningen voor een 2e maal in te vullen.
//-------------------------------------------------------------------------
function selfCorrect() {
	for (var i = 0; i < document.forma.length; i++)
		{
		var gapID = document.forma.elements[i];
		if (gapID.type == "text")
			{
			if (gapID.style.background == "#ff9999" 
			    || gapID.style.background == "#cccccc" )
			        {
				if (currFB >= 
				    fbfout[getIndex(gapID.name)].length-1)
					{
					autoCorrect(gapID,i);
					} else {
					resetGap(gapID,i);
					}				    
			 	}
			}
		}
	if (!FBLocked){  // Disable clicking 2 times on the SelfCorr button 
	currFB = currFB +1;
	FBLocked = true;
	}		
}
//-------------------------------------------------------------------------


//------------------- Fills the gap with the correct answer(s) ------------
function autoCorrect(gapID,i){
	gapID.style.background = '#FFFF00';
	gapID.value = antw[i][0];
	var setcookie = "gap" + i +"=1";
	document.cookie = setcookie; 
	gapID.readOnly = true;
}
//------------------------------------------------------------------------- 


//-------------------------------------------------------------------------
function verbeter()
{
	for (var i = 0; i < document.forma.length; i++)
	{
	var gapID = document.forma.elements[i];
	if (gapID.type == "text")
		{
		var antwoord = gapID.value;
		//antwoord = antwoord.toLowerCase();
		var juist_a = antw[i][0];
		var juist_b = antw[i][1];
		var juist_c = antw[i][2];
		document.all.feedback.innerHTML = 
		"Klik op de verbeterde antwoorden voor toelichting.";
	if (antwoord != "" && gapID.style.background != "#ffff00")
		{
		if (antwoord == juist_a 
		    || antwoord == juist_b || antwoord == juist_c)
			{
			gapID.style.background = '#99FF99';
			var setcookie = "gap" + i +"=1";
			document.cookie = setcookie; 
			gapID.readOnly = true;
			}
			else
			{
			gapID.style.background = '#FF9999';
			var setcookie = "gap" + i +"=0";
			document.cookie = setcookie; 
			}
		}	 
		else if (gapID.style.background != "#ffff00")
			{
			gapID.style.background = '#CCCCCC';
			document.all.feedback.innerHTML = "";
			}
		}
		//start Education Services
		else 
		{
		gapID.style.visibility = "hidden"; 
		}
		//end Education Services		
	}
	FBLocked = false;	
} 
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
function fb_close()
{
document.all.feedbacklayer.style.visibility = 'hidden';
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
function fb_hide()
{
document.all.feedbacklayer.style.display = 'none';
}
//-------------------------------------------------------------------------

	
//-------------------------------------------------------------------------
/*function fb_close()
{
document.all.feedbacklayer.style.display = 'none';
}*/
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
function getCookie(NameOfCookie)
{
  if (document.cookie.length > 0) 
	{ 
    begin = document.cookie.indexOf(NameOfCookie+"="); 
    if (begin != -1)
   		{ 
		begin += NameOfCookie.length+1; 
      	end = document.cookie.indexOf(";", begin);
      	if (end == -1) end = document.cookie.length;
      	return unescape(document.cookie.substring(begin, end));       } 
  	}
return null;  
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
function getIndex(gapID) {
    for (var i=0;i < document.forma.elements.length;i++)
        if (document.forma.elements[i].name == gapID)
            return i;
    return -1;
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
function delCookiesOnReset() 
{
	for (var i = 0; i < document.forma.length; i++)
		{
		var gapID = document.forma.elements[i];
		if (gapID.type == "text")
			{
			 resetGap(gapID,i)
			}
		}
	currFB = 0;		
}
//-------------------------------------------------------------------------


//------------------- Reset a gap to it's initial state -------------------
function resetGap(gapID,i) {
	gapID.style.background = '#FFFFCC';
	gapID.style.visibility = "visible"; 
	gapID.value = "";
	document.all.feedback.innerHTML = "";
	var setcookie = "gap" + i +"=2";
	document.cookie = setcookie;
	tel = 0;
	gapID.readOnly = false;
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
function fback(gapID, gapIndex)
	{
//	document.all.feedback.innerHTML = gapIndex;
	var juist = getCookie(gapID)
	if (juist == 1)
		{
		document.all.feedback.innerHTML = fbjuist[gapIndex];
		}
	else if (juist == 0)
		{
		//alert(fbfout[gapIndex]);
		var tempFB = fbfout[gapIndex][currFB];
		var i = 1;
		while (tempFB == "") {
		tempFB = fbfout[gapIndex][currFB-i];
		i++;
		}		
		document.all.feedback.innerHTML = tempFB;
		}
	else
		{
		document.all.feedback.innerHTML = "";
		}
	}	
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
function fb_mover()
{
var cur_ypos = window.event.y;
var new_ypos = cur_ypos + 10;
var cur_xpos = window.event.x;
var temp_xpos = cur_xpos - 150;
	if(temp_xpos > 470){new_xpos = 470;}
	else if(temp_xpos < 20){new_xpos = 20;}
	else new_xpos = temp_xpos;
document.all.feedbacklayer.style.top = '50';
document.all.feedbacklayer.style.left = '0';
document.all.feedback.style.width = '300';
document.all.feedback.style.height = '50';
document.all.feedbacklayer.style.display = 'block';
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
function toonFeedback(deze)
	{
	if (deze.value != "")
		{
		var gapID = deze.name;
		gapIndex = getIndex(gapID);
		fback(gapID, gapIndex);
		fb_mover();
		}
	}
//-------------------------------------------------------------------------

	
//-------------------------------------------------------------------------
/*function count()
	{
	tel ++;
	if (tel == 4)
		{
		for (var i = 0; i < document.forma.length; i++)
			{
			var gapID = document.forma.elements[i];
			if (gapID.type == "text")
				{
				var antwoord = gapID.value;
				var juist_a = antw[i][0];
				var juist_b = antw[i][1];
				var juist_c = antw[i][2];
				document.all.feedback.innerHTML = "";
				if (antwoord == juist_a 
				    || antwoord == juist_b 
				    || antwoord == juist_c)
					{
					}
				else
					{
					gapID.style.background = '#FFFF00';
					gapID.value = juist_a;
					var setcookie = "gap" + i +"=1";
					document.cookie = setcookie; 
					}
				}
			}
		}
	}*/
//-------------------------------------------------------------------------
//---------------------------------- eof ----------------------------------
