/*
 * Copyright (C) 1995-2011 by 4system Polska Sp. z o.o.
 * All Rights Reserved.
 */
 
componentTextModify = function(name)
{
	this.componentElement = componentElement;
	this.componentElement(name);
	
	this.correctAnswersList = new Array();
	this.rememberItemsArr = new Array();
	
	this.complete = false;
	this.basicText = '';
	this.counter = 0;
	this.addInactive = false;
	
	this.iTimerID = null;
	this.allowGF = true;

	this.interactions = true;
	this.interactionsType = "numeric";
};

componentTextModify.prototype = new componentElement();
componentTextModify.prototype.type = "componentTextModify";

componentTextModify.prototype.onCreate = function(obj)
{
	this.captureMouseEvents();
	this.correctAnswersList = this.correctAnswer;
	
	var font = {};
	font.family = this.fontFamily;
	font.size = this.fontSize;
	font.color = this.fontColor;
	
	if (this.allowGF && project.globalFormating && this.isDefaultFont(font) && !this.isDefaultFont(project.font))
	{
		this.fontFamily = project.font.family;
		this.fontSize = project.font.size;
		this.fontColor = project.font.color;
	};
};

componentTextModify.prototype.isDefaultFont = function(font)
{
	var result = true;
	if (font.family != 'Arial') {
		result = false;
	} else if (font.size != 2) {
		result = false;
	} else if (font.color.replace(/#/g, "") != '000000') {
		result = false;
	}
	return result;
};

componentTextModify.prototype.getFontSize = function(value, format)
{
	var fontSizesPX = new Array(0,10,13,16,18,24,32,48);
	var fontSizesPT = new Array(0, 8,10,12,14,18,24,36);
	var pxSize = fontSizesPT[parseInt(value)];
	if (format == "px") {
		pxSize = fontSizesPX[parseInt(value)];
	}
	return pxSize;
};

componentTextModify.prototype.onPaint = function(obj)
{
	var s = "";
	var dispAndCorrArray = this.text.toString().split("||");
	//selectedColor = this.selectedColor;
	selectedColor = this.markColor;
	var onlyText = '';
	
	bgColor = this.bgColor;
	if (PageInterface.GetValue("state") == psDesigning) {
		var ansArray = this.correctAnswer.split(",");
		var wasHit = false;
		if (this.showCounter){
			s += '<table border="0" cellSpacing="0" cellPadding="0"><tr><td valign="top">&nbsp;&nbsp;<b>';
			if (this.anotherText == '-') {
					s += '<span id='+this.id+'_span_counter style="background-color:'+this.selectedColor+';';
					s += ' font-size:'+this.getFontSize(this.fontSize, 'px')+'px; color:'+this.fontColor+'; ';
				
				if (this.answerCount == '') var answerCount = this.getAnswerCount(dispAndCorrArray);
				else answerCount = this.answerCount;
				
				s += ' font-family:'+this.fontFamily+';">'+answerCount+'</span>&nbsp;&nbsp;</b>';
				s += '</td>';
			};
			s += '<td>';
		};
		
		for (var i=0; i < dispAndCorrArray.length; i++) {
			var textArray = dispAndCorrArray[i].split('@#@');
			for (var j=0; j < ansArray.length; j++) {
				if (textArray[1] != '') {
					s += "<span id='" + this.id + "_span_" + i + "' "+
						"style='background-color:" + this.selectedColor + "; font-size:" + this.getFontSize(this.fontSize, "px") + "px; color:" + this.fontColor + "; font-family:" + this.fontFamily + ";' "+
						"onclick = \"(this.style.backgroundColor == '" + bgColor + "')?this.style.backgroundColor='" + selectedColor + "':this.style.backgroundColor='" + bgColor + "'\">" ;
					onlyText = this.repalceStrbyStr(textArray[0], "$", "'");
					s += onlyText;								
					s += "</span> ";
					wasHit = true;
					break;
				}
			}
			if (!wasHit){
				s += "<span id='" + this.id + "_span_" + i + "' "+
					"style='background-color:" + this.bgColor + "; font-size:" + this.getFontSize(this.fontSize, "px") + "px; color:" + this.fontColor + "; font-family:" + this.fontFamily + ";' "+
					"onclick = \"(this.style.backgroundColor == '" + bgColor + "')?this.style.backgroundColor='" + selectedColor + "':this.style.backgroundColor='" + bgColor + "'\">";
				onlyText = this.repalceStrbyStr(textArray[0], "$", "'");
				s += onlyText;								
				s += "</span> ";
			}
			wasHit = false;
		};
		s += '</td></tr></table>'
	} else {
		var splited = this.buttonsAndPopups.split('||');
		if (this.answerCount == '') var answerCount = this.getAnswerCount(dispAndCorrArray);
			else answerCount = this.answerCount;
		
		this.counter = answerCount;
		if (this.showCounter){
			s += '<table border="0" cellSpacing="0" cellPadding="0"><tr><td valign="top">&nbsp;&nbsp;<b>';
			if (this.anotherText == '-') {
				s += '<span id='+this.id+'_span_counter style="background-color:'+this.selectedColor+';';
				s += ' font-size:'+this.getFontSize(this.fontSize, 'px')+'px; color:'+this.fontColor+'; ';
				
				
				s += ' font-family:'+this.fontFamily+';">'+answerCount+'</span>&nbsp;&nbsp;</b>';
				s += '</td>';
			}else if (page.all[this.anotherText]){
				this.basicText = page.all[this.anotherText].text;
				text = this.basicText.replace('{=counter}', this.counter);
				page.all[this.anotherText].text = text;
				page.all[this.anotherText].paint();
			};
			s += '<td>';
		};
		
		for (var i=0; i < dispAndCorrArray.length; i++) {
			var textArray = dispAndCorrArray[i].split('@#@');			
			var j = 0;
			do {
				var spl = splited[j].split('#!#');
				var one = spl[0].split('~');
				j++;
			}while(typeof(splited[j]) != 'undefined' && one[1] != textArray[0])
			
			if (one[1] == textArray[0]){
				var popups = splited[j-1].split('#!#');
				var popup1 = popups[1];
				var popup2 = popups[2];
			}else{
				var popup1 = '';
				var popup2 = '';
			};
			
		 	s += "<span id='" + this.id + "_span_" + i + "' "+
				"style='background-color:" + this.bgColor + "; font-size:" + this.getFontSize(this.fontSize, "px") + "px; color:" + this.fontColor + "; font-family:" + this.fontFamily + ";' "+
				"onclick = \'pc."+this.id+".clickSPAN(this, \""+bgColor+"\", \""+selectedColor+"\", \""+textArray[1]+"\", \""+popup1+"\", \""+popup2+"\");\'>";
			onlyText = this.repalceStrbyStr(textArray[0], "$", "'");
			s += onlyText;								
			s += "</span> ";	
		};
		s += '</td></tr></table>'
	};
	s += '<div id='+this.id+'divInput style="visibility: hidden; left:0; top:0; position: absolute">';

	if (this.showWhyButton){
		s += '<img id='+this.id+'ButtonWHYInput src="' + resourcesURL + this.buttonWHY_srcOut + '"';
		s += ' onMouseover="pc.'+this.id+'.mouseOverWHYButton(this);"';
		s += ' onMouseout="pc.'+this.id+'.mouseOutWHYButton(this);"';
		s += ' onMousedown="pc.'+this.id+'.mouseDownWHYButton(this);" style="cursor: hand">';	
	};
	
	if (this.showAddButton){
		s += '<img id='+this.id+'ButtonAddInput src="' + resourcesURL + this.buttonAdd_srcOut + '"';
		s += ' onMouseover="pc.'+this.id+'.mouseOverAddbutton(this);"';
		s += ' onMouseout="pc.'+this.id+'.mouseOutAddbutton(this);"';
		s += ' onMousedown="pc.'+this.id+'.mouseDownAddbutton(this);" style="cursor: hand">';
	};
	
	s += '<input id='+this.id+'InputInsideText style="background: '+this.backgroundInputColor+';';
	s += ' border-color: '+this.borderInputColor+'; border-width : '+this.inputBorder+'px; width: 100px" onKeyup="pc.'+this.id+'.keyUp(this);" onKeydown="pc.'+this.id+'.confirmChange(event);">';	
	
	s += '<img id='+this.id+'ButtonHideDiv src="' + resourcesURL + this.buttonHideDiv + '"';
	s += ' onMousedown="pc.'+this.id+'.mouseDownButtonHideDiv(this, true);" style="cursor: hand">';
	
	if (this.showInfoButton){
		s += '<img id='+this.id+'ButtonInfo src="' + resourcesURL + this.buttonInfo_srcOut + '"';
		s += ' onMouseover="pc.'+this.id+'.mouseOverInfoButton(this);"';
		s += ' onMouseout="pc.'+this.id+'.mouseOutInfoButton(this);"';
		s += ' onMousedown="pc.'+this.id+'.mouseDownInfoButton(this);" style="cursor: hand">';
	};
	s += '</div>';

	this.setHTML(s);
	//this.onRepaint();
};

componentTextModify.prototype.onAfterLoad = function(obj) //pg2- add working with nationalCharacters component
{
	var inputObj = document.getElementById(this.id + "InputInsideText");
	if (inputObj) {
		for (var i in pc) {
			var obj = pc[i];
			if (obj) {
				var objType = obj.type;
				if (objType == "componentNationalCharacters") {
					try {
						inputObj.onclick = new Function("pc." + obj.id + ".setElement('', '" + obj.id + "', '" + inputObj.id + "')");
					} catch(e) {
						alert(e.message);
					}
				}
			}
        }
	}
};

componentTextModify.prototype.confirmChange = function(event)
{
	if (event.keyCode == 13){
		var button = document.getElementById(this.id+'ButtonHideDiv');
		if (button){		
			this.mouseDownButtonHideDiv(button, true);
			if (is.moz) window.blur();
		}
	}	
}

componentTextModify.prototype.repalceStrbyStr =  function(baseStr, str, value)
{
	while (baseStr.indexOf(str) > -1){
		baseStr = baseStr.replace(str, value);
	}
	return baseStr;
}

componentTextModify.prototype.getAnswerCount = function(arr)
{
	var result = 0;
	for(var i=0; i < arr.length; i++){
		var oneWord = arr[i].split("@#@");
		if (oneWord[1] != '') result += 1;
	}
	return result;
}

componentTextModify.prototype.mouseDownButtonHideDiv = function(sender, allowReplace)
{
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var div = document.getElementById(this.id+'divInput');
	var input = document.getElementById(this.id+'InputInsideText');
	var value = input.value;
	div.style.visibility = 'hidden';
	
	var sender = this.rememberItemsArr[0];
	var bgCol = this.rememberItemsArr[1];
	var selCol = this.rememberItemsArr[2];
	var text = this.rememberItemsArr[3];
	var correct = this.rememberItemsArr[4];
	
	if (sender){
		if (ns) var spanColor = this.RGBtoHex(sender.style.backgroundColor);
			else var spanColor = sender.style.backgroundColor;
		(spanColor.toLowerCase() == selCol)?sender.style.backgroundColor = bgCol:sender.style.backgroundColor = selCol;
		if (allowReplace) {
			if (value == '') value = '_';
			sender.innerHTML = value;
		};
	};
	this.rememberItemsArr[0] = null;
	var newValue = this.repalceStrbyStr(value, "'", "$" );
	var isCorrect = this.checkCounterDown(newValue, correct);
	
	if (sender && isCorrect){
		if (this.anotherText == '-'){
			var counterSpan = document.getElementById(this.id+'_span_counter');
			if (counterSpan && this.counter != 0) counterSpan.innerHTML = eval(--this.counter);
		}else if (page.all[this.anotherText] && this.counter != 0){
			text = this.basicText.replace('{=counter}', --this.counter);
			page.all[this.anotherText].text = text;
			page.all[this.anotherText].paint();
		};
	};
};

componentTextModify.prototype.checkCounterDown = function(value, correctValues)
{
	if (typeof(correctValues) == 'undefined') return;
	var corrWordArr = correctValues.split('#');
	
	for (var i=0; i < corrWordArr.length; i++){
		if (corrWordArr[i] == value) return true;
	};
	return false;
};


componentTextModify.prototype.mouseOverWHYButton = function(sender)
{
	sender.src = resourcesURL + this.buttonWHY_srcIn;
};

componentTextModify.prototype.mouseOutWHYButton = function(sender)
{
	sender.src = resourcesURL + this.buttonWHY_srcOut;
};

componentTextModify.prototype.mouseDownWHYButton = function(sender)
{
	if (page.all[this.rememberItemsArr[6]]) page.all[this.rememberItemsArr[6]].show();
};

componentTextModify.prototype.mouseOverAddbutton = function(sender)
{
	if (this.addInactive){
		sender.src = resourcesURL + this.buttonAddInactive_srcIn;
	}else{
		sender.src = resourcesURL + this.buttonAdd_srcIn;
	}
};

componentTextModify.prototype.mouseOutAddbutton = function(sender)
{
	if (this.addInactive){
		sender.src = resourcesURL + this.buttonAddInactive_srcOut;
	}else{
		sender.src = resourcesURL + this.buttonAdd_srcOut;
	}
};

componentTextModify.prototype.hideAddButton = function(obj, action)
{
	this.addInactive = true;
	if (action == 'out'){
		this.mouseOutAddbutton(obj);
	}else{
		this.mouseOverAddbutton(obj);
	};
};

componentTextModify.prototype.showAddLetterButton = function(obj, action)
{
	this.addInactive = false;
	if (action == 'out'){
		this.mouseOutAddbutton(obj);
	}else{
		this.mouseOverAddbutton(obj);
	};
};

componentTextModify.prototype.mouseOverInfoButton = function(sender)
{
	sender.src = resourcesURL + this.buttonInfo_srcIn;
};

componentTextModify.prototype.mouseOutInfoButton = function(sender)
{
	sender.src = resourcesURL + this.buttonInfo_srcOut;
};

componentTextModify.prototype.mouseDownInfoButton = function(sender)
{
	if (page.all[this.rememberItemsArr[5]]) page.all[this.rememberItemsArr[5]].show();
};

componentTextModify.prototype.mouseDownAddbutton = function(sender)
{	
	if (this.addInactive) return;
	
	if(this.complete){
		if (page.all[this.rememberItemsArr[5]]) page.all[this.rememberItemsArr[5]].show();
	}else{
		if (this.rememberItemsArr[4] == ''){
			var correct = this.rememberItemsArr[3];
		}else{
			var correct = this.rememberItemsArr[4];
		};
		var input = document.getElementById(this.id+'InputInsideText');
		var correctWord = '';
		if (correct != ''){
			var wordaArr = this.rememberItemsArr[4].split('#');
			for (var i=0; i < wordaArr.length; i++){
				var value = wordaArr[i].split(input.value);
				if (value[0] == '' && typeof(value[1]) != 'undefined'){
					correctWord = wordaArr[i];
					var arr = value[1].split('');
					if (typeof(arr[0]) != 'undefined' && arr[0] != '#') {
						if (input.value == ''){
							input.value = input.value + value[0];
						}else{
							input.value = input.value + arr[0];
						};
						break;
					};
				}else if (input.value == ''){
					input.value = input.value + value[0];
				}
			}
		};
		if (input.value == correctWord) {
			this.hideAddButton(sender, 'out');
		};
		this.setColor(input, this.correctColor);
		this.iTimerID = setTimeout('document.getElementById("'+this.id+'InputInsideText").focus()', 100);
	};
};

componentTextModify.prototype.checkShowButton = function(value, words)
{
	if (!this.showInfoButton) return false;
	
	var wordArr = value.split('');
	var corrWordArr = words.split('#');
	var result = true;
	
	for (var i=0; i < corrWordArr.length; i++){
		var oneWord = corrWordArr[i].split('');
		for(var j=0; j < oneWord.length; j++){
			if (oneWord.length < wordArr.length) return false;
			if (typeof(wordArr[j]) == 'undefined' || (oneWord[j] != wordArr[j])){
				result = false;
				break;
			}else{
				result = true;
			};
		};
		if (result) return result;
	};
	return result;
};

componentTextModify.prototype.showCorrectWords = function(sender, bgCol, selCol, corrWord, popupInfo, popupWhy)
{
	var ns = (navigator.appName.indexOf("Netscape") != -1);

	var div = document.getElementById(this.id+'divInput');
	if (corrWord != ''){
		div.style.visibility = 'inherit';
		div.style.left = (this.w/2)-75;
		div.style.top = this.h-30;
		
		var button = document.getElementById(this.id+'ButtonWHYInput');
		if (page.all[popupInfo]){
			if (button) button.style.visibility = 'inherit';
		}else{
			if (button) button.style.visibility = 'hidden';
		};
		
		button = document.getElementById(this.id+'ButtonAddInput');
		if (page.all[popupWhy]){
			if (button) {
				button.src = resourcesURL + this.ButtonInfo_srcOut;
				this.showAddLetterButton(button, 'out');
			};
		}else{
			if (button){
				this.hideAddButton(button, 'out');
			}
		};		
		button = document.getElementById(this.id+'ButtonHideDiv');
		if (button) {
			button.style.visibility = 'hidden';
		};
		
		var input = document.getElementById(this.id+'InputInsideText');
		input.value = corrWord;
		
		this.rememberItemsArr[0] = sender;
		this.rememberItemsArr[1] = bgCol;
		this.rememberItemsArr[2] = selCol;
		this.rememberItemsArr[3] = sender.innerHTML;
		this.rememberItemsArr[4] = corrWord;
		this.rememberItemsArr[5] = popupInfo;
		this.rememberItemsArr[6] = popupWhy;	
	}else{
		div.style.visibility = 'hidden';
	}
	return;
};

componentTextModify.prototype.checkIsCorrectValue = function(value, corrValues)
{
	if (corrValues == '') return true;
	
	var splitedValue = value.split('');
	var correctWords = corrValues.split('#');
	
	var result = false;
	for (var i=0; i < correctWords.length; i++){
		var oneWord = correctWords[i].split('');
		
		if (eval(oneWord.length+1) > splitedValue.length){			
			for (var j=0; j < splitedValue.length; j++){
				
				if (typeof(oneWord[j]) != 'undefined' && oneWord[j] != ''){
					if (splitedValue[j] == oneWord[j]){
						result = true;
					}else {
						result = false;
						break;
					};
				};
			};
		};
		if (result) return result;
	}
	return result;
};

componentTextModify.prototype.keyUp = function(keyUpObj)
{
	if (this.complete) return;
	
	if (keyUpObj){
		var correctValue = this.checkIsCorrectValue(keyUpObj.value, this.rememberItemsArr[4]);	
		var button = document.getElementById(this.id+'ButtonAddInput');
		
		if (correctValue != '' || keyUpObj.value == '') {
			this.setColor(keyUpObj, this.correctColor);
			if (button) {
				var corrArr = this.rememberItemsArr[4].split('#');
				for (var i=0; i < corrArr.length; i++){
					if (corrArr[i].indexOf(keyUpObj.value) > -1 && keyUpObj.value != corrArr[i]){
						this.showAddLetterButton(button, 'out');
						break;
					}else{
						this.hideAddButton(button, 'out');
					};
				};
			};
		}else {
			this.setColor(keyUpObj, this.incorrectColor);
			if (button) {
				this.hideAddButton(button, 'out');
			};
		};
	};
	return;
};

componentTextModify.prototype.setColor = function(obj, color)
{
	if (this.automaticCheck){
		obj.style.background = color;
	};
};

componentTextModify.prototype.clickSPAN = function(sender, bgCol, selCol, corrWord, popupWhy, popupInfo)
{
	if(this.locked) {
		return;
		var oneCorr = corrWord.split('#');
		this.showCorrectWords(sender, bgCol, selCol, oneCorr[0], popupInfo, popupWhy);
	};
	
	var counterSpan = document.getElementById(this.id+'_span_counter');
	if (counterSpan && counterSpan.innerHTML < 1 ) return;
	
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var isCorrect = this.checkShowButton(sender.innerHTML, corrWord);
	var div = document.getElementById(this.id+'divInput');

	if (corrWord != '' && !isCorrect){
		div.style.visibility = 'inherit';
		div.style.left = (this.w/2)-75;
		div.style.top = this.h-30;
		
		var button = document.getElementById(this.id+'ButtonWHYInput');
		if (page.all[popupWhy]){
			if (button) button.style.visibility = 'inherit';
		}else{
			if (button) button.style.visibility = 'hidden';
		};
		
		var button = document.getElementById(this.id+'ButtonInfo');
		if (page.all[popupInfo]){
			if (button) button.style.visibility = 'inherit';
		}else{
			if (button) button.style.visibility = 'hidden';
		};		
		
		var input = document.getElementById(this.id+'InputInsideText');
		input.value = sender.innerHTML;
		
		button = document.getElementById(this.id+'ButtonAddInput');
		var correctValue = this.checkIsCorrectValue(sender.innerHTML, corrWord);	
		if (correctValue){
			if (button) {
				this.showAddLetterButton(button, 'out');
			}
			if (input) {
				this.setColor(input, this.correctColor);
			}
		}else{
			if (button) {
				this.hideAddButton(button, 'out');
			}
			if (input) {
				this.setColor(input, this.incorrectColor);
			}
		};	
	}else{
		div.style.visibility = 'hidden';
	}

	var spanColor = '';
	
	if (this.rememberItemsArr[0]){
		if (ns) spanColor = this.RGBtoHex(this.rememberItemsArr[0].style.backgroundColor);
			else spanColor = this.rememberItemsArr[0].style.backgroundColor;
			
		(spanColor.toLowerCase() == selCol)?this.rememberItemsArr[0].style.backgroundColor = bgCol:this.rememberItemsArr[0].style.backgroundColor = selCol;
	};
	
	if (ns) spanColor = this.RGBtoHex(sender.style.backgroundColor);
		else spanColor = sender.style.backgroundColor;
		
	(spanColor.toLowerCase() == selCol)?sender.style.backgroundColor = bgCol:sender.style.backgroundColor = selCol;
	
	
	this.rememberItemsArr[0] = sender;
	this.rememberItemsArr[1] = bgCol;
	this.rememberItemsArr[2] = selCol;
	this.rememberItemsArr[3] = sender.innerHTML;
	this.rememberItemsArr[4] = corrWord;
	this.rememberItemsArr[5] = popupInfo;
	this.rememberItemsArr[6] = popupWhy;
};

componentTextModify.prototype.inTable = function(table, value)
{
	for (var i=0; i < table.length; i++ ) {
		if (value == table[i]) return true;
	}
	return false;
};

componentTextModify.prototype.onRepaint = function(obj)
{
	if (PageInterface.GetValue("allowCAI") && this.showCorrectAnswerIndicator)
	{
		this.complete = true;
		
		var dispAndCorrArray = this.text.toString().split("||");
		var colored = false;
		
		for (var i=0; i < dispAndCorrArray.length; i++ ) {
			var span = document.getElementById(this.id+"_span_"+i);
			var textArray = dispAndCorrArray[i].split('@#@');
			var value = span.innerHTML;
			value = this.repalceStrbyStr(value, "'", "$" );
			
			if (textArray[1] == ''){
				//span.style.backgroundColor = this.correctColor;
			}else{
				var corrWordsArr = textArray[1].split('#');
				for (var j=0; j < corrWordsArr.length; j++){
					if (this.caseSensitive == 1){
						if (value != corrWordsArr[j]) {
							span.style.backgroundColor = this.incorrectColor;
							colored = false;
						}else {
							span.style.backgroundColor = this.correctColor;
							colored = true;
						};
					}else{
						if (value.toLowerCase() != corrWordsArr[j].toLowerCase()){
							span.style.backgroundColor = this.incorrectColor;
							colored = false;
						}else{
							span.style.backgroundColor = this.correctColor;
							colored = true;
						};
					};
					if (colored) break;
				};		
			};
		};
	};
};

componentTextModify.prototype.RGBtoHex =  function(color)
{
	if (color.indexOf('rgb') == -1) return color;
	color = color.replace('rgb(', '');
	color = color.replace(')', '');
	color = color.replace(/ /g, '');
	
	var arr = color.split(',');
	return '#' + this.toHex(parseInt(arr[0])) + this.toHex(parseInt(arr[1])) + this.toHex(parseInt(arr[2]));	
};

componentTextModify.prototype.toHex =  function(N)
{
	if (N==null) return "00";
	N=parseInt(N); if (N==0 || isNaN(N)) return "00";
	N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);

	return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
};

componentTextModify.prototype.getAnswer = function(obj)
{
	var valInt = "";
	var sep = "";
	var textArray = this.text.toString().split("||");		
  	if (this.ignoreAnswer) return "";
	
	for (var i=0; i < textArray.length; i++ ) {
		span = document.getElementById(this.id + "_span_" + i);
		if (valInt != '') sep = ",";
		valInt += sep + span.innerHTML;
	};
	return(valInt);
};

componentTextModify.prototype.setAnswer = function(valInt, showCorrect)
{
	if (valInt == '' || typeof(valInt) == 'undefined') return; 
	var ansArray = valInt.toString().split(",");
	
	if (valInt != '' && !showCorrect){
		for (var i=0; i < ansArray.length; i++ ) {
			span = document.getElementById(this.id+"_span_"+i);
			span.innerHTML = ansArray[i];
		};
	}else{
		var dispAndCorrArray = this.text.toString().split("||");
		for (var i=0; i < dispAndCorrArray.length; i++ ) {
			var textArray = dispAndCorrArray[i].split('@#@');
			if (textArray[1] != ''){
				var arr = textArray[1].split('#');
				span = document.getElementById(this.id+"_span_"+i);
				span.innerHTML = arr[0];
			};
		};
	};
};

componentTextModify.prototype.checkAnswer = function() 
{
	this.mouseDownButtonHideDiv();
	return(this.parseCheckAnswer(this)); 
};

componentTextModify.prototype.parseCheckAnswer = function(obj) 
{
	var dispAndCorrArray = this.text.toString().split("||");
	var result = false;
	
	for (var i=0; i < dispAndCorrArray.length; i++ ) {
		var textArray = dispAndCorrArray[i].split('@#@');
		var span = document.getElementById(this.id+"_span_"+i);
		var value = span.innerHTML;
		value = this.repalceStrbyStr(value, "'", "$");
		if (textArray[1] != ''){
			var corrWordsArr = textArray[1].split('#');
			result = false;
			for (var j=0; j < corrWordsArr.length; j++){
				if (this.caseSensitive == 1){
					if (value == corrWordsArr[j]){
						result = true;
						break;
					}
				}else{
					if (value.toLowerCase() == corrWordsArr[j].toLowerCase()){
						result = true;
						break;
					}
				}
			}
			if (!result) return false;
		}else if (value != textArray[0]) {
			return false;			
		}
	};
	return result;
};

componentTextModify.prototype.componentTextModifyBaseUnselectable = componentTextModify.prototype.unselectable;
componentTextModify.prototype.unselectable = function()
{
	this.componentTextModifyBaseUnselectable();
	span = document.getElementById(this.id+"InputInsideText");
	if (span) span.unselectable = "";
};

componentTextModify.prototype.onLock = function() 
{
	this.locked = true;
	this.mouseDownButtonHideDiv(this.rememberItemsArr[0], false);
  	return true;
};

componentTextModify.prototype.onUnLock = function() 
{
	this.locked = false;
  	return true; 
};

componentTextModify.prototype.interactionsCorrectResponsesCount = function() 
{
	var length = 1;
	return length;
}

componentTextModify.prototype.interactionsCorrectResponses = function() {
	return this.correctAnswersList;
}

componentTextModify.prototype.interactionsCorrectResponsesAsText = function() {
	return this.correctAnswersList;
}

componentTextModify.prototype.interactionsStudentResponse = function() {
	return this.getAnswer();
}; 

componentTextModify.prototype.interactionsStudentResponseAsText = function() {
	return this.getAnswer();
}; 

componentTextModify.prototype.onFree = function() {
	if (this.iTimerID != null) 
		window.clearTimeout(this.iTimerID);
}
/********************************************************************/
