var ConsultationPrototype = Class.create();

ConsultationPrototype.prototype = {
	initialize: function() {
	},
	showAnswer: function(question, categoryId)
	{
		var argsObj = new Object();
		argsObj["operation"]  = "showAnswer";
		argsObj["questionId"] = question;
		argsObj["categoryId"] = categoryId;
		makeCall('Consultation/showConsultation', argsObj);
	},
	hideQuestion: function(question)
	{
		$('questionText_' + question).style.display = "none";
		$('questionDiv_' + question).style.display = "block";
	},
	showQuestion: function(question)
	{
		View.getInstance('question_' + question).innerHTML = '';
		$('questionText_' + question).style.display = "block";
		$('questionDiv_' + question).style.display = "none";
	},
	addQuestion: function(rubricId, categoryId)
	{
		var error = false;
		var bottomsArr = new Array('questionSave');
		Xms.lockUnLockBottons(bottomsArr,'lock');
		var err = new Array ('empty', 'tooLong');
		var elementsArr = new Array ('theme', 'questionText');
		
		Xms.clearErrors(elementsArr, null);
		var themeObj		= $('theme');
		var questionTextObj = $('questionText');
		
		var theme		= themeObj.getValue();
		var questionText = questionTextObj.getValue();
		
		Xms.clearErrors(null, err);
		if(questionText == '') {
			error = Xms.showErrors(themeObj,'empty');
		} else if(questionText.length > 2000) {
			error = Xms.showErrors(questionTextObj,'tooLong');
			questionTextObj.setValue(questionText.substr(0, 2000));
		}
		
		if(!error) {
			var argsObj = new Object();
			argsObj["operation"]	= "saveQuestion";
			argsObj["themeId"]	  = theme;
			argsObj["questionText"] = Filter.encodeURIComponent(questionText);
			argsObj["rubricId"]	 = rubricId;
			argsObj["categoryId"]   = categoryId;
			argsObj["link"]		 = this.link;
			makeCall('Consultation/showConsultation', argsObj);
		} else {
			Xms.lockUnLockBottons(bottomsArr,'unlock');
		}
	},
	initLink: function(link)
	{
		this.link = link;
	},
	showAddAnswerForm: function(questionId)
	{
		var argsObj = new Object();
		argsObj["operation"]  = "showAddAnswerForm";
		argsObj["questionId"] = questionId;
		makeCall('Consultation/showConsultation', argsObj);
	},
	hideFormAnswer: function(questionId)
	{
		View.getInstance('question_' + question).innerHTML = '';
		$('questionText_' + question).style.display = "block";
		$('questionDiv_' + question).style.display = "none";
	},
	addAnswer: function(questionId)
	{
		var error = false;
		var bottomsArr = new Array('answerSave_' + questionId, 'answerCancel_' + questionId);
		Xms.lockUnLockBottons(bottomsArr,'lock');
		var err = new Array ('empty_' + questionId, 'tooLong_' + questionId);
		var elementsArr = new Array ('answerText_' + questionId);
		
		Xms.clearErrors(elementsArr, null);
		var answerTextObj = $('answerText_' + questionId);
		
		var answerText = answerTextObj.getValue();
		
		Xms.clearErrors(null, err);
		if(answerText == '') {
			error = Xms.showErrors(answerTextObj,'empty_' + questionId);
		} else if(answerText.length > 2000) {
			error = Xms.showErrors(answerTextObj,'tooLong_' + questionId);
			answerTextObj.setValue(answerText.substr(0, 2000));
		}

		if(!error) {
			var argsObj = new Object();
			argsObj["operation"]	= "saveAnswer";
			argsObj["questionId"]   = questionId;
			argsObj["answerText"]   = Filter.encodeURIComponent(answerText);
			makeCall('Consultation/showConsultation', argsObj);
		} else {
			Xms.lockUnLockBottons(bottomsArr,'unlock');
		}
	},
	editAnswer: function(questionId)
	{
		var argsObj = new Object();
		argsObj["operation"]  = "showEditAnswerForm";
		argsObj["questionId"] = questionId;
		makeCall('Consultation/showConsultation', argsObj);
	}
}

var Consultation = new ConsultationPrototype();