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

componentPollOpenAnswer = function(name) {
	this.__componentText = __componentText;
	this.__componentText(name);

	this.waitingTryCount = 0;

	this.resourcesStatus = "online";
	this.resourcesURL = "";

	this.interactions 		= true;
	this.interactionsType 	= "fill-in"; 
};

componentPollOpenAnswer.prototype = new __componentText;
componentPollOpenAnswer.prototype.type = "componentPollOpenAnswer";

componentPollOpenAnswer.prototype.onCreate = function(obj)
{
	this.captureMouseEvents();
	if (lms && this.disableOnlineOfflineMix != false ) {
		this.resourcesStatus = lms.resourcesStatus();
		this.resourcesURL = lms.resourcesURL();
	} else this.resourcesURL = resourcesURL;
	
	this.pollQuestion = this.initDynamicContent(this.pollQuestion);
	this.choiceValues = this.initDynamicContent(this.choiceValues);
	
	if (this.execution) {
		this.contentObj = this.findContentObj();
		if (this.contentObj) {
			this.contentObj.innerHTML = this.initText(this.contentObj.innerHTML);
			this.reinit();
		}
	}
};

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

componentPollOpenAnswer.prototype.getAnswer = function() 
{
	var form = document.getElementById( "polls_radio_tab_" + this.id );
	var i, obj;
	var valStr= "";
	obj = document.getElementById(this.id + "_openQuestion");
	if(obj.value!="") valStr += obj.value;
	return(valStr);
};

componentPollOpenAnswer.prototype.setAnswer = function(valStr) 
{
	var obj = document.getElementById(this.id+"_openQuestion");
	if (obj){
		obj.value = valStr;
	};
};

componentPollOpenAnswer.prototype.parseCheckAnswer = function(obj) {
  if (!obj) return false;
  return true;
};

componentPollOpenAnswer.prototype.onLock = function() {
	var obj;
	obj = document.getElementById(this.id+"_openQuestion");
	if (obj) obj.disabled = true;
	return(true);
};

componentPollOpenAnswer.prototype.onUnLock = function() {
  return(true); 
};

componentPollOpenAnswer.prototype.onPaint = function(obj)
{
	if (!this.execution){
		var width = this.w - this.borderWidth*2;
		var t = '';
		t += '<span style="color:' + this.fontColor + '; font-family:' + this.fontFamily + '; font-size:' + this.fontSize + ';">' + this.pollQuestion + '</span>';	
		
		if (this.readOnly){
			var readOnly = 'readonly';
		}else{
			var readOnly = '';
		};
		
		if (this.showDefaultValue){
			var defaultValue = this.choiceValues;
		}else{
			var defaultValue = '';
		};		
		
		t += '<input id="' + this.id + '_openQuestion" style="width:'+this.inputWidth+'px;" value="'+defaultValue+'">';
		this.setHTML(t);
	}else{		
		var input = document.getElementById(this.id + "_openQuestion");
		if(input){
			if (this.showDefaultValue){
				input.value = this.choiceValues;
			}
			if (this.readOnly){
				input.readOnly = true;
			};			
		};
	};
};

componentPollOpenAnswer.prototype.baseUnselectable = componentPollOpenAnswer.prototype.unselectable;
componentPollOpenAnswer.prototype.unselectable = function() 
{
	this.baseUnselectable();
	var input = document.getElementById(this.id + "_openQuestion");
	if (input){
		input.unselectable = "";
	};
};

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

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

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

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

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