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

componentPolls_radioVert = function(name) {
	this.componentPollSingleAnswer = componentPollSingleAnswer;
	this.componentPollSingleAnswer(name);

	this.waitingTryCount = 0;

	this.resourcesStatus = "online";
	this.resourcesURL = "";
	
	this.dotChecked = -1;

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

	this.isLocked = false;
	this.radiosLen = 0;
};

componentPolls_radioVert.prototype = new componentPollSingleAnswer;
componentPolls_radioVert.prototype.type = "componentPolls_radioVert";

componentPolls_radioVert.prototype.onCreate = function(obj) 
{
	this.captureMouseEvents();
	
	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.imagesNameArr = [	this.imgChecked, this.imgNotChecked ];
	this.getPreloadImagesArr();
	
	this.pollQuestion = this.initDynamicContent(this.pollQuestion);
	this.choiceValues = this.initDynamicContent(this.choiceValues);
	this.inputTitle = this.initDynamicContent(this.inputTitle);		
	
	var dotsTable = document.getElementById(this.id + "_Dots");
	var dotsDIV = document.getElementById(this.id + "_dotsDIV");
	var textDIV = document.getElementById(this.id + "_pollQuestionDIV");
	var sizeDIV = document.getElementById(this.id + "_sizeDIV");
	
	var row = dotsTable.insertRow(dotsTable.rows.length);
	if (this.useUserCaptions) {
		var additionalRow = dotsTable.insertRow(dotsTable.rows.length);
	}
	var tableWidth = 0;
	var imgNCW = this.imgW;
	var imgNCH = this.imgH;
	
	var choiceValues = this.choiceValues.split('||');
	this.radiosLen = this.radiosNumber;
	if (this.useUserCaptions) {
		this.radiosLen = choiceValues.length;
	};

	for (var i=0; i < this.radiosLen; i++){
		if (i != 0){
			var cell = row.insertCell(row.cells.length);
			cell.width = this.spaceWidth;
			if (this.useUserCaptions) {
				cell = additionalRow.insertCell(additionalRow.cells.length);
				cell.width = this.spaceWidth;
			};
		};
		
		var cell = row.insertCell(row.cells.length);
		cell.style.verticalAlign = this.valign;
		//cell.style.cursor = 'pointer';
		cell.align = 'center';
		cell.innerHTML = '<img id="'+this.id+'#!#'+i+'" src="'+this.resourcesURL + this.imgNotChecked+'" />'
		cell.imgSrcID = this.id+'#!#'+i;
		cell.compName = this.id;
		cell.onclick = this.clickCell;
		if (this.useUserCaptions) {
			var cell = additionalRow.insertCell(additionalRow.cells.length);
			cell.style.verticalAlign = this.valign;
			cell.align = 'center';
			cell.innerHTML = choiceValues[i];
			sizeDIV.innerHTML = choiceValues[i];
			tableWidth += sizeDIV.offsetWidth + this.spaceWidth;
		}
		else {
			tableWidth += imgNCW + this.spaceWidth;
		}
	};
	
	if (this.notConcern){
		var cell = row.insertCell(row.cells.length);
		cell.width = this.spaceWidth;
		cell.innerHTML = '|'
		cell.style.textAlign = 'center';
		cell.style.verticalAlign = this.valign;
		if (this.useUserCaptions) {
			cell = additionalRow.insertCell(additionalRow.cells.length);
			cell.width = this.spaceWidth;
			cell.innerHTML = '';
		}
	
		cell = row.insertCell(row.cells.length);
		cell.style.verticalAlign = this.valign;
		cell.style.cursor = 'pointer';
		cell.align = 'center';
		cell.innerHTML = '<img id="'+this.id+'#!#'+i+'" src="'+this.resourcesURL + this.imgNotChecked+'" />'
		cell.imgSrcID = this.id+'#!#'+i;
		cell.compName = this.id;
		cell.onclick = this.clickCellNotConcern;
		
		if (this.useUserCaptions) {
			cell = additionalRow.insertCell(additionalRow.cells.length);
			cell.style.verticalAlign = this.valign;
			cell.align = 'center';
			cell.innerHTML = this.notConcernText;
			tableWidth += sizeDIV.offsetWidth + this.spaceWidth;
		}else{
			tableWidth += imgNCW + this.spaceWidth;			
		}
	};
	
	this.dotChecked = -1;
	
	dotsTable.style.width = tableWidth;
	if (this.dir == "rtl") {
		textDIV.style.left = tableWidth;
	} else {
		dotsDIV.style.left = this.w - tableWidth - this.borderWidth * 2;
	}
	dotsDIV.style.width = this.w - tableWidth;
	dotsDIV.style.clip = 'rect(0px ' + tableWidth + 'px ' + this.h + 'px 0px)';
	textDIV.style.width = this.w - tableWidth;
	textDIV.style.height = this.h;
	textDIV.style.clip = 'rect(0px '+eval(this.w - tableWidth)+'px '+this.h+'px 0px)';
	
	textDIV.dir = this.dir;
	
	if (this.execution) {
		this.contentObj = this.findContentObj();
		if (this.contentObj) {
			this.contentObj.innerHTML = this.initText(this.contentObj.innerHTML);
			this.reinit();
		}
	}
};

componentPolls_radioVert.prototype.onPaint = function(obj)
{
	return;
}

componentPolls_radioVert.prototype.clickCellNotConcern = function(obj)
{
	var compObj = eval('pc.'+this.compName);
	if (compObj.isLocked) return;

	var imgDot = document.getElementById(this.imgSrcID);

	compObj.cleanOtherFields();

	imgDot.src = compObj.resourcesURL + compObj.imgChecked
	
	compObj.dotChecked = 0;
}

componentPolls_radioVert.prototype.clickCell = function(obj)
{
	var compObj = eval('pc.'+this.compName);
	if (compObj.isLocked) return;
	
	var imgDot = document.getElementById(this.imgSrcID);
	
	compObj.cleanOtherFields();
	
	imgDot.src = compObj.resourcesURL + compObj.imgChecked
	
	var arrID = this.imgSrcID.split('#!#');
	
	compObj.dotChecked = parseInt(arrID[1]) + 1;
};

componentPolls_radioVert.prototype.cleanOtherFields = function(obj)
{
	var rLen = this.radiosLen;
	if (this.notConcern){
		rLen += 1;
	};
	for (var i=0; i < rLen; i++){
		var imgDot = document.getElementById(this.id+"#!#"+i);
		imgDot.src = this.resourcesURL + this.imgNotChecked;
	};
};

componentPolls_radioVert.prototype.getAnswer = function() 
{
	if (this.dotChecked == -1) return "";
	var ansVal = this.choiceValues.split('||');
	
	if (this.useUserCaptions) {
		if (this.dotChecked == 0) return this.notConcernText;
		return ansVal[this.dotChecked-1].toString();
	}else{
		return this.dotChecked.toString();
	}
};

componentPolls_radioVert.prototype.setAnswer = function(valInt) 
{
	if (typeof(valInt) == 'undefined' || valInt == '')return;

	var rLen = this.radiosLen;
	if (this.notConcern){
		rLen += 1;
	};	
	
	for (var i=0; i < rLen; i++){
		var imgDot = document.getElementById(this.id+"#!#"+i);
		if ((i + 1) == valInt ) {
			imgDot.src = this.resourcesURL + this.imgChecked;
			this.dotChecked = valInt;
		}else {
			imgDot.src = this.resourcesURL + this.imgNotChecked;
		};
	};
};

componentPolls_radioVert.prototype.onLock = function() 
{
	this.isLocked = true;
};

componentPolls_radioVert.prototype.onUnLock = function() 
{
	this.isLocked = false;
};

componentPolls_radioVert.prototype.interactionsCorrectResponses = function()
{
	return "";
};

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

componentPolls_radioVert.prototype.interactionsCorrectResponsesAsText = function()
{
	return "";
};

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

componentPolls_radioVert.prototype.interactionsCorrectResponsesCount = function()
{
	return 1;
};
