/* ----------------------------------------------------------------------------------------
File Name: General_Functions.js

	This file handles general functions.
	
	Written By:  Yonit Rusho
	Date:	     23 March 2003

 ----------------------------------------------------------------------------------------*/

var Item_was			= ""; //holds the last clicked item's id.
var Item_was_in			= ""; //holds the SPAN that the clicked item was in.
var replaceCache		= "";
var replaceCache2		= "";
var RememberGROUP		= "";
var El_group			= 0;  //holds the element's group
var objRememberSelected = "";//SMC, DMC
var strSelectedChecked	= "";
var bFirstTime			= true;//for the random functionality. To avoid a second random.

/************************************* GENERAL FUNCTIONS **************************************/

//-------------Preload images-------------------

function PreLoadImages()
{
	var obj_IFRAME = document.frames("ifr_ExerciseInterface");
	if (document.images) 
	{
		obj_IFRAME.arImLoad = new Array (
		"play_over",
		"stop_playing_over",
		"stop_record_over",
		"record_over",
		"Next_over"
		);

		obj_IFRAME.arImList = new Array ();
		for (counter in obj_IFRAME.arImLoad) 
		{
			obj_IFRAME.arImList[counter] = new Image();
			obj_IFRAME.arImList[counter].src = "../images/" + obj_IFRAME.arImLoad[counter] + ".gif";
		}
	}
}

//------------	This function controls the distractors randomize engine.--------------
function fnRandomEngine()
{
	try
	{
		if(bFirstTime)
		{
			fnRandomDistractors(1);//random distracors
			bFirstTime = false;
		}
		else
			fnRandomDistractors(0);//To avoid a second random: use the previouse results.
	}
	catch(e)
	{
		return;
	}
}


//------------	This function disable selecting distractors.--------------
function CheckIfDisableDistractors(El,type)
{
	if(boolDisableDistractors)
	{
		if(type == 1) //SMC, DMC (disables selecting a RadioButton)
		{
			if((objRememberSelected != "None" && objRememberSelected.id != El.id) || (objRememberSelected == "None"))
				El.checked = false;
			objRememberSelected.checked = true;
		}
		if(type == 2) //MF1, MF3, SFL (disables selecting SPANS)
			return false;
		if(type == 3) //TYP (disables typing)
			El.contentEditable = false;
		if(type == 4) //MMC (disables selecting a CheckBox)
		{
			if(strSelectedChecked == true)
				El.checked = true;
			else
				El.checked = false;
		}
	}
	else
		return true
}

//------ OVER FUNCTIONS FOR SOUND BUTTONS' BACKGROUND CHANGING ------------
function sounds_btn_OverIt(El)
{
	El.className = "BUTTON_" + El.State + "_over";
}


function sounds_btn_OutIt(El)
{
	El.className = "BUTTON_" + El.State;
}


//-------------GENERAL OVER FUNCTIONS--------------------
var Item_was2 = ""; //holds the last clicked item's id.

function TextOver(El)
{
	if(El.id != Item_was2)
		El.className = "MT1_over";
}


function TextOut(El)
{
	if(El.id != Item_was2)
		El.className = "MT1_normal";
}

/*This function alert that a distractor was selected, for any use.
	For example, I (Yonit) use it to know if I have to clear all in Clear or just wrong
	answers. If the user clicked on anything, exept from the Right Answer button, it
	should clear all.*/
function DistractorWasSelected()
{
	boolDistractorSelected = true;
}


/******************************************************************************************
 Function SelectDistractor(El,logic) and function DropZone(El,logic)
	Parameters: El -> the clicked Distractor or empty line.
				logic -> the logic: SFL, DFL

	Description: These functions are for the SFL and the DFL logics. They are called from the XSLs.
	They handle the Click & Click functionalities.
*****************************************************************************************/
function SelectDistractor(El,logic)//resets other Distractors and changes the current Distractor's style. 
{

	if(!CheckIfDisableDistractors(El,2))//Disable the option to choose a distractor.
		return false
	
	var Doc_El = document.frames("ifr_ExerciseInterface").document
	array_innerTBL = new Array()
	array_TBL1 = new Array()
	
	El.Clicked = true;
	
	if(Item_was_in == "")
	{
		Item_was_in = El.parentElement.id;
		Item_was = El.id;
	}
	
	if(El.parentElement && El.parentElement.id.substr(0,3) != "TD_") //The span is already in TBL1
	{
		El.className = "SFL_MF_selected_" + El.tagName;
	}
	
	if(El.parentElement && El.parentElement.id.substr(0,2) != "Q_")	 //The click was in TBL2
	{	
		if(logic == "DFL") 
			array_innerTBL = Doc_El.all.TBL2.all.innerTBL.all;
		else if(logic == "SFL")
			array_innerTBL = Doc_El.all.TBL2.all;
			
		for(i=0; i < array_innerTBL.length; i++) 
		{
			if(array_innerTBL(i).Clicked && array_innerTBL(i).Clicked == true)
			{
				array_innerTBL(i).className = "SFL_MF_selected_" + El.tagName;
				array_innerTBL(i).Clicked = false;
			}
			else
			{
				array_innerTBL(i).className ="SFL_MF_select";
				if(Item_was_in != El.id && Doc_El.all.item(Item_was_in).id.substr(0,3) == "TD_")//Click on 2 elements in TBL2, one after the other.
				{
					Item_was_in = El.parentElement.id;
					Item_was = El.id;
				}	
			}
		}
		
	}	
	else	 //The click was in TBL1
		El.className = "SFL_MF_selected_" + El.tagName;
	
	//---------Highlight blank SPANs----------
	/*array_TBL1 = Doc_El.all.TBL1.all;
					
	for(i=0; i < array_TBL1.length; i++) 
	{
		if(array_TBL1[i].id.substr(0,3) == "spn" || array_TBL1[i].id.substr(0,3) == "Dis")
		{
			if(array_TBL1[i].id == El.id)//Don't highlight with background this word 
				array_TBL1[i].className = "SFL_MF_selected_" + array_TBL1[i].tagName;
			else
				array_TBL1[i].className = "SFL_MF_selectedTBL1_" + array_TBL1[i].tagName;
			
		}
	}*/
	//----------------------------------------
	
	if(El.id != Doc_El.all.item(Item_was).id)
		DropZone(El,logic)
}


/******************************************************************************************
*****************************************************************************************/
		
function DropZone(El,logic)
{


	if(!CheckIfDisableDistractors(El,2))//Disable the option to choose a distractor.
		return false
		
	var Doc_El = document.frames("ifr_ExerciseInterface").document
	
	if(Item_was == "" && El.innerHTML.search("______") != -1)
		return
	else	
	{	
		if(logic == "DFL")
			El.className = "SFL_MF_select";
				
		else if(logic == "SFL")
		{
			if(El.id.substr(0,3) == "spn" && Doc_El.all.item(Item_was).id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).parentElement.id.substr(0,1) == "Q")
				El.className = "blank_line";
			else if(El.id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).parentElement.id.substr(0,2) == "TD")
				El.className = "SFL_MF_select";
			else if(El.id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).parentElement.id.substr(0,1) == "Q")	
				El.className = "SFL_MF_TBL1_select";
		}
			
		replaceCache2 = Doc_El.all.item(Item_was).outerHTML;
		replaceCache = El.outerHTML;
	
		if(El.id.substr(0,3) == "spn" && Doc_El.all.item(Item_was_in).id.substr(0,3) == "TD_")
			Doc_El.all.item(Item_was).outerHTML = "";
		else
			Doc_El.all.item(Item_was).outerHTML = replaceCache;	
		El.outerHTML = replaceCache2;
	
	
		if(logic == "DFL")
			Doc_El.all.item(Item_was).className = "SFL_MF_select";
		else if(logic == "SFL")	
		{
			//first click in TBL2 and second in TBL1 OR both in TBL1, when the second is a blank line
			if(El.id.substr(0,3) == "spn" && Doc_El.all.item(Item_was).id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).parentElement.id.substr(0,1) == "Q")
				Doc_El.all.item(Item_was).className = "SFL_MF_TBL1_select";
			
			//first click in TBL1 and second in TBL2 (replace)
			else if(El.id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).parentElement.id.substr(0,1) == "Q")	
				Doc_El.all.item(Item_was).className = "SFL_MF_TBL1_select";
			
			//first click in TBL2 and second in TBL1(replace)
			else if(El.id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).id.substr(0,3) == "Dis" && Doc_El.all.item(Item_was).parentElement.id.substr(0,2) == "TD")	
				Doc_El.all.item(Item_was).className = "SFL_MF_select";
		}
			
		/*//reset TBL1
		array_TBL1 = Doc_El.all.TBL1.all;
									
		for(i=0; i < array_TBL1.length; i++) 
		{
			if(array_TBL1[i].id.substr(0,3) == "spn")
				array_TBL1[i].className = "SFL_MF_TBL1_select";
			if(array_TBL1[i].id.substr(0,3) == "Dis")
				array_TBL1[i].className = "SFL_MF_TBL1_select";
		}
		*/
		Item_was_in = "";
		Item_was = "";
	}	
}


/******************************************************************************************
 Function SelectDistractorMF(El,logic) and function DropZoneMF(El,logic)
	Parameters: El -> the clicked Distractor or empty line.
				logic -> the logic: MF1, MF3
	
	Description: These functions are for the MF1 and the MF3 logics. They are called from the XSLs.
	They handle the Click & Click functionalities.
*****************************************************************************************/
function SelectDistractorMF(El,logic)//resets other Distractors and changes the current Distractor's style. 
{
	//bug fix: if it is MF1, and one pressed on view right answers, then we are not allowed to change anything.
	if (logic == "MF1") {
		if (!document.frames("ifr_ExerciseInterface").document.all.Group1)
			return false;
	}

	if(!CheckIfDisableDistractors(El,2))//Disable the option to choose a distractor.
		return false
	
	var Doc_El = document.frames("ifr_ExerciseInterface").document
	array_innerTBL = new Array()
	array_TBL1 = new Array()
				
	El.Clicked = true;
			
	if(El_group == 0)
		calculate(El,1)
				
	if(Item_was_in == "")
	{
		Item_was_in = El.parentElement.id;
		Item_was = El.id;
	}
				
	if(El.parentElement && El.parentElement.id.substr(0,2) != "Q_")	 //The click was in TBL2
	{	
		array_innerTBL = Doc_El.all.TBL2.all;
						
		for(i=0; i < array_innerTBL.length; i++) 
		{
			if(array_innerTBL(i).Clicked && array_innerTBL(i).Clicked == true)
			{
				array_innerTBL(i).className = "SFL_MF_selected_" + El.tagName;
				array_innerTBL(i).Clicked = false;
			}
			else
			{
				array_innerTBL(i).className = "SFL_MF_select";
				if(Item_was_in != El.id && Doc_El.all.item(Item_was_in).id.substr(0,3) == "TD_")//Click on 2 elements in TBL2, one after the other.
				{
					Item_was_in = El.parentElement.id;
					Item_was = El.id;
								
					calculate(El,1)
				}	
			}
		}
					
	}	
				
	//Highlight spans in group
	array_TBL1 = Doc_El.all.TBL1.all;
					
	for(i=0; i < array_TBL1.length; i++) 
	{
		if(array_TBL1[i].id.substr(0,3) == "spn" || array_TBL1[i].id.substr(0,3) == "Dis")
		{
			
			if(array_TBL1[i].id.substr(0,3) == "spn")
			{
				p1 = array_TBL1[i].id.lastIndexOf("_");
				group = array_TBL1[i].id.substring(p1+1);
			}	
			else if(array_TBL1[i].id.substr(0,3) == "Dis")
			{
				p1 = array_TBL1[i].id.indexOf("_")
				p2 = array_TBL1[i].id.lastIndexOf("_")
				group = array_TBL1[i].id.substring(p1+1,p2);
			}
			
											
			if(El_group == group)
			{
				//if(array_TBL1[i].id == El.id)//Don't highlight with background this word 
					array_TBL1[i].className = "SFL_MF_selected_" + array_TBL1[i].tagName;
				//else
				//	array_TBL1[i].className = "SFL_MF_TBL1_select";//not highlighted
				RememberGROUP = group;
			}	
			else
				array_TBL1[i].className = "SFL_MF_TBL1_select";//not highlighted
		}	
	}
				
	if(El.id != Doc_El.all.item(Item_was).id)
		DropZoneMF(El,logic)
}
			

/******************************************************************************************
*****************************************************************************************/
function DropZoneMF(El,logic)
{
	if(!CheckIfDisableDistractors(El,2))//Disable the option to choose a distractor.
		return false
	
	var Doc_El = document.frames("ifr_ExerciseInterface").document;
	
	if(El.id.substr(0,3) == "spn")
	{
		p1 = El.id.lastIndexOf("_");
		group = El.id.substring(p1+1);
		
	}	
	else if(El.id.substr(0,3) == "Dis")
	{
		calculate(El,2)
	}

	if(Item_was == "" && El.innerHTML.search("______") != -1)
		return
	else
	{
		if(group == El_group)	
		{
			El.className = "SFL_MF_select";
								
			replaceCache2 = Doc_El.all.item(Item_was).outerHTML;
			replaceCache = El.outerHTML;
				
			if(El.id.substr(0,3) == "spn" && Doc_El.all.item(Item_was_in).id.substr(0,3) == "TD_")
				Doc_El.all.item(Item_was).outerHTML = "";
			else
				Doc_El.all.item(Item_was).outerHTML = replaceCache;	

			El.outerHTML = replaceCache2;
				
			Doc_El.all.item(Item_was).className = "SFL_MF_select";
			
			Item_was_in = "";
			Item_was = "";
			El_group = 0;
			RememberGROUP = "";
				
			//reset TBL1
			array_TBL1 = Doc_El.all.TBL1.all;
										
			for(i=0; i < array_TBL1.length; i++) 
			{
				if(array_TBL1[i].id.substr(0,3) == "spn")
					array_TBL1[i].className = "SFL_MF_TBL1_select";
				if(array_TBL1[i].id.substr(0,3) == "Dis")
					array_TBL1[i].className = "SFL_MF_TBL1_select";
			}
		}
		else
		{
			if(El.id.substr(0,3) == "spn")
				El.className = "SFL_MF_TBL1_select";
			if(El.id.substr(0,3) == "Dis")//Unselected TBL1 distractor.
				El.className = "SFL_MF_TBL1_select";
			Doc_El.all.item(Item_was).className = "SFL_MF_selected_" + Doc_El.all.item(Item_was).tagName;
		}
	}
}
			
function calculate(El,num)
{
	p1 = El.id.indexOf("_")
	p2 = El.id.lastIndexOf("_")
	if(num == 1)
		El_group = El.id.substring(p1+1,p2);
	else if(num == 2)
		group = El.id.substring(p1+1,p2);
}


/******************************************************************************************
 Function SelectUserResponse(El,logic)
	Description: This function copies the selected WORD (SLW logic) or SENTENCE (SLS logic)
				 to a span element in the right column.
*****************************************************************************************/
function SelectUserResponse(El,logic)
{
	if(!CheckIfDisableDistractors(El,2))//Disable the option to choose a distractor.
		return false
	
	var obj_IFRAME = document.frames("ifr_ExerciseInterface");
	if(El.id.search("Text") != -1)//Find and save word
	{
		var findWord = obj_IFRAME.document.selection.createRange();
		//var oRng2	 = findWord.duplicate();
		
		if(logic == "SLW")
			findWord.expand("word");
		if(logic == "SLS")
			findWord.expand("sentence");	
		selectedWord = findWord.text;
		rightAnswer = 0;
		
		//------------------------------------------------------------------------
		//The following check is to avoid multiple clicking on the same 
		//sentence and a selection of all document.
		selectedWord2 = selectedWord;
		while(selectedWord2.search(" ") !== -1) //while there are spaces in the string. 
			selectedWord2 = selectedWord2.replace(" ","") //remove them
		
		str = obj_IFRAME.document.all.item("Dis_" + El.parentElement.id.substring(4)).innerText
		while(str.search(" ") !== -1) //while there are spaces in the string. 
			str = str.replace(" ","") //remove them
			
		if(str.search(selectedWord2) == -1 || (logic == "SLW" && selectedWord2.length >20))//A word will not be that long
			selectedWord = "";

		//------------------------------------------------------------------------
	}
	else if(El.id.search("UserResponse") != -1)//Save word
	{
		selectedWord = El.innerHTML;
		if(logic == "SLW") {

			selectedWord = selectedWord.replace(",","");
			selectedWord = selectedWord.replace(".","");
			selectedWord = selectedWord.replace("?","");
			selectedWord = selectedWord.replace("!","");
			selectedWord = selectedWord.replace(":","");
			selectedWord = selectedWord.replace(";","");


		}

		rightAnswer = 1;
	}
	
	
	obj_IFRAME.document.all.item("sel_" + El.parentElement.id.substring(4)).innerHTML = "<span rightAnswer='" + rightAnswer + "'>" + selectedWord + "</span>";
	
	//obj_IFRAME.document.all.hd.value = obj_IFRAME.document.all.item("Dis_" + El.parentElement.id.substring(4)).innerText+"******"+selectedWord
}

//-------------OVER FUNCTIONS FOR CLICK AND CLICK LOGICS--------------------
function OverClickedLogics(El,logic)
{
	if(El.id != Item_was)
	{
		if(logic == "DFL")
		{
			El.className = logic + "_over_" + El.tagName;
		}
		else
		{
			p1 = El.id.indexOf("_")
			p2 = El.id.lastIndexOf("_")
			Over_group = El.id.substring(p1+1,p2);
			
			if(El.parentElement.id.substr(0,2) == "TD")
				El.className = logic + "_over_" + El.tagName;
			else if(El.parentElement.id.substr(0,2) == "Q_" && RememberGROUP != Over_group)
			{
				if(Item_was == "")//If the over is not after a click in TBL2.
					El.className = logic + "_TBL1_over_" + El.tagName;
			}
		}
	}
}

function OutClickedLogics(El,logic)
{
	if(El.id != Item_was)
	{
		if(logic == "DFL")
		{
			El.className = logic + "_select";
		}
		else
		{
			p1 = El.id.indexOf("_")
			p2 = El.id.lastIndexOf("_")
			Over_group = El.id.substring(p1+1,p2);
			
			if(El.parentElement.id.substr(0,2) == "TD")
				El.className = logic + "_select";
			else if(El.parentElement.id.substr(0,2) == "Q_" && RememberGROUP != Over_group)
			{
				if(Item_was == "")//If the over is not after a click in TBL2.
					El.className = logic + "_TBL1_select";
			}
		}
	}
}


/******************************************************************************************
 Function ReplaceDistractorsMT1(El)
	Description: This function highlights the selected distractor and changes distractors rows
	on replace (second click).
*****************************************************************************************/
var replace = true;

function ReplaceDistractorsMT1(El)
{
	if(!CheckIfDisableDistractors(El,2))//Disable the option to choose a distractor.
		return false
	
	var obj_IFRAME = document.frames("ifr_ExerciseInterface").document.all;
	
	var str, i, ColumnID, x;
	p1 = El.parentElement.id.indexOf("_");
	ColumnID = parseInt(El.parentElement.id.substr(p1+1));
	
	var str, replace, i, columnID, x;
	replace=true;
	
	for (i=1; i<=obj_IFRAME.TBL1.rows.length-1; i++)
	{
		CELL = obj_IFRAME.TBL1.rows(i).cells(ColumnID);
		
		if(CELL.children(1))//there is a feedback span in it
		{
			CELL.removeChild(CELL.children(1));
		}
		
		if (CELL.firstChild.className == "MT1_selected")
		{	
			CELL.firstChild.className = "MT1_normal";//highlight
			
			El.className = "MT1_normal";
			
			//---------replace------------
			replaceCacheMT1 = El.outerHTML;
			El.outerHTML = CELL.innerHTML;
			CELL.innerHTML = replaceCacheMT1;
			
			Item_was2 = ""; //enable over state on this distractor
			replace = false;
		}
	}
	if (replace==true)
	{
		Item_was2 = El.id; //disable over state on this distractor
		El.className = "MT1_selected"; 
	}  
}


//-------------MRW OVER FUNCTIONS--------------------
var Item_was2 = ""; //holds the last clicked item's id.
var overMRW_Dictionary_obj = new ActiveXObject("Scripting.Dictionary"); //for the Dictionary ActiveXObject

function TextOverMRW(El)
{
	if(!overMRW_Dictionary_obj.Exists(El.id))
		El.className = "MRW_over";
}

function TextOutMRW(El)
{
	if(!overMRW_Dictionary_obj.Exists(El.id))
		El.className = "MRW_normal";
}


/******************************************************************************************
 Function SelectDistractorMRW(El)
	Description: This function highlights the selected distractor in each couple of distractors.
*****************************************************************************************/
function SelectDistractorMRW(El)
{
	if(!CheckIfDisableDistractors(El,2))//Disable the option to choose a distractor.
		return false

	var obj_IFRAME = document.frames("ifr_ExerciseInterface").document.all;
	
	LeftOrRightDistractor = parseInt(El.id.substr(10,1));
	
	switch(LeftOrRightDistractor)
	{
		case 1:
			side = 2;
			break;
		case 2:
			side = 1;
			break;
	}
	
	dis		= "Distractor" + side + "_" + El.id.substr(12);
	overDis = "Distractor" + LeftOrRightDistractor + "_" + El.id.substr(12);
	
	obj_IFRAME.item(dis).className = "MRW_normal";
	obj_IFRAME.item(dis).state = 0;
	
	El.className = "MRW_selected";
	El.state = 1;
	
	if(!overMRW_Dictionary_obj.Exists(overDis))
		overMRW_Dictionary_obj.add(overDis,overDis); //dis is the key
	
	if(overMRW_Dictionary_obj.Exists(dis))
		overMRW_Dictionary_obj.Remove (dis)
}

	//===================================
	/*	This function will trim leading and/or trailing spaces from a string
		arg = the value you wish to have trimmed.
		func = "left" for Ltrim(), "right" for RTrim() or "both" for Trim()*/
	function trim(arg,func)
	{
		var trimvalue = "";
		arglen = arg.length;
		
		if (arglen < 1) return trimvalue;

		if (func == "left" || func == "both") 
		{
			k = 0;
			pos = -1;
		
			while (k < arglen) 
			{
				if (arg.charCodeAt(k) != 32 && !isNaN(arg.charCodeAt(k))) 
				{
					pos = k;
					break;
				}
				k++;
			}
		}

		if (func == "right" || func == "both") 
		{
			var lastpos = -1;
			k = arglen;
			while (k >= 0) 
			{
				if (arg.charCodeAt(k) != 32 && !isNaN(arg.charCodeAt(k))) 
				{
					lastpos = k;
					break;
				}
					k--;
			}
			
			if (func == "left") 
				trimvalue = arg.substring(pos,arglen-1);

			if (func == "right") 
				trimvalue = arg.substring(0,lastpos+1);

			if (func == "both") 
				trimvalue = arg.substring(pos,lastpos + 1);

			return trimvalue;
		}
	}
	
	
	
	
/***************************************** TAB ************************************************/
	
	function PaintCell(El)
	{
		if(!CheckIfDisableDistractors(El,2))//Disable the option to choose a distractor.
			return false
		
		var cell;
		
		if(El.parentElement.parentElement.parentElement.oneColAtATime == "No")//User can select more than one column in a row
		{
			if (El.Checked == "True")
			{
				El.className = "TAB_UnCheckedCell";
				El.Checked = "False";
			}
			else 
			{
				El.className = "TAB_CheckedCell";
				El.Checked = "True";
			}
		}
		
		else //User can select only one column in a row
		{
			//alert(El.parentElement.cells.length)
			for(i=0; i<El.parentElement.cells.length; i++)
			{
				cell = El.parentElement.cells(i);
				//alert(El.id+El.Checked+cell.id+cell.Checked)
				if(cell.id.substr(0,2) == "td" && cell.Checked == "True")//another td is selected
				{
					cell.className = "TAB_UnCheckedCell";
					cell.Checked = "False";
					//break;
				}
			}
			
			//check the clicked td
			El.className = "TAB_CheckedCell";
			El.Checked = "True";
		}
	}
	
/************************************* DR1 & SR1 *****************************************************/
			
	var tmp_RecordingPATH_str = "";
	var tmp_RecordingPATH_str2 = "";
	var RecordingPATH_str = RecordingPATH
	var RecordingPATH_str2 = RecordingPATH2
		
	//Sound files from a previous exercise will not be used in the current one.
	function CreateRecordingFolder(logic)
	{
		var Doc_El = document.frames("ifr_ExerciseInterface");
		
		Doc_El.document.all.Play.disabled = true;
		Doc_El.document.all.Record.disabled = true;
		if(Doc_El.document.all.Clear)
			Doc_El.document.all.Clear.disabled = true;
		try
		{
			var	fso	= new ActiveXObject("Scripting.FileSystemObject");
	
			calculateRecordingPATH_str()
			
			if(!fso.FolderExists(tmp_RecordingPATH_str))
				fso.CreateFolder(tmp_RecordingPATH_str)
			else if(!fso.FolderExists(tmp_RecordingPATH_str2))
				fso.CreateFolder(tmp_RecordingPATH_str2)
			
			fso	= null;
			
			Doc_El.document.all.Play.disabled = false;
			if(logic == "SR1")
				Doc_El.document.all.Record.disabled = false; //in DR1: Stay disabled untill user chooses A or B.
			if(Doc_El.document.all.Clear)
				Doc_El.document.all.Clear.disabled = false;		
		}
			
		catch(e)
		{	
			return
		}
	}
	
	function DeleteRecordingFolder(logic)
	{
		var Doc_El = document.frames("ifr_ExerciseInterface");
		if(Doc_El.document.all.Play)
			Doc_El.document.all.Play.disabled = true;
		if(Doc_El.document.all.Record)
			Doc_El.document.all.Record.disabled = true;
		if(Doc_El.document.all.Clear)
			Doc_El.document.all.Clear.disabled = true;
		try
		{
			var	fso	= new ActiveXObject("Scripting.FileSystemObject");
			
			calculateRecordingPATH_str()
			
			if(fso.FolderExists(tmp_RecordingPATH_str))
				fso.DeleteFolder(tmp_RecordingPATH_str) //remove folder & its content.
			else if(fso.FolderExists(tmp_RecordingPATH_str2))
				fso.DeleteFolder(tmp_RecordingPATH_str2) //remove folder & its content.
			
			fso	= null;

			//clear recording Timeout
			if(logic && logic == "DR1")
				clearTimeout(stopDR1);
			else if(logic && logic == "SR1")
				clearTimeout(stop);
			
			if(Doc_El.document.all.Play)
				Doc_El.document.all.Play.disabled = false;
			if(Doc_El.document.all.Record)
				Doc_El.document.all.Record.disabled = false;
			if(Doc_El.document.all.Clear)
				Doc_El.document.all.Clear.disabled = false;	
		}
			
		catch(e)
		{	
			return
		}
	}
	
//***********************************************************//
	function calculateRecordingPATH_str()
	{
		if(RecordingPATH_str.substr(RecordingPATH_str.length-1,1) == "\\") //remove: "\"
		{
			tmp_RecordingPATH_str = RecordingPATH_str.substring(0,RecordingPATH_str.length-1)
			tmp_RecordingPATH_str2 = RecordingPATH_str2.substring(0,RecordingPATH_str2.length-1)
		}
		else
		{	
			tmp_RecordingPATH_str = RecordingPATH_str	//create a folder for recorded files
			tmp_RecordingPATH_str2 = RecordingPATH_str2	//create a folder for recorded files
		}
	}
	
/************************************* DR1 *****************************************************/
			
	var part = "none"
	var FULL_soundArray = new Array()
	var firstTime3 = true;
	
	function SignPart(El)
	{
		if(!CheckIfDisableDistractors(El,2))//Disable the option to sign a part.
			return false

		var Doc_El = document.frames("ifr_ExerciseInterface");
		part = El.substr(2,1);
		if(firstTime3)
		{
			Doc_El.document.all.Record.disabled = false; //Enable button, since user has chosen A or B.
			Doc_El.document.all.Record.className = "BUTTON_record";
			firstTime3 = false; 
		}
	}
	
	//holds all the soundSRCs from the XML
	function Build_FULLsoundArray()
	{
		var Doc_El = document.frames("ifr_ExerciseInterface");
		var TDs_Array		= new Array()
		var counter = 0;
		TDs_Array = Doc_El.document.getElementsByTagName("TD")
		
		for(i=0; i < TDs_Array.length; i++)
			if(TDs_Array[i].id.substr(0,4) == "par_")
			{
				FULL_soundArray[counter] = TDs_Array[i].SoundSrc;
				counter++;
			}
		//alert(FULL_soundArray)
	}
			
													
/***************************************** SR1 ************************************************/
	var ChosenRowSound = "";
	var ChosenRow = 1;
	
	function SignRow (El)
	{
		if(!CheckIfDisableDistractors(El,2))//Disable the option to sign a row .
			return false

		var Doc_El = document.frames("ifr_ExerciseInterface");
		var Coll = Doc_El.document.all.tags("TR");
		
		for (var i=0; i<=Coll.length-1; i++)
			if (Coll(i).id.substr(0,3)=="par")
				Coll(i).className  = "show_table";
		
		El.className  = "title_show_table";
		ChosenRowSound = El.SoundSrc;
		p1 = El.id.indexOf("_");
		ChosenRow = El.id.substr(p1+1)
	}


/***************************************** SMC, DMC ************************************************/
	
function RememberSelectedInput(El)
{
	var strGroupName = El.name
	var objRB = document.frames("ifr_ExerciseInterface").document.all.item(strGroupName);
	var countInputs = 0;
	var intRbLength = objRB.length;
	
	for(i=0;i<intRbLength;i++)
	{
		if(objRB[i].checked == true)
		{
			objRememberSelected = objRB[i];
			break;
		}
		else
			countInputs++;
	}
	
	if(countInputs == intRbLength)//Nothing was selected
		objRememberSelected = "None";
}


/***************************************** MMC ************************************************/

function RememberSelectedInputMMC(El)
{
	strSelectedChecked = El.checked;
}


/***************************************** TYP ************************************************/

/******************************************************************************************
	Description: This function displays next answer in the input, 
	after the user has clicked on next. 
*****************************************************************************************/
var strRightAnswer;
var recurse = false;


function fncDisplayNextAnswer(distractorID,ArrIndex,array_UserResponsesIndex,once)
{
	var array_UserResponses_in_XML = new Array()
	var obj_IFRAME = document.frames("ifr_ExerciseInterface").document;
	
	array_UserResponses_in_XML = oExerciseXml.documentElement.getElementsByTagName("UserResponse")
	
	rightAnswerNode = array_UserResponses_in_XML[array_UserResponsesIndex].selectSingleNode("//Exercise/Distractor[@id = " + distractorID + "]");
	
	//There are more then one right answer
	intNextIconCounter = arrNextIconCounter[ArrIndex];
	
	oRight = rightAnswerNode.selectSingleNode("RightAnswer[" + intNextIconCounter + "]");
	
	if(oRight)
	{
		displayIt = oRight.getAttribute('display')
		
		if(displayIt && displayIt == "no")//Do not display the next right answer
		{
			recurse = true;
			arrNextIconCounter[ArrIndex] += 1;
			fncDisplayNextAnswer(distractorID,ArrIndex,array_UserResponsesIndex)
			recurse = false;
		}	
		else
			strRightAnswer = oRight.text;//Get answers.
	}
	else //From beginning
	{
		arrNextIconCounter[ArrIndex] = 0;
		strRightAnswer = rightAnswerNode.selectSingleNode("RightAnswer[0]").text;//Get answers.
	}
	
	if(once && !recurse)
	{
		arrNextIconCounter[ArrIndex] += 1;	
		once = false; //To avoid adding 1 over and over
	}
	
	UserResponseID	= array_UserResponses_in_XML[array_UserResponsesIndex].getAttribute("id");
	
	obj_IFRAME.all.item("UserResponse" + UserResponseID).value = strRightAnswer;//Display first answer.
}


/***************************************** ELS ************************************************/

/******************************************************************************************
	Description: This function eliminates the clicked sentence and displays a 
	graphical icon instead.
*****************************************************************************************/
function EliminateSentence(El)
{
	var objIFRAME = document.frames("ifr_ExerciseInterface").document.all;

    xmlParagraph = oExerciseXml.documentElement.selectSingleNode("//Exercise/Paragraph[@id = '" + El.parNum + "']")
	
	for (i=0; i<xmlParagraph.childNodes.length; i++)
	{
		strTagName		= xmlParagraph.childNodes[i].tagName;
		
		//Return previouse sentense only if just one sentense can be selected.
		if(strTagName != "Title" && xmlParagraph.getAttribute("oneCanBeSelected") == "true")
		{
			intParagraphNum = El.parNum;
			intTagNum		= xmlParagraph.childNodes[i].getAttribute("id");
			
			strIconObj		= "icon_" + intParagraphNum + "_" + strTagName + "_" + intTagNum;
			strObj			= intParagraphNum + "_" + strTagName + "_" + intTagNum;
			
			objIFRAME.item(strObj).style.display = "inline";
			objIFRAME.item(strIconObj).style.display = "none";
		}
	}
	El.style.display = "none";
	
	objIFRAME.item("icon_" + El.id).innerHTML = strELS_Icon;
	objIFRAME.item("icon_" + El.id).style.display = "inline";
}


/******************************************************************************************
	Description: This function eliminates the graphical icon and displays the 
	original sentence instead.
*****************************************************************************************/
function DisplaySentenceAgain(El)
{
	var objIFRAME = document.frames("ifr_ExerciseInterface").document.all;

	El.style.display = 'none';
	objIFRAME.item(El.id.substring(5)).style.display = "inline";
}


/***************************************** MFL ************************************************/

/******************************************************************************************
	Description: This function displays the distractors bank, relevant to the 
	clicked	blank.
*****************************************************************************************/
function displayDistBank(El,icon)
{
	var intLeft = "", strBankID, intTop = "";
	var objIFRAME = document.frames("ifr_ExerciseInterface").document.all;
	
	p1 = El.id.indexOf("_")
	strBankID = "DistUserResponseBank_" + El.id.substring(3,p1) + "_" + El.id.substring(p1+1);
	strDisplay = objIFRAME.item(strBankID).style.display;
	
	hideAllBanks()
	
	if(strDisplay == "none")//Display bank
	{
		//intLeft = El.offsetLeft + El.offsetParent.offsetLeft + El.offsetParent.clientWidth + 50;
		intLeft = icon.offsetLeft + icon.offsetParent.offsetLeft //+ El.offsetParent.clientWidth-300;
		intTop = icon.offsetTop + icon.offsetParent.offsetTop;
		objIFRAME.item(strBankID).style.top = intTop*1.19;
		objIFRAME.item(strBankID).style.left = intLeft*0.82;
		objIFRAME.item(strBankID).style.display = "inline";
	}
	else	//Hide bank (second click)
		objIFRAME.item(strBankID).style.display = "none";
}

function hideAllBanks()
{
	var arrDIVs	= new Array()
	var objIFRAME = document.frames("ifr_ExerciseInterface").document;
	
	arrDIVs	= objIFRAME.getElementsByTagName("DIV")
	
	for(i=0; i < arrDIVs.length; i++)
		if(arrDIVs[i].id.indexOf("DistUserResponseBank_") >= 0)//It is a bank
			arrDIVs[i].style.display = 'none';
}


/******************************************************************************************
	Description: This function copies the clicked distractor's innerHTML from the 
	bank to the blank.
*****************************************************************************************/
function getDistFromBank(El)
{
	var objIFRAME = document.frames("ifr_ExerciseInterface").document.all;
	
	p1 = El.id.lastIndexOf("_");

	if(El.tagName == 'IMG')
		objIFRAME.item("spn" + El.id.substring(11,p1)).innerHTML = "<IMG id=disInBlank_" + El.id.substring(11) + " src='" + El.src + "'/>"
	else
		objIFRAME.item("spn" + El.id.substring(11,p1)).innerHTML = "<span id=disInBlank_" + El.id.substring(11) + ">" + El.innerHTML + "</span>";
	
	objIFRAME.item("DistUserResponseBank_" + El.id.substring(11,p1)).style.display = 'none'; 
}
