/*
 * Copyright (C) 1995-2011 by 4system Polska Sp. z o.o.
 * All Rights Reserved. v4
 */

componentRPL = function(name) {
	this.componentElement = componentElement;
	this.componentElement(name);
  
	this.compAudio = null;

	this._optCount = 0;
	this._lastQuestSize = 0;

	this.points = 0;
	this.maxPoints = 0;
	this.comments = ""; //komentarz do odpowiedzi
	this.numberOfQuestion = 0; //licznik ile pytan zadano
	this.questionList = ''; //lista kolejnych pytan np. 1,4,5,6
	this.lastQuestion = 0;
	this.listQuestionsId = '';
	this.imagesList = '';
	this.preImages = new Array();
	this.preloadTimer = null;
	this.groupList = '';  
	this.listOfUsedGroup = '';  
	this.askedQuestions = 0;
	this.QuestionFont = '';
	this.AnswerFont = '';
	this.QuestionFontEnd = '';
	this.AnswerFontEnd = '';	
	this.defaultContent = "";
	this.idDisplayedQuestion = 0;
	
	this.kindOfFile = 'image';
	
	this.cloudsArr = new Array();
	this.rplCloudsArr = new Array();

	this.panelRPLOBJ = null;
	this.answersArrRemember = new Array();
	this.questionRemember = '';
	
	this.correctAnswersList = "";
	this.interactions = true;
	this.interactionsType = "matching";
	this.usrAns = 0;
	
	this.resourcesURL = "";
	this.disableOnlineOfflineMix = false;
	
	this.groupAnswers = new Array();
};

componentRPL.prototype = new componentElement;
componentRPL.prototype.type = "componentRPL";

componentRPL.prototype.onCreate = function() 
{
	this.captureMouseEvents();
	this.points = 0;	
	this.resourcesURL = resourcesURL;
	this.resourcesStatus = "online";
	this.resourcesURL = resourcesURL;
	if (PageInterface.GetValue("state") != psDesigning && lms && lms.name != "lmsOffline") {
		this.resourcesStatus = lms.resourcesStatus();
		if (this.disableOnlineOfflineMix) this.resourcesURL = resourcesURL;
		else this.resourcesURL = lms.resourcesURL();
	}
    this.resourcesURL = unescape(this.resourcesURL);
	
	this.makeListOfImages();
	
	if (this.cloudFrom == 'cloudFromPage'){
		this.makeArrOfClouds();
	}else if (this.cloudFrom == 'cloudFromRPL'){
		this.makeThreeDialogues();
	};
	if (PageInterface.GetValue("state") != psDesigning) {
		var audioElement = new componentAudio();
		audioElement.myParent = this;
		audioElement.id = this.id+'Audio'; 
		audioElement.src = this.src;
		audioElement.pvWMP64 = false;
		audioElement.pvWMP7up = false;
		audioElement.step = -1;
		audioElement.editorPaint = this.editorPaint;
		this.compAudio = PageInterface.Execute("addChild", audioElement);
	};
};

componentRPL.prototype.editorPaint = function()
{
	return '';
}

componentRPL.prototype.addSizeDiv = function()
{
	var sizeDiv = '<div id="'+this.id+'SizeDiv" style="visibility: hidden; position: absolute; width:100px; height:100px font-family:' + this.fontFamilyQ
	+ '; font-size:' + getFontSize(this.fontSizeQ, "px") + 'px;"></div>';
	
	var ob = document.getElementById(this.id);
	ob.innerHTML += sizeDiv;
	
//	document.body.innerHTML += sizeDiv;
}

componentRPL.prototype.makeThreeDialogues = function()
{
	var cloudsSrc = new Array(this.cloudSmall, this.cloudAverage, this.cloudBig)
	
	for (var i=0; i < 3; i++){		
		var e = new componentDialogue;
		e.myParent = this;
		e.id = this.id+'Dialogue_'+i; 
		var img = new Image 
		img.src = this.resourcesURL + cloudsSrc[i];
		
		switch (this.cloudAlign){
			case 'left' : 
						var tempX = this.x;
						break;
			case 'center' : 
						var tempX = this.x + this.w/2 - img.width/2;
						break;
			case 'right' : 
						var tempX = this.x + this.w - img.width;
						break;
		};
		e.x = tempX;
		e.y = this.y;
		e.w = img.width;
		e.h = img.height;
		if (cloudsSrc[i].indexOf('.png') != -1 && is.ie && is.ie55UP && !is.ie7UP){
			e.p_checkMarkers = true;		
			e.p_checkPNG = true;		
		}else{
			e.p_checkMarkers = false;		
			e.p_checkPNG = false;	
		}
		e.pngFix = true;	
		e.textFromLeft = 30; 
		e.textFromRight = 50;
		e.textFromUp = 10;
		e.textFromDown = 15;
		e.text.text = "";
		e.text.align = "center";
		e.text.valign = "middle";
		e.text.w = e.w - e.textFromLeft - e.textFromRight;
		e.text.h = e.h - e.textFromUp - e.textFromDown;
		e.cloud.src = cloudsSrc[i];
		e.cloud.x = 0;
		e.cloud.y = 0;
		e.cloud.w = img.width;
		e.cloud.h = img.height;
		e.step = -1;
		
		this.rplCloudsArr.push(e);
		page.addChild(e);
	};
};

componentRPL.prototype.showRPLCloud = function(text)
{
	var pageDiv = document.getElementById(this.id+'SizeDiv');
	for (var i=0; i < this.rplCloudsArr.length; i++){
		this.rplCloudsArr[i].hide();
	};
	
	for (var i=0; i < this.rplCloudsArr.length; i++){
		pageDiv.style.width = this.rplCloudsArr[i].text.w;
		pageDiv.innerHTML = text;
		
		if (pageDiv.offsetHeight < this.rplCloudsArr[i].text.h || i == 2){
			if (this.rplCloudsArr[i].execution){
				document.getElementById(this.rplCloudsArr[i].id + "_contentObj").innerHTML = text;
			}else{
				this.rplCloudsArr[i].show();
				var content = this.rplCloudsArr[i].text.findContentObj();
				if (content) content.innerHTML = text;
			};
  			return;
		};		
	};
};

componentRPL.prototype.onPaint = function() 
{
    this.setGroupList();
	this.setListQuestionsId();
	
    if (this.randomizeQuestions){
        var temp = this.listQuestionsId.split("!!");
        var rand = parseInt(Math.random()*(temp.length-1));
        
        this.drawSimulation(temp[rand]);
    }else{
        var splitContent = this.content.split("!!");
        var firstModule = splitContent[0].split("##");
        var questID = firstModule[0].split("||");
        
        this.drawSimulation(questID[0]);
    };
};

componentRPL.prototype.rePaint = function() {
  return;
};

componentRPL.prototype.preload = function(image) 
{       
	if (image.indexOf('.swf') > -1 || image.indexOf('.avi') > -1) return;
	
	if (document.images) {
		var img = new Image();
		this.preImages.push(img)
		this.preImages[this.preImages.length-1].src = this.resourcesURL + image;
	};
};   

componentRPL.prototype.makeListOfImages = function() 
{
	var splitContent = this.content.split("!!");//podział na poszczególne pytania
    var secondModule = splitContent[1].split("##");
	
	for (var i=0; i < secondModule.length-1; i++){
		var temp = secondModule[i].split(";;");
		this.preload(temp[1]);
	};
	
	this.preload(this.cloudSmall);
	this.preload(this.cloudAverage);
	this.preload(this.cloudBig);
	this.preload(this.buttonSrc);
	this.preload(this.buttonOkSrc);
	this.preload(this.buttonReset);
	
	this.preloadCheck(0);
};

componentRPL.prototype.preloadCheck = function(k)
{
	var i = 0;      
	var b = 0;     
	var counter = k+1;
	var length = this.preImages.length;
	var errors = this.preImages[i].complete;
	
	while (i < length && this.preImages[i].complete || b-->0){
		i++;   
	}
	
	if (i >= length || counter == 50){  //czekaj 30 sek. czy zaladowały się grafiki jak nie to wyświetl błąd
		if (!errors) showMessage("There was errors during preload images.");
	}else{
		this.preloadTimer = setTimeout('page.all["'+this.id+'"].preloadCheck('+counter+');',100);
	};
	return;
};

componentRPL.prototype.setGroupList = function() {
// wkładanie do grupy np. grA##1##2##!!grB##3##4##5 
    var splitContent = this.content.split("!!");
    var firstModule = splitContent[0].split("##");
    var secondModule = splitContent[1].split("##");
    var groups = new Array();
    var temp = '';
    var index = 0;
    
    for (var i=0; i < firstModule.length; i++){
        var ans = secondModule[i].split(";;");
        var answers = ans[0].split("@@");
        var quest = firstModule[i].split("||");
        
        if (answers[0] != ''){
            if (temp.indexOf(answers[0]) == -1){
                temp += answers[0] + '!!';
                groups[index] = answers[0];
                groups[index] += '##' + quest[0];             
                index += parseInt(1);
            }else{
                var k = -1;
                do{
                    k += parseInt(1);
                }while ((groups[k].indexOf(answers[0]) == -1) && (answers[0] != ''))
                groups[parseInt(k)] += '##' + quest[0];
            }
        }
    }
    
    for (var i=0; i < groups.length; i++)
        this.groupList += groups[i] + '!!';
        
};

componentRPL.prototype.setListQuestionsId = function() {
	var splitContent = this.content.split("!!"); // content !! summary    
	var questionArr = splitContent[0].split("##");
    
    for (var i=0; i < questionArr.length; i++){
        var oneQuestion = questionArr[i].split("||");
        
        this.listQuestionsId += oneQuestion[0] + "!!";
    }
    
    return questionArr.length-1;
}

componentRPL.prototype.getPointsMax = function(module) {
    
    if (this.lastQuestion == 0){
        var max = 0;
        
        for (var i=2; i < module.length; i++ ){
            var point = module[i].split("&&");
            
            if (max < point[2]){
                max = point[2];
            }
        }       
        this.maxPoints += parseInt(max);
        this.numberOfQuestion += 1;
        this.askedQuestions += 1;
    }
};

componentRPL.prototype.rememberGroup = function(qId) {
	//grA##1##2##!!grB##3##4##5 
	var splited = this.groupList.split('!!');
	var i = -1;

	var splitContent = this.content.split("!!");//podział na poszczególne pytania
    var i = parseInt(-1); 
    
    var firstModule = splitContent[0].split("##");//firstModule - modul zawierający: numer pytania, tresc pytania i grafikę do pytania;
    do{        
        i += 1;
        var question = firstModule[i].split("||");
    }while (qId != question[0])
	
	var secondModule = splitContent[1].split("##");     
    var splitedAnswers = secondModule[[parseInt(i)]].split(";;");//odnalezienie odpowiedzi 
    question = firstModule[parseInt(i)].split("||");
	
	var t = splitedAnswers[0].split('@@');

	if (typeof(t[1]) != 'undefined') this.listOfUsedGroup += t[1] + '##';
};

componentRPL.prototype.audioPlay = function(file)
{
	if (file == '') return;
	var res = false;
	var player = document.getElementById(this.id+'AudioMediaPlayer');
	
	if (player) {
		player.url = this.resourcesURL + file;
		if (this.compAudio.pvWMP7up) {
			if (player.controls) res = player.controls.play();
		} else if (this.compAudio.pvWMP64) {
			res = player.Play();
		};
	};
	return res;
};

componentRPL.prototype.audioStop = function()
{
	if (this.compAudio)	this.compAudio.actionMediaStop();	
};

componentRPL.prototype.hideAllClouds = function()
{
	for (var i=0; i < this.rplCloudsArr.length; i++){
		this.rplCloudsArr[i].hide();
	};	
	for(var k in this.cloudsArr){
		this.cloudsArr[k][1].hide();
	};
};

componentRPL.prototype.changeTextInCloud = function(questionNo, text)
{
	if (!this.cloudsArr[questionNo]) return;
	
	this.hideAllClouds();
	
	var cloudObj = this.cloudsArr[questionNo][1];
	if (cloudObj.execution){
		cloudObj.show();
		document.getElementById(cloudObj.id + "_contentObj").innerHTML = text;
	}else{
		cloudObj.text.text = text;
		cloudObj.paint();
	};
};

componentRPL.prototype.getSceneObiekt = function(sceneFile, size) 
{
	var t = '';
	switch(size){
		case 'userSize' : 
			var width = this.screenImageWidth + 'px'; 
			var height = this.screenImageHeight + 'px'; 
			break;
		case 'orginalSize' : 
			var width = '450px'; //it's nessesery to swf and video 
			var height = '225px'; 
			break;
	};
	
	if (sceneFile.indexOf('.swf') > -1){
		t += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="'+ width +'" height="'+ height +'" id="'+ this.id +'flashPlayer" align="middle">';
		t += '  <param name="movie" value="'+ this.resourcesURL + sceneFile +'">';
		t += '  <param name="allowScriptAccess" value="sameDomain" />';
		t += '  <param name="bgcolor" value="transparent">';
		t += '  <param name="quality" value="high">';
		t += '  <param name="play" value="false">';
		t += '  <param name="loop" value="false">';
		t += '  <param name="WMode" value="transparent">';
		t += '  <param name="scale" value="showall">';
		t += '  <param name="salign" value="L">';
		t += '  <param name="FlashVars" value="">';
		t += '  <embed wmode="transparent" src="'+ this.resourcesURL + sceneFile +'" quality="high" bgcolor="transparent" name="'+ this.id +'flashPlayer" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="'+ width +'" height="'+ height +'"></embed>';
		t += '</object>';
		this.kindOfFile = 'flash';
	}else if ((sceneFile.indexOf('.wmv') > -1) || (sceneFile.indexOf('.avi') > -1) || (sceneFile.indexOf('.mpeg') > -1)){
		if (is.ie){
			t +='	<OBJECT id="' + this.id + 'MediaPlayer" ';
			t +='		width="' + width + '" height="' + height + '" ';
			t +='		CLASSID=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6 ';
			t +='		standby="Loading Microsoft Windows Media Player components..."';
			t +='		TYPE="application/x-oleobject">';
			t +='		<param name="url" VALUE="' + this.resourcesURL + sceneFile + '" />';		
			t +='		<param name="uiMode" value="none" />';
			t +='		<param name="Volume" value="100" />';
			t +='		<param name="ShowControls" VALUE="true" />';
			t +='		<param name="ShowTracker" VALUE="false" />';
			t +='		<param name="ShowStatusBar" VALUE="false" />';
			t +='		<param name="VideoBorder3D" VALUE="false" />';
			t +='		<param name="VideoBorderWidth" VALUE="false" />';
			t +='		<param name="AutoStart" value="false" />';
			t +='		<param name="AnimationAtStart" value="false" />';
			t +='		<param name="TransparentAtStart" value="false" />';
			t +='	</OBJECT>';
		}else{
			t += '<object id="video1MediaPlayer" width="' + width + '" height="' + height + '" data="' + this.resourcesURL + sceneFile + '" type="application/x-ms-wmp">';
			t +='<param name="url" VALUE="' + this.resourcesURL + sceneFile + '" />';		
			t += '<param value="true" name="autostart"/>';
			t += '<param value="none" name="uiMode"/>';
			t += '<param value="false" name="enableContextMenu"/>';
			t += '<param value="false" name="enabled"/>';
			t += '</object>';	
		}
		this.kindOfFile = 'wideo';
	}else{
		t += '<img id="' + this.id + '_img" border="0" src="'+ this.resourcesURL + sceneFile + '"';
		//t += ' style="width:' + width + '; height:' + height + ';">'; //pg2
		t += '>';
		this.kindOfFile = 'image';
	};
	
	return t;
}

componentRPL.prototype.drawSimulation = function(questionNo) 
{
	this.audioStop();
	this.addSizeDiv();
    
	var width = this.w - 2*this.borderWidth - 2;
	var height = this.h - 2*this.borderWidth - 2; 
    
	this._optCount = 0;
	
	this.QuestionFont = "<font size='"+this.fontSizeQ+"' face='"+this.fontFamilyQ+"' color='"+this.fontColorQ+"'>";
	this.QuestionFontEnd = "</font>";
    if (parseInt(this.fontBoldQ) == 1) {
		this.QuestionFont += "<b>";
		this.QuestionFontEnd = "</b>" + this.QuestionFontEnd;
	}
    
    this.AnswerFont = "<font size='"+this.fontSizeA+"' face='"+this.fontFamilyA+"' color='"+this.fontColorA+"'>";
	this.AnswerFontEnd = "</font>";
    if (parseInt(this.fontBoldA) == 1) {
		this.AnswerFont += "<b>";
		this.AnswerFontEnd = "</b>" + this.AnswerFontEnd;
	};
    
	var splitContent = this.content.split("!!");//podział na poszczególne pytania

    var i = parseInt(-1); 
    
    var firstModule = splitContent[0].split("##");//firstModule - modul zawierający: numer pytania, tresc pytania i grafikę do pytania;
    
    do{        
        i += 1;
        var question = firstModule[i].split("||");
        var suppose = question[0];//jak nie znajdzie odpowiednika do konca szukania bierze ostatni z listy
    }while ((questionNo != question[0]) && (i < parseInt(firstModule.length-1)))
    
    /*
    if ((questionNo != question[0]) && (i >= (firstModule.length-1))){ 
        //i = suppose;  
        i = parseInt(i-1);  
    }
  */  
	this.idDisplayedQuestion = question[0];
    var secondModule = splitContent[1].split("##");     
	
	var separateAnswers = secondModule[[parseInt(i)]].split('#@audioFile=');//odnalezienie odpowiedzi 
	var splitedAnswers = separateAnswers[0].split(";;");//odnalezienie odpowiedzi 
    question = firstModule[parseInt(i)].split("||");//odnalezienie pytania
	
    this.getPointsMax(splitedAnswers);//secondModule - modul zawierający: grupę, grafikę, odpowiedz1, komentarz1, punkty1, idz do1; ... itd
    
	if (this.screenImageWidth != 1 && this.screenImageHeight != 1)
	{
		var t = '<table dir="'+this.dir+'" border="0" cellpadding="2" cellspacing="'+this.borderAnswerWidth+'" style="width:' + width + 'px; height:' + height + 'px;" >';
		t += '<tr>';
		t += '<td align="center" colspan="2" valign="' + this.screenImageVAlign + '">';
		
		t += this.getSceneObiekt(splitedAnswers[1], 'userSize');
		
		// t += '   <img id="' + this.id + '_img" border="0" src="'+ resourcesURL + splitedAnswers[1] + '"';
		// t += '   style="width:' + this.screenImageWidth + 'px; height:' + this.screenImageHeight + 'px">';
		
		t += '</td>';
		t += '</tr>';
	}else{
		var t = '<table dir="'+this.dir+'" border="0" cellpadding="2" cellspacing="'+this.borderAnswerWidth+'" style="width:' + width + 'px; height:' + height + 'px;" >';
		t += '<tr><td align="center" colspan="2" valign="' + this.screenImageVAlign + '"  style="height:' + this.imageHeight + 'px;">';
		//t += '<img id="' + this.id + '_img" src="'+ resourcesURL + splitedAnswers[1] + '" >';
		
		t += this.getSceneObiekt(splitedAnswers[1], 'orginalSize');
		
		t += '</td></tr>';
		// t += '<tr><td colspan="2" valign="top" height="20px" id="' + this.id + '_questionText">' + QuestionFont + question[1] + '</font></td></tr>';
		// t += '<tr style="height: 1px;"><td></td></tr>';
	};
	
	if (this.cloudFrom == 'noCloud'){
		t += '<tr>';
		t += '  <td colspan="2" valign="top" style="width: 100%" id="' + this.id + '_questionText">';
		t += this.QuestionFont + question[1] + this.QuestionFontEnd + '</div></td>';
		t += '</tr>';
		t += '<tr style="height: 1px;"><td></td></tr>';
	}else if (this.cloudFrom == 'cloudFromPage'){
		this.changeTextInCloud(question[0], question[1]);
	}else if (this.cloudFrom == 'cloudFromRPL'){
		this.showRPLCloud(question[1]);
	};
	
	this.questionRemember = question[1];
	
	//t += '<table border="2" style="width:' + width + 'px; height:' + height + 'px;" >';
    if (this.randomizeAnswers){//losuje odpowiedzi !
        //answers, randomQuestion, thisQuestion, imge - parametry
        t += this.randomAnswer(splitedAnswers, this.randomizeQuestions, question[0]);
    }else{
        var color ='';
        var counter = 0;
		
		var img = new Image();
		img.src = this.resourcesURL + this.buttonSrc;
		var imageWidth = img.width;			
		
        for (var i=2; i < splitedAnswers.length-1; i++) {
            var answerArr = splitedAnswers[i].split("&&");//0-odp, 1-com,2-points,3-goto
            
			this.answersArrRemember.push(answerArr[0]);
			
            if (answerArr[0] == '') answerArr[0] = '';
            if (answerArr[1] == '') answerArr[1] = '';  
            if (answerArr[2] == '') answerArr[2] = 0;  
                
            if (counter == 0){
               color = this.answer1Color;
               counter = 1;
            }else{
               color = this.answer2Color;
               counter = 0;
            }
			
            if (this.randomizeQuestions){
			
				var changed = this.changeRabits(answerArr[1]);//zamienia zajaczki tzn " lub ' na \" lub \'
				
				var commands = question[0] + ',' + answerArr[2] + ',\'' + changed + '\'' + ',\'' + splitedAnswers[1] + '\',' + eval(this.answersArrRemember.length-1);
                //thisQuestion, points, comment, graph
				
                if (answerArr[0] != ''){	
					if (this.isAnswerRollover){
						t += '<tr style="background: '+color+';" onMouseover="this.style.background=\''+this.answerRolloverColor+'\'" onMouseout="this.style.background=\''+color+'\'">';
					}else{
						t += '<tr style="background: '+color+';">';
					};
					
					t += '<td id="' + this.id + '_tdopt' + this._optCount + '" valign="' + this.buttonVAlign + '" height="20px">';
					if (this.buttonSrc.indexOf('.png') != -1 && is.ie && is.ie55UP && !is.ie7UP){
						t += '<span id="' + this.id + '_but3" src="' + this.resourcesURL + this.buttonSrc + '"';
						t += ' style="width:'+imageWidth+'px; height:100%; cursor: pointer;';
						t += ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
						t += '(src=\'' + this.resourcesURL + this.buttonSrc + '\', sizingMethod="scale");" onClick="owner.randomOption(' + commands + ');"></span>';
					}else {
						t += '<img id="' + this.id + '_but3" src="'+ this.resourcesURL + this.buttonSrc + '" style="cursor: pointer" onClick="owner.randomOption(' + commands + ');">';
					};
					t += '</td>';					
					
					t += '<td id="' + this.id + '_opt' + i.toString() + '" style="width:95%; cursor:pointer;"  onClick="owner.randomOption(' + commands + ');">'+ this.AnswerFont + answerArr[0] + this.AnswerFontEnd+'</td></tr>';
                }
            }else{
                //srawdzenie czy jest to skok do pytania czy skok do grupy question[0]
                var groupId = answerArr[3];
              
                if ((groupId.indexOf("g") != -1) || (groupId.indexOf("End") != -1)){
                //jesli jest pusty lub jest skok do grupy
                    answerArr[3] = 1;
                    var group = groupId;
                }else{
					if (answerArr[3] == '') answerArr[3] = 0;
                    var group = '';
				}
				
                //chosenOption (optNo, points, comment, graph, group_name);
				
				var changed = this.changeRabits(answerArr[1]);//zamienia zajaczki tzn " lub ' na \" lub \'
				
				var commands = answerArr[3] + ',' + answerArr[2] + ',\'' + changed + '\'' + ',\'' + splitedAnswers[1] + '\'' + ',\'' + group + '\',' + eval(this.answersArrRemember.length-1);
				
                //var commands = answerArr[3] + ',' + answerArr[2] + ',' + ',\'' + splitedAnswers[1] + '\'' + ',\'' + group + '\'';
				
                if (answerArr[0] != ''){
					if (this.isAnswerRollover){
						t += '<tr style="background: '+color+';" onMouseover="this.style.background=\''+this.answerRolloverColor+'\'" onMouseout="this.style.background=\''+color+'\'">';
					}else{
						t += '<tr style="background: '+color+';">';
					};
					
					t += '<td id="' + this.id + '_tdopt' + this._optCount + '" valign="' + this.buttonVAlign + '" height="20px">';
					if (this.buttonSrc.indexOf('.png') != -1 && is.ie && is.ie55UP && !is.ie7UP){
						t += '<span id="' + this.id + '_but3" src="' + this.resourcesURL + this.buttonSrc + '"';
						t += ' style="width:'+imageWidth+'px; height:100%; cursor: pointer;';
						t += ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
						t += '(src=\'' + this.resourcesURL + this.buttonSrc + '\', sizingMethod="scale");" onClick="owner.chosenOption(' + commands + ');"></span>';
					}else {
						t += '<img id="' + this.id + '_but3" src="'+ this.resourcesURL + this.buttonSrc + '" style="cursor: pointer" onClick="owner.chosenOption(' + commands + ');">';
					};
					t += '</td>';						
					
					t += '<td id="' + this.id + '_opt' + i.toString() + '" style="width:95%; cursor:pointer;" onClick="owner.chosenOption(' + commands + ');">'+ this.AnswerFont + answerArr[0] + this.AnswerFontEnd+'</td></tr>';
                }
            }
			
			this._optCount++;
        }	
    }
    
    t += "<tr><td colspan='2'></td></tr>"; 
	t += '</table>';
	
	if (typeof(separateAnswers[1]) != 'undefined')
		this.audioPlay(separateAnswers[1]);	
	
	this.setHTML(t);
	this.playWideo();
	this.correctSizes(width, height);
};

componentRPL.prototype.playWideo = function(el)
{
	if (this.kindOfFile == 'wideo' ){
		var player = document.getElementById(this.id + "MediaPlayer");
		
		if (player) {
			res = player.controls.play();
		}
	}
};

componentRPL.prototype.getPosition = function(el)
{
	var obj = document.getElementById(el);
	if (obj) {
		w = obj.offsetWidth;
		h = obj.offsetHeight;
		if (obj.offsetParent)
		{
			for (var posX = 0, posY = 0; obj.offsetParent; obj = obj.offsetParent) {
				posX += obj.offsetLeft;
				posY += obj.offsetTop;
			}
			return[posX, posY, w, h];
		} else {
			return[obj.x, obj.y, w, h];
		}
	} else {
		return [0, 0, 0, 0];
	}
}

componentRPL.prototype.correctSizes = function(width, height)
{
	var maxHeight = 0;
	var optCount = this._optCount;
	
	this._lastQuestSize = -1;
	
	var questionText = document.getElementById(this.id + "_questionText");
	if (questionText)
	{
		var posArr = this.getPosition(this.id + "_questionText");
		
		if (posArr[3] < 50)
		{
			this._lastQuestSize = posArr[3];
			
			questionText.style.height = 50;
			maxHeight += 50;
		}else{
			maxHeight += posArr[3];
			this._lastQuestSize = posArr[3];
		}
	}
	
	for (var i=0; i < optCount + 1; i++)
	{
		var objId = this.id + '_tdopt' + i;
		var posArr = this.getPosition(objId);
		if (posArr[3] != 0)
		{
			if (posArr[3] < 34)
			{
				var obj = document.getElementById(objId);
				obj.style.height = 34;
				maxHeight += 34;
			}
			else
			{
				maxHeight += posArr[3];
			}
		}
	}
	
	var offsetH = 20;
	var posArr = this.getPosition(this.id + "_img");
	
	if (this._lastQuestSize != -1)
	{
		var questionText = document.getElementById(this.id + "_questionText");
		
		var arr = this.getPosition(this.id + "_questionText");
		//while (posArr[3] + maxHeight + offsetH > height && questionText.style.height > this._lastQuestSize)
		while (posArr[3] + maxHeight + offsetH > height && arr[3] > this._lastQuestSize)
		{
			arr = this.getPosition(this.id + "_questionText");
			questionText.style.height = arr[3] - 1;
			maxHeight-=1;
		}
	}
	
	var posArr = this.getPosition(this.id + "_img");
	if (posArr[3] != 0)
	{
		if (posArr[3] + maxHeight + offsetH > height)
		{
			var obj = document.getElementById(this.id + "_img");
			obj.style.height = height - maxHeight - offsetH;
		}
	}
};

componentRPL.prototype.changeRabits = function(coment)
{
	coment = coment.replace(/"/g, "&quot;");
	coment = coment.replace(/'/g, "&#146;");
	
	return coment;
};

componentRPL.prototype.randomAnswer = function(answers, randomQuestion, thisQuestion) {

    var rand = 0;
    var i = parseInt(0);
    var randomed = '';
    var listUsedAnswers = '';
    var counter = 0;
    var color = '';
	
	var img = new Image();
	img.src = this.resourcesURL + this.buttonSrc;
	var imageWidth = img.width;			
	var imageHeight = img.height;			

    do{
        rand = parseInt(Math.random()*(answers.length-3));
        if (listUsedAnswers.indexOf(rand) == -1){
            listUsedAnswers += rand;            
            var answersRow = answers[rand+2].split("&&");//0-odp, 1-com,2-points,3-goto
			
			this.answersArrRemember.push(answersRow[0]);
			
            if (answersRow[0] == '') answersRow[0] = '';
            if (answersRow[1] == '') answersRow[1] = '';  
            if (answersRow[2] == '') answersRow[2] = 0;    
          
            if (counter == 0){
               color = this.answer1Color;
               counter = 1;
            }else{
               color = this.answer2Color;
               counter = 0;
            }        
            
			if (randomQuestion == 1){
                
                //thisQuestion, points, comment, graph
				
				var changed = this.changeRabits(answersRow[1]);//zamienia zajaczki tzn " lub ' na \" lub \'
				
				var commands = thisQuestion + ',' + answersRow[2] + ',\'' + changed + '\'' + ',\'' + answers[1] + '\',' + eval(this.answersArrRemember.length-1);
				
                if (answersRow[0] != ''){
					if (this.isAnswerRollover){
						randomed += '<tr style="background: '+color+';" onMouseover="this.style.background=\''+this.answerRolloverColor+'\'" onMouseout="this.style.background=\''+color+'\'">';
					}else{
						randomed += '<tr style="background: '+color+';">';
					};
					
					randomed += '<td id="' + this.id + '_tdopt' + this._optCount + '" valign="' + this.buttonVAlign + '" height="20px">';
					if (this.buttonSrc.indexOf('.png') != -1 && is.ie && is.ie55UP && !is.ie7UP){
						randomed += '<span id="' + this.id + '_but3" src="' + this.resourcesURL + this.buttonSrc + '"';
						randomed += ' style="width:'+imageWidth+'px; height:'+imageHeight+'px; cursor: pointer;';
						randomed += ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
						randomed += '(src=\'' + this.resourcesURL + this.buttonSrc + '\', sizingMethod="scale");" onClick="owner.randomOption(' + commands + ');"></span>';
					}else {
						randomed += '<img id="' + this.id + '_but3" src="'+ this.resourcesURL + this.buttonSrc + '" style="cursor: pointer" onClick="owner.randomOption(' + commands + ');">';
					};
					randomed += '</td>';						
					
					randomed += '<td id="' + this.id + '_opt' + i.toString() + '" style="width:95%; cursor:pointer; " onClick="owner.randomOption(' + commands + ');">'+ this.AnswerFont + answersRow[0] + this.AnswerFontEnd+'</td></tr>';
                }
            }else{
                //srawdzenie czy jest to skok do pytania czy skok do grupy
                var groupId = answersRow[3];
				
                if ((groupId.indexOf("g") != -1) || (groupId.indexOf("End") != -1)){
                //jesli jest pusty lub jest skok do grupy
                    answersRow[3] = thisQuestion;
                    var group = groupId;
                }else{
                    if (answersRow[3] == '') answersRow[3] = 0; 
                    var group = '';
                }  
				
				var changed = this.changeRabits(answersRow[1]);//zamienia zajaczki tzn " lub ' na \" lub \'
				
				var commands = answersRow[3] + ',' + answersRow[2] + ',\'' + changed + '\'' + ',\'' + answers[1] + '\'' + ',\'' + group + '\',' + eval(this.answersArrRemember.length-1);
				
                if (answersRow[0] != ''){
					if (this.isAnswerRollover){
						randomed += '<tr style="background: '+color+';" onMouseover="this.style.background=\''+this.answerRolloverColor+'\'" onMouseout="this.style.background=\''+color+'\'">';
					}else{
						randomed += '<tr style="background: '+color+';">';
					};
					
					randomed += '<td id="' + this.id + '_tdopt' + this._optCount + '" valign="' + this.buttonVAlign + '" height="20px">';
					if (this.buttonSrc.indexOf('.png') != -1 && is.ie && is.ie55UP && !is.ie7UP){
						randomed += '<span id="' + this.id + '_but3" src="' + this.resourcesURL + this.buttonSrc + '"';
						randomed += ' style="width:'+imageWidth+'px; height:'+imageHeight+'; cursor: pointer;';
						randomed += ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
						randomed += '(src=\'' + this.resourcesURL + this.buttonSrc + '\', sizingMethod="scale");" onClick="owner.chosenOption(' + commands + ');"></span>';
					}else {
						randomed += '<img id="' + this.id + '_but3" src="'+ this.resourcesURL + this.buttonSrc + '" style="cursor: pointer" onClick="owner.chosenOption(' + commands + ');">';
					};
					randomed += '</td>';						
					
					randomed += '<td id="' + this.id + '_opt' + i.toString() + '" style="width:95%; cursor: pointer;" onClick="owner.chosenOption(' + commands + ');">'+ this.AnswerFont + answersRow[0] + this.AnswerFontEnd+'</td></tr>';
                }
            }            
            i += 1;
        }
		this._optCount++;
    }while (i != (answers.length-3))
    
    return randomed;
}

componentRPL.prototype.chosenOption = function(optNo, points, comment, graph, group_name, answerArrID) {
	
	this.points = parseInt(this.points) + parseInt(points);
	
	if (!this.groupAnswers["answer"+points.toString()])
	{
		this.groupAnswers["answer"+points.toString()] = 0;
	}
	this.groupAnswers["answer"+points.toString()]++;
	
	if (this.panelRPLOBJ){
		this.panelRPLOBJ.showQuestionAndAnswerAtPanel(this.questionRemember, this.answersArrRemember[answerArrID])
	};
    
	if (this.displayCommentToGroup){// jak jest komentarz do grup
		this.rememberGroup(this.idDisplayedQuestion);
	}else if (this.comments == "") {
		this.comments += comment;
	} else {
		this.comments += "||" + comment;
	}

    if ((group_name != '') && (group_name != 'End')){
        var gr = this.groupList.split("!!");
        var k = -1;
        
        //znajdz grupę       
        do{
            k += parseInt(1);
        }while ((gr[k].indexOf(group_name) == -1) && (k < (gr.length-2)))
        
        
        if ((gr[k].indexOf(group_name) == -1) && (k >= (gr.length-2))){//jesli nie znalazłeś do 50 razy żadnego pytania różnego od siebie do skocz do siebie
        }else{ //jesli znalazłeś skocz do losowego pytania z tej grupy
            var id= gr[k].split("##");
            rand = parseInt(Math.random()*(id.length-1));
            optNo = id[rand+1];
        }    
    }else{
        if (group_name == 'End'){
			if (this.displayComment && comment != ''){
				this.showCommment(comment, graph, optNo, group_name);
				return;
			}
			this.checkIsSummaryDisplay();
			return;
       }
    }
    //=========================
    if (optNo == 0) optNo = 1; //do testów
    
	if (this.displayComment && comment != ''){
        this.showCommment(comment, graph, optNo, group_name);
        return;
    }
       
    this.drawSimulation(optNo); 
    return; 
};

componentRPL.prototype.replaceResultText = function() 
{
    if (this.summaryText != ''){
        var tekst = this.summaryText;
		tekst = tekst.replace("[points]", this.points);
			   
		if (this.userMaxPoints == 0) {
			var perc = parseInt((this.points*100)/this.maxPoints);
			tekst = tekst.replace("[percent]", perc);
			tekst = tekst.replace("[max_points]", this.maxPoints);
		}else{	
			var perc = parseInt((this.points*100)/this.userMaxPoints);
			tekst = tekst.replace("[percent]", perc);
			tekst = tekst.replace("[max_points]", this.userMaxPoints);
		}
    }
	
	return tekst;
};

componentRPL.prototype.executeScript = function() 
{
	if (!this.runScript) return;
	
	if (this.displayCommentToGroup){
		if (this.userMaxPoints != 0){
			if (this.points == this.userMaxPoints){
				eval(this.script);
			}
		}
	}else{
		if (this.points == this.maxPoints){
			eval(this.script);
		}
	}
	
	if (!this.displayCommentToGroup && this.comments == '') eval(this.script);
	
	return;
};

componentRPL.prototype.deleteInfo = function() 
{
	this.points = 0;
	this.maxPoints = 0;
	this.comments = ""; //komentarz do odpowiedzi
	this.numberOfQuestion = 0; //licznik ile pytan zadano
	this.questionList = ''; //lista kolejnych pyta np. 1,4,5,6 
	this.lastQuestion = 0;
	this.listQuestionsId = '';
	this.groupList = '';  
	this.listOfUsedGroup = '';  
	this.askedQuestions = 0;
	this.QuestionFont = '';
	this.AnswerFont = '';
	this.defaultContent = "";
	this.idDisplayedQuestion = 0;
  
	if (this.panelRPLOBJ){
		this.panelRPLOBJ.deleteAllRows();
	};  
}

componentRPL.prototype.refreshElement = function() {
	this.deleteInfo();
}

componentRPL.prototype.setTryAgain = function() 
{	
	this.deleteInfo();
	this.onPaint();
};

componentRPL.prototype.getCompareText = function() 
{
	var rplPageGix = this.rplComparePageName.split(":")[0];
	
	var lastResult = lms.getCourseData('page_'+rplPageGix+'_rpl');
	var lastPoints = 0;
	
	if (lastResult) lastPoints = parseInt(lastResult.split("::")[0]);
	
	var actualPoints = this.points;
	
	var text = "";
	
	if (actualPoints > lastPoints) text = this.symBetter;
	else if (actualPoints < lastPoints) text = this.symWorse;
	else if (actualPoints == lastPoints) text = this.symSame;
	
	text = text.replace('[actual]', actualPoints);
	text = text.replace('[last]', lastPoints);
	
	return text;
}

componentRPL.prototype.onlyPointsSummary = function() {
	var t = '';
	t += '<table dir="'+this.dir+'" border="0" style="width:100%; height:100%">';
	t += '<tr><td align="center" style="vertical-align: bottom">';
	
	var color = this.answer1Color;
	//var color = this.answer2Color;
	if (this.allowResetSimulation()) {	
		t += this.getResetButtonTable(color);
	}else{
		t += this.getPointsText(color);		
	}	
	t += '</td></tr></table>';
	
	this.hideAllClouds();
	this.setHTML(t);
	this.points = 0;
	return;
}

componentRPL.prototype.drawCompareSummary = function() {
	var width = this.w - 2*this.borderWidth - 2;
	var height = this.h - 2*this.borderWidth - 2; 
	height -= 45;

	var t = '';
	t += '<div style="position: relative; width:' + width + 'px; height:' + (height - (this.fontSizeQ*10)) + 'px; overflow: auto;">';
	t += '<table dir="'+this.dir+'" border="0" style="width:100%;">';
	t += "<tr><td valign='middle' align='center' background-color='transparent'>";
	t += this.getCompareText();
	t += "</td></tr>";
	if (this.allowResetSimulation()) {	
		t += this.getResetButtonTable("", "transparent");
	}		
	t += "</table></div>";
	
	this.hideAllClouds();
	this.setHTML(t);
	this.points = 0;
};

componentRPL.prototype.drawSummaryGroup = function() {
	var splited = this.listOfUsedGroup.split("##");
    var counter = 0;
	var k = -1;

	var width = this.w - 2*this.borderWidth - 2;
	var height = this.h - 2*this.borderWidth - 2; 
	height -= 45;
	var com = '';
	
	this.executeScript();
	
	var t = '<table dir="'+this.dir+'" border="0" style="width:100%;">';
	t += "<tr><td colspan='2' align='center' height='20px'>"+ this.QuestionFont + this.summaryTextUp + this.QuestionFontEnd + "</td></tr>";
	t += '</table>';
	//t += '<div style="width:' + width + 'px; height:' + height + 'px; overflow: scroll;">';
	t += '<div style="position: relative; width:' + width + 'px; height:' + (height - (this.fontSizeQ*10)) + 'px; overflow: auto;">';
	t += '<table dir="'+this.dir+'" border="0" style="width:100%;">';
	
	var printedGroup = '';
	var color = this.answer1Color;
	
	if (this.groupComment != ''){
		for(var i=0; i < splited.length-1; i++){
			if (counter == 0){
			   color = this.answer1Color;
			   counter = 1;
			}else{
			   color = this.answer2Color;
			   counter = 0;
			}
			
			k = -1;
			
			var temp = this.groupComment.split('&&');
			do{
				k++;
				var a = temp[k].split('||');
			}while (splited[i] != a[0])
			
			if (printedGroup.indexOf(splited[i]) == -1) {
				printedGroup += splited[i] + '##';
				
				if (splited[i] != '') {
					t += "<tr><td valign='top' align='center' height='20px' bgcolor='"+color+"'>";
					t += this.AnswerFont+splited[i]+this.AnswerFontEnd;
					t += "</td><td style='width:80%' bgcolor='"+color+"'>";
					t += this.AnswerFont+ a[1] +this.AnswerFontEnd+"</td></tr>";
				}
			}
		}  
    }  
    //t += "<tr><td style='width:95%' colspan='2' align='right' height='20px' bgcolor='"+color+"'>"+ QuestionFont + tekst +"</font></td></tr>";
    
    t += "<tr><td colspan='2'></td></tr>";
	t += '</table>';
	t += '</div>';

	if (this.allowResetSimulation()) {	
		t += this.getResetButtonTable(color);
	}else{
		t += this.getPointsText(color);		
	}	
	
	this.hideAllClouds();
	this.setHTML(t);
	this.points = 0;
};

componentRPL.prototype.drawSummary = function() {
    
	var splited = this.comments.split("||");
    var counter = 0;
	
	var width = this.w - 2*this.borderWidth - 2;
	var height = this.h - 2*this.borderWidth - 2; 
	height -= 45;
	var com = '';
	
	var t = '<table dir="'+this.dir+'" border="0" style="width:100%;">';
	t += "<tr><td colspan='0' align='center' height='20px'>";
	t += this.QuestionFont + this.summaryTextUp + this.QuestionFontEnd +"</td></tr>";
	t += '</table>';
	t += '<div style="position: relative; width:' + width + 'px; height:' + (height - (this.fontSizeQ*10)) + 'px; overflow: auto;">';
	t += '<table dir="'+this.dir+'" border="0" style="width:100%;">';
	//t += "<tr><td colspan='2' align='center' height='20px'>"+ QuestionFont + this.summaryTextUp+"</font></td></tr>";
	
	var color = this.answer1Color;
	var number = 1;
	
    for(var i=0; i < splited.length; i++){
        if (counter == 0){
           color = this.answer1Color;
           counter = 1;
        }else{
           color = this.answer2Color;
           counter = 0;
        }
        if (splited[i] != '') {
			t += "<tr><td valign='top' align='center' height='20px' bgcolor='"+color+"'>";
			t += this.AnswerFont+(number)+this.AnswerFontEnd+"</td><td style='width:95%' bgcolor='"+color+"'>";
			t += this.AnswerFont+splited[i]+this.AnswerFontEnd+"</td></tr>";
			number++;
		}
    }  

    t += "<tr><td colspan='2'></td></tr>";
	t += '</table>';
	t += '</div>';
	
	if (this.allowResetSimulation()) {	
		t += this.getResetButtonTable(color);
	}else{
		t += this.getPointsText(color);		
	}	
	
	this.hideAllClouds();
	this.setHTML(t);
	this.points = 0;
	return;
}

componentRPL.prototype.getPointsTextCell = function(color) 
{
	var tekst = this.replaceResultText();
	var t = '';
	t += '<td align="right" bgcolor="'+color+'">'+ this.QuestionFont + tekst + this.QuestionFontEnd + '</td>';
	return t;
}

componentRPL.prototype.getPointsText = function(color) 
{
	var t = "";
	t += '<table dir="'+this.dir+'" cellspacing="0" border="0" style="width:100%;"><tr>';
	t += this.getPointsTextCell(color);
	t += '</tr></table>';
	return t;
}

componentRPL.prototype.getResetButtonTable = function(color) 
{
	var t = "";
	t += '<table dir="'+this.dir+'" cellspacing="0" border="0" style="width:100%;">';
	t += '<tr><td valign="middle" bgcolor="'+color+'">';
	t += this.QuestionFont + this.resetText + this.QuestionFontEnd;
	t += '</td><td bgcolor="'+color+'">';
	t += '<img id="' + this.id + '_reset" src="'+ this.resourcesURL + this.buttonReset;
	t += '"  style="cursor: hand" onClick="pc.'+this.id+'.setTryAgain();"></td>';
	t += this.getPointsTextCell(color);
	t += '</tr></table>';
	return t;	
}

componentRPL.prototype.getSimulationResult = function() 
{
	var perc = 0;
	if (this.userMaxPoints == 0) {
		var perc = parseInt((this.points*100)/this.maxPoints);
	}else{	
		var perc = parseInt((this.points*100)/this.userMaxPoints);
	}
	return perc;
}

componentRPL.prototype.drawResetButton = function() {
	var color = this.answer1Color;
	var width = this.w - 2*this.borderWidth - 2;
	var height = this.h - 2*this.borderWidth - 2; 	

	var t = '';	
	t += '<table dir="'+this.dir+'" cellspacing="0" border="0" style="width:'+width+'">';
	t += this.getResetButtonTable("", color);
	t += '</table>';
	
	this.setHTML(t);
};

componentRPL.prototype.invokeEvents = function() {	

	//if (this.allowResetSimulation()) return;
	
	//this.invokeEvent('Completed'); //pg2
	
	var resultInPerc = this.getSimulationResult();	
	if ((resultInPerc >= this.range1Open) && (resultInPerc < this.range1Close)){
		this.invokeEvent('RPL1stRange');
	}else if ((resultInPerc >= this.range2Open) && (resultInPerc <= this.range2Close)){
		this.invokeEvent('RPL2ndRange');
	}else this.executeScript();    
}

componentRPL.prototype.allowResetSimulation = function(){
	return (this.resetSimulation && !this.checkAnswer() && PageInterface.GetValue("tryLeft") != 0);
}

componentRPL.prototype.storeResult = function(){
	if (this.rememberResult) 
	{
		var thisPageGix = PageInterface.GetValue('pageGix');
		var storeStr = this.points+"::"+((this.userMaxPoints == 0)?this.maxPoints:this.userMaxPoints);
		
		lms.setCourseData('page_'+thisPageGix+'_rpl', storeStr);
	}
}
componentRPL.prototype.setEndSimulationInProgress = function() {	
	if (this.panelRPLOBJ){
		this.panelRPLOBJ.setEndProgressbar();
	};		
}
componentRPL.prototype.checkIsSummaryDisplay = function() {	
	var visible = this.visible;
	
	if (this.checkExercise){
		this.lastQuestion = 1;
		PageInterface.Execute("checkAnswer", this);
    };
	this.storeResult(); //pg2-bo przechodzil q... do nastepnej strony przed zapisaniem wynikow
	this.invokeEvents();	
	//this.storeResult();
	
	if (this.compareSummary) { //pg2- "if" rearange
		this.drawCompareSummary();
	} else {
		if (this.dontDisplaySummary){//NIE pokazuj podsumowania
			this.onlyPointsSummary();
		} else
		if (this.displaySummary){//pokaz podsumowanie
			this.drawSummary();
			this.setEndSimulationInProgress();
		} else
		if (this.displayCommentToGroup){//pokaz podsumowanie dla grup
			this.drawSummaryGroup();
			this.setEndSimulationInProgress();
		} else
		if (visible) {//pokaz scenke
			this.show();
			this.audioStop();
		}
	}
	this.invokeEvent('Completed'); //pg2-przeniesione
};

componentRPL.prototype.randomOption = function(thisQuestion, points, comment, graph, answerArrID) {
    //goTo, Points, Comment
    
    this.listQuestionsId = this.listQuestionsId.replace(thisQuestion+'!!',"");
    var avaiableQuestions = this.listQuestionsId.split("!!");    
    var aQLenght = parseInt(avaiableQuestions.length-1);
    var nextQuestion = 0;
    var index = -1;
	
    this.points = parseInt(this.points) + parseInt(points);
	
	if (!this.groupAnswers["answer"+points.toString()])
	{
		this.groupAnswers["answer"+points.toString()] = 0;
	}
	this.groupAnswers["answer"+points.toString()]++;
	
	if (this.comments == "") this.comments += comment;
        else this.comments += "||" + comment;   
    
    rand = parseInt(Math.random()*(avaiableQuestions.length-1));//0 - (ilosc pytan -1)
    nextQuestion = avaiableQuestions[rand];      
	
	if (this.panelRPLOBJ){
		this.panelRPLOBJ.showQuestionAndAnswerAtPanel(this.questionRemember, this.answersArrRemember[answerArrID])
	};
    
    if (this.listQuestionsId == ''){    
		if (this.displayComment && comment != '') {
            this.showCommment(comment, graph, nextQuestion, 'Not_blank');
            return;
        }
		this.checkIsSummaryDisplay();
        return;
    }
    
    if(this.askedQuestions == this.numberOfAskedQuestons){
        this.lastQuestion = 1;
		if (this.displayComment && comment != '') {
            this.showCommment(comment, graph, nextQuestion, 'Not_blank');
            return;
        }
		this.checkIsSummaryDisplay();
        return;
    }

    
    //=========================    
    if (this.displayComment && comment != '') {
        this.showCommment(comment, graph, nextQuestion, '');
        return;
    }      
    
    this.drawSimulation(nextQuestion);  
}

componentRPL.prototype.nextQuest = function(q) {

    if (q != 0){
        this.drawSimulation(q);  
    }else{
		this.checkIsSummaryDisplay();
        return;
    };
}

componentRPL.prototype.showCommment = function(answerComment, picture, question, gr_name) {

	var width = this.w - 2*this.borderWidth - 2;
	var height = this.h - 2*this.borderWidth - 2; 


	var t = '<table dir="'+this.dir+'" border="0" style="width:' + width + 'px; height:' + height + 'px;" >';
	t += '<tr><td align="center" colspan="2" height="100px"><img id="' + this.id + '_img" src="'+ this.resourcesURL + picture + '"></td></tr>';
    
	if (gr_name == ''){
        t += '<tr><td width="10%" height="100px"><img id="' + this.id + '_but3" src="'+ this.resourcesURL + this.buttonOkSrc + '" style="cursor: hand" onClick="owner.nextQuest(' + question + ');"></td><td bgcolor='+this.answer1Color+'>' + this.AnswerFont + answerComment + this.AnswerFontEnd + '</td></tr>'; 
    }else{
        t += '<tr><td width="10%" height="100px"><img id="' + this.id + '_but3" src="'+ this.resourcesURL + this.buttonOkSrc + '" style="cursor: hand" onClick="owner.nextQuest(0);"></td><td bgcolor='+this.answer1Color+'>' + this.AnswerFont + answerComment + this.AnswerFontEnd + '</td></tr>';
	}
    
    t += '<tr><td></td></tr>';
    t += '</table>';

	this.setHTML(t);
}

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

componentRPL.prototype.parseCheckAnswer = function() 
{
	var max = 0;
	if (this.userMaxPoints == 0){
		max = this.maxPoints;
	}else{
		max = this.maxPoints;
	};
	if (((this.points / max) *100) >= this.correctAnswer) { //pg2- ">=" instead of ">"
		return true;
	}else{
		return false;
	};
};

componentRPL.prototype.getAnswer = function() 
{
	if (this.parseCheckAnswer()){
		return this.correctAnswer;
	}else {
		var max = 0;
		if (this.userMaxPoints == 0){
			max = this.maxPoints;
		}else{
			max = this.userMaxPoints;
		};
 		var usAnswer = ((this.points / max) *100);
		this.usrAns = parseInt(usAnswer);
		return this.usrAns;
	}
}

componentRPL.prototype.setAnswer = function(valStr, showCorrect) 
{
	if (showCorrect == null || showCorrect == "undefined") showCorrect = true;
	
	if (showCorrect){
		this.usrAns = 100;
	}else{
		this.usrAns = valStr;
	}
};

componentRPL.prototype.makeArrOfClouds = function() 
{
	for(var i=0; i < page.children.length; i++){
		var obj = page.children[i];
		if (obj.type == 'componentDialogue'){
			if (!this.cloudsArr[obj.step]) this.cloudsArr[obj.step] = new Array();
			
			this.cloudsArr[obj.step][0] = obj.name;
			this.cloudsArr[obj.step][1] = obj;
		};
	};
};

/********************************************************************/

componentRPL.prototype.interactionsCorrectResponsesCount = function()
{
	var answerCount = 1;
	return answerCount;
};

componentRPL.prototype.interactionsCorrectResponses = function()
{
	//return this.correctAnswersList; //pg2-removed
	return this.correctAnswer; //pg2
};

componentRPL.prototype.interactionsStudentResponse = function()
{
	if (PageInterface.GetValue("isExam")){
		return "rpl:"+this.getAnswer();	
	}else{
		return this.getAnswer();
	};
};

componentRPL.prototype.interactionsCorrectResponsesAsText = function()
{
	//return this.correctAnswersList; //pg2-removed
	return escape(this.correctAnswer); //pg2
};

componentRPL.prototype.interactionsStudentResponseAsText = function()
{
	return escape(this.getAnswer()); //pg2-escape
};

